import bodyParser from "body-parser"; import express from "express"; import dotenv from "dotenv"; import cors from "cors"; import { CoreComplexClient, setServerURL } from "core-complex-client"; dotenv.config(); const app = express(); app.use(bodyParser.json({ limit: "30mb", extended: true })); app.use(bodyParser.urlencoded({ limit: "30mb", extended: true })); app.use(cors()); setServerURL(process.env.SERVER_URL); const coreClient = new CoreComplexClient({ rsaPublicKey: process.env.PUBLIC_KEY, privateKeyID: process.env.PRIVATE_KEY_ID, privateKey: process.env.PRIVATE_KEY, appID: process.env.APP_ID }); app.get("/healthCheck", (req, res) => { res.status(200).json("It works!"); }); //NAuth app.post("/nauth/changePassword", async (req, res) => { await coreClient.NAuth.changePassword({ newPassword: req.body.newPassword, oldPassword: req.body.oldPassword }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nauth/login", async (req, res) => { await coreClient.NAuth.login({ mail: req.body.mail, password: req.body.password }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nauth/mailVerify", async (req, res) => { await coreClient.NAuth.mailVerify({ hash: req.body.hash, code: req.body.code }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.get("/nauth/me", async (req, res) => { await coreClient.NAuth.me() .then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nauth/refreshToken", async (req, res) => { await coreClient.NAuth.refreshToken({ token: req.body.token }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nauth/register", async (req, res) => { await coreClient.NAuth.register({ isApproveContracts: req.body.isApproveContracts, phoneAreaCode: req.body.phoneAreaCode, firstName: req.body.firstName, password: req.body.password, lastName: req.body.lastName, userName: req.body.userName, language: req.body.language, phone: req.body.phone, mail: req.body.mail }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nauth/reSendCodeSMSOTP", async (req, res) => { await coreClient.NAuth.reSendCodeSMSOTP({ mail: req.body.mail }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nauth/resetNewPassword", async (req, res) => { await coreClient.NAuth.resetNewPassword({ newPassword: req.body.newPassword, mail: req.body.mail, code: req.body.code }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nauth/resetPasswordCheckCode", async (req, res) => { await coreClient.NAuth.resetPasswordCheckCode({ mail: req.body.mail, code: req.body.code }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nauth/smsOTP", async (req, res) => { await coreClient.NAuth.smsOTP({ mail: req.body.mail, code: req.body.code }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nauth/startMailVerify", async (req, res) => { await coreClient.NAuth.startMailVerify({ mail: req.body.mail }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nauth/startResetPassword", async (req, res) => { await coreClient.NAuth.startResetPassword({ mail: req.body.mail }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); //NChar app.post("/nchar/addPhoneNumber", async (req, res) => { await coreClient.NChar.addPhoneNumber({ phoneAreaCode: req.body.phoneAreaCode, phone: req.body.phone }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nchar/checkChangeMailCode", async (req, res) => { await coreClient.NChar.checkChangeMailCode({ mail: req.body.mail, code: req.body.code }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nchar/deletePhoneNumber", async (req, res) => { await coreClient.NChar.deletePhoneNumber({ phoneAreaCode: req.body.phoneAreaCode, phone: req.body.phone }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.get("/nchar/me", async (req, res) => { await coreClient.NChar.me() .then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nchar/setPrimaryPhoneNumber", async (req, res) => { await coreClient.NChar.setPrimaryPhoneNumber({ phoneAreaCode: req.body.phoneAreaCode, phone: req.body.phone }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nchar/startChangeMail", async (req, res) => { await coreClient.NChar.startChangeMail({ mail: req.body.mail }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.post("/nchar/changeUserName", async (req, res) => { await coreClient.NChar.changeUserName({ userName: req.body.userName }).then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); app.get("/nchar/getPastUserNameChanges", async (req, res) => { await coreClient.NChar.getPastUserNameChanges() .then((resp) => { res.status(200).json(resp); }).catch((err) => { console.log("err:", err) res.status(400).json("something-went-wrong"); }); }); const PORT = process.env.PORT || 5000; app.listen(PORT, () => { console.log("Server is running on port " + PORT); });