@arc-publishing/sdk-sales
Version:
JS Sales SDK for working with Arc Subs Sales API
40 lines • 1.98 kB
JavaScript
import { __assign, __awaiter, __generator } from "tslib";
import JSONResponseHandler from '@arc-publishing/sdk-subs-core/lib/utils/JSONResponseHandler';
import { isPaginatedOrders } from './order';
import Sales from './sales';
import { headers, logPrefix } from './constants';
import { mergeOrders } from './utils';
export default function getOrderHistory(start, pageSize, options) {
if (start === void 0) { start = 0; }
if (pageSize === void 0) { pageSize = 10; }
if (options === void 0) { options = {}; }
return __awaiter(this, void 0, void 0, function () {
var isLoggedIn;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, Sales._Identity.isLoggedIn()];
case 1:
isLoggedIn = _a.sent();
if (!isLoggedIn) {
throw new Error("".concat(logPrefix, " Missing or invalid jwt"));
}
return [2, fetch("".concat(Sales.apiOrigin, "/sales/public/v1/order/history?pageSize=").concat(pageSize, "&start=").concat(start).concat(options.status ? "&status=".concat(options.status) : ''), {
method: 'GET',
cache: 'no-cache',
headers: __assign({ Authorization: "Bearer ".concat(Sales._Identity.userIdentity.accessToken) }, headers)
})
.then(JSONResponseHandler)
.then(function (json) {
if (isPaginatedOrders(json)) {
Sales.orders = mergeOrders(Sales.orders, json.orders);
return json;
}
else {
throw json;
}
})];
}
});
});
}
//# sourceMappingURL=getOrderHistory.js.map