@arc-publishing/sdk-sales
Version:
JS Sales SDK for working with Arc Subs Sales API
37 lines • 1.71 kB
JavaScript
import { __assign, __awaiter, __generator } from "tslib";
import JSONResponseHandler from '@arc-publishing/sdk-subs-core/lib/utils/JSONResponseHandler';
import { isReedemCodeResponse } from './subscription';
import Sales from './sales';
import { headers, logPrefix } from './constants';
export default function shareSubscription(id, email) {
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/").concat(id, "/share"), {
method: 'PUT',
body: JSON.stringify({
email: email
}),
headers: __assign({ Authorization: "Bearer ".concat(Sales._Identity.userIdentity.accessToken) }, headers)
})
.then(JSONResponseHandler)
.then(function (json) {
if (isReedemCodeResponse(json)) {
return json;
}
else {
throw json;
}
})];
}
});
});
}
//# sourceMappingURL=shareSubscription.js.map