@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
91 lines • 4.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.declineDeleteAccount = exports.approveDeleteAccount = void 0;
var tslib_1 = require("tslib");
var APIErrorResponse_1 = require("../serviceHelpers/APIErrorResponse");
var JSONResponseHandler_1 = tslib_1.__importDefault(require("../serviceHelpers/JSONResponseHandler"));
var logout_1 = require("../sdk/logout");
var identity_1 = tslib_1.__importDefault(require("./identity"));
var constants_1 = require("./constants");
function requestDeleteAccount() {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var isLoggedIn;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, identity_1.default.isLoggedIn()];
case 1:
isLoggedIn = _a.sent();
if (!isLoggedIn) {
throw new Error("".concat(constants_1.logPrefix, " Missing or invalid jwt"));
}
return [2, fetch("".concat(identity_1.default.apiOrigin, "/identity/public/v1/user/anonymize"), {
method: 'DELETE',
headers: tslib_1.__assign({ Authorization: "Bearer ".concat(identity_1.default.userIdentity.accessToken) }, constants_1.headers)
})
.then(JSONResponseHandler_1.default)
.then(function (json) {
if ((0, APIErrorResponse_1.isAPIErrorResponse)(json)) {
throw json;
}
else {
return json;
}
})];
}
});
});
}
exports.default = requestDeleteAccount;
function approveDeleteAccount(nonce) {
return identity_1.default.heartbeat()
.then(function () {
return fetch("".concat(identity_1.default.apiOrigin, "/identity/public/v1/user/anonymize/approve/").concat(nonce), {
method: 'PUT',
headers: tslib_1.__assign({ Authorization: "Bearer ".concat(identity_1.default.userIdentity.accessToken) }, constants_1.headers),
body: JSON.stringify({})
});
})
.then(JSONResponseHandler_1.default)
.then(function (json) {
if ((0, APIErrorResponse_1.isAPIErrorResponse)(json)) {
throw json;
}
else {
identity_1.default.clearSession();
(0, logout_1.dispatchLogoutEvent)();
return json;
}
});
}
exports.approveDeleteAccount = approveDeleteAccount;
function declineDeleteAccount(nonce, reason) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var isLoggedIn;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, identity_1.default.isLoggedIn()];
case 1:
isLoggedIn = _a.sent();
if (!isLoggedIn) {
throw new Error("".concat(constants_1.logPrefix, " Missing or invalid jwt"));
}
return [2, fetch("".concat(identity_1.default.apiOrigin, "/identity/public/v1/user/anonymize/decline/").concat(nonce), {
method: 'PUT',
headers: tslib_1.__assign({ Authorization: "Bearer ".concat(identity_1.default.userIdentity.accessToken) }, constants_1.headers),
body: JSON.stringify({ reason: reason })
})
.then(JSONResponseHandler_1.default)
.then(function (json) {
if ((0, APIErrorResponse_1.isAPIErrorResponse)(json)) {
throw json;
}
else {
return json;
}
})];
}
});
});
}
exports.declineDeleteAccount = declineDeleteAccount;
//# sourceMappingURL=requestDeleteAccount.js.map