paccurate
Version:
Reduce fulfillment costs and wasted material by finding the optimal way to pack every shipment, in real time.
32 lines • 844 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.post = post;
const node_fetch_1 = require("node-fetch");
class ResponseError extends Error {
constructor(code, message) {
super(message);
this.code = code;
}
}
const method = 'POST';
/**
* Sends a post request to Paccurate API.
*
* @param url - API endpoint.
* @param body - Packing configuration.
* @param options - Request options.
* @returns - Pack response.
*/
async function post(url, body, options) {
const response = await (0, node_fetch_1.default)(url, {
body: JSON.stringify(body),
method,
...options,
});
const data = await response.json();
if (response.ok) {
return data;
}
throw new ResponseError(data.code, data.message);
}
//# sourceMappingURL=request.js.map