feathers-shippo
Version:
A Feathers JS adapter for the Shippo API
29 lines (28 loc) • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShippoRates = void 0;
const errors_1 = require("@feathersjs/errors");
const service_1 = require("../service");
class ShippoRates extends service_1.ShippoService {
constructor(options, app) {
options = Object.assign(Object.assign({ limiters: (0, service_1.shippoLimiters)(options.token) }, options), { path: 'rates', methods: ['get', 'find'] });
super(options, app);
}
_find(params) {
var _a, _b;
if (!((_a = params === null || params === void 0 ? void 0 : params.query) === null || _a === void 0 ? void 0 : _a.shipment) || !((_b = params === null || params === void 0 ? void 0 : params.query) === null || _b === void 0 ? void 0 : _b.rates)) {
throw new errors_1.BadRequest('params.query.shipment and params.query.rates are required for Shippo rates');
}
const shippoParams = Object.assign(Object.assign({}, params), { query: Object.assign({}, params.query) });
delete shippoParams.query.shipment;
delete shippoParams.query.rates;
return this.schedule('get', () => {
var _a, _b;
return this.shippo
.get(`shipments/${(_a = params === null || params === void 0 ? void 0 : params.query) === null || _a === void 0 ? void 0 : _a.shipment}/rates/${(_b = params === null || params === void 0 ? void 0 : params.query) === null || _b === void 0 ? void 0 : _b.rates}`, (0, service_1.axiosOpts)(shippoParams))
.then(this.handleResult)
.catch(this.handleError);
});
}
}
exports.ShippoRates = ShippoRates;