diff --git a/src/models/batch.js b/src/models/batch.js deleted file mode 100644 index 8b5534e90..000000000 --- a/src/models/batch.js +++ /dev/null @@ -1,17 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://docs.easypost.com/docs/batches Batch} represents a collection of {@link Shipment shipments} that can be processed together. - * @public - * @extends EasyPostObject - */ -export default class Batch extends EasyPostObject { - static label_url; - static num_shipments; - static pickup; - static reference; - static scan_form; - static shipments; - static state; - static status; -} diff --git a/src/models/batch.ts b/src/models/batch.ts new file mode 100644 index 000000000..7888b9ea6 --- /dev/null +++ b/src/models/batch.ts @@ -0,0 +1,17 @@ +import EasyPostObject from './easypost_object'; + +/** + * A {@link https://docs.easypost.com/docs/batches Batch} represents a collection of {@link Shipment shipments} that can be processed together. + * @public + * @extends EasyPostObject + */ +export default class Batch extends EasyPostObject { + declare label_url?: string | null; + declare num_shipments?: number | null; + declare pickup?: Record | null; + declare reference?: string | null; + declare scan_form?: Record | null; + declare shipments?: Record[] | null; + declare state?: string | null; + declare status?: Record | null; +} diff --git a/src/models/order.js b/src/models/order.js deleted file mode 100644 index 476583001..000000000 --- a/src/models/order.js +++ /dev/null @@ -1,33 +0,0 @@ -import Constants from '../constants'; -import EasyPostObject from './easypost_object'; - -/** - * An {@link https://docs.easypost.com/docs/orders Order} represents a collection of packages, intended only for multi-parcel shipments. - * @public - * @extends EasyPostObject - */ -export default class Order extends EasyPostObject { - static buyer_address; - static from_address; - static is_return; - static messages; - static rates; - static reference; - static return_address; - static shipments; - static to_address; - - /** - * Get the lowest rate for this {@link Order}. - * @public - * @param {string[]} [carriers] - List of allowed carriers to filter by - * @param {string[]} [services] - List of allowed services to filter by - * @returns {Rate} - The lowest rate - * @throws {FilteringError} - If no applicable rates are found - */ - lowestRate(carriers, services) { - const rates = this.rates || []; - - return Constants.Utils.getLowestRate(rates, carriers, services); - } -} diff --git a/src/models/order.ts b/src/models/order.ts new file mode 100644 index 000000000..57767bc37 --- /dev/null +++ b/src/models/order.ts @@ -0,0 +1,38 @@ +import Constants from '../constants'; +import EasyPostObject from './easypost_object'; + +/** + * An {@link https://docs.easypost.com/docs/orders Order} represents a collection of packages, intended only for multi-parcel shipments. + * @public + * @extends EasyPostObject + */ +export default class Order extends EasyPostObject { + declare buyer_address?: Record | null; + declare from_address?: Record | null; + declare is_return?: boolean | null; + declare messages?: Record[] | null; + declare rates?: Parameters[0] | null; + declare reference?: string | null; + declare return_address?: Record | null; + declare shipments?: Record[] | null; + declare to_address?: Record | null; + + /** + * Get the lowest rate for this {@link Order}. + * @public + * @param {string[]} [carriers] - List of allowed carriers to filter by + * @param {string[]} [services] - List of allowed services to filter by + * @returns {Rate} - The lowest rate + * @throws {FilteringError} - If no applicable rates are found + */ + lowestRate( + carriers?: string[], + services?: string[], + ): ReturnType { + const rates = ((this as Order & { rates?: unknown[] }).rates || []) as Parameters< + typeof Constants.Utils.getLowestRate + >[0]; + + return Constants.Utils.getLowestRate(rates, carriers, services); + } +} diff --git a/src/models/pickup.js b/src/models/pickup.js deleted file mode 100644 index c5087a17c..000000000 --- a/src/models/pickup.js +++ /dev/null @@ -1,36 +0,0 @@ -import Constants from '../constants'; -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://docs.easypost.com/docs/pickups Pickup} represents a scheduled carrier pickup of packages from an {@link https://docs.easypost.com/docs/addresses Address}. - * @public - * @extends EasyPostObject - */ -export default class Pickup extends EasyPostObject { - static address; - static carrier_accounts; - static confirmation; - static instructions; - static is_account_address; - static max_datetime; - static messages; - static min_datetime; - static pickup_rates; - static reference; - static shipment; - static status; - - /** - * Get the lowest rate for this {@link Pickup}. - * @public - * @param {string[]} [carriers] - List of allowed carriers to filter by - * @param {string[]} [services] - List of allowed services to filter by - * @returns {Rate} - The lowest rate - * @throws {FilteringError} - If no applicable rates are found - */ - lowestRate(carriers, services) { - const rates = this.pickup_rates || []; - - return Constants.Utils.getLowestRate(rates, carriers, services); - } -} diff --git a/src/models/pickup.ts b/src/models/pickup.ts new file mode 100644 index 000000000..f1e46b70b --- /dev/null +++ b/src/models/pickup.ts @@ -0,0 +1,40 @@ +import Constants from '../constants'; +import EasyPostObject from './easypost_object'; + +/** + * A {@link https://docs.easypost.com/docs/pickups Pickup} represents a scheduled carrier pickup of packages from an {@link https://docs.easypost.com/docs/addresses Address}. + * @public + * @extends EasyPostObject + */ +export default class Pickup extends EasyPostObject { + declare address?: Record | null; + declare carrier_accounts?: Record[] | null; + declare confirmation?: string | null; + declare instructions?: string | null; + declare is_account_address?: boolean | null; + declare max_datetime?: string | null; + declare messages?: Record[] | null; + declare min_datetime?: string | null; + declare pickup_rates?: Parameters[0] | null; + declare reference?: string | null; + declare shipment?: Record | null; + declare status?: 'unknown' | 'scheduled' | 'canceled' | null; + + /** + * Get the lowest rate for this {@link Pickup}. + * @public + * @param {string[]} [carriers] - List of allowed carriers to filter by + * @param {string[]} [services] - List of allowed services to filter by + * @returns {Rate} - The lowest rate + * @throws {FilteringError} - If no applicable rates are found + */ + lowestRate( + carriers?: string[], + services?: string[], + ): ReturnType { + const rates = ((this as Pickup & { pickup_rates?: unknown[] }).pickup_rates || + []) as Parameters[0]; + + return Constants.Utils.getLowestRate(rates, carriers, services); + } +} diff --git a/src/models/pickup_rate.js b/src/models/pickup_rate.ts similarity index 57% rename from src/models/pickup_rate.js rename to src/models/pickup_rate.ts index 4e52d5765..7e94394ff 100644 --- a/src/models/pickup_rate.js +++ b/src/models/pickup_rate.ts @@ -6,9 +6,9 @@ import EasyPostObject from './easypost_object'; * @extends EasyPostObject */ export default class PickupRate extends EasyPostObject { - static carrier; - static currency; - static pickup_id; - static rate; - static service; + declare carrier?: string | null; + declare currency?: string | null; + declare pickup_id?: string | null; + declare rate?: string | null; + declare service?: string | null; } diff --git a/src/models/rate.js b/src/models/rate.js deleted file mode 100644 index 2b757f9e4..000000000 --- a/src/models/rate.js +++ /dev/null @@ -1,24 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://docs.easypost.com/docs/shipments/rates Rate} represents pricing information for shipping a specific {@link Parcel} with a specific carrier and service level. - * @public - * @extends EasyPostObject - */ -export default class Rate extends EasyPostObject { - static billing_type; - static carrier_account_id; - static carrier; - static currency; - static delivery_date_guaranteed; - static delivery_date; - static delivery_days; - static est_delivery_days; - static list_currency; - static list_rate; - static rate; - static retail_currency; - static retail_rate; - static service; - static shipment_id; -} diff --git a/src/models/rate.ts b/src/models/rate.ts new file mode 100644 index 000000000..85707d487 --- /dev/null +++ b/src/models/rate.ts @@ -0,0 +1,24 @@ +import EasyPostObject from './easypost_object'; + +/** + * A {@link https://docs.easypost.com/docs/shipments/rates Rate} represents pricing information for shipping a specific {@link Parcel} with a specific carrier and service level. + * @public + * @extends EasyPostObject + */ +export default class Rate extends EasyPostObject { + declare billing_type?: string | null; + declare carrier_account_id?: string | null; + declare carrier?: string | null; + declare currency?: string | null; + declare delivery_date_guaranteed?: boolean | null; + declare delivery_date?: string | null; + declare delivery_days?: number | null; + declare est_delivery_days?: number | null; + declare list_currency?: string | null; + declare list_rate?: string | null; + declare rate?: string | null; + declare retail_currency?: string | null; + declare retail_rate?: string | null; + declare service?: string | null; + declare shipment_id?: string | null; +} diff --git a/src/models/refund.js b/src/models/refund.ts similarity index 52% rename from src/models/refund.js rename to src/models/refund.ts index dab7c280d..38c234f3c 100644 --- a/src/models/refund.js +++ b/src/models/refund.ts @@ -6,9 +6,9 @@ import EasyPostObject from './easypost_object'; * @extends EasyPostObject */ export default class Refund extends EasyPostObject { - static carrier; - static confirmation_number; - static shipment_id; - static status; - static tracking_code; + declare carrier?: string | null; + declare confirmation_number?: string | null; + declare shipment_id?: string | null; + declare status?: 'submitted' | 'refunded' | 'rejected' | null; + declare tracking_code?: string | null; } diff --git a/src/models/scan_form.js b/src/models/scan_form.ts similarity index 52% rename from src/models/scan_form.js rename to src/models/scan_form.ts index b4e7d4312..4c63ecd2f 100644 --- a/src/models/scan_form.js +++ b/src/models/scan_form.ts @@ -6,11 +6,11 @@ import EasyPostObject from './easypost_object'; * @extends EasyPostObject */ export default class ScanForm extends EasyPostObject { - static address; - static batch_id; - static form_file_type; - static form_url; - static message; - static status; - static tracking_codes; + declare address?: Record | null; + declare batch_id?: string | null; + declare form_file_type?: string | null; + declare form_url?: string | null; + declare message?: string | null; + declare status?: 'creating' | 'created' | 'failed' | null; + declare tracking_codes?: string[] | null; }