UNPKG

@arc-publishing/sdk-sales

Version:
43 lines 2.19 kB
import { __assign, __awaiter, __generator } from "tslib"; import JSONResponseHandler from '@arc-publishing/sdk-subs-core/lib/utils/JSONResponseHandler'; import { isSubscriptionIDResponse } from './subscription'; import Sales from './sales'; import { headers, logPrefix } from './constants'; export default function redeemEnterpriseSubscription(nonce) { return __awaiter(this, void 0, void 0, function () { var isLoggedIn; var _this = this; 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/v2/subscriptions/enterprise"), { method: 'POST', body: JSON.stringify({ nonce: nonce }), headers: __assign({ Authorization: "Bearer ".concat(Sales._Identity.userIdentity.accessToken) }, headers) }) .then(JSONResponseHandler) .then(function (json) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: if (!isSubscriptionIDResponse(json)) return [3, 2]; return [4, Sales.getSubscriptionDetails(json.subscriptionID)]; case 1: _a.sent(); return [2, json]; case 2: throw json; } }); }); })]; } }); }); } //# sourceMappingURL=redeemEnterpriseSubscription.js.map