postmen-ts
v0.0.10
Published
Typescript Postmen Wrapper
Downloads
3
Readme
postmen-ts
Postmen types for third-party use
Installing
Using npm:
$ npm install postmen-ts
Example Usage
import { CalculateRatesRequest, CalculateRatesResponse, Common, ShipperAccount, Shipment } from "postmen-ts";
import axios, { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
public Rate(shipment: any) {
return new Promise<any> ((resolve, reject) => {
const CalculateRatesRequest = {} as CalculateRatesRequest;
CalculateRatesRequest.async = false;
CalculateRatesRequest.is_document = false;
CalculateRatesRequest.ship_date = new Date().toISOString().slice(0, 10);
CalculateRatesRequest.shipment = this._mapShipment(shipment) as Shipment;
CalculateRatesRequest.shipper_accounts = this._getShipperAccounts() as ShipperAccount[];
this.axios.post(Common.Endpoint.Rates, CalculateRatesRequest)
.then((response: AxiosResponse) => {
const calculateRateResponse = response.data?.data as CalculateRatesResponse;
resolve(calculateRateResponse);
})
.catch((error: any) => {
reject(error);
});
});
}