UNPKG

feathers-shippo

Version:

A Feathers JS adapter for the Shippo API

53 lines (52 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ShippoTracks = void 0; const errors_1 = require("@feathersjs/errors"); const service_1 = require("../service"); // https://goshippo.com/docs/rate-limits/ const liveMinTimes = { create: (0, service_1.calcMinTime)(500), update: (0, service_1.calcMinTime)(500), get: (0, service_1.calcMinTime)(500), find: (0, service_1.calcMinTime)(500), remove: (0, service_1.calcMinTime)(500) }; const testMinTimes = { create: (0, service_1.calcMinTime)(50), update: (0, service_1.calcMinTime)(50), get: (0, service_1.calcMinTime)(50), find: (0, service_1.calcMinTime)(50), 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 ShippoTracks extends service_1.ShippoService { constructor(options, app) { options = Object.assign(Object.assign({ limiters: shippoLimiters(options.token) }, options), { path: 'tracks', methods: ['get', 'create'] }); super(options, app); } _get(id, params) { var _a; if (!((_a = params === null || params === void 0 ? void 0 : params.query) === null || _a === void 0 ? void 0 : _a.carrier)) { throw new errors_1.BadRequest('params.query.carrier is required'); } const shippoParams = Object.assign(Object.assign({}, params), { query: Object.assign({}, params.query) }); const carrier = shippoParams.query.carrier; delete shippoParams.query.carrier; return this.resource .get(`${carrier}/${id}`, shippoParams) .then(this.handleResult) .catch(this.handleError); } } exports.ShippoTracks = ShippoTracks;