Skip to content

Commit

Permalink
I-36 Remove dependency to PATH const
Browse files Browse the repository at this point in the history
  • Loading branch information
reginaldbondoc committed Nov 30, 2022
1 parent f9bf418 commit d8aa5b5
Show file tree
Hide file tree
Showing 57 changed files with 54 additions and 125 deletions.
5 changes: 1 addition & 4 deletions frontend/components/utilities/SecurityClient.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { PATH } from "~/const";
import token from "~/pages/api/auth/Token";

export default class SecurityClient {
static authOrigins = [PATH];
static #token = "";

contructor() {}
Expand All @@ -13,13 +11,12 @@ export default class SecurityClient {

static async fetchCall(resource, options) {
let req = new Request(resource, options);
const destOrigin = new URL(req.url).origin;

if (this.#token == "") {
this.setToken(await token());
}

if (this.#token && this.authOrigins.includes(destOrigin)) {
if (this.#token) {
req.headers.set("Authorization", "Bearer " + this.#token);
return fetch(req);
}
Expand Down
2 changes: 0 additions & 2 deletions frontend/const.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const PATH = process.env.NEXT_PUBLIC_WEBSITE_URL;

export const publicPaths = [
`/`,
// `/integrations`,
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/auth/ChangePassword2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -14,7 +13,7 @@ const changePassword2 = ({
verifier,
clientProof,
}) => {
return SecurityClient.fetchCall(PATH + "/api/v1/password/change-password", {
return SecurityClient.fetchCall("/api/v1/password/change-password", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/auth/CheckAuth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient.js";

/**
Expand All @@ -9,7 +8,7 @@ import SecurityClient from "~/utilities/SecurityClient.js";
* @returns
*/
const checkAuth = async (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/auth/checkAuth", {
return SecurityClient.fetchCall("/api/v1/auth/checkAuth", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 1 addition & 3 deletions frontend/pages/api/auth/CheckEmailVerificationCode.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { PATH } from "~/const";

/**
* This route check the verification code from the email that user just recieved
* @param {*} email
* @param {*} code
* @returns
*/
const checkEmailVerificationCode = (email, code) => {
return fetch(PATH + "/api/v1/signup/email/verify", {
return fetch("/api/v1/signup/email/verify", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 1 addition & 3 deletions frontend/pages/api/auth/CompleteAccountInformationSignup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { PATH } from "~/const";

/**
* This function is called in the end of the signup process.
* It sends all the necessary nformation to the server.
Expand Down Expand Up @@ -28,7 +26,7 @@ const completeAccountInformationSignup = ({
verifier,
token,
}) => {
return fetch(PATH + "/api/v1/signup/complete-account/signup", {
return fetch("/api/v1/signup/complete-account/signup", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { PATH } from "~/const";

/**
* This function is called in the end of the signup process.
* It sends all the necessary nformation to the server.
Expand All @@ -26,7 +24,7 @@ const completeAccountInformationSignupInvite = ({
verifier,
token,
}) => {
return fetch(PATH + "/api/v1/signup/complete-account/invite", {
return fetch("/api/v1/signup/complete-account/invite", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/auth/IssueBackupPrivateKey.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -13,7 +12,7 @@ const issueBackupPrivateKey = ({
clientProof,
}) => {
return SecurityClient.fetchCall(
PATH + "/api/v1/password/backup-private-key",
"/api/v1/password/backup-private-key",
{
method: "POST",
headers: {
Expand Down
4 changes: 1 addition & 3 deletions frontend/pages/api/auth/Login1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { PATH } from "~/const";

/**
* This is the first step of the login process (pake)
* @param {*} email
* @param {*} clientPublicKey
* @returns
*/
const login1 = (email, clientPublicKey) => {
return fetch(PATH + "/api/v1/auth/login1", {
return fetch("/api/v1/auth/login1", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 1 addition & 3 deletions frontend/pages/api/auth/Login2.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { PATH } from "~/const";

/**
* This is the second step of the login process
* @param {*} email
* @param {*} clientPublicKey
* @returns
*/
const login2 = (email, clientProof) => {
return fetch(PATH + "/api/v1/auth/login2", {
return fetch("/api/v1/auth/login2", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/auth/Logout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -9,7 +8,7 @@ import SecurityClient from "~/utilities/SecurityClient";
* @returns
*/
const logout = async (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/auth/logout", {
return SecurityClient.fetchCall("/api/v1/auth/logout", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/auth/SRP1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -7,7 +6,7 @@ import SecurityClient from "~/utilities/SecurityClient";
* @returns
*/
const SRP1 = ({ clientPublicKey }) => {
return SecurityClient.fetchCall(PATH + "/api/v1/password/srp1", {
return SecurityClient.fetchCall("/api/v1/password/srp1", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 1 addition & 3 deletions frontend/pages/api/auth/SendVerificationEmail.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { PATH } from "~/const";

/**
* This route send the verification email to the user's email (contains a 6-digit verification code)
* @param {*} email
*/
const sendVerificationEmail = (email) => {
fetch(PATH + "/api/v1/signup/email/signup", {
fetch("/api/v1/signup/email/signup", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 1 addition & 3 deletions frontend/pages/api/auth/Token.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { PATH } from "~/const";

const token = async (req, res) => {
return fetch(PATH + "/api/v1/auth/token", {
return fetch("/api/v1/auth/token", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 1 addition & 3 deletions frontend/pages/api/auth/VerifySignupInvite.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { PATH } from "~/const";

/**
* This route verifies the signup invite link
* @param {*} email
* @param {*} code
* @returns
*/
const verifySignupInvite = ({ email, code }) => {
return fetch(PATH + "/api/v1/invite-org/verify", {
return fetch("/api/v1/invite-org/verify", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
4 changes: 1 addition & 3 deletions frontend/pages/api/auth/publicKeyInfisical.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
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.
* @param {*} req
* @param {*} res
* @returns
*/
const publicKeyInfisical = (req, res) => {
return fetch(PATH + "/api/v1/key/publicKey/infisical", {
return fetch("/api/v1/key/publicKey/infisical", {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand Down
2 changes: 0 additions & 2 deletions frontend/pages/api/files/GetSecrets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient.js";

/**
Expand All @@ -9,7 +8,6 @@ import SecurityClient from "~/utilities/SecurityClient.js";
*/
const getSecrets = async (workspaceId, env) => {
return SecurityClient.fetchCall(
PATH +
"/api/v1/secret/" +
workspaceId +
"?" +
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/files/UploadSecrets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -8,7 +7,7 @@ import SecurityClient from "~/utilities/SecurityClient";
* @returns
*/
const uploadSecrets = async ({ workspaceId, secrets, keys, environment }) => {
return SecurityClient.fetchCall(PATH + "/api/v1/secret/" + workspaceId, {
return SecurityClient.fetchCall("/api/v1/secret/" + workspaceId, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/integrations/ChangeHerokuConfigVars.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

const changeHerokuConfigVars = ({ integrationId, key, secrets }) => {
return SecurityClient.fetchCall(
PATH + "/api/v1/integration/" + integrationId + "/sync",
"/api/v1/integration/" + integrationId + "/sync",
{
method: "POST",
headers: {
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/integrations/DeleteIntegration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -8,7 +7,7 @@ import SecurityClient from "~/utilities/SecurityClient";
*/
const deleteIntegration = ({ integrationId }) => {
return SecurityClient.fetchCall(
PATH + "/api/v1/integration/" + integrationId,
"/api/v1/integration/" + integrationId,
{
method: "DELETE",
headers: {
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/integrations/DeleteIntegrationAuth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -8,7 +7,7 @@ import SecurityClient from "~/utilities/SecurityClient";
*/
const deleteIntegrationAuth = ({ integrationAuthId }) => {
return SecurityClient.fetchCall(
PATH + "/api/v1/integration-auth/" + integrationAuthId,
"/api/v1/integration-auth/" + integrationAuthId,
{
method: "DELETE",
headers: {
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/integrations/GetIntegrationApps.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

const getIntegrationApps = ({ integrationAuthId }) => {
return SecurityClient.fetchCall(
PATH + "/api/v1/integration-auth/" + integrationAuthId + "/apps",
"/api/v1/integration-auth/" + integrationAuthId + "/apps",
{
method: "GET",
headers: {
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/integrations/GetIntegrations.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

const getIntegrations = () => {
return SecurityClient.fetchCall(PATH + "/api/v1/integration/integrations", {
return SecurityClient.fetchCall("/api/v1/integration/integrations", {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/integrations/StartIntegration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -8,7 +7,7 @@ import SecurityClient from "~/utilities/SecurityClient";
*/
const startIntegration = ({ integrationId, appName, environment }) => {
return SecurityClient.fetchCall(
PATH + "/api/v1/integration/" + integrationId,
"/api/v1/integration/" + integrationId,
{
method: "PATCH",
headers: {
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/integrations/authorizeIntegration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -8,7 +7,7 @@ import SecurityClient from "~/utilities/SecurityClient";
*/
const AuthorizeIntegration = ({ workspaceId, code, integration }) => {
return SecurityClient.fetchCall(
PATH + "/api/v1/integration-auth/oauth-token",
"/api/v1/integration-auth/oauth-token",
{
method: "POST",
headers: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -8,7 +7,7 @@ import SecurityClient from "~/utilities/SecurityClient";
*/
const getWorkspaceAuthorizations = ({ workspaceId }) => {
return SecurityClient.fetchCall(
PATH + "/api/v1/workspace/" + workspaceId + "/authorizations",
"/api/v1/workspace/" + workspaceId + "/authorizations",
{
method: "GET",
headers: {
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/integrations/getWorkspaceIntegrations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -8,7 +7,7 @@ import SecurityClient from "~/utilities/SecurityClient";
*/
const getWorkspaceIntegrations = ({ workspaceId }) => {
return SecurityClient.fetchCall(
PATH + "/api/v1/workspace/" + workspaceId + "/integrations",
"/api/v1/workspace/" + workspaceId + "/integrations",
{
method: "GET",
headers: {
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/organization/GetOrg.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -8,7 +7,7 @@ import SecurityClient from "~/utilities/SecurityClient";
* @returns
*/
const getOrganization = (req, res) => {
return SecurityClient.fetchCall(PATH + "/api/v1/organization/" + req.orgId, {
return SecurityClient.fetchCall("/api/v1/organization/" + req.orgId, {
method: "GET",
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/api/organization/GetOrgProjects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PATH } from "~/const";
import SecurityClient from "~/utilities/SecurityClient";

/**
Expand All @@ -9,7 +8,7 @@ import SecurityClient from "~/utilities/SecurityClient";
*/
const getOrganizationProjects = (req, res) => {
return SecurityClient.fetchCall(
PATH + "/api/organization/" + req.orgId + "/workspaces",
"/api/organization/" + req.orgId + "/workspaces",
{
method: "GET",
headers: {
Expand Down
Loading

0 comments on commit d8aa5b5

Please sign in to comment.