Continue removing unused frontend components/logic, improve querying in select pages

This commit is contained in:
Tuan Dang
2023-08-10 12:18:17 +07:00
parent b47f61f1ad
commit 9963724a6a
44 changed files with 181 additions and 1536 deletions
@@ -1,25 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
interface Props {
integrationId: string;
}
/**
* This route deletes an integration from a certain project
* @param {*} integrationId
* @returns
*/
const deleteIntegration = ({ integrationId }: Props) =>
SecurityClient.fetchCall(`/api/v1/integration/${integrationId}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return (await res.json()).integration;
}
return undefined;
});
export default deleteIntegration;
@@ -1,26 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
interface Props {
integrationAuthId: string;
}
/**
* This route deletes an integration authorization from a certain project
* @param {*} integrationAuthId
* @returns
*/
const deleteIntegrationAuth = ({ integrationAuthId }: Props) =>
SecurityClient.fetchCall(`/api/v1/integration-auth/${integrationAuthId}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return (await res.json()).integrationAuth;
}
console.log("Failed to delete an integration authorization");
return undefined;
});
export default deleteIntegrationAuth;
@@ -1,21 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
interface Props {
integrationAuthId: string;
}
const getIntegrationApps = ({ integrationAuthId }: Props) =>
SecurityClient.fetchCall(`/api/v1/integration-auth/${integrationAuthId}/apps`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return (await res.json()).apps;
}
console.log("Failed to get available apps for an integration");
return undefined;
});
export default getIntegrationApps;
@@ -1,17 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
const getIntegrationOptions = () =>
SecurityClient.fetchCall("/api/v1/integration-auth/integration-options", {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return (await res.json()).integrationOptions;
}
console.log("Failed to get (cloud) integration options");
return undefined;
});
export default getIntegrationOptions;
@@ -1,35 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
interface Props {
integrationId: string;
appName: string;
environment: string;
}
/**
* This route starts the integration after teh default one if gonna set up.
* @param {*} integrationId
* @returns
*/
const startIntegration = ({ integrationId, appName, environment }: Props) =>
SecurityClient.fetchCall(`/api/v1/integration/${integrationId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
update: {
app: appName,
environment,
isActive: true
}
})
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to start an integration");
return undefined;
});
export default startIntegration;
@@ -1,26 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
interface Props {
workspaceId: string;
}
/**
* This route gets authorizations of a certain project (Heroku, etc.)
* @param {*} workspaceId
* @returns
*/
const getWorkspaceAuthorizations = ({ workspaceId }: Props) =>
SecurityClient.fetchCall(`/api/v1/workspace/${workspaceId}/authorizations`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return (await res.json()).authorizations;
}
console.log("Failed to get project authorizations");
return undefined;
});
export default getWorkspaceAuthorizations;
@@ -1,26 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
interface Props {
workspaceId: string;
}
/**
* This route gets integrations of a certain project (Heroku, etc.)
* @param {*} workspaceId
* @returns
*/
const getWorkspaceIntegrations = ({ workspaceId }: Props) =>
SecurityClient.fetchCall(`/api/v1/workspace/${workspaceId}/integrations`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return (await res.json()).integrations;
}
console.log("Failed to get the project integrations");
return undefined;
});
export default getWorkspaceIntegrations;
@@ -1,55 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route starts the integration after teh default one if gonna set up.
* Update integration with id [integrationId] to sync envars from the project's
* [environment] to the integration [app] with active state [isActive]
* @param {Object} obj
* @param {String} obj.integrationId - id of integration
* @param {Boolean} obj.isActive - active state
* @param {String} obj.environment - project environment to push secrets from
* @param {String} obj.app - name of app
* @param {String} obj.appId - (optional) app ID for integration
* @param {String} obj.targetEnvironment - target environment for integration
* @param {String} obj.owner - (optional) owner login of repo for GitHub integration
* @returns
*/
const updateIntegration = ({
integrationId,
isActive,
environment,
app,
appId,
targetEnvironment,
owner
}: {
integrationId: string;
isActive: boolean;
environment: string;
app: string;
appId: string | null;
targetEnvironment: string | null;
owner: string | null;
}) =>
SecurityClient.fetchCall(`/api/v1/integration/${integrationId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
app,
environment,
isActive,
appId,
targetEnvironment,
owner
})
}).then(async (res) => {
if (res && res.status === 200) {
return (await res.json()).integration;
}
console.log("Failed to start an integration");
return undefined;
});
export default updateIntegration;
@@ -1,22 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route lets us get info about a certain org
* @param {string} orgId - the organization ID
* @returns
*/
const getOrganization = ({ orgId }: { orgId: string }) =>
SecurityClient.fetchCall(`/api/v1/organization/${orgId}`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res?.status === 200) {
return (await res.json()).organization;
}
console.log("Failed to get org info");
return undefined;
});
export default getOrganization;
@@ -1,24 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route lets us get all the project memebrships of users in an org.
* @param {*} req
* @param {*} res
* @returns
*/
const getOrganizationProjectMemberships = (req: { orgId: string }) =>
SecurityClient.fetchCall(`/api/v1/organization/${req.orgId}/workspace-memberships`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return res.json();
}
console.log("Failed to get project memberships for users in an org");
return undefined;
});
export default getOrganizationProjectMemberships;
@@ -1,25 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route lets us get all the users in an org.
* @param {*} req
* @param {*} res
* @returns
*/
// TODO: this file is not used anywhere
const getOrganizationProjects = (req: { orgId: string }) =>
SecurityClient.fetchCall(`/api/organization/${req.orgId}/workspaces`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return (await res.json()).workspaces;
}
console.log("Failed to get projects for an org");
return undefined;
});
export default getOrganizationProjects;
@@ -1,23 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route redirects the user to the right stripe billing page.
* @param {*} req
* @param {*} res
* @returns
*/
const StripeRedirect = ({ orgId }: { orgId: string }) =>
SecurityClient.fetchCall(`/api/v1/organization/${orgId}/customer-portal-session`, {
method: "POST",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
window.location.href = (await res.json()).url;
return;
}
console.log("Failed to redirect to Stripe");
});
export default StripeRedirect;
@@ -1,25 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route add an incident contact email to a certain organization
* @param {*} param0
* @returns
*/
const addIncidentContact = (organizationId: string, email: string) =>
SecurityClient.fetchCall(`/api/v1/organization/${organizationId}/incidentContactOrg`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
email
})
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to add an incident contact");
return undefined;
});
export default addIncidentContact;
@@ -1,27 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This function change the access of a user in a certain organization
* @param {string} organizationId
* @param {string} membershipId
* @param {string} role
* @returns
*/
const changeUserRoleInOrganization = (organizationId: string, membershipId: string, role: string) =>
SecurityClient.fetchCall(`/api/v2/organizations/${organizationId}/memberships/${membershipId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
role
})
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to change the user role in an org");
return undefined;
});
export default changeUserRoleInOrganization;
@@ -1,25 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route deletes an incident Contact from a certain organization
* @param {*} param0
* @returns
*/
const deleteIncidentContact = (organizationId: string, email: string) =>
SecurityClient.fetchCall(`/api/v1/organization/${organizationId}/incidentContactOrg`, {
method: "DELETE",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
email
})
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to delete an incident contact");
return undefined;
});
export default deleteIncidentContact;
@@ -1,22 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This function removes a certain member from a certain organization
* @param {*} membershipId
* @returns
*/
const deleteUserFromOrganization = (membershipId: string) =>
SecurityClient.fetchCall(`/api/v1/membership-org/${membershipId}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to delete a user from an org");
return undefined;
});
export default deleteUserFromOrganization;
@@ -1,27 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
export interface IIncidentContactOrg {
_id: string;
email: string;
organization: string;
}
/**
* This routes gets all the incident contacts of a certain organization
* @param {*} workspaceId
* @returns
*/
const getIncidentContacts = (organizationId: string): Promise<IIncidentContactOrg[]> =>
SecurityClient.fetchCall(`/api/v1/organization/${organizationId}/incidentContactOrg`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return (await res.json()).incidentContactsOrg;
}
console.log("Failed to get incident contacts");
return undefined;
});
export default getIncidentContacts;
@@ -1,26 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route lets us rename a certain org.
* @param {*} req
* @param {*} res
* @returns
*/
const renameOrg = (orgId: string, newOrgName: string) =>
SecurityClient.fetchCall(`/api/v1/organization/${orgId}/name`, {
method: "PATCH",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
name: newOrgName
})
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to rename an organization");
return undefined;
});
export default renameOrg;
@@ -1,26 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This function adds a user to a project
* @param {*} email
* @param {*} workspaceId
* @returns
*/
const addUserToWorkspace = (email: string, workspaceId: string) =>
SecurityClient.fetchCall(`/api/v1/workspace/${workspaceId}/invite-signup`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
email
})
}).then(async (res) => {
if (res && res.status === 200) {
return res.json();
}
console.log("Failed to add a user to project");
return undefined;
});
export default addUserToWorkspace;
@@ -1,26 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This function change the access of a user in a certain workspace
* @param {*} membershipId
* @param {*} role
* @returns
*/
const changeUserRoleInWorkspace = (membershipId: string, role: string) =>
SecurityClient.fetchCall(`/api/v1/membership/${membershipId}/change-role`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
role
})
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to change the user role in a project");
return undefined;
});
export default changeUserRoleInWorkspace;
@@ -1,22 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This function removes a certain member from a certain workspace
* @param {*} membershipId
* @returns
*/
const deleteUserFromWorkspace = (membershipId: string) =>
SecurityClient.fetchCall(`/api/v1/membership/${membershipId}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to delete a user from a project");
return undefined;
});
export default deleteUserFromWorkspace;
@@ -1,22 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route deletes a specified workspace.
* @param {*} workspaceId
* @returns
*/
const deleteWorkspace = (workspaceId: string) =>
SecurityClient.fetchCall(`/api/v1/workspace/${workspaceId}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res && res.status === 200) {
return res;
}
console.log("Failed to delete a project");
return undefined;
});
export default deleteWorkspace;
@@ -1,22 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route lets us get the public keys of everyone in your workspace.
* @param {string} workspaceId
* @returns
*/
const getWorkspaceKeys = ({ workspaceId }: { workspaceId: string }) =>
SecurityClient.fetchCall(`/api/v1/workspace/${workspaceId}/keys`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res?.status === 200) {
return (await res.json()).publicKeys;
}
console.log("Failed to get the public keys of everyone in the workspace");
return undefined;
});
export default getWorkspaceKeys;
@@ -1,22 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route lets us get the tags for a certain project
* @param {string} workspaceId
* @returns
*/
const getWorkspaceTags = ({ workspaceId }: { workspaceId: string }) =>
SecurityClient.fetchCall(`/api/v2/workspace/${workspaceId}/tags`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res?.status === 200) {
return (await res.json()).workspaceTags;
}
console.log("Failed to get the tags available in a certain project");
return undefined;
});
export default getWorkspaceTags;
@@ -1,22 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
/**
* This route lets us get all the users in the workspace.
* @param {string} workspaceId - workspace ID
* @returns
*/
const getWorkspaceUsers = ({ workspaceId }: { workspaceId: string }) =>
SecurityClient.fetchCall(`/api/v1/workspace/${workspaceId}/users`, {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res?.status === 200) {
return (await res.json()).users;
}
console.log("Failed to get Project Users");
return undefined;
});
export default getWorkspaceUsers;
@@ -1,31 +0,0 @@
import SecurityClient from "@app/components/utilities/SecurityClient";
interface Workspace {
__v: number;
_id: string;
name: string;
autoCapitalization: boolean;
organization: string;
environments: Array<{ name: string; slug: string }>;
}
/**
* This route lets us get the workspaces of a certain user
* @returns
*/
const getWorkspaces = () =>
SecurityClient.fetchCall("/api/v1/workspace", {
method: "GET",
headers: {
"Content-Type": "application/json"
}
}).then(async (res) => {
if (res?.status === 200) {
const data = (await res.json()) as unknown as { workspaces: Workspace[] };
return data.workspaces;
}
throw new Error("Failed to get projects");
});
export default getWorkspaces;