ggez-banking-sdk
Version:
A Node.js package to handle GGEZ Banking API endpoints, Simplify the process of managing CRUD operations with this efficient and easy-to-use package.
272 lines (271 loc) • 10.7 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSecurity = void 0;
const dataStructure_1 = __importDefault(require("../helper/dataStructure"));
const restApi_1 = __importDefault(require("../restApi"));
const helper_1 = __importDefault(require("../helper"));
const useSecurity = (token, userInfo, userId, baseUrl, geoCoordinates, lang) => {
const { dataSecurity } = (0, dataStructure_1.default)();
const { checkResponse, headerConfig } = (0, helper_1.default)(userInfo);
const { checkGlobalResponse } = checkResponse();
const { changeDataSecurityCode, resetDataPassword, resetDataQuestion, updateDataUserPreferences, dataValidateSecurityCode, dataEnrollGoogleAuth, dataActivateGoogleAuth, dataDeleteGoogleAuth, } = dataSecurity();
const headerConfigSecurity = () => {
let headersData = {
header: true,
isUrlEncoded: false,
token: token,
lang: lang,
};
let headers = headerConfig(headersData);
return headers;
};
const ResetPassword = async (values) => {
let data = resetDataPassword({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/security/reset/${userId}`, headerConfigSecurity(), data);
let { newUserInfo } = checkGlobalResponse("password", response, "ResetPassword", "reset");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Password Changed Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const ResetSecurityQuestions = async (values) => {
let data = resetDataQuestion({ ...values, geoCoordinates: geoCoordinates });
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/security/reset/${userId}`, headerConfigSecurity(), data);
let { newUserInfo } = checkGlobalResponse("security", response, "ResetSecurityQuestions", "resetQuestions");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Questions Changed Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const ChangeUserSecurityCode = async (values) => {
let data = changeDataSecurityCode({
...values,
geoCoordinates: geoCoordinates,
});
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/security/reset/${userId}`, headerConfigSecurity(), data);
let { newUserInfo } = checkGlobalResponse("security", response, "ChangeUserSecurityCode", "resetSecurityCode");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ??
"User Security Code Changed Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const UpdateUserPreferences = async (values) => {
let data = updateDataUserPreferences({
...values,
geoCoordinates: geoCoordinates,
});
try {
const response = await restApi_1.default.restApi(baseUrl, "PUT", `v1/user/preferences/${userId}`, { ...headerConfigSecurity(), language: values.preferredLanguageCode }, data);
let { newUserInfo } = checkGlobalResponse("preferences", response, "UpdateUserPreferences", "updateObjectInfo");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Preference Updated Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const ValidateSecurityCode = async (values) => {
let data = dataValidateSecurityCode({
...values,
geoCoordinates: geoCoordinates,
});
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/security/validate/${userId}`, headerConfigSecurity(), data);
let { newUserInfo } = checkGlobalResponse("securityCode", response, "ValidateSecurityCode");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "Message send successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
/** Authentication Google */
const EnrollGoogleAuth = async () => {
let data = dataEnrollGoogleAuth();
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/auth/enroll/${userId}`, headerConfigSecurity(), data);
let { newUserInfo } = checkGlobalResponse("authentication_data", response, "EnrollGoogleAuth", "update");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ?? "User Enrolled successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const ActivateGoogleAuth = async (values) => {
let data = dataActivateGoogleAuth({
...values,
geoCoordinates: geoCoordinates,
});
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/auth/activate/${userId}`, headerConfigSecurity(), data);
let { newUserInfo } = checkGlobalResponse("authentication_data", response, "ActivateGoogleAuth", "create");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ??
"Account Authentication Activated successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const deActivateGoogleAuth = async (values) => {
let data = dataActivateGoogleAuth({
...values,
geoCoordinates: geoCoordinates,
});
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/auth/deactivate/${userId}`, headerConfigSecurity(), data);
let { newUserInfo } = checkGlobalResponse("authentication_data", response, "deActivateGoogleAuth", "update");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ??
"Account Authentication deactivated successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const deleteGoogleAuth = async (values) => {
let data = dataDeleteGoogleAuth({
...values,
geoCoordinates: geoCoordinates,
});
try {
const response = await restApi_1.default.restApi(baseUrl, "POST", `v1/user/auth/delete/${userId}`, headerConfigSecurity(), data);
let { newUserInfo } = checkGlobalResponse("authentication_data", response, "deleteGoogleAuth", "delete");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ??
"Account authentication deleted successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
const GetSecurityOperation = async () => {
try {
const response = await restApi_1.default.restApi(baseUrl, "GET", `v1/user/activity/${userId}`, headerConfigSecurity());
let { newUserInfo } = checkGlobalResponse("activity", response, "GetSecurityOperation", "get");
return {
response: response,
newUser: newUserInfo,
message: response?.data?.result?.message ??
"Get Security Operation Successfully",
status: "success",
};
}
catch (error) {
return {
response: error.response,
newUser: null,
message: error.message,
status: "failed",
};
}
};
return {
ResetPassword,
ResetSecurityQuestions,
ChangeUserSecurityCode,
UpdateUserPreferences,
ValidateSecurityCode,
EnrollGoogleAuth,
ActivateGoogleAuth,
deActivateGoogleAuth,
deleteGoogleAuth,
GetSecurityOperation,
};
};
exports.useSecurity = useSecurity;