diff --git a/audit-ci.jsonc b/audit-ci.jsonc index 009d43352..e2c0a08d5 100644 --- a/audit-ci.jsonc +++ b/audit-ci.jsonc @@ -4,6 +4,7 @@ "critical": true, // Can't update ESLint yet because we must support Node 16 "allowlist": [ + "GHSA-2v37-7h3g-55p8", "GHSA-3ppc-4f35-3m26", "GHSA-23c5-xmqv-rm74", "GHSA-7r86-cg39-jmmj", diff --git a/src/models/address.js b/src/models/address.js deleted file mode 100644 index aff20ae41..000000000 --- a/src/models/address.js +++ /dev/null @@ -1,24 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * An {@link https://docs.easypost.com/docs/addresses Address} represents people, places, and organizations in a number of contexts. - * @public - * @extends EasyPostObject - */ -export default class Address extends EasyPostObject { - static street1; - static street2; - static city; - static state; - static zip; - static country; - static residential; - static carrier_facility; - static name; - static company; - static phone; - static email; - static federal_tax_id; - static state_tax_id; - static verifications; -} diff --git a/src/models/address.ts b/src/models/address.ts new file mode 100644 index 000000000..eee80766c --- /dev/null +++ b/src/models/address.ts @@ -0,0 +1,24 @@ +import EasyPostObject from './easypost_object'; + +/** + * An {@link https://docs.easypost.com/docs/addresses Address} represents people, places, and organizations in a number of contexts. + * @public + * @extends EasyPostObject + */ +export default class Address extends EasyPostObject { + declare street1?: string | null; + declare street2?: string | null; + declare city?: string | null; + declare state?: string | null; + declare zip?: string | null; + declare country?: string | null; + declare residential?: boolean | null; + declare carrier_facility?: string | null; + declare name?: string | null; + declare company?: string | null; + declare phone?: string | null; + declare email?: string | null; + declare federal_tax_id?: string | null; + declare state_tax_id?: string | null; + declare verifications?: Record | null; +} diff --git a/src/models/customs_info.js b/src/models/customs_info.js deleted file mode 100644 index e448a737f..000000000 --- a/src/models/customs_info.js +++ /dev/null @@ -1,19 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://docs.easypost.com/docs/customs-infos CustomsInfo} represents a collection of {@link CustomsItem CustomsItems} and associated information for generating international shipping customs forms. - * @public - * @extends EasyPostObject - */ -export default class CustomsInfo extends EasyPostObject { - static content_explanation; - static contents_type; - static customs_certify; - static customs_items; - static customs_signer; - static declaration; - static eel_pfc; - static non_delivery_option; - static restriction_comments; - static restriction_type; -} diff --git a/src/models/customs_info.ts b/src/models/customs_info.ts new file mode 100644 index 000000000..e40b06047 --- /dev/null +++ b/src/models/customs_info.ts @@ -0,0 +1,20 @@ +import EasyPostObject from './easypost_object'; + +/** + * A {@link https://docs.easypost.com/docs/customs-infos CustomsInfo} represents a collection of {@link CustomsItem CustomsItems} and associated information for generating international shipping customs forms. + * @public + * @extends EasyPostObject + */ +export default class CustomsInfo extends EasyPostObject { + declare content_explanation?: string | null; + declare contents_type?: string | null; + declare customs_certify?: boolean | null; + declare customs_items?: unknown[] | null; + declare customs_signer?: string | null; + declare declaration?: string | null; + declare eel_pfc?: string | null; + declare non_delivery_option?: 'abandon' | 'return' | null; + declare restriction_comments?: string | null; + declare restriction_type?: + 'none' | 'other' | 'quarantine' | 'sanitary_phytosanitary_inspection' | null; +} diff --git a/src/models/customs_item.js b/src/models/customs_item.js deleted file mode 100644 index ec60ac54f..000000000 --- a/src/models/customs_item.js +++ /dev/null @@ -1,17 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://docs.easypost.com/docs/customs-items CustomsItem} represents a single item being shipped internationally. - * @public - * @extends EasyPostObject - */ -export default class CustomsItem extends EasyPostObject { - static code; - static currency; - static description; - static hs_tariff_number; - static origin_country; - static quantity; - static value; - static weight; -} diff --git a/src/models/customs_item.ts b/src/models/customs_item.ts new file mode 100644 index 000000000..e2aac7b6c --- /dev/null +++ b/src/models/customs_item.ts @@ -0,0 +1,17 @@ +import EasyPostObject from './easypost_object'; + +/** + * A {@link https://docs.easypost.com/docs/customs-items CustomsItem} represents a single item being shipped internationally. + * @public + * @extends EasyPostObject + */ +export default class CustomsItem extends EasyPostObject { + declare code?: string | null; + declare currency?: string | null; + declare description?: string | null; + declare hs_tariff_number?: string | null; + declare origin_country?: string | null; + declare quantity?: number | null; + declare value?: number | null; + declare weight?: number | null; +} diff --git a/src/models/parcel.js b/src/models/parcel.ts similarity index 64% rename from src/models/parcel.js rename to src/models/parcel.ts index d8c31515a..17285fcea 100644 --- a/src/models/parcel.js +++ b/src/models/parcel.ts @@ -6,9 +6,9 @@ import EasyPostObject from './easypost_object'; * @extends EasyPostObject */ export default class Parcel extends EasyPostObject { - static height; - static length; - static predefined_package; - static weight; - static width; + declare height?: number | null; + declare length?: number | null; + declare predefined_package?: string | null; + declare weight?: number | null; + declare width?: number | null; } diff --git a/src/models/postage_label.js b/src/models/postage_label.js deleted file mode 100644 index e72a55252..000000000 --- a/src/models/postage_label.js +++ /dev/null @@ -1,18 +0,0 @@ -import EasyPostObject from './easypost_object'; - -/** - * A {@link PostageLabel} represents a physical label to affix to a {@link Parcel parcel} when shipping. - * @public - * @extends EasyPostObject - */ -export default class PostageLabel extends EasyPostObject { - static label_date; - static label_epl2_url; - static label_file_type; - static label_pdf_url; - static label_resolution; - static label_size; - static label_type; - static label_url; - static label_zpl_url; -} diff --git a/src/models/postage_label.ts b/src/models/postage_label.ts new file mode 100644 index 000000000..72540cfdc --- /dev/null +++ b/src/models/postage_label.ts @@ -0,0 +1,18 @@ +import EasyPostObject from './easypost_object'; + +/** + * A {@link PostageLabel} represents a physical label to affix to a {@link Parcel parcel} when shipping. + * @public + * @extends EasyPostObject + */ +export default class PostageLabel extends EasyPostObject { + declare label_date?: string | null; + declare label_epl2_url?: string | null; + declare label_file_type?: string | null; + declare label_pdf_url?: string | null; + declare label_resolution?: number | null; + declare label_size?: string | null; + declare label_type?: string | null; + declare label_url?: string | null; + declare label_zpl_url?: string | null; +} diff --git a/src/models/shipment.js b/src/models/shipment.js deleted file mode 100644 index 8d82b5e18..000000000 --- a/src/models/shipment.js +++ /dev/null @@ -1,49 +0,0 @@ -import Constants from '../constants'; -import EasyPostObject from './easypost_object'; - -/** - * A {@link https://docs.easypost.com/docs/shipments Shipment} represents a physical {@link Parcel}, the origin and destination {@link Address Addresses}, and any associated {@link CustomsInfo}. - * @public - * @extends EasyPostObject - */ -export default class Shipment extends EasyPostObject { - static batch_id; - static batch_message; - static batch_status; - static buyer_address; - static customs_info; - static fees; - static forms; - static from_address; - static insurance; - static is_return; - static messages; - static options; - static parcel; - static postage_label; - static rates; - static reference; - static refund_status; - static return_address; - static scan_form; - static selected_rate; - static status; - static to_address; - static tracker; - static tracking_code; - static usps_zone; - - /** - * Get the lowest rate for this {@link Shipment}. - * @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/shipment.ts b/src/models/shipment.ts new file mode 100644 index 000000000..236d56eaf --- /dev/null +++ b/src/models/shipment.ts @@ -0,0 +1,54 @@ +import Constants from '../constants'; +import EasyPostObject from './easypost_object'; + +/** + * A {@link https://docs.easypost.com/docs/shipments Shipment} represents a physical {@link Parcel}, the origin and destination {@link Address Addresses}, and any associated {@link CustomsInfo}. + * @public + * @extends EasyPostObject + */ +export default class Shipment extends EasyPostObject { + declare batch_id?: string | null; + declare batch_message?: string | null; + declare batch_status?: string | null; + declare buyer_address?: Record | null; + declare customs_info?: Record | null; + declare fees?: Record[] | null; + declare forms?: Record[] | null; + declare from_address?: Record | null; + declare insurance?: Record | null; + declare is_return?: boolean | null; + declare messages?: Record[] | null; + declare options?: Record | null; + declare parcel?: Record | null; + declare postage_label?: Record | null; + declare rates?: Parameters[0] | null; + declare reference?: string | null; + declare refund_status?: 'submitted' | 'refunded' | 'rejected' | null; + declare return_address?: Record | null; + declare scan_form?: Record | null; + declare selected_rate?: Parameters[0][number] | null; + declare status?: string | null; + declare to_address?: Record | null; + declare tracker?: Record | null; + declare tracking_code?: string | null; + declare usps_zone?: string | null; + + /** + * Get the lowest rate for this {@link Shipment}. + * @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 Shipment & { rates?: unknown[] }).rates || []) as Parameters< + typeof Constants.Utils.getLowestRate + >[0]; + + return Constants.Utils.getLowestRate(rates, carriers, services); + } +}