diff --git a/src/models/easypost_object.js b/src/models/easypost_object.js deleted file mode 100644 index deb10eb4..00000000 --- a/src/models/easypost_object.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * An EasyPostObject is the base class for all EasyPost API resources. - * @internal - * @abstract - */ -export default class EasyPostObject { - static id; - static object; - static mode; - static created_at; - static updated_at; - static _params; - - static [Symbol.hasInstance](instance) { - if (instance == null || typeof instance !== 'object') { - return false; - } - - const modelConstructor = instance[Symbol.for('easypost.modelConstructor')]; - if (typeof modelConstructor === 'function') { - return modelConstructor === this; - } - - // Fallback for plain API payloads that include object names like "Address" or "Shipment". - return typeof instance.object === 'string' && instance.object === this.name; - } -} diff --git a/src/models/easypost_object.ts b/src/models/easypost_object.ts new file mode 100644 index 00000000..46b25e60 --- /dev/null +++ b/src/models/easypost_object.ts @@ -0,0 +1,32 @@ +/** + * An EasyPostObject is the base class for all EasyPost API resources. + * @internal + * @abstract + */ +export default class EasyPostObject { + static id: string; + static object: string; + static mode: string; + static created_at: string; + static updated_at: string; + static _params: Record; + + static [Symbol.hasInstance](instance: unknown): boolean { + if (instance == null || typeof instance !== 'object') { + return false; + } + + const modelConstructor = (instance as Record)[ + Symbol.for('easypost.modelConstructor') + ]; + if (typeof modelConstructor === 'function') { + return modelConstructor === this; + } + + // Fallback for plain API payloads that include object names like "Address" or "Shipment". + return ( + typeof (instance as Record).object === 'string' && + (instance as Record).object === this.name + ); + } +} diff --git a/src/services/base_service.js b/src/services/base_service.ts similarity index 99% rename from src/services/base_service.js rename to src/services/base_service.ts index 66aced01..10cd2d82 100644 --- a/src/services/base_service.js +++ b/src/services/base_service.ts @@ -207,7 +207,7 @@ export default (easypostClient) => * @param {*} params The parameters passed when fetching the response. * @returns {*} A plain object or array suitable for JSON serialization. */ - static _convertToEasyPostObject(response, params) { + static _convertToEasyPostObject(response, params = {}) { const modelResponse = this._buildEasyPostObject(response, params); return this._toPlainEasyPostObject(modelResponse);