@arc-publishing/sdk-sales
Version:
JS Sales SDK for working with Arc Subs Sales API
43 lines • 2.18 kB
JavaScript
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 redeemAssociateInvitation(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/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) {
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=redeemAssociateInvitation.js.map