feathers-shippo
Version:
A Feathers JS adapter for the Shippo API
63 lines (62 loc) • 2.36 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShippoBatches = void 0;
const service_1 = require("../service");
// https://goshippo.com/docs/rate-limits/
const liveMinTimes = {
create: (0, service_1.calcMinTime)(50),
update: (0, service_1.calcMinTime)(50),
get: (0, service_1.calcMinTime)(400),
find: (0, service_1.calcMinTime)(50),
remove: (0, service_1.calcMinTime)(50)
};
const testMinTimes = {
create: (0, service_1.calcMinTime)(5),
update: (0, service_1.calcMinTime)(5),
get: (0, service_1.calcMinTime)(40),
find: (0, service_1.calcMinTime)(5),
remove: (0, service_1.calcMinTime)(50)
};
const shippoLimiters = (token) => {
const minTimes = token.startsWith('shippo_live')
? liveMinTimes
: testMinTimes;
return {
create: (0, service_1.shippoLimiter)('create', minTimes),
update: (0, service_1.shippoLimiter)('update', minTimes),
get: (0, service_1.shippoLimiter)('get', minTimes),
find: (0, service_1.shippoLimiter)('find', minTimes),
remove: (0, service_1.shippoLimiter)('remove', minTimes)
};
};
class ShippoBatches extends service_1.ShippoService {
constructor(options, app) {
options = Object.assign(Object.assign({ limiters: shippoLimiters(options.token) }, options), { path: 'batches', methods: ['get', 'create'] });
super(options, app);
}
_update(id, data, params) {
return this.schedule('create', () => {
return this.shippo
.post(`batches/${id}/add_shipments`, data, (0, service_1.axiosOpts)(params))
.then(this.handleResult)
.catch(this.handleError);
});
}
_patch(id, data, params) {
return this.schedule('create', () => {
return this.shippo
.post(`batches/${id}/remove_shipments`, data, (0, service_1.axiosOpts)(params))
.then(this.handleResult)
.catch(this.handleError);
});
}
_remove(id, params) {
return this.schedule('create', () => {
return this.shippo
.post(`batches/${id}/purchase`, (0, service_1.axiosOpts)(params))
.then(this.handleResult)
.catch(this.handleError);
});
}
}
exports.ShippoBatches = ShippoBatches;