chayns-components
Version:
A set of beautiful React components for developing chayns® applications.
83 lines (81 loc) • 2.46 kB
JavaScript
;
exports.__esModule = true;
exports.putUserSignature = exports.getUserSignature = exports.deleteUserSignature = void 0;
const SERVER_URL = 'https://webapi.tobit.com/AccountService/v1.0/General/PersonKeyValue/signature';
const getUserSignature = async () => {
if (!chayns.env.user.isAuthenticated) {
return null;
}
try {
const response = await fetch(SERVER_URL, {
method: 'GET',
headers: {
accept: 'application/json',
authorization: `bearer ${chayns.env.user.tobitAccessToken}`
}
});
if (response.status === 200) {
const {
value
} = await response.json();
return value;
}
if (response.status === 204) {
return null;
}
console.error('[chayns components] Signature: failed to get user signature', response.status);
} catch (ex) {
console.error('[chayns components] Signature: failed to get user signature', ex);
}
return null;
};
exports.getUserSignature = getUserSignature;
const putUserSignature = async dataURL => {
if (!chayns.env.user.isAuthenticated) {
return false;
}
try {
const response = await fetch(SERVER_URL, {
method: 'PUT',
headers: {
accept: 'application/json',
authorization: `bearer ${chayns.env.user.tobitAccessToken}`,
'content-type': 'application/json'
},
body: JSON.stringify({
value: dataURL
})
});
if (response.ok) {
return true;
}
console.error('[chayns components] Signature: failed to put user signature', response.status);
} catch (ex) {
console.error('[chayns components] Signature: failed to put user signature', ex);
}
return false;
};
exports.putUserSignature = putUserSignature;
const deleteUserSignature = async () => {
if (!chayns.env.user.isAuthenticated) {
return false;
}
try {
const response = await fetch(SERVER_URL, {
method: 'DELETE',
headers: {
accept: 'application/json',
authorization: `bearer ${chayns.env.user.tobitAccessToken}`
}
});
if (response.ok || response.status === 304) {
return true;
}
console.error('[chayns components] Signature: failed to delete user signature', response.status);
} catch (ex) {
console.error('[chayns components] Signature: failed to delete user signature', ex);
}
return false;
};
exports.deleteUserSignature = deleteUserSignature;
//# sourceMappingURL=signature.js.map