import axios from "axios"; import { BASE_URL } from "../core/env"; import { consoleLogger } from "../core/logger"; import { hashAPIPath } from "../core/hash"; const buildHashedQueryUrl = async (queryUrl) => { try { const signRes = await axios.get( "/api/endpoint/gethash_api?path=" + encodeURIComponent(queryUrl) ); if (!signRes?.data?.hash) { throw new Error("Hash signature unavailable"); } return queryUrl + signRes.data.hash; } catch (error) { if (typeof window === "undefined" && process.env.HASHKEY) { return queryUrl + hashAPIPath(queryUrl); } throw error; } }; export const getPersonalAccount = (contactid) => { return axios .get( BASE_URL + "/api/endpoint/getpersonalaccount_api?contactid=" + contactid ) .then((res) => { return res.data; }) .catch((error) => { consoleLogger(error); }); }; export const getLogin = (emailAddress, pwd) => { return axios .get( "/api/endpoint/getlogin_api?emailAddress=" + emailAddress + "&pwd=" + pwd ) .then((res) => res.data) .catch((error) => { consoleLogger(error); }); }; export const updatePassword = (contactId, newpassword) => { var queryUrl = "/api/endpoint/updateaccount_api?contactId=" + contactId; var data = { "pinswg_custom_password": newpassword }; var config = { method: "post", url: queryUrl, data: data }; return axios(config) .then((res) => { return res.data; }) .catch((error) => { consoleLogger(error); }); }; export const updateAccount = async (contactId, updateBody, ssr) => { var queryUrl = (ssr ? BASE_URL : "") + "/api/endpoint/updateaccount_api?contactId=" + contactId; var data = updateBody; var config = { method: "post", url: queryUrl, data: data }; return axios(config) .then((res) => { return res.data; }) .catch((error) => { consoleLogger(error); }); }; export const createAccount = (formValues) => { var data = formValues; var queryUrl = "/api/endpoint/createaccount_api"; var config = { method: "post", url: queryUrl, data: data }; return axios(config) .then((res) => { return res.data; }) .catch((error) => { consoleLogger(error); }); }; export const getEmailAccountCheck = (emailAddress) => { return axios .get( "/api/endpoint/getemailaccountcheck_api?emailAddress=" + emailAddress ) .then((res) => res.data) .catch((error) => { consoleLogger(error); }); }; export const getPortalLogin = async (emailAddress) => { var queryUrl = "/api/endpoint/getportallogin_api?emailAddress=" + emailAddress; return axios .get(BASE_URL + (await buildHashedQueryUrl(queryUrl))) .then((res) => res.data) .catch((error) => { consoleLogger(error); return JSON.stringify(error); }); }; export const getPortalLoginProxy = async (emailAddress) => { var queryUrl = "/api/endpoint/getportalloginproxy_api?emailAddress=" + emailAddress; return axios .get(queryUrl) .then((res) => res.data) .catch((error) => { consoleLogger(error); return JSON.stringify(error); }); }; export const getPreferredLanguage = async (email) => { return axios .get( BASE_URL + "/api/endpoint/getpreferredlanguage_api?emailAddress=" + email ) .then((res) => { return res.data; }) .catch((error) => { consoleLogger(error); return error.response; }); };