Add frontend, backend and CLI

This commit is contained in:
Maidul Islam
2022-11-17 17:54:35 -05:00
parent 8d00c5cdb7
commit bea0ff6e05
276 changed files with 50230 additions and 72 deletions
+26
View File
@@ -0,0 +1,26 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This route lets us get info about a certain org
* @param {*} req
* @param {*} res
* @returns
*/
const getOrganization = (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + req.orgId, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then(async res => {
if (res.status == 200) {
return (await res.json()).organization;
} else {
console.log('Failed to get org info');
}
})
};
export default getOrganization;
@@ -0,0 +1,26 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This route lets us get all the users in an org.
* @param {*} req
* @param {*} res
* @returns
*/
const getOrganizationProjects = (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/organization/" + req.orgId + "/workspaces", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then(async res => {
if (res.status == 200) {
return (await res.json()).workspaces;
} else {
console.log('Failed to get projects for an org');
}
})
};
export default getOrganizationProjects;
@@ -0,0 +1,26 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This route lets us get the current subscription of an org.
* @param {*} req
* @param {*} res
* @returns
*/
const getOrganizationSubscriptions = (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + req.orgId + "/subscriptions", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then(async res => {
if (res.status == 200) {
return (await res.json()).subscriptions;
} else {
console.log('Failed to get org subscriptions');
}
})
};
export default getOrganizationSubscriptions;
@@ -0,0 +1,26 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This route lets us get all the projects of a certain user in an org.
* @param {*} req
* @param {*} res
* @returns
*/
const getOrganizationUserProjects = (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + req.orgId + "/my-workspaces", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then(async res => {
if (res.status == 200) {
return (await res.json()).workspaces;
} else {
console.log('Failed to get projects of a user in an org');
}
})
};
export default getOrganizationUserProjects;
@@ -0,0 +1,26 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This route lets us get all the users in an org.
* @param {*} req
* @param {*} res
* @returns
*/
const getOrganizationUsers = (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + req.orgId + "/users", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then(async res => {
if (res.status == 200) {
return (await res.json()).users;
} else {
console.log('Failed to get org users');
}
})
};
export default getOrganizationUsers;
@@ -0,0 +1,26 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This route redirects the user to the right stripe billing page.
* @param {*} req
* @param {*} res
* @returns
*/
const StripeRedirect = ({orgId}) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + orgId + "/customer-portal-session", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
})
.then(async res => {
if (res.status == 200) {
return window.location.href = (await res.json()).url;
} else {
console.log('Failed to redirect to Stripe');
}
})
};
export default StripeRedirect;
@@ -0,0 +1,28 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This route add an incident contact email to a certain organization
* @param {*} param0
* @returns
*/
const addIncidentContact = (organizationId, email) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + organizationId + "/incidentContactOrg", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: email,
}),
})
.then(async res => {
if (res.status == 200) {
return res;
} else {
console.log('Failed to add an incident contact');
}
})
};
export default addIncidentContact;
@@ -0,0 +1,30 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This function sends an email invite to a user to join an org
* @param {*} email
* @param {*} orgId
* @returns
*/
const addUserToOrg = (email, orgId) => {
return SecurityClient.fetchCall(PATH + "/api/v1/invite-org/signup", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
inviteeEmail: email,
organizationId: orgId,
}),
})
.then(async res => {
if (res.status == 200) {
return res;
} else {
console.log('Failed to add a user to an org');
}
})
};
export default addUserToOrg;
@@ -0,0 +1,28 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This route deletes an incident Contact from a certain organization
* @param {*} param0
* @returns
*/
const deleteIncidentContact = (organizaionId, email) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + organizaionId + "/incidentContactOrg", {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: email,
}),
})
.then(async res => {
if (res.status == 200) {
return res;
} else {
console.log('Failed to delete an incident contact');
}
})
};
export default deleteIncidentContact;
@@ -0,0 +1,25 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This function removes a certain member from a certain organization
* @param {*} membershipId
* @returns
*/
const deleteUserFromOrganization = (membershipId) => {
return SecurityClient.fetchCall(PATH + "/api/v1/membership-org/" + membershipId, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
})
.then(async res => {
if (res.status == 200) {
return res;
} else {
console.log('Failed to delete a user from an org');
}
})
};
export default deleteUserFromOrganization;
@@ -0,0 +1,25 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This routes gets all the incident contacts of a certain organization
* @param {*} workspaceId
* @returns
*/
const getIncidentContacts = (organizationId) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + organizationId + "/incidentContactOrg", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then(async res => {
if (res.status == 200) {
return (await res.json()).incidentContactsOrg;
} else {
console.log('Failed to get incident contacts');
}
})
};
export default getIncidentContacts;
@@ -0,0 +1,26 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This route lets us get the all the orgs of a certain user.
* @param {*} req
* @param {*} res
* @returns
*/
const getOrganizations = (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then(async res => {
if (res.status == 200) {
return (await res.json()).organizations;
} else {
console.log('Failed to get orgs of a user');
}
})
};
export default getOrganizations;
@@ -0,0 +1,29 @@
import SecurityClient from "../../../components/utilities/SecurityClient";
import { PATH } from "../../../const";
/**
* This route lets us rename a certain org.
* @param {*} req
* @param {*} res
* @returns
*/
const renameOrg = (orgId, newOrgName) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + orgId + "/name", {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
name: newOrgName,
}),
})
.then(async res => {
if (res.status == 200) {
return res;
} else {
console.log('Failed to rename an organization');
}
})
};
export default renameOrg;