@hybeck/aramex-api-js
Version:
Packages to manage all delivery apis in one palace with typescript
110 lines (109 loc) • 3.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.aramexTestCredentials = void 0;
exports.initializeAramexClient = initializeAramexClient;
exports.getAramexShippingCost = getAramexShippingCost;
exports.requestAramexDelivery = requestAramexDelivery;
exports.requestAramexReturn = requestAramexReturn;
exports.getAramexShipmentStatus = getAramexShipmentStatus;
exports.createAramexAddress = createAramexAddress;
exports.calculateAramexChargeableWeight = calculateAramexChargeableWeight;
const helper_1 = require("../helper");
let clientInfo = {};
let baseUrl = "";
// Initialize Aramex API client
function initializeAramexClient(config) {
baseUrl = config.sandbox
? "https://ws.dev.aramex.net/ShippingAPI.V2"
: "https://ws.aramex.net/ShippingAPI.V2";
clientInfo = {
UserName: config.username,
Password: config.password,
Version: "v2",
AccountNumber: config.accountNumber,
AccountPin: config.accountPin,
AccountEntity: config.accountEntity,
AccountCountryCode: config.accountCountryCode,
Source: 24,
};
}
// Get shipping cost
async function getAramexShippingCost(origin, destination, shipmentDetails) {
const payload = {
ClientInfo: clientInfo,
Transaction: null,
OriginAddress: origin,
DestinationAddress: destination,
ShipmentDetails: shipmentDetails,
};
return (0, helper_1.post)("RateCalculator/Service_1_0.svc/json/CalculateRate", payload, baseUrl);
}
// Request delivery
async function requestAramexDelivery(shipment, consignee, details) {
const payload = {
ClientInfo: clientInfo,
Transaction: null,
Shipments: [
{
...shipment,
Consignee: consignee,
Details: details,
},
],
};
return (0, helper_1.post)("Shipping/Service_1_0.svc/json/CreateShipments", payload, baseUrl);
}
// Request return
async function requestAramexReturn(shipment, consignee, details) {
const payload = {
ClientInfo: clientInfo,
Transaction: null,
Shipments: [
{
...shipment,
Consignee: consignee,
Details: details,
ShipmentType: "RTN",
},
],
};
return (0, helper_1.post)("Shipping/Service_1_0.svc/json/CreateShipments", payload, baseUrl);
}
// Get shipment status
async function getAramexShipmentStatus(shipmentNumbers) {
const payload = {
ClientInfo: clientInfo,
Transaction: null,
Shipments: shipmentNumbers,
};
return (0, helper_1.post)("Tracking/Service_1_0.svc/json/TrackShipments", payload, baseUrl);
}
// Test credentials
exports.aramexTestCredentials = {
username: "testingapi@aramex.com",
password: "R123456789$r",
accountNumber: "20016",
accountPin: "331421",
accountEntity: "AMM",
accountCountryCode: "JO",
sandbox: true,
};
// Create Address helper function
function createAramexAddress(address) {
return {
Line1: address.Line1 || "",
Line2: address.Line2 || "",
Line3: address.Line3 || "",
City: address.City || "",
StateOrProvinceCode: address.StateOrProvinceCode || "",
PostCode: address.PostCode || "",
CountryCode: address.CountryCode || "",
};
}
// Calculate chargeable weight
function calculateAramexChargeableWeight(dimensions, actualWeight) {
const dimensionalFactor = 5000;
const volumetricWeight = (dimensions.Length * dimensions.Width * dimensions.Height) /
dimensionalFactor;
return Math.max(actualWeight, volumetricWeight);
}