Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
run({ apiKey }) {
const shippoObj = new Shippo(apiKey);
shippoObj.set("version", "2016-10-25");
let allCarriers = [];
// recursively fetch carriers because shippo returns paginated results
function fetchCarriers() {
try {
const response = Meteor.wrapAsync(shippoObj.carrieraccount.list, shippoObj.carrieraccount)();
allCarriers = allCarriers.concat(response.results);
if (!response.next) {
response.results = allCarriers;
return response;
}
// the Shippo module uses "createFullPath" to form the url for the request
// https://github.com/goshippo/shippo-node-client/blob/master/lib/Resource.js#L40-L48
// hence we're passing the next url in this way
run({ apiKey }) {
const shippoObj = new Shippo(apiKey);
shippoObj.set("version", "2016-10-25");
const getAddressListFiber = Meteor.wrapAsync(shippoObj.address.list, shippoObj.address);
try {
const addressList = getAddressListFiber();
return addressList;
} catch (error) {
Logger.error(error.message);
throw new Meteor.Error("server-error", error.message);
}
}
});
run({ rateId, apiKey }) {
const shippoObj = new Shippo(apiKey);
shippoObj.set("version", "2016-10-25");
const createTransactionFiber = Meteor.wrapAsync(shippoObj.transaction.create, shippoObj.transaction);
try {
const transaction = createTransactionFiber({
rate: rateId,
label_file_type: "PDF",
async: false
});
if (transaction.object_status !== "SUCCESS") {
const error = transaction.messages[0].text;
Logger.error(error);
throw new Meteor.Error("server-error", error);
}
run({ shippoAddressFrom, shippoAddressTo, shippoParcel, purpose, apiKey, carrierAccounts }) {
const shippoObj = new Shippo(apiKey);
shippoObj.set("version", "2016-10-25");
const createShipmentFiber = Meteor.wrapAsync(shippoObj.shipment.create, shippoObj.shipment);
try {
const shipment = createShipmentFiber({
object_purpose: purpose,
address_from: shippoAddressFrom,
address_to: shippoAddressTo,
parcel: shippoParcel,
carrier_accounts: carrierAccounts,
async: false
});
return shipment;
} catch (error) {
Logger.error(error.message);