UNPKG

@arc-publishing/sdk-sales

Version:
41 lines 1.97 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 redeemGiftSubscription(token) { 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/v1/subscription/gift/redeem"), { method: 'POST', body: JSON.stringify({ token: token }), 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) { if (isSubscriptionIDResponse(json)) { return [2, json]; } else { throw json; } return [2]; }); }); })]; } }); }); } //# sourceMappingURL=redeemGiftSubscription.js.map