UNPKG

@arc-publishing/sdk-sales

Version:
39 lines 1.96 kB
import { __assign, __awaiter, __generator, __rest } from "tslib"; import JSONResponseHandler from '@arc-publishing/sdk-subs-core/lib/utils/JSONResponseHandler'; import Sales from './sales'; import { headers, logPrefix } from './constants'; import { mergeSubscriptions } from './utils'; export default function getAllActiveSubscriptions() { 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/subscription/allactive"), { method: 'GET', headers: __assign({ Authorization: "Bearer ".concat(Sales._Identity.userIdentity.accessToken) }, headers) }) .then(JSONResponseHandler) .then(function (json) { if (Array.isArray(json)) { var subs = json.map(function (_a) { var statusID = _a.statusID, sub = __rest(_a, ["statusID"]); return (__assign(__assign({}, sub), { status: statusID })); }); Sales.subscriptions = mergeSubscriptions(Sales.subscriptions, subs); return subs; } else { throw json; } })]; } }); }); } //# sourceMappingURL=getAllActiveSubscriptions.js.map