🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

@easypost/api

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@easypost/api - npm Package Compare versions

Comparing version
8.1.0
to
8.2.0
+29
src/services/luma_service.js
import baseService from './base_service';
export default (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.
*/
class LumaService extends baseService(easypostClient) {
/**
* Get service recommendations from Luma that meet the criteria of your ruleset.
* @param {Object} params - The parameters to get a Luma promise with.
* @returns {Object} - An object containing the Luma promise.
*/
static async getPromise(params) {
const url = `luma/promise`;
const wrappedParams = {
shipment: params,
};
try {
const response = await easypostClient._post(url, wrappedParams);
return this._convertToEasyPostObject(response.body.luma_info, wrappedParams);
} catch (e) {
return Promise.reject(e);
}
}
};
+7
-0
# CHANGELOG
## v8.2.0 (2025-06-18)
- Adds the following functions
- `shipment.createAndBuyLuma`
- `shipment.buyLuma`
- `luma.getPromise`
## v8.1.0 (2025-05-29)

@@ -4,0 +11,0 @@

+1
-1

@@ -1,1 +0,1 @@

"use strict";const g=require("os"),k=require("superagent"),w=require("util"),rt=require("uuid"),x=require("crypto"),at="8.1.0",ct={version:at};class v extends Error{constructor({message:n}={}){super(n)}}class O extends v{}class I extends v{}class S extends v{}class N{getLowestSmartRate(n,t,e){const s=new Set(["percentile_50","percentile_75","percentile_85","percentile_90","percentile_95","percentile_97","percentile_99"]);let a=null;const c=e.toLowerCase();if(!s.has(c))throw new I({message:`Invalid deliveryAccuracy value, must be one of: ${new Array(...s).join(", ")}`});for(let i=0;i<n.length;i+=1){const o=n[i];o.time_in_transit[c]>parseInt(t,10)||(a===null||parseFloat(o.rate)<parseFloat(a.rate))&&(a=o)}if(a===null)throw new O({message:w.format(h.NO_OBJECT_FOUND,"rates")});return a}getLowestRate(n,t=null,e=null){if(t){const s=t.map(a=>a.toLowerCase());n=n.filter(a=>s.includes(a.carrier.toLowerCase()))}if(e){const s=e.map(a=>a.toLowerCase());n=n.filter(a=>s.includes(a.service.toLowerCase()))}if(n.length===0)throw new O({message:w.format(h.NO_OBJECT_FOUND,"rates")});return n.reduce((s,a)=>parseFloat(a.rate)<parseFloat(s.rate)?a:s,n[0])}validateWebhook(n,t,e){var c,i;let s={};const a=(i=(c=t["X-Hmac-Signature"])!=null?c:t["x-hmac-signature"])!=null?i:null;if(a!=null){const o=e.normalize("NFKD"),d=Buffer.from(o,"utf8"),p=Buffer.from(n).toString("utf8").replace(/("weight":\s*)(\d+)(\s*)(?=,|\})/g,"$1$2.0"),f=`hmac-sha256-hex=${x.createHmac("sha256",d).update(p,"utf-8").digest("hex")}`;try{if(x.timingSafeEqual(Buffer.from(a,"utf8"),Buffer.from(f,"utf8")))s=JSON.parse(p);else throw new S({message:h.WEBHOOK_DOES_NOT_MATCH})}catch{throw new S({message:h.WEBHOOK_DOES_NOT_MATCH})}}else throw new S({message:h.INVALID_WEBHOOK_SIGNATURE});return s}}class h{static get CARRIER_ACCOUNTS_WITH_CUSTOM_CREATE_WORKFLOWS(){return["FedexAccount","FedexSmartpostAccount"]}static get CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH(){return["AmazonShippingAccount","UpsAccount","UpsMailInnovationsAccount","UpsSurepostAccount"]}static EXTERNAL_API_CALL_FAILED="Communication with %s failed, please try again later";static INVALID_API_KEY_TYPE="Invalid API key type.";static INVALID_PARAMETER="Invalid parameter: %s.";static INVALID_PAYMENT="The chosen payment method is not a credit card. Please try again.";static INVALID_WEBHOOK_SIGNATURE="Webhook does not contain a valid HMAC signature.";static MISSING_REQUIRED_PARAMETER="Missing required parameter: %s.";static NO_OBJECT_FOUND="No %s found.";static NO_PAYMENT_METHODS="No payment methods are set up. Please add a payment method and try again.";static API_DID_NOT_RETURN_ERROR_DETAILS="API did not return error details.";static WEBHOOK_DOES_NOT_MATCH="Webhook received did not originate from EasyPost or had a webhook secret mismatch.";static END_OF_PAGINATION="There are no more pages to retrieve.";static ERROR_DESERIALIZATION="Error deserializing JSON response";static Utils=new N}class m extends v{constructor({message:n,code:t,statusCode:e,errors:s}={}){super({message:n}),this.code=t,this.errors=s,this.message=n,this.statusCode=e}}class nt extends m{}class it extends m{}class ot extends m{}class ut extends m{}class lt extends m{}class dt extends m{}class _t extends m{}class pt extends m{}class ht extends m{}class mt extends m{}class yt extends m{}class ft extends m{}class vt extends m{}class bt extends m{}class wt{static traverseJsonElement(n,t){if(n instanceof Object)for(const e of Object.values(n))this.traverseJsonElement(e,t);else if(n instanceof Array)for(const e of n)this.traverseJsonElement(e,t);else t.push(n.toString())}static handleApiError(n){const{statusCode:t}=n,{code:e,message:s,errors:a}=n.body.error,c={message:s,code:e,statusCode:t,errors:a};try{const i=[];this.traverseJsonElement(c.message,i),c.message=i.join(", ")}catch{const o={message:h.ERROR_DESERIALIZATION,code:"ERROR_DESERIALIZATION_ERROR"};return new v(o)}if(t>=300&&t<400)return new mt(c);switch(t){case 400:return new nt(c);case 401:return new vt(c);case 402:return new pt(c);case 403:return new it(c);case 404:return new _t(c);case 405:return new dt(c);case 408:return new ft(c);case 422:return new lt(c);case 429:return new ht(c);case 500:return new ut(c);case 503:return new yt(c);case 504:return new ot(c);default:return new bt(c)}}}class Pt extends v{}class u{static id;static object;static mode;static created_at;static updated_at;static _params}class $ extends u{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}class D extends u{static active;static key}class H extends u{static label_url;static num_shipments;static pickup;static reference;static scan_form;static shipments;static state;static status}class M extends u{static ad_href;static ad;static background_color;static color;static logo_href;static logo;static name;static theme;static user_id}class U extends u{static billing_type;static clone;static credentials;static description;static fields;static readable;static reference;static test_credentials}class Et extends u{static fields;static type}class gt extends u{static id;static object;static mode;static attachments;static contact_email;static created_at;static description;static history;static insurance_amount;static insurance_id;static payment_method;static recipient_name;static reference;static requested_amount;static shipment_id;static status_detail;static status_timestamp;static status;static tracking_code;static type;static updated_at}class L extends u{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}class B extends u{static code;static currency;static description;static hs_tariff_number;static origin_country;static quantity;static value;static weight}class q extends u{static street1;static street2;static city;static state;static zip;static country;static name;static company;static phone;static email}class C extends u{static completed_urls;static description;static pending_urls;static previous_attributes;static result;static status}class St extends u{static form_type;static form_url;static submitted_electronically}class F extends u{static amount;static fee;static from_address;static messages;static provider_id;static provider;static reference;static shipment_id;static status;static to_address;static tracking_code;static tracker}class W extends u{static buyer_address;static from_address;static is_return;static messages;static rates;static reference;static return_address;static shipments;static to_address;lowestRate(n,t){const e=this.rates||[];return h.Utils.getLowestRate(e,n,t)}}class K extends u{static height;static length;static predefined_package;static weight;static width}class V extends u{static response_body}class z extends u{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;lowestRate(n,t){const e=this.pickup_rates||[];return h.Utils.getLowestRate(e,n,t)}}class G extends u{static carrier;static currency;static pickup_id;static rate;static service}class J extends u{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}class Y extends u{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}class X extends u{static carrier;static confirmation_number;static shipment_id;static status;static tracking_code}class b extends u{static end_date;static include_children;static send_email;static start_date;static status;static url_expires_at;static url}class Q extends u{static address;static batch_id;static form_file_type;static form_url;static message;static status;static tracking_codes}class Z extends u{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;lowestRate(n,t){const e=this.rates||[];return h.Utils.getLowestRate(e,n,t)}}class tt extends u{static carrier_detail;static carrier;static est_delivery_date;static fees;static finalized;static is_return;static public_url;static shipment_id;static signed_by;static status_detail;static status;static tracking_code;static tracking_details;static weight}class et extends u{static api_keys;static balance;static cc_fee_rate;static children;static email;static insurance_fee_minimum;static insurance_fee_rate;static name;static parent_id;static phone_number;static price_per_shipment;static recharge_amount;static secondary_recharge_amount}class st extends u{static disabled_at;static url}class P extends v{constructor(){super({message:h.END_OF_PAGINATION})}}const R={adr:$,ak:D,batch:H,brd:M,ca:U,cfrep:b,clm:gt,cstinfo:L,cstitem:B,es:q,evt:C,hook:st,ins:F,order:W,payload:V,pickup:z,pickuprate:G,pl:J,plrep:b,prcl:K,rate:Y,refrep:b,rfnd:X,sf:Q,shp:Z,shpinvrep:b,shprep:b,trk:tt,trkrep:b,user:et},j={Address:$,ApiKey:D,Batch:H,Brand:M,CarrierAccount:U,CarrierType:Et,CustomsInfo:L,CustomsItem:B,EasyPostObject:u,EndShipper:q,Event:C,Form:St,Insurance:F,Order:W,Parcel:K,Payload:V,Pickup:z,PickupRate:G,PostageLabel:J,Rate:Y,Refund:X,Report:b,ScanForm:Q,Shipment:Z,Tracker:tt,User:et,Webhook:st},l=r=>class{static _convertToEasyPostObject(t,e){if(Array.isArray(t))return t.map(s=>typeof s=="object"?this._convertToEasyPostObject(s,e):s);if(typeof t=="object"&&t!==null){let s;if(j[t.object]!==void 0)s=new j[t.object];else if(t.id!==void 0&&R[t.id.substr(0,t.id.indexOf("_"))]!==void 0){const a=t.id.substr(0,t.id.indexOf("_"));s=new R[a]}else s=new u;return Object.keys(t).forEach(a=>{s[a]=this._convertToEasyPostObject(t[a],e)}),s._params=e,s}return t}static async _create(t,e){try{const s=await r._post(t,e);return this._convertToEasyPostObject(s.body,e)}catch(s){return Promise.reject(s)}}static async _all(t,e={}){try{const s=await r._get(t,e);return this._convertToEasyPostObject(s.body,e)}catch(s){return Promise.reject(s)}}static async _retrieve(t){try{const e=await r._get(t);return this._convertToEasyPostObject(e.body)}catch(e){return Promise.reject(e)}}static async _getNextPage(t,e,s,a=null,c={}){var y,f,E;const i=s[e];if(i==null||i.length==0||!s.has_more)throw new P;const o=(f=(y=s._params)!=null?y:i[0]._params)!=null?f:{},d={...o,page_size:(E=o.page_size)!=null?E:a,before_id:i[i.length-1].id,...c},p=await this._all(t,d);if(p==null||p[e].length==0)throw new P;return p}},Tt=r=>class extends l(r){static async create(t){const e="addresses",s={address:t};if(t.verify){const a=t;s.verify=t.verify,delete a.verify}if(t.verify_strict){const a=t;s.verify_strict=t.verify_strict,delete a.verify_strict}return this._create(e,s)}static async createAndVerify(t){const e="addresses/create_and_verify",s={address:t};try{const a=await r._post(e,s);return this._convertToEasyPostObject(a.body.address,s)}catch(a){return Promise.reject(a)}}static async all(t={}){return this._all("addresses",t)}static async getNextPage(t,e=null){return this._getNextPage("addresses","addresses",t,e)}static async retrieve(t){const e=`addresses/${t}`;return this._retrieve(e)}static async verifyAddress(t){try{const e=`addresses/${t}/verify`,s=await r._get(e);return this._convertToEasyPostObject(s.body.address)}catch(e){return Promise.reject(e)}}},Ot=r=>class extends l(r){static async all(t={}){return this._all("api_keys",t)}static async retrieveApiKeysForUser(t){const e="api_keys";try{const s=await r._get(e),a=this._convertToEasyPostObject(s.body);if(a.id==t)return a.keys;a.children.forEach(c=>{if(c.id==t)return c.keys})}catch(s){return Promise.reject(s)}throw new O({message:w.format(h.NO_OBJECT_FOUND,"child")})}},At="pdf",xt=r=>class extends l(r){static async create(t){const e="batches",s={batch:t};return this._create(e,s)}static async addShipments(t,e){const s=`batches/${t}/add_shipments`,a={shipments:e.map(c=>({id:c}))};try{const c=await r._post(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async removeShipments(t,e){const s=`batches/${t}/remove_shipments`,a={shipments:e.map(c=>({id:c}))};try{const c=await r._post(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async generateLabel(t,e=At){const s=`batches/${t}/label`,a={file_format:e};try{const c=await r._post(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async createScanForm(t){const e=`batches/${t}/scan_form`;try{const s=await r._post(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async buy(t){const e=`batches/${t}/buy`;try{const s=await r._post(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async all(t={}){return this._all("batches",t)}static async retrieve(t){const e=`batches/${t}`;return this._retrieve(e)}},Rt=r=>class extends l(r){static async retrieveStatelessRates(t){const e="beta/rates",s={shipment:t};try{const a=await r._post(e,s);return this._convertToEasyPostObject(a.body.rates,s)}catch(a){return Promise.reject(a)}}},jt=r=>class extends l(r){static async addPaymentMethod(t,e,s="primary"){const a={payment_method:{stripe_customer_id:t,payment_method_reference:e,priority:s}};return(await r._post("beta/referral_customers/payment_method",a)).body}static async refundByAmount(t){const e={refund_amount:t};return(await r._post("beta/referral_customers/refunds",e)).body}static async refundByPaymentLog(t){const e={payment_log_id:t};return(await r._post("beta/referral_customers/refunds",e)).body}static async createCreditCardClientSecret(){return(await r._post("beta/setup_intents",null)).body}static async createBankAccountClientSecret(t){const e=t?{return_url:t}:null;return(await r._post("beta/financial_connections_sessions",e)).body}};class T extends v{}const kt=r=>class extends l(r){static async fundWallet(t,e="primary"){const s=await this._getPaymentInfo(e.toLowerCase()),a=s[0],c=s[1],i=`${a}/${c}/charges`,o={amount:t};await r._post(i,o)}static async deletePaymentMethod(t){const e=await this._getPaymentInfo(t.toLowerCase()),s=e[0],a=e[1],c=`${s}/${a}`;await r._delete(c)}static async retrievePaymentMethods(){const e=await r._get("payment_methods");if(e.body.id===null)throw new T({message:h.NO_PAYMENT_METHODS});return e.body}static async _getPaymentInfo(t){const e=await this.retrievePaymentMethods(),a={primary:"primary_payment_method",secondary:"secondary_payment_method"}[t];let c,i,o;const d="The chosen payment method is not valid. Please try again.";if(a!==void 0&&e[a]!==null)if(c=e[a].id,i=e[a].object,i==="CreditCard")o="credit_cards";else if(i==="BankAccount")o="bank_accounts";else throw new T({message:d});else throw new T({message:d});return[o,c]}},It=r=>class extends l(r){static async create(t){const e=t.type;if(!e)throw new I({message:w.format(h.MISSING_REQUIRED_PARAMETER,"CarrierAccount type")});const s=this._selectCarrierAccountCreationEndpoint(e),a=this._wrapCarrierAccountParams(e,t);return this._create(s,a)}static async update(t,e){const s={carrier_account:e};try{const a=await r._patch(`carrier_accounts/${t}`,s);return this._convertToEasyPostObject(a.body,s)}catch(a){return Promise.reject(a)}}static async delete(t){const e=`carrier_accounts/${t}`;try{return await r._delete(e),Promise.resolve()}catch(s){return Promise.reject(s)}}static _selectCarrierAccountCreationEndpoint(t){return h.CARRIER_ACCOUNTS_WITH_CUSTOM_CREATE_WORKFLOWS.includes(t)?"carrier_accounts/register":h.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.includes(t)?"carrier_accounts/register_oauth":"carrier_accounts"}static _wrapCarrierAccountParams(t,e){return h.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.includes(t)?{carrier_account_oauth_registrations:e}:{carrier_account:e}}static async all(t={}){return this._all("carrier_accounts",t)}static async retrieve(t){const e=`carrier_accounts/${t}`;return this._retrieve(e)}},Nt=r=>class extends l(r){static async retrieve(t=null,e=null){const s="metadata/carriers",a={...t&&t.length>0&&{carriers:t.join(",")},...e&&e.length>0&&{types:e.join(",")}};try{const c=await r._get(s,a);return this._convertToEasyPostObject(c.body.carriers||[],a)}catch(c){return Promise.reject(c)}}},$t=r=>class extends l(r){static async all(t={}){const e="carrier_types";try{const s=await r._get(e,t);return this._convertToEasyPostObject(s.body,t)}catch(s){return Promise.reject(s)}}},Dt=r=>class extends l(r){static async create(t){return this._create("claims",t)}static async all(t={}){return this._all("claims",t)}static async getNextPage(t,e=null){return this._getNextPage("claims","claims",t,e)}static async retrieve(t){const e=`claims/${t}`;return this._retrieve(e)}static async cancel(t){const e=`claims/${t}/cancel`;return this._create(e)}},Ht=r=>class extends l(r){static async create(t){const e="customs_infos",s={customs_info:t};return this._create(e,s)}static async retrieve(t){const e=`customs_infos/${t}`;return this._retrieve(e)}},Mt=r=>class extends l(r){static async create(t){const e="customs_items",s={customs_item:t};return this._create(e,s)}static async retrieve(t){const e=`customs_items/${t}`;return this._retrieve(e)}},Ut=r=>class extends l(r){static async create(t){const e="end_shippers",s={address:t};return this._create(e,s)}static async update(t,e){const s=`end_shippers/${t}`,a={address:e};try{const c=await r._put(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async retrieve(t){const e=`end_shippers/${t}`;return this._retrieve(e)}static async all(t={}){return this._all("end_shippers",t)}},Lt=r=>class extends l(r){static async retrieveAllPayloads(t){const e=`events/${t}/payloads`;try{const s=await r._get(e);return this._convertToEasyPostObject(s.body.payloads)}catch(s){return Promise.reject(s)}}static async retrievePayload(t,e){const s=`events/${t}/payloads/${e}`;try{const a=await r._get(s);return this._convertToEasyPostObject(a.body)}catch(a){return Promise.reject(a)}}static async all(t={}){return this._all("events",t)}static async getNextPage(t,e=null){return this._getNextPage("events","events",t,e)}static async retrieve(t){const e=`events/${t}`;return this._retrieve(e)}},Bt=r=>class extends l(r){static async create(t){const e="insurances",s={insurance:t};return this._create(e,s)}static async all(t={}){return this._all("insurances",t)}static async getNextPage(t,e=null){return this._getNextPage("insurances","insurances",t,e)}static async retrieve(t){const e=`insurances/${t}`;return this._retrieve(e)}static async refund(t){const e=`insurances/${t}/refund`,s=await r._post(e);return this._convertToEasyPostObject(s.body)}},qt=r=>class extends l(r){static async create(t){const e="orders",s={order:t};return this._create(e,s)}static async buy(t,e,s){const a=`orders/${t}/buy`,c={carrier:e,service:s};try{const i=await r._post(a,c);return this._convertToEasyPostObject(i.body,c)}catch(i){return Promise.reject(i)}}static async getRates(t){const e=`orders/${t}/rates`;try{const s=await r._get(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async retrieve(t){const e=`orders/${t}`;return this._retrieve(e)}},Ct=r=>class extends l(r){static async create(t){const e="parcels",s={parcel:t};return this._create(e,s)}static async retrieve(t){const e=`parcels/${t}`;return this._retrieve(e)}},Ft=r=>class extends l(r){static async create(t){const e="pickups",s={pickup:t};return this._create(e,s)}static async buy(t,e,s){const a=`pickups/${t}/buy`,c={carrier:e,service:s};try{const i=await r._post(a,c);return this._convertToEasyPostObject(i.body,c)}catch(i){return Promise.reject(i)}}static async cancel(t){const e=`pickups/${t}/cancel`;try{const s=await r._post(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async all(t={}){return this._all("pickups",t)}static async getNextPage(t,e=null){return this._getNextPage("pickups","pickups",t,e)}static async retrieve(t){const e=`pickups/${t}`;return this._retrieve(e)}},Wt=r=>class extends l(r){static async retrieve(t){const e=`rates/${t}`;return this._retrieve(e)}};class Kt extends m{}function A(r,n){return _.copyClient(r,{apiKey:n})}async function Vt(r){return(await r._get("partners/stripe_public_key")).body.public_key}async function zt(r,n,t,e,s){const a=`https://api.stripe.com/v1/tokens?card[number]=${n}&card[exp_month]=${t}&card[exp_year]=${e}&card[cvc]=${s}`,c=k.post(a).set({Authorization:`Bearer ${r}`,"Content-Type":"application/x-www-form-urlencoded"});try{return(await c).body.id}catch{throw new Kt({message:w.format(h.EXTERNAL_API_CALL_FAILED,"Stripe")})}}async function Gt(r,n,t,e){const s=A(r,n),a="credit_cards",c={credit_card:{stripe_object_id:t,priority:e}};return(await s._post(a,c)).body}const Jt=r=>class extends l(r){static async create(t){const e="referral_customers",s={user:t};return this._create(e,s)}static async updateEmail(t,e){const s=`referral_customers/${t}`,a={user:{email:e}};return await r._put(s,a),!0}static async addCreditCard(t,e,s,a,c,i="primary"){const o=await Vt(r),d=await zt(o,e,s,a,c);return await Gt(r,t,d,i)}static async addCreditCardFromStripe(t,e,s="primary"){const a=A(r,t),c={credit_card:{payment_method_id:e,priority:s}},o=await a._post("credit_cards",c);return this._convertToEasyPostObject(o.body,c)}static async addBankAccountFromStripe(t,e,s,a="primary"){const c=A(r,t),i={financial_connections_id:e,mandate_data:s,priority:a},d=await c._post("bank_accounts",i);return this._convertToEasyPostObject(d.body,i)}static async all(t={}){return this._all("referral_customers",t)}static async getNextPage(t,e=null){return this._getNextPage("referral_customers","referral_customers",t,e)}},Yt=r=>class extends l(r){static async create(t){const e="refunds",s={refund:t};return this._create(e,s)}static async all(t={}){return this._all("refunds",t)}static async getNextPage(t,e=null){return this._getNextPage("refunds","refunds",t,e)}static async retrieve(t){const e=`refunds/${t}`;return this._retrieve(e)}},Xt=r=>class extends l(r){static async create(t){const e=`reports/${t.type}`;return this._create(e,t)}static async all(t={}){const e=t.type,s=`reports/${e}`;delete t.type;try{const a=await r._get(s,t);return this._convertToEasyPostObject(a.body,{...t,type:e})}catch(a){return Promise.reject(a)}}static async getNextPage(t,e=null){const s=`reports/${t.reports[0]._params.type}`;return this._getNextPage(s,"reports",t,e)}static async retrieve(t){const e=`reports/${t}`;return this._retrieve(e)}},Qt=r=>class extends l(r){static async create(t){const e="scan_forms";t.shipments&&(t.shipments=t.shipments.map(a=>typeof a=="string"?{id:a}:{id:a.id}));const s={scan_form:t};return this._create(e,s)}static async all(t={}){return this._all("scan_forms",t)}static async getNextPage(t,e=null){return this._getNextPage("scan_forms","scan_forms",t,e)}static async retrieve(t){const e=`scan_forms/${t}`;return this._retrieve(e)}},Zt=r=>class extends l(r){static async create(t){const e="shipments",s={shipment:t};return this._create(e,s)}static async buy(t,e,s=null,a=null){let c=e;typeof e=="object"&&(c=e.id);const i=`shipments/${t}/buy`,o={rate:{id:c}};s&&(o.insurance=s),a&&(o.end_shipper_id=a);try{const d=await r._post(i,o);return this._convertToEasyPostObject(d.body,o)}catch(d){return Promise.reject(d)}}static async convertLabelFormat(t,e){const s=`shipments/${t}/label`,a={file_format:e};try{const c=await r._get(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async regenerateRates(t){const e=`shipments/${t}/rerate`,s={};try{const a=await r._post(e,s);return this._convertToEasyPostObject(a.body,s)}catch(a){return Promise.reject(a)}}static async getSmartRates(t){const e=`shipments/${t}/smartrate`;try{const s=await r._get(e);return this._convertToEasyPostObject(s.body.result)}catch(s){return Promise.reject(s)}}static async insure(t,e){const s=`shipments/${t}/insure`,a={amount:e};try{const c=await r._post(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async generateForm(t,e,s={}){const a=`shipments/${t}/forms`,c={form:{...s,type:e}};try{const i=await r._post(a,c);return this._convertToEasyPostObject(i.body,c)}catch(i){return Promise.reject(i)}}static async refund(t){const e=`shipments/${t}/refund`;try{const s=await r._post(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async lowestSmartRate(t,e,s){const a=await this.getSmartRates(t);return h.Utils.getLowestSmartRate(a,e,s.toLowerCase())}static async all(t={}){return this._all("shipments",t)}static async getNextPage(t,e=null){return this._getNextPage("shipments","shipments",t,e)}static async retrieve(t){const e=`shipments/${t}`;return this._retrieve(e)}static async retrieveEstimatedDeliveryDate(t,e){var c;const s=`shipments/${t}/smartrate/delivery_date`,a={planned_ship_date:e};try{const i=await r._get(s,a);return this._convertToEasyPostObject((c=i.body.rates)!=null?c:[],a)}catch(i){return Promise.reject(i)}}static async recommendShipDate(t,e){var c;const s=`shipments/${t}/smartrate/precision_shipping`,a={desired_delivery_date:e};try{const i=await r._get(s,a);return this._convertToEasyPostObject((c=i.body.rates)!=null?c:[],a)}catch(i){return Promise.reject(i)}}},te=r=>class extends l(r){static async estimateDeliveryDate(t){const e="smartrate/deliver_by";try{const s=await r._post(e,t);return this._convertToEasyPostObject(s.body,t)}catch(s){return Promise.reject(s)}}static async recommendShipDate(t){const e="smartrate/deliver_on";try{const s=await r._post(e,t);return this._convertToEasyPostObject(s.body,t)}catch(s){return Promise.reject(s)}}},ee=r=>class extends l(r){static async create(t){const e="trackers",s={tracker:t};return this._create(e,s)}static async all(t={}){return this._all("trackers",t)}static async getNextPage(t,e=null){return this._getNextPage("trackers","trackers",t,e)}static async retrieve(t){const e=`trackers/${t}`;return this._retrieve(e)}},se=r=>class extends l(r){static async create(t){const e="users",s={user:t};return this._create(e,s)}static async update(t,e){const s=`users/${t}`,a={user:e};try{const c=await r._patch(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async retrieve(t){const e=`users/${t}`;try{const s=await r._get(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async retrieveMe(){const t="users";try{const e=await r._get(t);return this._convertToEasyPostObject(e.body)}catch(e){return Promise.reject(e)}}static async delete(t){const e=`users/${t}`;try{return await r._delete(e),Promise.resolve()}catch(s){return Promise.reject(s)}}static async updateBrand(t,e){const s=`users/${t}/brand`,a={brand:e};try{const c=await r._patch(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async allChildren(t){const e="users/children";try{const s=await r._get(e,t);return this._convertToEasyPostObject(s.body,t)}catch(s){return Promise.reject(s)}}static async getNextPage(t,e=null){return this._getNextPage("users/children","children",t,e)}static async _getNextPage(t,e,s,a=null){var p,y,f;const c=s[e];if(c==null||c.length==0||!s.has_more)throw new P;const i=(y=(p=s._params)!=null?p:c[0]._params)!=null?y:{},o={...i,page_size:(f=i.page_size)!=null?f:a,after_id:c[c.length-1].id},d=await this._all(t,o);if(d==null||d[e].length==0)throw new P;return d}},re=r=>class extends l(r){static async create(t){const e="webhooks",s={webhook:t};return this._create(e,s)}static async update(t,e){const s=`webhooks/${t}`;try{const a=await r._patch(s,e);return this._convertToEasyPostObject(a.body,e)}catch(a){return Promise.reject(a)}}static async delete(t){const e=`webhooks/${t}`;try{return await r._delete(e),Promise.resolve()}catch(s){return Promise.reject(s)}}static async all(t={}){return this._all("webhooks",t)}static async retrieve(t){const e=`webhooks/${t}`;return this._retrieve(e)}};class _{constructor(n,t={}){const{useProxy:e,timeout:s,baseUrl:a,superagentMiddleware:c,requestMiddleware:i}=t;if(!n&&!e)throw new Pt({message:w.format(h.MISSING_REQUIRED_PARAMETER,"API Key")});this.key=n,this.timeout=s||_.DEFAULT_TIMEOUT,this.baseUrl=a||_.DEFAULT_BASE_URL,this.agent=k,this.requestMiddleware=i,this.requestHooks=[],this.responseHooks=[],this.Utils=new N,c&&(this.agent=c(this.agent)),this._attachServices(_.SERVICES)}addRequestHook(n){this.requestHooks=[...this.requestHooks,n]}removeRequestHook(n){this.requestHooks=this.requestHooks.filter(t=>t!==n)}clearRequestHooks(){this.requestHooks=[]}addResponseHook(n){this.responseHooks=[...this.responseHooks,n]}removeResponseHook(n){this.responseHooks=this.responseHooks.filter(t=>t!==n)}clearResponseHooks(){this.responseHooks=[]}static copyClient(n,t={}){const{apiKey:e,useProxy:s,timeout:a,baseUrl:c,superagentMiddleware:i,requestMiddleware:o}=t,d=i?i(n.agent):n.agent;return new _(e||n.key,{useProxy:s||n.useProxy,timeout:a||n.timeout,baseUrl:c||n.baseUrl,agent:d,requestMiddleware:o||n.requestMiddleware})}static _buildHeaders(n={}){return{..._.DEFAULT_HEADERS,...n}}_attachServices(n){Object.keys(n).forEach(t=>{this[t]=n[t](this)})}_buildPath(n=""){if(n.indexOf("http")===0)return n;let t=this.baseUrl+n;return t=n.includes("beta")?t.replace("/v2",""):t,t}_createResponseHooksValue(n,t){return{...n,httpStatus:t.status,responseBody:t.body,headers:t.headers,responseTimestamp:Date.now()}}async _request(n="",t=_.METHODS.GET,e={},s={}){const a=this._buildPath(n),c=_._buildHeaders(s);let i=this.agent[t](a).set(c);this.requestMiddleware&&(i=this.requestMiddleware(i)),this.key&&i.auth(this.key);const o=new URL(a);e!==void 0&&(t===_.METHODS.GET||t===_.METHODS.DELETE?(i.query(e),Object.entries(e).forEach(([p,y])=>{o.searchParams.append(p,y)})):i.send(e));const d={method:t,path:o.toString(),requestBody:i._data,headers:c,requestTimestamp:Date.now(),requestUUID:rt.v4()};this.requestHooks.forEach(p=>p(d));try{const p=await i;if(this.responseHooks.length>0){const y=this._createResponseHooksValue(d,p);this.responseHooks.forEach(f=>f(y))}return p}catch(p){if(p.response&&p.response.body){const y=this._createResponseHooksValue(d,p.response);throw this.responseHooks.forEach(f=>f(y)),wt.handleApiError(p.response)}else throw p}}_get(n,t={},e={}){return this._request(n,_.METHODS.GET,t,e)}_post(n,t={},e={}){return this._request(n,_.METHODS.POST,t,e)}_put(n,t={},e={}){return this._request(n,_.METHODS.PUT,t,e)}_patch(n,t={},e={}){return this._request(n,_.METHODS.PATCH,t,e)}_delete(n,t={},e={}){return this._request(n,_.METHODS.DELETE,t,e)}}_.MS_SECOND=1e3;_.DEFAULT_TIMEOUT=60*_.MS_SECOND;_.DEFAULT_BASE_URL="https://api.easypost.com/v2/";_.DEFAULT_HEADERS={Accept:"application/json","Content-Type":"application/json","User-Agent":`EasyPost/v2 NodejsClient/${ct.version} Nodejs/${process.versions.node} OS/${g.platform()} OSVersion/${g.release()} OSArch/${g.arch()}`};_.METHODS={GET:"get",POST:"post",PUT:"put",PATCH:"patch",DELETE:"del"};_.SERVICES={Address:Tt,ApiKey:Ot,Batch:xt,BetaRate:Rt,BetaReferralCustomer:jt,Billing:kt,CarrierAccount:It,CarrierMetadata:Nt,CarrierType:$t,Claim:Dt,CustomsInfo:Ht,CustomsItem:Mt,EndShipper:Ut,Event:Lt,Insurance:Bt,Order:qt,Parcel:Ct,Pickup:Ft,Rate:Wt,ReferralCustomer:Jt,Refund:Yt,Report:Xt,ScanForm:Qt,Shipment:Zt,SmartRate:te,Tracker:ee,User:se,Webhook:re};module.exports=_;
"use strict";const g=require("os"),k=require("superagent"),P=require("util"),rt=require("uuid"),x=require("crypto"),at="8.2.0",ct={version:at};class v extends Error{constructor({message:n}={}){super(n)}}class O extends v{}class I extends v{}class S extends v{}class N{getLowestSmartRate(n,t,e){const s=new Set(["percentile_50","percentile_75","percentile_85","percentile_90","percentile_95","percentile_97","percentile_99"]);let a=null;const c=e.toLowerCase();if(!s.has(c))throw new I({message:`Invalid deliveryAccuracy value, must be one of: ${new Array(...s).join(", ")}`});for(let i=0;i<n.length;i+=1){const o=n[i];o.time_in_transit[c]>parseInt(t,10)||(a===null||parseFloat(o.rate)<parseFloat(a.rate))&&(a=o)}if(a===null)throw new O({message:P.format(h.NO_OBJECT_FOUND,"rates")});return a}getLowestRate(n,t=null,e=null){if(t){const s=t.map(a=>a.toLowerCase());n=n.filter(a=>s.includes(a.carrier.toLowerCase()))}if(e){const s=e.map(a=>a.toLowerCase());n=n.filter(a=>s.includes(a.service.toLowerCase()))}if(n.length===0)throw new O({message:P.format(h.NO_OBJECT_FOUND,"rates")});return n.reduce((s,a)=>parseFloat(a.rate)<parseFloat(s.rate)?a:s,n[0])}validateWebhook(n,t,e){var c,i;let s={};const a=(i=(c=t["X-Hmac-Signature"])!=null?c:t["x-hmac-signature"])!=null?i:null;if(a!=null){const o=e.normalize("NFKD"),d=Buffer.from(o,"utf8"),p=Buffer.from(n).toString("utf8").replace(/("weight":\s*)(\d+)(\s*)(?=,|\})/g,"$1$2.0"),f=`hmac-sha256-hex=${x.createHmac("sha256",d).update(p,"utf-8").digest("hex")}`;try{if(x.timingSafeEqual(Buffer.from(a,"utf8"),Buffer.from(f,"utf8")))s=JSON.parse(p);else throw new S({message:h.WEBHOOK_DOES_NOT_MATCH})}catch{throw new S({message:h.WEBHOOK_DOES_NOT_MATCH})}}else throw new S({message:h.INVALID_WEBHOOK_SIGNATURE});return s}}class h{static get CARRIER_ACCOUNTS_WITH_CUSTOM_CREATE_WORKFLOWS(){return["FedexAccount","FedexSmartpostAccount"]}static get CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH(){return["AmazonShippingAccount","UpsAccount","UpsMailInnovationsAccount","UpsSurepostAccount"]}static EXTERNAL_API_CALL_FAILED="Communication with %s failed, please try again later";static INVALID_API_KEY_TYPE="Invalid API key type.";static INVALID_PARAMETER="Invalid parameter: %s.";static INVALID_PAYMENT="The chosen payment method is not a credit card. Please try again.";static INVALID_WEBHOOK_SIGNATURE="Webhook does not contain a valid HMAC signature.";static MISSING_REQUIRED_PARAMETER="Missing required parameter: %s.";static NO_OBJECT_FOUND="No %s found.";static NO_PAYMENT_METHODS="No payment methods are set up. Please add a payment method and try again.";static API_DID_NOT_RETURN_ERROR_DETAILS="API did not return error details.";static WEBHOOK_DOES_NOT_MATCH="Webhook received did not originate from EasyPost or had a webhook secret mismatch.";static END_OF_PAGINATION="There are no more pages to retrieve.";static ERROR_DESERIALIZATION="Error deserializing JSON response";static Utils=new N}class m extends v{constructor({message:n,code:t,statusCode:e,errors:s}={}){super({message:n}),this.code=t,this.errors=s,this.message=n,this.statusCode=e}}class nt extends m{}class it extends m{}class ot extends m{}class ut extends m{}class lt extends m{}class dt extends m{}class _t extends m{}class pt extends m{}class ht extends m{}class mt extends m{}class yt extends m{}class ft extends m{}class vt extends m{}class bt extends m{}class Pt{static traverseJsonElement(n,t){if(n instanceof Object)for(const e of Object.values(n))this.traverseJsonElement(e,t);else if(n instanceof Array)for(const e of n)this.traverseJsonElement(e,t);else t.push(n.toString())}static handleApiError(n){const{statusCode:t}=n,{code:e,message:s,errors:a}=n.body.error,c={message:s,code:e,statusCode:t,errors:a};try{const i=[];this.traverseJsonElement(c.message,i),c.message=i.join(", ")}catch{const o={message:h.ERROR_DESERIALIZATION,code:"ERROR_DESERIALIZATION_ERROR"};return new v(o)}if(t>=300&&t<400)return new mt(c);switch(t){case 400:return new nt(c);case 401:return new vt(c);case 402:return new pt(c);case 403:return new it(c);case 404:return new _t(c);case 405:return new dt(c);case 408:return new ft(c);case 422:return new lt(c);case 429:return new ht(c);case 500:return new ut(c);case 503:return new yt(c);case 504:return new ot(c);default:return new bt(c)}}}class wt extends v{}class u{static id;static object;static mode;static created_at;static updated_at;static _params}class $ extends u{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}class D extends u{static active;static key}class H extends u{static label_url;static num_shipments;static pickup;static reference;static scan_form;static shipments;static state;static status}class M extends u{static ad_href;static ad;static background_color;static color;static logo_href;static logo;static name;static theme;static user_id}class U extends u{static billing_type;static clone;static credentials;static description;static fields;static readable;static reference;static test_credentials}class Et extends u{static fields;static type}class gt extends u{static id;static object;static mode;static attachments;static contact_email;static created_at;static description;static history;static insurance_amount;static insurance_id;static payment_method;static recipient_name;static reference;static requested_amount;static shipment_id;static status_detail;static status_timestamp;static status;static tracking_code;static type;static updated_at}class L extends u{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}class B extends u{static code;static currency;static description;static hs_tariff_number;static origin_country;static quantity;static value;static weight}class q extends u{static street1;static street2;static city;static state;static zip;static country;static name;static company;static phone;static email}class F extends u{static completed_urls;static description;static pending_urls;static previous_attributes;static result;static status}class St extends u{static form_type;static form_url;static submitted_electronically}class C extends u{static amount;static fee;static from_address;static messages;static provider_id;static provider;static reference;static shipment_id;static status;static to_address;static tracking_code;static tracker}class W extends u{static buyer_address;static from_address;static is_return;static messages;static rates;static reference;static return_address;static shipments;static to_address;lowestRate(n,t){const e=this.rates||[];return h.Utils.getLowestRate(e,n,t)}}class K extends u{static height;static length;static predefined_package;static weight;static width}class V extends u{static response_body}class z extends u{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;lowestRate(n,t){const e=this.pickup_rates||[];return h.Utils.getLowestRate(e,n,t)}}class G extends u{static carrier;static currency;static pickup_id;static rate;static service}class J extends u{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}class Y extends u{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}class X extends u{static carrier;static confirmation_number;static shipment_id;static status;static tracking_code}class b extends u{static end_date;static include_children;static send_email;static start_date;static status;static url_expires_at;static url}class Q extends u{static address;static batch_id;static form_file_type;static form_url;static message;static status;static tracking_codes}class Z extends u{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;lowestRate(n,t){const e=this.rates||[];return h.Utils.getLowestRate(e,n,t)}}class tt extends u{static carrier_detail;static carrier;static est_delivery_date;static fees;static finalized;static is_return;static public_url;static shipment_id;static signed_by;static status_detail;static status;static tracking_code;static tracking_details;static weight}class et extends u{static api_keys;static balance;static cc_fee_rate;static children;static email;static insurance_fee_minimum;static insurance_fee_rate;static name;static parent_id;static phone_number;static price_per_shipment;static recharge_amount;static secondary_recharge_amount}class st extends u{static disabled_at;static url}class w extends v{constructor(){super({message:h.END_OF_PAGINATION})}}const R={adr:$,ak:D,batch:H,brd:M,ca:U,cfrep:b,clm:gt,cstinfo:L,cstitem:B,es:q,evt:F,hook:st,ins:C,order:W,payload:V,pickup:z,pickuprate:G,pl:J,plrep:b,prcl:K,rate:Y,refrep:b,rfnd:X,sf:Q,shp:Z,shpinvrep:b,shprep:b,trk:tt,trkrep:b,user:et},j={Address:$,ApiKey:D,Batch:H,Brand:M,CarrierAccount:U,CarrierType:Et,CustomsInfo:L,CustomsItem:B,EasyPostObject:u,EndShipper:q,Event:F,Form:St,Insurance:C,Order:W,Parcel:K,Payload:V,Pickup:z,PickupRate:G,PostageLabel:J,Rate:Y,Refund:X,Report:b,ScanForm:Q,Shipment:Z,Tracker:tt,User:et,Webhook:st},l=r=>class{static _convertToEasyPostObject(t,e){if(Array.isArray(t))return t.map(s=>typeof s=="object"?this._convertToEasyPostObject(s,e):s);if(typeof t=="object"&&t!==null){let s;if(j[t.object]!==void 0)s=new j[t.object];else if(t.id!==void 0&&R[t.id.substr(0,t.id.indexOf("_"))]!==void 0){const a=t.id.substr(0,t.id.indexOf("_"));s=new R[a]}else s=new u;return Object.keys(t).forEach(a=>{s[a]=this._convertToEasyPostObject(t[a],e)}),s._params=e,s}return t}static async _create(t,e){try{const s=await r._post(t,e);return this._convertToEasyPostObject(s.body,e)}catch(s){return Promise.reject(s)}}static async _all(t,e={}){try{const s=await r._get(t,e);return this._convertToEasyPostObject(s.body,e)}catch(s){return Promise.reject(s)}}static async _retrieve(t){try{const e=await r._get(t);return this._convertToEasyPostObject(e.body)}catch(e){return Promise.reject(e)}}static async _getNextPage(t,e,s,a=null,c={}){var y,f,E;const i=s[e];if(i==null||i.length==0||!s.has_more)throw new w;const o=(f=(y=s._params)!=null?y:i[0]._params)!=null?f:{},d={...o,page_size:(E=o.page_size)!=null?E:a,before_id:i[i.length-1].id,...c},p=await this._all(t,d);if(p==null||p[e].length==0)throw new w;return p}},Tt=r=>class extends l(r){static async create(t){const e="addresses",s={address:t};if(t.verify){const a=t;s.verify=t.verify,delete a.verify}if(t.verify_strict){const a=t;s.verify_strict=t.verify_strict,delete a.verify_strict}return this._create(e,s)}static async createAndVerify(t){const e="addresses/create_and_verify",s={address:t};try{const a=await r._post(e,s);return this._convertToEasyPostObject(a.body.address,s)}catch(a){return Promise.reject(a)}}static async all(t={}){return this._all("addresses",t)}static async getNextPage(t,e=null){return this._getNextPage("addresses","addresses",t,e)}static async retrieve(t){const e=`addresses/${t}`;return this._retrieve(e)}static async verifyAddress(t){try{const e=`addresses/${t}/verify`,s=await r._get(e);return this._convertToEasyPostObject(s.body.address)}catch(e){return Promise.reject(e)}}},Ot=r=>class extends l(r){static async all(t={}){return this._all("api_keys",t)}static async retrieveApiKeysForUser(t){const e="api_keys";try{const s=await r._get(e),a=this._convertToEasyPostObject(s.body);if(a.id==t)return a.keys;a.children.forEach(c=>{if(c.id==t)return c.keys})}catch(s){return Promise.reject(s)}throw new O({message:P.format(h.NO_OBJECT_FOUND,"child")})}},At="pdf",xt=r=>class extends l(r){static async create(t){const e="batches",s={batch:t};return this._create(e,s)}static async addShipments(t,e){const s=`batches/${t}/add_shipments`,a={shipments:e.map(c=>({id:c}))};try{const c=await r._post(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async removeShipments(t,e){const s=`batches/${t}/remove_shipments`,a={shipments:e.map(c=>({id:c}))};try{const c=await r._post(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async generateLabel(t,e=At){const s=`batches/${t}/label`,a={file_format:e};try{const c=await r._post(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async createScanForm(t){const e=`batches/${t}/scan_form`;try{const s=await r._post(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async buy(t){const e=`batches/${t}/buy`;try{const s=await r._post(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async all(t={}){return this._all("batches",t)}static async retrieve(t){const e=`batches/${t}`;return this._retrieve(e)}},Rt=r=>class extends l(r){static async retrieveStatelessRates(t){const e="beta/rates",s={shipment:t};try{const a=await r._post(e,s);return this._convertToEasyPostObject(a.body.rates,s)}catch(a){return Promise.reject(a)}}},jt=r=>class extends l(r){static async addPaymentMethod(t,e,s="primary"){const a={payment_method:{stripe_customer_id:t,payment_method_reference:e,priority:s}};return(await r._post("beta/referral_customers/payment_method",a)).body}static async refundByAmount(t){const e={refund_amount:t};return(await r._post("beta/referral_customers/refunds",e)).body}static async refundByPaymentLog(t){const e={payment_log_id:t};return(await r._post("beta/referral_customers/refunds",e)).body}static async createCreditCardClientSecret(){return(await r._post("beta/setup_intents",null)).body}static async createBankAccountClientSecret(t){const e=t?{return_url:t}:null;return(await r._post("beta/financial_connections_sessions",e)).body}};class T extends v{}const kt=r=>class extends l(r){static async fundWallet(t,e="primary"){const s=await this._getPaymentInfo(e.toLowerCase()),a=s[0],c=s[1],i=`${a}/${c}/charges`,o={amount:t};await r._post(i,o)}static async deletePaymentMethod(t){const e=await this._getPaymentInfo(t.toLowerCase()),s=e[0],a=e[1],c=`${s}/${a}`;await r._delete(c)}static async retrievePaymentMethods(){const e=await r._get("payment_methods");if(e.body.id===null)throw new T({message:h.NO_PAYMENT_METHODS});return e.body}static async _getPaymentInfo(t){const e=await this.retrievePaymentMethods(),a={primary:"primary_payment_method",secondary:"secondary_payment_method"}[t];let c,i,o;const d="The chosen payment method is not valid. Please try again.";if(a!==void 0&&e[a]!==null)if(c=e[a].id,i=e[a].object,i==="CreditCard")o="credit_cards";else if(i==="BankAccount")o="bank_accounts";else throw new T({message:d});else throw new T({message:d});return[o,c]}},It=r=>class extends l(r){static async create(t){const e=t.type;if(!e)throw new I({message:P.format(h.MISSING_REQUIRED_PARAMETER,"CarrierAccount type")});const s=this._selectCarrierAccountCreationEndpoint(e),a=this._wrapCarrierAccountParams(e,t);return this._create(s,a)}static async update(t,e){const s={carrier_account:e};try{const a=await r._patch(`carrier_accounts/${t}`,s);return this._convertToEasyPostObject(a.body,s)}catch(a){return Promise.reject(a)}}static async delete(t){const e=`carrier_accounts/${t}`;try{return await r._delete(e),Promise.resolve()}catch(s){return Promise.reject(s)}}static _selectCarrierAccountCreationEndpoint(t){return h.CARRIER_ACCOUNTS_WITH_CUSTOM_CREATE_WORKFLOWS.includes(t)?"carrier_accounts/register":h.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.includes(t)?"carrier_accounts/register_oauth":"carrier_accounts"}static _wrapCarrierAccountParams(t,e){return h.CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.includes(t)?{carrier_account_oauth_registrations:e}:{carrier_account:e}}static async all(t={}){return this._all("carrier_accounts",t)}static async retrieve(t){const e=`carrier_accounts/${t}`;return this._retrieve(e)}},Nt=r=>class extends l(r){static async retrieve(t=null,e=null){const s="metadata/carriers",a={...t&&t.length>0&&{carriers:t.join(",")},...e&&e.length>0&&{types:e.join(",")}};try{const c=await r._get(s,a);return this._convertToEasyPostObject(c.body.carriers||[],a)}catch(c){return Promise.reject(c)}}},$t=r=>class extends l(r){static async all(t={}){const e="carrier_types";try{const s=await r._get(e,t);return this._convertToEasyPostObject(s.body,t)}catch(s){return Promise.reject(s)}}},Dt=r=>class extends l(r){static async create(t){return this._create("claims",t)}static async all(t={}){return this._all("claims",t)}static async getNextPage(t,e=null){return this._getNextPage("claims","claims",t,e)}static async retrieve(t){const e=`claims/${t}`;return this._retrieve(e)}static async cancel(t){const e=`claims/${t}/cancel`;return this._create(e)}},Ht=r=>class extends l(r){static async create(t){const e="customs_infos",s={customs_info:t};return this._create(e,s)}static async retrieve(t){const e=`customs_infos/${t}`;return this._retrieve(e)}},Mt=r=>class extends l(r){static async create(t){const e="customs_items",s={customs_item:t};return this._create(e,s)}static async retrieve(t){const e=`customs_items/${t}`;return this._retrieve(e)}},Ut=r=>class extends l(r){static async create(t){const e="end_shippers",s={address:t};return this._create(e,s)}static async update(t,e){const s=`end_shippers/${t}`,a={address:e};try{const c=await r._put(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async retrieve(t){const e=`end_shippers/${t}`;return this._retrieve(e)}static async all(t={}){return this._all("end_shippers",t)}},Lt=r=>class extends l(r){static async retrieveAllPayloads(t){const e=`events/${t}/payloads`;try{const s=await r._get(e);return this._convertToEasyPostObject(s.body.payloads)}catch(s){return Promise.reject(s)}}static async retrievePayload(t,e){const s=`events/${t}/payloads/${e}`;try{const a=await r._get(s);return this._convertToEasyPostObject(a.body)}catch(a){return Promise.reject(a)}}static async all(t={}){return this._all("events",t)}static async getNextPage(t,e=null){return this._getNextPage("events","events",t,e)}static async retrieve(t){const e=`events/${t}`;return this._retrieve(e)}},Bt=r=>class extends l(r){static async create(t){const e="insurances",s={insurance:t};return this._create(e,s)}static async all(t={}){return this._all("insurances",t)}static async getNextPage(t,e=null){return this._getNextPage("insurances","insurances",t,e)}static async retrieve(t){const e=`insurances/${t}`;return this._retrieve(e)}static async refund(t){const e=`insurances/${t}/refund`,s=await r._post(e);return this._convertToEasyPostObject(s.body)}},qt=r=>class extends l(r){static async getPromise(t){const e="luma/promise",s={shipment:t};try{const a=await r._post(e,s);return this._convertToEasyPostObject(a.body.luma_info,s)}catch(a){return Promise.reject(a)}}},Ft=r=>class extends l(r){static async create(t){const e="orders",s={order:t};return this._create(e,s)}static async buy(t,e,s){const a=`orders/${t}/buy`,c={carrier:e,service:s};try{const i=await r._post(a,c);return this._convertToEasyPostObject(i.body,c)}catch(i){return Promise.reject(i)}}static async getRates(t){const e=`orders/${t}/rates`;try{const s=await r._get(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async retrieve(t){const e=`orders/${t}`;return this._retrieve(e)}},Ct=r=>class extends l(r){static async create(t){const e="parcels",s={parcel:t};return this._create(e,s)}static async retrieve(t){const e=`parcels/${t}`;return this._retrieve(e)}},Wt=r=>class extends l(r){static async create(t){const e="pickups",s={pickup:t};return this._create(e,s)}static async buy(t,e,s){const a=`pickups/${t}/buy`,c={carrier:e,service:s};try{const i=await r._post(a,c);return this._convertToEasyPostObject(i.body,c)}catch(i){return Promise.reject(i)}}static async cancel(t){const e=`pickups/${t}/cancel`;try{const s=await r._post(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async all(t={}){return this._all("pickups",t)}static async getNextPage(t,e=null){return this._getNextPage("pickups","pickups",t,e)}static async retrieve(t){const e=`pickups/${t}`;return this._retrieve(e)}},Kt=r=>class extends l(r){static async retrieve(t){const e=`rates/${t}`;return this._retrieve(e)}};class Vt extends m{}function A(r,n){return _.copyClient(r,{apiKey:n})}async function zt(r){return(await r._get("partners/stripe_public_key")).body.public_key}async function Gt(r,n,t,e,s){const a=`https://api.stripe.com/v1/tokens?card[number]=${n}&card[exp_month]=${t}&card[exp_year]=${e}&card[cvc]=${s}`,c=k.post(a).set({Authorization:`Bearer ${r}`,"Content-Type":"application/x-www-form-urlencoded"});try{return(await c).body.id}catch{throw new Vt({message:P.format(h.EXTERNAL_API_CALL_FAILED,"Stripe")})}}async function Jt(r,n,t,e){const s=A(r,n),a="credit_cards",c={credit_card:{stripe_object_id:t,priority:e}};return(await s._post(a,c)).body}const Yt=r=>class extends l(r){static async create(t){const e="referral_customers",s={user:t};return this._create(e,s)}static async updateEmail(t,e){const s=`referral_customers/${t}`,a={user:{email:e}};return await r._put(s,a),!0}static async addCreditCard(t,e,s,a,c,i="primary"){const o=await zt(r),d=await Gt(o,e,s,a,c);return await Jt(r,t,d,i)}static async addCreditCardFromStripe(t,e,s="primary"){const a=A(r,t),c={credit_card:{payment_method_id:e,priority:s}},o=await a._post("credit_cards",c);return this._convertToEasyPostObject(o.body,c)}static async addBankAccountFromStripe(t,e,s,a="primary"){const c=A(r,t),i={financial_connections_id:e,mandate_data:s,priority:a},d=await c._post("bank_accounts",i);return this._convertToEasyPostObject(d.body,i)}static async all(t={}){return this._all("referral_customers",t)}static async getNextPage(t,e=null){return this._getNextPage("referral_customers","referral_customers",t,e)}},Xt=r=>class extends l(r){static async create(t){const e="refunds",s={refund:t};return this._create(e,s)}static async all(t={}){return this._all("refunds",t)}static async getNextPage(t,e=null){return this._getNextPage("refunds","refunds",t,e)}static async retrieve(t){const e=`refunds/${t}`;return this._retrieve(e)}},Qt=r=>class extends l(r){static async create(t){const e=`reports/${t.type}`;return this._create(e,t)}static async all(t={}){const e=t.type,s=`reports/${e}`;delete t.type;try{const a=await r._get(s,t);return this._convertToEasyPostObject(a.body,{...t,type:e})}catch(a){return Promise.reject(a)}}static async getNextPage(t,e=null){const s=`reports/${t.reports[0]._params.type}`;return this._getNextPage(s,"reports",t,e)}static async retrieve(t){const e=`reports/${t}`;return this._retrieve(e)}},Zt=r=>class extends l(r){static async create(t){const e="scan_forms";t.shipments&&(t.shipments=t.shipments.map(a=>typeof a=="string"?{id:a}:{id:a.id}));const s={scan_form:t};return this._create(e,s)}static async all(t={}){return this._all("scan_forms",t)}static async getNextPage(t,e=null){return this._getNextPage("scan_forms","scan_forms",t,e)}static async retrieve(t){const e=`scan_forms/${t}`;return this._retrieve(e)}},te=r=>class extends l(r){static async create(t){const e="shipments",s={shipment:t};return this._create(e,s)}static async buy(t,e,s=null,a=null){let c=e;typeof e=="object"&&(c=e.id);const i=`shipments/${t}/buy`,o={rate:{id:c}};s&&(o.insurance=s),a&&(o.end_shipper_id=a);try{const d=await r._post(i,o);return this._convertToEasyPostObject(d.body,o)}catch(d){return Promise.reject(d)}}static async convertLabelFormat(t,e){const s=`shipments/${t}/label`,a={file_format:e};try{const c=await r._get(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async regenerateRates(t){const e=`shipments/${t}/rerate`,s={};try{const a=await r._post(e,s);return this._convertToEasyPostObject(a.body,s)}catch(a){return Promise.reject(a)}}static async getSmartRates(t){const e=`shipments/${t}/smartrate`;try{const s=await r._get(e);return this._convertToEasyPostObject(s.body.result)}catch(s){return Promise.reject(s)}}static async insure(t,e){const s=`shipments/${t}/insure`,a={amount:e};try{const c=await r._post(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async generateForm(t,e,s={}){const a=`shipments/${t}/forms`,c={form:{...s,type:e}};try{const i=await r._post(a,c);return this._convertToEasyPostObject(i.body,c)}catch(i){return Promise.reject(i)}}static async refund(t){const e=`shipments/${t}/refund`;try{const s=await r._post(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async lowestSmartRate(t,e,s){const a=await this.getSmartRates(t);return h.Utils.getLowestSmartRate(a,e,s.toLowerCase())}static async all(t={}){return this._all("shipments",t)}static async getNextPage(t,e=null){return this._getNextPage("shipments","shipments",t,e)}static async retrieve(t){const e=`shipments/${t}`;return this._retrieve(e)}static async retrieveEstimatedDeliveryDate(t,e){var c;const s=`shipments/${t}/smartrate/delivery_date`,a={planned_ship_date:e};try{const i=await r._get(s,a);return this._convertToEasyPostObject((c=i.body.rates)!=null?c:[],a)}catch(i){return Promise.reject(i)}}static async recommendShipDate(t,e){var c;const s=`shipments/${t}/smartrate/precision_shipping`,a={desired_delivery_date:e};try{const i=await r._get(s,a);return this._convertToEasyPostObject((c=i.body.rates)!=null?c:[],a)}catch(i){return Promise.reject(i)}}static async createAndBuyLuma(t){const e="shipments/luma",s={shipment:t};try{const a=await r._post(e,s);return this._convertToEasyPostObject(a.body,s)}catch(a){return Promise.reject(a)}}static async buyLuma(t,e){const s=`shipments/${t}/luma`;try{const a=await r._post(s,e);return this._convertToEasyPostObject(a.body,e)}catch(a){return Promise.reject(a)}}},ee=r=>class extends l(r){static async estimateDeliveryDate(t){const e="smartrate/deliver_by";try{const s=await r._post(e,t);return this._convertToEasyPostObject(s.body,t)}catch(s){return Promise.reject(s)}}static async recommendShipDate(t){const e="smartrate/deliver_on";try{const s=await r._post(e,t);return this._convertToEasyPostObject(s.body,t)}catch(s){return Promise.reject(s)}}},se=r=>class extends l(r){static async create(t){const e="trackers",s={tracker:t};return this._create(e,s)}static async all(t={}){return this._all("trackers",t)}static async getNextPage(t,e=null){return this._getNextPage("trackers","trackers",t,e)}static async retrieve(t){const e=`trackers/${t}`;return this._retrieve(e)}},re=r=>class extends l(r){static async create(t){const e="users",s={user:t};return this._create(e,s)}static async update(t,e){const s=`users/${t}`,a={user:e};try{const c=await r._patch(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async retrieve(t){const e=`users/${t}`;try{const s=await r._get(e);return this._convertToEasyPostObject(s.body)}catch(s){return Promise.reject(s)}}static async retrieveMe(){const t="users";try{const e=await r._get(t);return this._convertToEasyPostObject(e.body)}catch(e){return Promise.reject(e)}}static async delete(t){const e=`users/${t}`;try{return await r._delete(e),Promise.resolve()}catch(s){return Promise.reject(s)}}static async updateBrand(t,e){const s=`users/${t}/brand`,a={brand:e};try{const c=await r._patch(s,a);return this._convertToEasyPostObject(c.body,a)}catch(c){return Promise.reject(c)}}static async allChildren(t){const e="users/children";try{const s=await r._get(e,t);return this._convertToEasyPostObject(s.body,t)}catch(s){return Promise.reject(s)}}static async getNextPage(t,e=null){return this._getNextPage("users/children","children",t,e)}static async _getNextPage(t,e,s,a=null){var p,y,f;const c=s[e];if(c==null||c.length==0||!s.has_more)throw new w;const i=(y=(p=s._params)!=null?p:c[0]._params)!=null?y:{},o={...i,page_size:(f=i.page_size)!=null?f:a,after_id:c[c.length-1].id},d=await this._all(t,o);if(d==null||d[e].length==0)throw new w;return d}},ae=r=>class extends l(r){static async create(t){const e="webhooks",s={webhook:t};return this._create(e,s)}static async update(t,e){const s=`webhooks/${t}`;try{const a=await r._patch(s,e);return this._convertToEasyPostObject(a.body,e)}catch(a){return Promise.reject(a)}}static async delete(t){const e=`webhooks/${t}`;try{return await r._delete(e),Promise.resolve()}catch(s){return Promise.reject(s)}}static async all(t={}){return this._all("webhooks",t)}static async retrieve(t){const e=`webhooks/${t}`;return this._retrieve(e)}};class _{constructor(n,t={}){const{useProxy:e,timeout:s,baseUrl:a,superagentMiddleware:c,requestMiddleware:i}=t;if(!n&&!e)throw new wt({message:P.format(h.MISSING_REQUIRED_PARAMETER,"API Key")});this.key=n,this.timeout=s||_.DEFAULT_TIMEOUT,this.baseUrl=a||_.DEFAULT_BASE_URL,this.agent=k,this.requestMiddleware=i,this.requestHooks=[],this.responseHooks=[],this.Utils=new N,c&&(this.agent=c(this.agent)),this._attachServices(_.SERVICES)}addRequestHook(n){this.requestHooks=[...this.requestHooks,n]}removeRequestHook(n){this.requestHooks=this.requestHooks.filter(t=>t!==n)}clearRequestHooks(){this.requestHooks=[]}addResponseHook(n){this.responseHooks=[...this.responseHooks,n]}removeResponseHook(n){this.responseHooks=this.responseHooks.filter(t=>t!==n)}clearResponseHooks(){this.responseHooks=[]}static copyClient(n,t={}){const{apiKey:e,useProxy:s,timeout:a,baseUrl:c,superagentMiddleware:i,requestMiddleware:o}=t,d=i?i(n.agent):n.agent;return new _(e||n.key,{useProxy:s||n.useProxy,timeout:a||n.timeout,baseUrl:c||n.baseUrl,agent:d,requestMiddleware:o||n.requestMiddleware})}static _buildHeaders(n={}){return{..._.DEFAULT_HEADERS,...n}}_attachServices(n){Object.keys(n).forEach(t=>{this[t]=n[t](this)})}_buildPath(n=""){if(n.indexOf("http")===0)return n;let t=this.baseUrl+n;return t=n.includes("beta")?t.replace("/v2",""):t,t}_createResponseHooksValue(n,t){return{...n,httpStatus:t.status,responseBody:t.body,headers:t.headers,responseTimestamp:Date.now()}}async _request(n="",t=_.METHODS.GET,e={},s={}){const a=this._buildPath(n),c=_._buildHeaders(s);let i=this.agent[t](a).set(c);this.requestMiddleware&&(i=this.requestMiddleware(i)),this.key&&i.auth(this.key);const o=new URL(a);e!==void 0&&(t===_.METHODS.GET||t===_.METHODS.DELETE?(i.query(e),Object.entries(e).forEach(([p,y])=>{o.searchParams.append(p,y)})):i.send(e));const d={method:t,path:o.toString(),requestBody:i._data,headers:c,requestTimestamp:Date.now(),requestUUID:rt.v4()};this.requestHooks.forEach(p=>p(d));try{const p=await i;if(this.responseHooks.length>0){const y=this._createResponseHooksValue(d,p);this.responseHooks.forEach(f=>f(y))}return p}catch(p){if(p.response&&p.response.body){const y=this._createResponseHooksValue(d,p.response);throw this.responseHooks.forEach(f=>f(y)),Pt.handleApiError(p.response)}else throw p}}_get(n,t={},e={}){return this._request(n,_.METHODS.GET,t,e)}_post(n,t={},e={}){return this._request(n,_.METHODS.POST,t,e)}_put(n,t={},e={}){return this._request(n,_.METHODS.PUT,t,e)}_patch(n,t={},e={}){return this._request(n,_.METHODS.PATCH,t,e)}_delete(n,t={},e={}){return this._request(n,_.METHODS.DELETE,t,e)}}_.MS_SECOND=1e3;_.DEFAULT_TIMEOUT=60*_.MS_SECOND;_.DEFAULT_BASE_URL="https://api.easypost.com/v2/";_.DEFAULT_HEADERS={Accept:"application/json","Content-Type":"application/json","User-Agent":`EasyPost/v2 NodejsClient/${ct.version} Nodejs/${process.versions.node} OS/${g.platform()} OSVersion/${g.release()} OSArch/${g.arch()}`};_.METHODS={GET:"get",POST:"post",PUT:"put",PATCH:"patch",DELETE:"del"};_.SERVICES={Address:Tt,ApiKey:Ot,Batch:xt,BetaRate:Rt,BetaReferralCustomer:jt,Billing:kt,CarrierAccount:It,CarrierMetadata:Nt,CarrierType:$t,Claim:Dt,CustomsInfo:Ht,CustomsItem:Mt,EndShipper:Ut,Event:Lt,Insurance:Bt,Luma:qt,Order:Ft,Parcel:Ct,Pickup:Wt,Rate:Kt,ReferralCustomer:Yt,Refund:Xt,Report:Qt,ScanForm:Zt,Shipment:te,SmartRate:ee,Tracker:se,User:re,Webhook:ae};module.exports=_;
{
"name": "@easypost/api",
"description": "EasyPost Node Client Library",
"version": "8.1.0",
"version": "8.2.0",
"author": "Easypost Engineering <oss@easypost.com>",

@@ -9,5 +9,5 @@ "homepage": "https://easypost.com",

".": {
"types": "./types/index.d.ts",
"import": "./dist/easypost.mjs",
"require": "./dist/easypost.js",
"types": "./types/index.d.ts"
"require": "./dist/easypost.js"
}

@@ -14,0 +14,0 @@ },

@@ -25,2 +25,3 @@ import os from 'os';

import InsuranceService from './services/insurance_service';
import LumaService from './services/luma_service';
import OrderService from './services/order_service';

@@ -375,2 +376,3 @@ import ParcelService from './services/parcel_service';

Insurance: InsuranceService,
Luma: LumaService,
Order: OrderService,

@@ -377,0 +379,0 @@ Parcel: ParcelService,

@@ -249,3 +249,3 @@ import Constants from '../constants';

const params = {
const wrappedParams = {
planned_ship_date: plannedShipDate,

@@ -255,5 +255,5 @@ };

try {
const response = await easypostClient._get(url, params);
const response = await easypostClient._get(url, wrappedParams);
return this._convertToEasyPostObject(response.body.rates ?? [], params);
return this._convertToEasyPostObject(response.body.rates ?? [], wrappedParams);
} catch (e) {

@@ -273,3 +273,3 @@ return Promise.reject(e);

const params = {
const wrappedParams = {
desired_delivery_date: desiredDeliveryDate,

@@ -279,5 +279,5 @@ };

try {
const response = await easypostClient._get(url, params);
const response = await easypostClient._get(url, wrappedParams);
return this._convertToEasyPostObject(response.body.rates ?? [], params);
return this._convertToEasyPostObject(response.body.rates ?? [], wrappedParams);
} catch (e) {

@@ -287,2 +287,41 @@ return Promise.reject(e);

}
/**
* Create and buy a Luma Shipment in one call.
* @param {Object} params - The parameters to create and buy a Shipment with Luma.
* @returns {Shipment} - The shipment with the given ID.
*/
static async createAndBuyLuma(params) {
const url = `shipments/luma`;
const wrappedParams = {
shipment: params,
};
try {
const response = await easypostClient._post(url, wrappedParams);
return this._convertToEasyPostObject(response.body, wrappedParams);
} catch (e) {
return Promise.reject(e);
}
}
/**
* Buy a Shipment with Luma.
* @param {string} id - The ID of the Shipment to buy with Luma.
* @param {Object} params - The parameters to buy a Shipment with Luma.
* @returns {Shipment} - The shipment with the given ID.
*/
static async buyLuma(id, params) {
const url = `shipments/${id}/luma`;
try {
const response = await easypostClient._post(url, params);
return this._convertToEasyPostObject(response.body, params);
} catch (e) {
return Promise.reject(e);
}
}
};

Sorry, the diff of this file is too big to display