ref(frontend): add ~/const path

This commit is contained in:
이강준
2022-11-27 16:12:25 +09:00
parent 2729b409e6
commit 66d2a2724e
59 changed files with 1077 additions and 1086 deletions
+67 -67
View File
@@ -1,85 +1,85 @@
import { useEffect,useState } from "react"; import { useEffect, useState } from "react";
import Image from "next/image"; import Image from "next/image";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import checkAuth from "~/pages/api/auth/CheckAuth"; import checkAuth from "~/pages/api/auth/CheckAuth";
import { publicPaths } from "../const"; import { publicPaths } from "~/const";
// #TODO: finish spinner only when the data loads fully // #TODO: finish spinner only when the data loads fully
// #TODO: Redirect somewhere if the page does not exist // #TODO: Redirect somewhere if the page does not exist
export default function RouteGuard({ children }) { export default function RouteGuard({ children }) {
const router = useRouter(); const router = useRouter();
const [authorized, setAuthorized] = useState(false); const [authorized, setAuthorized] = useState(false);
useEffect(() => { useEffect(() => {
// on initial load - run auth check // on initial load - run auth check
(async () => { (async () => {
await authCheck(router.asPath); await authCheck(router.asPath);
})(); })();
// on route change start - hide page content by setting authorized to false // on route change start - hide page content by setting authorized to false
// #TODO: add the loading page when not yet authorized. // #TODO: add the loading page when not yet authorized.
const hideContent = () => setAuthorized(false); const hideContent = () => setAuthorized(false);
// const onError = () => setAuthorized(true) // const onError = () => setAuthorized(true)
router.events.on("routeChangeStart", hideContent); router.events.on("routeChangeStart", hideContent);
// router.events.on("routeChangeError", onError); // router.events.on("routeChangeError", onError);
// on route change complete - run auth check // on route change complete - run auth check
router.events.on("routeChangeComplete", authCheck); router.events.on("routeChangeComplete", authCheck);
// unsubscribe from events in useEffect return function // unsubscribe from events in useEffect return function
return () => { return () => {
router.events.off("routeChangeStart", hideContent); router.events.off("routeChangeStart", hideContent);
router.events.off("routeChangeComplete", authCheck); router.events.off("routeChangeComplete", authCheck);
// router.events.off("routeChangeError", onError); // router.events.off("routeChangeError", onError);
}; };
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);
/** /**
* redirect to login page if accessing a private page and not logged in * redirect to login page if accessing a private page and not logged in
* @param {*} url - the url of the page we are trying to go to * @param {*} url - the url of the page we are trying to go to
*/ */
async function authCheck(url) { async function authCheck(url) {
// Make sure that we don't redirect when the user is on the following pages. // Make sure that we don't redirect when the user is on the following pages.
const path = "/" + url.split("?")[0].split("/")[1]; const path = "/" + url.split("?")[0].split("/")[1];
// Check if the user is authenticated // Check if the user is authenticated
const response = await checkAuth(); const response = await checkAuth();
// #TODO: figure our why sometimes it doesn't output a response // #TODO: figure our why sometimes it doesn't output a response
if (!publicPaths.includes(path)) { if (!publicPaths.includes(path)) {
try { try {
if (response.status !== 200) { if (response.status !== 200) {
router.push("/login"); router.push("/login");
console.log("Unauthorized to access."); console.log("Unauthorized to access.");
setAuthorized(false); setAuthorized(false);
} else { } else {
setAuthorized(true); setAuthorized(true);
console.log("Authorized to access."); console.log("Authorized to access.");
} }
} catch (error) { } catch (error) {
console.log( console.log(
"Error (probably the authCheck route is stuck again...):", "Error (probably the authCheck route is stuck again...):",
error error
); );
} }
} }
} }
if (authorized) { if (authorized) {
return children; return children;
} else { } else {
return ( return (
<div className="w-screen h-screen bg-bunker-800 flex items-center justify-center"> <div className="w-screen h-screen bg-bunker-800 flex items-center justify-center">
<Image <Image
src="/images/loading/loading.gif" src="/images/loading/loading.gif"
height={70} height={70}
width={120} width={120}
alt="google logo" alt="google logo"
></Image> ></Image>
</div> </div>
); );
} }
} }
+18 -18
View File
@@ -1,28 +1,28 @@
import token from "~/pages/api/auth/Token"; import token from "~/pages/api/auth/Token";
import { PATH } from "../../const"; import { PATH } from "~/const";
export default class SecurityClient { export default class SecurityClient {
static authOrigins = [PATH]; static authOrigins = [PATH];
static #token = ""; static #token = "";
contructor() {} contructor() {}
static setToken(token) { static setToken(token) {
this.#token = token; this.#token = token;
} }
static async fetchCall(resource, options) { static async fetchCall(resource, options) {
let req = new Request(resource, options); let req = new Request(resource, options);
const destOrigin = new URL(req.url).origin; const destOrigin = new URL(req.url).origin;
if (this.#token == "") { if (this.#token == "") {
this.setToken(await token()); this.setToken(await token());
} }
if (this.#token && this.authOrigins.includes(destOrigin)) { if (this.#token && this.authOrigins.includes(destOrigin)) {
req.headers.set("Authorization", "Bearer " + this.#token); req.headers.set("Authorization", "Bearer " + this.#token);
return fetch(req); return fetch(req);
} }
} }
} }
+3
View File
@@ -8,6 +8,9 @@
"~/utilities/*": [ "~/utilities/*": [
"components/utilities/*" "components/utilities/*"
], ],
"~/*": [
"const"
],
"~/pages/*": [ "~/pages/*": [
"pages/*" "pages/*"
], ],
+33 -33
View File
@@ -7,7 +7,7 @@ import Layout from "~/components/basic/layout";
import RouteGuard from "~/components/RouteGuard"; import RouteGuard from "~/components/RouteGuard";
import { ENV } from "~/utilities/config"; import { ENV } from "~/utilities/config";
import { publicPaths } from "../const.js"; import { publicPaths } from "~/const";
import "@fortawesome/fontawesome-svg-core/styles.css"; import "@fortawesome/fontawesome-svg-core/styles.css";
import "../styles/globals.css"; import "../styles/globals.css";
@@ -15,49 +15,49 @@ import "../styles/globals.css";
config.autoAddCss = false; config.autoAddCss = false;
const App = ({ Component, pageProps, ...appProps }) => { const App = ({ Component, pageProps, ...appProps }) => {
const router = useRouter(); const router = useRouter();
const posthog = initPostHog(); const posthog = initPostHog();
useEffect(() => { useEffect(() => {
// Init for auto capturing // Init for auto capturing
const posthog = initPostHog(); const posthog = initPostHog();
const handleRouteChange = () => { const handleRouteChange = () => {
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
if (ENV == "production") { if (ENV == "production") {
posthog.capture("$pageview"); posthog.capture("$pageview");
} }
} }
}; };
router.events.on("routeChangeComplete", handleRouteChange); router.events.on("routeChangeComplete", handleRouteChange);
return () => { return () => {
router.events.off("routeChangeComplete", handleRouteChange); router.events.off("routeChangeComplete", handleRouteChange);
}; };
}, [router.events]); }, [router.events]);
// If it's one of these routes, don't add the layout (e.g., these routes are external) // If it's one of these routes, don't add the layout (e.g., these routes are external)
if ( if (
publicPaths.includes("/" + appProps.router.pathname.split("/")[1]) || publicPaths.includes("/" + appProps.router.pathname.split("/")[1]) ||
!Component.requireAuth !Component.requireAuth
) { ) {
return <Component {...pageProps} />; return <Component {...pageProps} />;
} }
return ( return (
<RouteGuard> <RouteGuard>
<Layout> <Layout>
<Component {...pageProps} /> <Component {...pageProps} />
</Layout> </Layout>
</RouteGuard> </RouteGuard>
); );
}; };
export default App; export default App;
{ {
/* <Script /* <Script
src="https://www.googletagmanager.com/gtag/js?id=G-DQ1XLJJGG1" src="https://www.googletagmanager.com/gtag/js?id=G-DQ1XLJJGG1"
strategy="afterInteractive" strategy="afterInteractive"
/> />
+27 -27
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This is the second step of the change password process (pake) * This is the second step of the change password process (pake)
@@ -8,33 +8,33 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const changePassword2 = ({ const changePassword2 = ({
encryptedPrivateKey, encryptedPrivateKey,
iv, iv,
tag, tag,
salt, salt,
verifier, verifier,
clientProof, clientProof,
}) => { }) => {
return SecurityClient.fetchCall(PATH + "/api/v1/password/change-password", { return SecurityClient.fetchCall(PATH + "/api/v1/password/change-password", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
clientProof: clientProof, clientProof: clientProof,
encryptedPrivateKey: encryptedPrivateKey, encryptedPrivateKey: encryptedPrivateKey,
iv: iv, iv: iv,
tag: tag, tag: tag,
salt: salt, salt: salt,
verifier: verifier, verifier: verifier,
}), }),
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to change the password"); console.log("Failed to change the password");
} }
}); });
}; };
export default changePassword2; export default changePassword2;
+13 -13
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient.js"; import SecurityClient from "~/utilities/SecurityClient.js";
import { PATH } from "../../../const.js"; import { PATH } from "~/const";
/** /**
* This function is used to check if the user is authenticated. * This function is used to check if the user is authenticated.
@@ -10,18 +10,18 @@ import { PATH } from "../../../const.js";
* @returns * @returns
*/ */
const checkAuth = async (req, res) => { const checkAuth = async (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/auth/checkAuth", { return SecurityClient.fetchCall(PATH + "/api/v1/auth/checkAuth", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}).then((res) => { }).then((res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Not authorized"); console.log("Not authorized");
} }
}); });
}; };
export default checkAuth; export default checkAuth;
@@ -1,4 +1,4 @@
import { PATH } from "../../../const.js"; import { PATH } from "~/const";
/** /**
* This route check the verification code from the email that user just recieved * This route check the verification code from the email that user just recieved
@@ -7,16 +7,16 @@ import { PATH } from "../../../const.js";
* @returns * @returns
*/ */
const checkEmailVerificationCode = (email, code) => { const checkEmailVerificationCode = (email, code) => {
return fetch(PATH + "/api/v1/signup/email/verify", { return fetch(PATH + "/api/v1/signup/email/verify", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,
code: code, code: code,
}), }),
}); });
}; };
export default checkEmailVerificationCode; export default checkEmailVerificationCode;
@@ -1,4 +1,4 @@
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This function is called in the end of the signup process. * This function is called in the end of the signup process.
@@ -16,37 +16,37 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const completeAccountInformationSignup = ({ const completeAccountInformationSignup = ({
email, email,
firstName, firstName,
lastName, lastName,
organizationName, organizationName,
publicKey, publicKey,
ciphertext, ciphertext,
iv, iv,
tag, tag,
salt, salt,
verifier, verifier,
token token,
}) => { }) => {
return fetch(PATH + "/api/v1/signup/complete-account/signup", { return fetch(PATH + "/api/v1/signup/complete-account/signup", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": "Bearer " + token, Authorization: "Bearer " + token,
}, },
body: JSON.stringify({ body: JSON.stringify({
email, email,
firstName, firstName,
lastName, lastName,
publicKey, publicKey,
encryptedPrivateKey: ciphertext, encryptedPrivateKey: ciphertext,
organizationName, organizationName,
iv, iv,
tag, tag,
salt, salt,
verifier, verifier,
}), }),
}); });
}; };
export default completeAccountInformationSignup; export default completeAccountInformationSignup;
@@ -1,4 +1,4 @@
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This function is called in the end of the signup process. * This function is called in the end of the signup process.
@@ -15,35 +15,35 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const completeAccountInformationSignupInvite = ({ const completeAccountInformationSignupInvite = ({
email, email,
firstName, firstName,
lastName, lastName,
publicKey, publicKey,
ciphertext, ciphertext,
iv, iv,
tag, tag,
salt, salt,
verifier, verifier,
token token,
}) => { }) => {
return fetch(PATH + "/api/v1/signup/complete-account/invite", { return fetch(PATH + "/api/v1/signup/complete-account/invite", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": "Bearer " + token, Authorization: "Bearer " + token,
}, },
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,
firstName: firstName, firstName: firstName,
lastName: lastName, lastName: lastName,
publicKey: publicKey, publicKey: publicKey,
encryptedPrivateKey: ciphertext, encryptedPrivateKey: ciphertext,
iv: iv, iv: iv,
tag: tag, tag: tag,
salt: salt, salt: salt,
verifier: verifier verifier: verifier,
}), }),
}); });
}; };
export default completeAccountInformationSignupInvite; export default completeAccountInformationSignupInvite;
@@ -1,42 +1,42 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This is the route that issues a backup private key that will afterwards be added into a pdf * This is the route that issues a backup private key that will afterwards be added into a pdf
*/ */
const issueBackupPrivateKey = ({ const issueBackupPrivateKey = ({
encryptedPrivateKey, encryptedPrivateKey,
iv, iv,
tag, tag,
salt, salt,
verifier, verifier,
clientProof, clientProof,
}) => { }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/password/backup-private-key", PATH + "/api/v1/password/backup-private-key",
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
clientProof: clientProof, clientProof: clientProof,
encryptedPrivateKey: encryptedPrivateKey, encryptedPrivateKey: encryptedPrivateKey,
iv: iv, iv: iv,
tag: tag, tag: tag,
salt: salt, salt: salt,
verifier: verifier, verifier: verifier,
}), }),
} }
).then((res) => { ).then((res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
return res; return res;
console.log("Failed to issue the backup key"); console.log("Failed to issue the backup key");
} }
}); });
}; };
export default issueBackupPrivateKey; export default issueBackupPrivateKey;
+11 -11
View File
@@ -1,4 +1,4 @@
import { PATH } from "../../../const.js"; import { PATH } from "~/const";
/** /**
* This is the first step of the login process (pake) * This is the first step of the login process (pake)
@@ -7,16 +7,16 @@ import { PATH } from "../../../const.js";
* @returns * @returns
*/ */
const login1 = (email, clientPublicKey) => { const login1 = (email, clientPublicKey) => {
return fetch(PATH + "/api/v1/auth/login1", { return fetch(PATH + "/api/v1/auth/login1", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,
clientPublicKey, clientPublicKey,
}), }),
}); });
}; };
export default login1; export default login1;
+19 -20
View File
@@ -1,4 +1,4 @@
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This is the second step of the login process * This is the second step of the login process
@@ -7,25 +7,24 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const login2 = (email, clientProof) => { const login2 = (email, clientProof) => {
return fetch(PATH + "/api/v1/auth/login2", { return fetch(PATH + "/api/v1/auth/login2", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,
clientProof, clientProof,
}), }),
credentials: "include" credentials: "include",
}) }).then((res) => {
.then(res => { if (res.status == 200) {
if (res.status == 200) { console.log("User logged in", res);
console.log("User logged in", res); return res;
return res; } else {
} else { console.log("Failed to log in");
console.log("Failed to log in"); }
} });
})
}; };
export default login2; export default login2;
+22 -22
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route logs the user out. Note: the user should authorized to do this. * This route logs the user out. Note: the user should authorized to do this.
@@ -10,27 +10,27 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const logout = async (req, res) => { const logout = async (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/auth/logout", { return SecurityClient.fetchCall(PATH + "/api/v1/auth/logout", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
credentials: "include", credentials: "include",
}).then((res) => { }).then((res) => {
if (res.status == 200) { if (res.status == 200) {
SecurityClient.setToken(""); SecurityClient.setToken("");
// Delete the cookie by not setting a value; Alternatively clear the local storage // Delete the cookie by not setting a value; Alternatively clear the local storage
localStorage.setItem("publicKey", ""); localStorage.setItem("publicKey", "");
localStorage.setItem("encryptedPrivateKey", ""); localStorage.setItem("encryptedPrivateKey", "");
localStorage.setItem("iv", ""); localStorage.setItem("iv", "");
localStorage.setItem("tag", ""); localStorage.setItem("tag", "");
localStorage.setItem("PRIVATE_KEY", ""); localStorage.setItem("PRIVATE_KEY", "");
console.log("User logged out", res); console.log("User logged out", res);
return res; return res;
} else { } else {
console.log("Failed to log out"); console.log("Failed to log out");
} }
}); });
}; };
export default logout; export default logout;
+16 -16
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This is the first step of the change password process (pake) * This is the first step of the change password process (pake)
@@ -8,21 +8,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const SRP1 = ({ clientPublicKey }) => { const SRP1 = ({ clientPublicKey }) => {
return SecurityClient.fetchCall(PATH + "/api/v1/password/srp1", { return SecurityClient.fetchCall(PATH + "/api/v1/password/srp1", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
clientPublicKey, clientPublicKey,
}), }),
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return await res.json(); return await res.json();
} else { } else {
console.log("Failed to do the first step of SRP"); console.log("Failed to do the first step of SRP");
} }
}); });
}; };
export default SRP1; export default SRP1;
@@ -1,19 +1,19 @@
import { PATH } from "../../../const.js"; import { PATH } from "~/const";
/** /**
* This route send the verification email to the user's email (contains a 6-digit verification code) * This route send the verification email to the user's email (contains a 6-digit verification code)
* @param {*} email * @param {*} email
*/ */
const sendVerificationEmail = (email) => { const sendVerificationEmail = (email) => {
fetch(PATH + "/api/v1/signup/email/signup", { fetch(PATH + "/api/v1/signup/email/signup", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,
}), }),
}); });
}; };
export default sendVerificationEmail; export default sendVerificationEmail;
+14 -15
View File
@@ -1,20 +1,19 @@
import { PATH } from "../../../const.js"; import { PATH } from "~/const";
const token = async (req, res) => { const token = async (req, res) => {
return fetch(PATH + "/api/v1/auth/token", { return fetch(PATH + "/api/v1/auth/token", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
credentials: "include" credentials: "include",
}) }).then(async (res) => {
.then(async res => { if (res.status == 200) {
if (res.status == 200) { return (await res.json()).token;
return (await res.json()).token; } else {
} else { console.log("Getting a new token failed");
console.log('Getting a new token failed'); }
} });
})
}; };
export default token; export default token;
+12 -12
View File
@@ -1,4 +1,4 @@
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route verifies the signup invite link * This route verifies the signup invite link
@@ -6,17 +6,17 @@ import { PATH } from "../../../const";
* @param {*} code * @param {*} code
* @returns * @returns
*/ */
const verifySignupInvite = ({email, code}) => { const verifySignupInvite = ({ email, code }) => {
return fetch(PATH + "/api/v1/invite-org/verify", { return fetch(PATH + "/api/v1/invite-org/verify", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
email, email,
code, code,
}), }),
}); });
}; };
export default verifySignupInvite; export default verifySignupInvite;
@@ -1,4 +1,4 @@
import { PATH } from "../../../const.js"; import { PATH } from "~/const";
/** /**
* This route lets us get the public key of infisical. Th euser doesn't have to be authenticated since this is just the public key. * This route lets us get the public key of infisical. Th euser doesn't have to be authenticated since this is just the public key.
@@ -7,12 +7,12 @@ import { PATH } from "../../../const.js";
* @returns * @returns
*/ */
const publicKeyInfisical = (req, res) => { const publicKeyInfisical = (req, res) => {
return fetch(PATH + "/api/v1/key/publicKey/infisical", { return fetch(PATH + "/api/v1/key/publicKey/infisical", {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
}; };
export default publicKeyInfisical; export default publicKeyInfisical;
+23 -23
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient.js"; import SecurityClient from "~/utilities/SecurityClient.js";
import { PATH } from "../../../const.js"; import { PATH } from "~/const";
/** /**
* This function fetches the encrypted secrets from the .env file * This function fetches the encrypted secrets from the .env file
@@ -9,28 +9,28 @@ import { PATH } from "../../../const.js";
* @returns * @returns
*/ */
const getSecrets = async (workspaceId, env) => { const getSecrets = async (workspaceId, env) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + PATH +
"/api/v1/secret/" + "/api/v1/secret/" +
workspaceId + workspaceId +
"?" + "?" +
new URLSearchParams({ new URLSearchParams({
environment: env, environment: env,
channel: "web", channel: "web",
}), }),
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return await res.json(); return await res.json();
} else { } else {
console.log("Failed to get project secrets"); console.log("Failed to get project secrets");
} }
}); });
}; };
export default getSecrets; export default getSecrets;
+19 -19
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This function uploads the encrypted .env file * This function uploads the encrypted .env file
@@ -9,24 +9,24 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const uploadSecrets = async ({ workspaceId, secrets, keys, environment }) => { const uploadSecrets = async ({ workspaceId, secrets, keys, environment }) => {
return SecurityClient.fetchCall(PATH + "/api/v1/secret/" + workspaceId, { return SecurityClient.fetchCall(PATH + "/api/v1/secret/" + workspaceId, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
secrets, secrets,
keys, keys,
environment, environment,
channel: "web", channel: "web",
}), }),
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to push secrets"); console.log("Failed to push secrets");
} }
}); });
}; };
export default uploadSecrets; export default uploadSecrets;
@@ -1,27 +1,27 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
const changeHerokuConfigVars = ({ integrationId, key, secrets }) => { const changeHerokuConfigVars = ({ integrationId, key, secrets }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/integration/" + integrationId + "/sync", PATH + "/api/v1/integration/" + integrationId + "/sync",
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
key, key,
secrets, secrets,
}), }),
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to sync secrets to Heroku"); console.log("Failed to sync secrets to Heroku");
} }
}); });
}; };
export default changeHerokuConfigVars; export default changeHerokuConfigVars;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route deletes an integration from a certain project * This route deletes an integration from a certain project
@@ -8,21 +8,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const deleteIntegration = ({ integrationId }) => { const deleteIntegration = ({ integrationId }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/integration/" + integrationId, PATH + "/api/v1/integration/" + integrationId,
{ {
method: "DELETE", method: "DELETE",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).workspace; return (await res.json()).workspace;
} else { } else {
console.log("Failed to delete an integration"); console.log("Failed to delete an integration");
} }
}); });
}; };
export default deleteIntegration; export default deleteIntegration;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route deletes an integration authorization from a certain project * This route deletes an integration authorization from a certain project
@@ -8,21 +8,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const deleteIntegrationAuth = ({ integrationAuthId }) => { const deleteIntegrationAuth = ({ integrationAuthId }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/integration-auth/" + integrationAuthId, PATH + "/api/v1/integration-auth/" + integrationAuthId,
{ {
method: "DELETE", method: "DELETE",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to delete an integration authorization"); console.log("Failed to delete an integration authorization");
} }
}); });
}; };
export default deleteIntegrationAuth; export default deleteIntegrationAuth;
@@ -1,23 +1,23 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
const getIntegrationApps = ({ integrationAuthId }) => { const getIntegrationApps = ({ integrationAuthId }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/integration-auth/" + integrationAuthId + "/apps", PATH + "/api/v1/integration-auth/" + integrationAuthId + "/apps",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).apps; return (await res.json()).apps;
} else { } else {
console.log("Failed to get available apps for an integration"); console.log("Failed to get available apps for an integration");
} }
}); });
}; };
export default getIntegrationApps; export default getIntegrationApps;
@@ -1,20 +1,20 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
const getIntegrations = () => { const getIntegrations = () => {
return SecurityClient.fetchCall(PATH + "/api/v1/integration/integrations", { return SecurityClient.fetchCall(PATH + "/api/v1/integration/integrations", {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).integrations; return (await res.json()).integrations;
} else { } else {
console.log("Failed to get project integrations"); console.log("Failed to get project integrations");
} }
}); });
}; };
export default getIntegrations; export default getIntegrations;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route starts the integration after teh default one if gonna set up. * This route starts the integration after teh default one if gonna set up.
@@ -8,28 +8,28 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const startIntegration = ({ integrationId, appName, environment }) => { const startIntegration = ({ integrationId, appName, environment }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/integration/" + integrationId, PATH + "/api/v1/integration/" + integrationId,
{ {
method: "PATCH", method: "PATCH",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
update: { update: {
app: appName, app: appName,
environment, environment,
isActive: true, isActive: true,
}, },
}), }),
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to start an integration"); console.log("Failed to start an integration");
} }
}); });
}; };
export default startIntegration; export default startIntegration;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This is the first step of the change password process (pake) * This is the first step of the change password process (pake)
@@ -8,26 +8,26 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const AuthorizeIntegration = ({ workspaceId, code, integration }) => { const AuthorizeIntegration = ({ workspaceId, code, integration }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/integration-auth/oauth-token", PATH + "/api/v1/integration-auth/oauth-token",
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
workspaceId, workspaceId,
code, code,
integration, integration,
}), }),
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to authorize the integration"); console.log("Failed to authorize the integration");
} }
}); });
}; };
export default AuthorizeIntegration; export default AuthorizeIntegration;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route gets authorizations of a certain project (Heroku, etc.) * This route gets authorizations of a certain project (Heroku, etc.)
@@ -8,21 +8,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getWorkspaceAuthorizations = ({ workspaceId }) => { const getWorkspaceAuthorizations = ({ workspaceId }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/workspace/" + workspaceId + "/authorizations", PATH + "/api/v1/workspace/" + workspaceId + "/authorizations",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).authorizations; return (await res.json()).authorizations;
} else { } else {
console.log("Failed to get project authorizations"); console.log("Failed to get project authorizations");
} }
}); });
}; };
export default getWorkspaceAuthorizations; export default getWorkspaceAuthorizations;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route gets integrations of a certain project (Heroku, etc.) * This route gets integrations of a certain project (Heroku, etc.)
@@ -8,21 +8,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getWorkspaceIntegrations = ({ workspaceId }) => { const getWorkspaceIntegrations = ({ workspaceId }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/workspace/" + workspaceId + "/integrations", PATH + "/api/v1/workspace/" + workspaceId + "/integrations",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).integrations; return (await res.json()).integrations;
} else { } else {
console.log("Failed to get the project integrations"); console.log("Failed to get the project integrations");
} }
}); });
}; };
export default getWorkspaceIntegrations; export default getWorkspaceIntegrations;
+13 -16
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us get info about a certain org * This route lets us get info about a certain org
@@ -9,21 +9,18 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getOrganization = (req, res) => { const getOrganization = (req, res) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + req.orgId, {
PATH + "/api/v1/organization/" + req.orgId, method: "GET",
{ headers: {
method: "GET", "Content-Type": "application/json",
headers: { },
"Content-Type": "application/json", }).then(async (res) => {
}, if (res.status == 200) {
} return (await res.json()).organization;
).then(async (res) => { } else {
if (res.status == 200) { console.log("Failed to get org info");
return (await res.json()).organization; }
} else { });
console.log("Failed to get org info");
}
});
}; };
export default getOrganization; export default getOrganization;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us get all the users in an org. * This route lets us get all the users in an org.
@@ -9,21 +9,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getOrganizationProjects = (req, res) => { const getOrganizationProjects = (req, res) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/organization/" + req.orgId + "/workspaces", PATH + "/api/organization/" + req.orgId + "/workspaces",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).workspaces; return (await res.json()).workspaces;
} else { } else {
console.log("Failed to get projects for an org"); console.log("Failed to get projects for an org");
} }
}); });
}; };
export default getOrganizationProjects; export default getOrganizationProjects;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us get the current subscription of an org. * This route lets us get the current subscription of an org.
@@ -9,21 +9,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getOrganizationSubscriptions = (req, res) => { const getOrganizationSubscriptions = (req, res) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/organization/" + req.orgId + "/subscriptions", PATH + "/api/v1/organization/" + req.orgId + "/subscriptions",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).subscriptions; return (await res.json()).subscriptions;
} else { } else {
console.log("Failed to get org subscriptions"); console.log("Failed to get org subscriptions");
} }
}); });
}; };
export default getOrganizationSubscriptions; export default getOrganizationSubscriptions;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us get all the projects of a certain user in an org. * This route lets us get all the projects of a certain user in an org.
@@ -9,21 +9,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getOrganizationUserProjects = (req, res) => { const getOrganizationUserProjects = (req, res) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/organization/" + req.orgId + "/my-workspaces", PATH + "/api/v1/organization/" + req.orgId + "/my-workspaces",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).workspaces; return (await res.json()).workspaces;
} else { } else {
console.log("Failed to get projects of a user in an org"); console.log("Failed to get projects of a user in an org");
} }
}); });
}; };
export default getOrganizationUserProjects; export default getOrganizationUserProjects;
+16 -16
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us get all the users in an org. * This route lets us get all the users in an org.
@@ -9,21 +9,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getOrganizationUsers = (req, res) => { const getOrganizationUsers = (req, res) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/organization/" + req.orgId + "/users", PATH + "/api/v1/organization/" + req.orgId + "/users",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).users; return (await res.json()).users;
} else { } else {
console.log("Failed to get org users"); console.log("Failed to get org users");
} }
}); });
}; };
export default getOrganizationUsers; export default getOrganizationUsers;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route redirects the user to the right stripe billing page. * This route redirects the user to the right stripe billing page.
@@ -9,21 +9,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const StripeRedirect = ({ orgId }) => { const StripeRedirect = ({ orgId }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/organization/" + orgId + "/customer-portal-session", PATH + "/api/v1/organization/" + orgId + "/customer-portal-session",
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (window.location.href = (await res.json()).url); return (window.location.href = (await res.json()).url);
} else { } else {
console.log("Failed to redirect to Stripe"); console.log("Failed to redirect to Stripe");
} }
}); });
}; };
export default StripeRedirect; export default StripeRedirect;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route add an incident contact email to a certain organization * This route add an incident contact email to a certain organization
@@ -8,24 +8,24 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const addIncidentContact = (organizationId, email) => { const addIncidentContact = (organizationId, email) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/organization/" + organizationId + "/incidentContactOrg", PATH + "/api/v1/organization/" + organizationId + "/incidentContactOrg",
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,
}), }),
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to add an incident contact"); console.log("Failed to add an incident contact");
} }
}); });
}; };
export default addIncidentContact; export default addIncidentContact;
+17 -17
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This function sends an email invite to a user to join an org * This function sends an email invite to a user to join an org
@@ -9,22 +9,22 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const addUserToOrg = (email, orgId) => { const addUserToOrg = (email, orgId) => {
return SecurityClient.fetchCall(PATH + "/api/v1/invite-org/signup", { return SecurityClient.fetchCall(PATH + "/api/v1/invite-org/signup", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
inviteeEmail: email, inviteeEmail: email,
organizationId: orgId, organizationId: orgId,
}), }),
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to add a user to an org"); console.log("Failed to add a user to an org");
} }
}); });
}; };
export default addUserToOrg; export default addUserToOrg;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route deletes an incident Contact from a certain organization * This route deletes an incident Contact from a certain organization
@@ -8,24 +8,24 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const deleteIncidentContact = (organizaionId, email) => { const deleteIncidentContact = (organizaionId, email) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/organization/" + organizaionId + "/incidentContactOrg", PATH + "/api/v1/organization/" + organizaionId + "/incidentContactOrg",
{ {
method: "DELETE", method: "DELETE",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,
}), }),
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to delete an incident contact"); console.log("Failed to delete an incident contact");
} }
}); });
}; };
export default deleteIncidentContact; export default deleteIncidentContact;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This function removes a certain member from a certain organization * This function removes a certain member from a certain organization
@@ -8,21 +8,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const deleteUserFromOrganization = (membershipId) => { const deleteUserFromOrganization = (membershipId) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/membership-org/" + membershipId, PATH + "/api/v1/membership-org/" + membershipId,
{ {
method: "DELETE", method: "DELETE",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to delete a user from an org"); console.log("Failed to delete a user from an org");
} }
}); });
}; };
export default deleteUserFromOrganization; export default deleteUserFromOrganization;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This routes gets all the incident contacts of a certain organization * This routes gets all the incident contacts of a certain organization
@@ -8,21 +8,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getIncidentContacts = (organizationId) => { const getIncidentContacts = (organizationId) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/organization/" + organizationId + "/incidentContactOrg", PATH + "/api/v1/organization/" + organizationId + "/incidentContactOrg",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).incidentContactsOrg; return (await res.json()).incidentContactsOrg;
} else { } else {
console.log("Failed to get incident contacts"); console.log("Failed to get incident contacts");
} }
}); });
}; };
export default getIncidentContacts; export default getIncidentContacts;
+13 -13
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us get the all the orgs of a certain user. * This route lets us get the all the orgs of a certain user.
@@ -9,18 +9,18 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getOrganizations = (req, res) => { const getOrganizations = (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization", { return SecurityClient.fetchCall(PATH + "/api/v1/organization", {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).organizations; return (await res.json()).organizations;
} else { } else {
console.log("Failed to get orgs of a user"); console.log("Failed to get orgs of a user");
} }
}); });
}; };
export default getOrganizations; export default getOrganizations;
+19 -19
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us rename a certain org. * This route lets us rename a certain org.
@@ -9,24 +9,24 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const renameOrg = (orgId, newOrgName) => { const renameOrg = (orgId, newOrgName) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/organization/" + orgId + "/name", PATH + "/api/v1/organization/" + orgId + "/name",
{ {
method: "PATCH", method: "PATCH",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
name: newOrgName, name: newOrgName,
}), }),
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to rename an organization"); console.log("Failed to rename an organization");
} }
}); });
}; };
export default renameOrg; export default renameOrg;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route gets service tokens for a specific user in a project * This route gets service tokens for a specific user in a project
@@ -8,35 +8,35 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const addServiceToken = ({ const addServiceToken = ({
name, name,
workspaceId, workspaceId,
environment, environment,
expiresIn, expiresIn,
publicKey, publicKey,
encryptedKey, encryptedKey,
nonce, nonce,
}) => { }) => {
return SecurityClient.fetchCall(PATH + "/api/v1/service-token/", { return SecurityClient.fetchCall(PATH + "/api/v1/service-token/", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
name, name,
workspaceId, workspaceId,
environment, environment,
expiresIn, expiresIn,
publicKey, publicKey,
encryptedKey, encryptedKey,
nonce, nonce,
}), }),
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).token; return (await res.json()).token;
} else { } else {
console.log("Failed to add service tokens"); console.log("Failed to add service tokens");
} }
}); });
}; };
export default addServiceToken; export default addServiceToken;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route gets service tokens for a specific user in a project * This route gets service tokens for a specific user in a project
@@ -8,21 +8,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getServiceTokens = ({ workspaceId }) => { const getServiceTokens = ({ workspaceId }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/workspace/" + workspaceId + "/service-tokens", PATH + "/api/v1/workspace/" + workspaceId + "/service-tokens",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).serviceTokens; return (await res.json()).serviceTokens;
} else { } else {
console.log("Failed to get service tokens"); console.log("Failed to get service tokens");
} }
}); });
}; };
export default getServiceTokens; export default getServiceTokens;
+13 -13
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route gets the information about a specific user. * This route gets the information about a specific user.
@@ -9,18 +9,18 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getUser = (req, res) => { const getUser = (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/user", { return SecurityClient.fetchCall(PATH + "/api/v1/user", {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).user; return (await res.json()).user;
} else { } else {
console.log("Failed to get user info"); console.log("Failed to get user info");
} }
}); });
}; };
export default getUser; export default getUser;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route registers a certain action for a user * This route registers a certain action for a user
@@ -9,26 +9,26 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const checkUserAction = ({ action }) => { const checkUserAction = ({ action }) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + PATH +
"/api/v1/user-action" + "/api/v1/user-action" +
"?" + "?" +
new URLSearchParams({ new URLSearchParams({
action, action,
}), }),
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).userAction; return (await res.json()).userAction;
} else { } else {
console.log("Failed to check a user action"); console.log("Failed to check a user action");
} }
}); });
}; };
export default checkUserAction; export default checkUserAction;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route registers a certain action for a user * This route registers a certain action for a user
@@ -8,21 +8,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const registerUserAction = ({ action }) => { const registerUserAction = ({ action }) => {
return SecurityClient.fetchCall(PATH + "/api/v1/user-action", { return SecurityClient.fetchCall(PATH + "/api/v1/user-action", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
action, action,
}), }),
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to register a user action"); console.log("Failed to register a user action");
} }
}); });
}; };
export default registerUserAction; export default registerUserAction;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This function adds a user to a project * This function adds a user to a project
@@ -9,24 +9,24 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const addUserToWorkspace = (email, workspaceId) => { const addUserToWorkspace = (email, workspaceId) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/workspace/" + workspaceId + "/invite-signup", PATH + "/api/v1/workspace/" + workspaceId + "/invite-signup",
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,
}), }),
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return await res.json(); return await res.json();
} else { } else {
console.log("Failed to add a user to project"); console.log("Failed to add a user to project");
} }
}); });
}; };
export default addUserToWorkspace; export default addUserToWorkspace;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This function change the access of a user in a certain workspace * This function change the access of a user in a certain workspace
@@ -9,24 +9,24 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const changeUserRoleInWorkspace = (membershipId, role) => { const changeUserRoleInWorkspace = (membershipId, role) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/membership/" + membershipId + "/change-role", PATH + "/api/v1/membership/" + membershipId + "/change-role",
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
role: role, role: role,
}), }),
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to change the user role in a project"); console.log("Failed to change the user role in a project");
} }
}); });
}; };
export default changeUserRoleInWorkspace; export default changeUserRoleInWorkspace;
+17 -17
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route creates a new workspace for a user. * This route creates a new workspace for a user.
@@ -8,22 +8,22 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const createWorkspace = (workspaceName, organizationId) => { const createWorkspace = (workspaceName, organizationId) => {
return SecurityClient.fetchCall(PATH + "/api/v1/workspace", { return SecurityClient.fetchCall(PATH + "/api/v1/workspace", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
workspaceName: workspaceName, workspaceName: workspaceName,
organizationId: organizationId, organizationId: organizationId,
}), }),
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).workspace; return (await res.json()).workspace;
} else { } else {
console.log("Failed to create a project"); console.log("Failed to create a project");
} }
}); });
}; };
export default createWorkspace; export default createWorkspace;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This function removes a certain member from a certain workspace * This function removes a certain member from a certain workspace
@@ -8,21 +8,18 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const deleteUserFromWorkspace = (membershipId) => { const deleteUserFromWorkspace = (membershipId) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(PATH + "/api/v1/membership/" + membershipId, {
PATH + "/api/v1/membership/" + membershipId, method: "DELETE",
{ headers: {
method: "DELETE", "Content-Type": "application/json",
headers: { },
"Content-Type": "application/json", }).then(async (res) => {
}, if (res.status == 200) {
} return res;
).then(async (res) => { } else {
if (res.status == 200) { console.log("Failed to delete a user from a project");
return res; }
} else { });
console.log("Failed to delete a user from a project");
}
});
}; };
export default deleteUserFromWorkspace; export default deleteUserFromWorkspace;
+13 -13
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route deletes a specified workspace. * This route deletes a specified workspace.
@@ -8,18 +8,18 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const deleteWorkspace = (workspaceId) => { const deleteWorkspace = (workspaceId) => {
return SecurityClient.fetchCall(PATH + "/api/v1/workspace/" + workspaceId, { return SecurityClient.fetchCall(PATH + "/api/v1/workspace/" + workspaceId, {
method: "DELETE", method: "DELETE",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to delete a project"); console.log("Failed to delete a project");
} }
}); });
}; };
export default deleteWorkspace; export default deleteWorkspace;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* Get the latest key pairs from a certain workspace * Get the latest key pairs from a certain workspace
@@ -8,23 +8,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getLatestFileKey = (workspaceId) => { const getLatestFileKey = (workspaceId) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/key/" + workspaceId + "/latest", PATH + "/api/v1/key/" + workspaceId + "/latest",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return await res.json(); return await res.json();
} else { } else {
console.log( console.log("Failed to get the latest key pairs for a certain project");
"Failed to get the latest key pairs for a certain project" }
); });
}
});
}; };
export default getLatestFileKey; export default getLatestFileKey;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us get the information of a certain project. * This route lets us get the information of a certain project.
@@ -9,21 +9,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getWorkspaceInfo = (req, res) => { const getWorkspaceInfo = (req, res) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/workspace/" + req.workspaceId, PATH + "/api/v1/workspace/" + req.workspaceId,
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).workspace; return (await res.json()).workspace;
} else { } else {
console.log("Failed to get project info"); console.log("Failed to get project info");
} }
}); });
}; };
export default getWorkspaceInfo; export default getWorkspaceInfo;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us get the public keys of everyone in your workspace. * This route lets us get the public keys of everyone in your workspace.
@@ -9,23 +9,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getWorkspaceKeys = (req, res) => { const getWorkspaceKeys = (req, res) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/workspace/" + req.workspaceId + "/keys", PATH + "/api/v1/workspace/" + req.workspaceId + "/keys",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).publicKeys; return (await res.json()).publicKeys;
} else { } else {
console.log( console.log("Failed to get the public keys of everyone in the workspace");
"Failed to get the public keys of everyone in the workspace" }
); });
}
});
}; };
export default getWorkspaceKeys; export default getWorkspaceKeys;
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us get all the users in the workspace. * This route lets us get all the users in the workspace.
@@ -9,21 +9,21 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getWorkspaceUsers = (req, res) => { const getWorkspaceUsers = (req, res) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/workspace/" + req.workspaceId + "/users", PATH + "/api/v1/workspace/" + req.workspaceId + "/users",
{ {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).users; return (await res.json()).users;
} else { } else {
console.log("Failed to get Project Users"); console.log("Failed to get Project Users");
} }
}); });
}; };
export default getWorkspaceUsers; export default getWorkspaceUsers;
+13 -13
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us get the public keys of everyone in your workspace. * This route lets us get the public keys of everyone in your workspace.
@@ -9,18 +9,18 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const getWorkspaces = (req, res) => { const getWorkspaces = (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/workspace", { return SecurityClient.fetchCall(PATH + "/api/v1/workspace", {
method: "GET", method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return (await res.json()).workspaces; return (await res.json()).workspaces;
} else { } else {
console.log("Failed to get projects"); console.log("Failed to get projects");
} }
}); });
}; };
export default getWorkspaces; export default getWorkspaces;
+19 -19
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route lets us rename a certain workspace. * This route lets us rename a certain workspace.
@@ -9,24 +9,24 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const renameWorkspace = (workspaceId, newWorkspaceName) => { const renameWorkspace = (workspaceId, newWorkspaceName) => {
return SecurityClient.fetchCall( return SecurityClient.fetchCall(
PATH + "/api/v1/workspace/" + workspaceId + "/name", PATH + "/api/v1/workspace/" + workspaceId + "/name",
{ {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
name: newWorkspaceName, name: newWorkspaceName,
}), }),
} }
).then(async (res) => { ).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to rename a project"); console.log("Failed to rename a project");
} }
}); });
}; };
export default renameWorkspace; export default renameWorkspace;
+20 -20
View File
@@ -1,6 +1,6 @@
import SecurityClient from "~/utilities/SecurityClient"; import SecurityClient from "~/utilities/SecurityClient";
import { PATH } from "../../../const"; import { PATH } from "~/const";
/** /**
* This route uplods the keys in an encrypted format. * This route uplods the keys in an encrypted format.
@@ -11,25 +11,25 @@ import { PATH } from "../../../const";
* @returns * @returns
*/ */
const uploadKeys = (workspaceId, userId, encryptedKey, nonce) => { const uploadKeys = (workspaceId, userId, encryptedKey, nonce) => {
return SecurityClient.fetchCall(PATH + "/api/v1/key/" + workspaceId, { return SecurityClient.fetchCall(PATH + "/api/v1/key/" + workspaceId, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
key: { key: {
userId: userId, userId: userId,
encryptedKey: encryptedKey, encryptedKey: encryptedKey,
nonce: nonce, nonce: nonce,
}, },
}), }),
}).then(async (res) => { }).then(async (res) => {
if (res.status == 200) { if (res.status == 200) {
return res; return res;
} else { } else {
console.log("Failed to upload keys for a new user"); console.log("Failed to upload keys for a new user");
} }
}); });
}; };
export default uploadKeys; export default uploadKeys;