Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
496 changes: 482 additions & 14 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/http-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { googleAuth } from "./routes/google_callback.js";

const app = express()

const allowedOrigins = ['http://localhost:3000' , 'http://localhost:3001' ];
const allowedOrigins = ['http://localhost:3000' , 'http://localhost:300/' ];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Fix CORS origin typo.

The second allowed origin was changed from 'http://localhost:3001' to 'http://localhost:300/', which appears to be an accidental typo. This will break CORS for any service running on port 3001.

🔎 Proposed fix
-const allowedOrigins = ['http://localhost:3000' , 'http://localhost:300/' ];
+const allowedOrigins = ['http://localhost:3000', 'http://localhost:3001'];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const allowedOrigins = ['http://localhost:3000' , 'http://localhost:300/' ];
const allowedOrigins = ['http://localhost:3000', 'http://localhost:3001'];
🤖 Prompt for AI Agents
In apps/http-backend/src/index.ts around line 16, the allowedOrigins array
contains a typo: 'http://localhost:300/' was mistakenly used instead of the
intended 'http://localhost:3001'; update that entry to 'http://localhost:3001'
so CORS allows requests from the correct port 3001 origin.

app.use(cors({
origin: allowedOrigins,
credentials: true,
Expand Down
2 changes: 1 addition & 1 deletion apps/http-backend/src/routes/google_callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ googleAuth.get('/callback', async(req: Request, res: Response)=>{
);

try {
const { tokens } = await oauth2.getToken(code);
const { tokens } = await oauth2.getToken(code);

// Save tokens to database if userId (state) is provided
if (state && typeof state === 'string') {
Expand Down
153 changes: 87 additions & 66 deletions apps/http-backend/src/routes/nodes.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,100 @@ import { statusCodes } from "@repo/common/zod";
import { GoogleSheetsNodeExecutor } from "@repo/nodes";

export const sheetRouter: Router = Router();
const sheetExecutor = new GoogleSheetsNodeExecutor()
const sheetExecutor = new GoogleSheetsNodeExecutor();


sheetRouter.get("/getDocuments/:cred", userMiddleware, async(req: AuthRequest, res: Response)=>{
try{
if (!req.user)
return res
.status(statusCodes.BAD_GATEWAY)
.json({ message: "User isnot logged in /not authorized" });
const credId = req.params.cred
if(!credId){
return res
.status(statusCodes.BAD_REQUEST)
.json({message: "credentials id not provided"})
}
const userId = req.user.sub
console.log("userid from node route: ", userId)
if(!userId) return res
.status(statusCodes.NOT_FOUND)
.json({message: "User id not provided"})
const sheets = await sheetExecutor.getSheets({userId: userId, credId: credId})
if ((sheets as any)?.success === false) {
return res.status(statusCodes.NOT_FOUND).json({
message: "files not found",
files: sheets
});
}
return res.status(statusCodes.OK).json({
message: "sheets are fetched successfully",
files: (sheets as any)?.data?.data?.files || []
})
}catch(e){
console.log("Error Fetching the credentials ", e instanceof Error ? e.message : "Unkown reason");
sheetRouter.get(
"/getDocuments/:cred",
userMiddleware,
async (req: AuthRequest, res: Response) => {
try {
if (!req.user)
return res
.status(statusCodes.BAD_GATEWAY)
.json({ message: "User isnot logged in /not authorized" });
const credId = req.params.cred;
if (!credId) {
return res
.status(statusCodes.BAD_REQUEST)
.json({ message: "credentials id not provided" });
}
const userId = req.user.sub;
console.log("userid from node route: ", userId);
if (!userId)
return res
.status(statusCodes.NOT_FOUND)
.json({ message: "User id not provided" });
const sheets = await sheetExecutor.getSheets({
userId: userId,
credId: credId,
});
if ((sheets as any)?.success === false) {
return res.status(statusCodes.NOT_FOUND).json({
message: "files not found",
files: sheets,
});
}
return res.status(statusCodes.OK).json({
message: "sheets are fetched successfully",
files: (sheets as any)?.data?.data?.files || [],
});
} catch (e) {
console.log(
"Error Fetching the credentials ",
e instanceof Error ? e.message : "Unkown reason"
);
return res
.status(statusCodes.INTERNAL_SERVER_ERROR)
.json({ message: "Internal server from fetching the credentials" });
}
})
}
);
Comment on lines +9 to +54

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo in error message.

Line 47 contains a typo: "Unkown" should be "Unknown".

🔎 Proposed fix
         "Error Fetching the credentials ",
-        e instanceof Error ? e.message : "Unkown reason"
+        e instanceof Error ? e.message : "Unknown reason"
       );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sheetRouter.get(
"/getDocuments/:cred",
userMiddleware,
async (req: AuthRequest, res: Response) => {
try {
if (!req.user)
return res
.status(statusCodes.BAD_GATEWAY)
.json({ message: "User isnot logged in /not authorized" });
const credId = req.params.cred;
if (!credId) {
return res
.status(statusCodes.BAD_REQUEST)
.json({ message: "credentials id not provided" });
}
const userId = req.user.sub;
console.log("userid from node route: ", userId);
if (!userId)
return res
.status(statusCodes.NOT_FOUND)
.json({ message: "User id not provided" });
const sheets = await sheetExecutor.getSheets({
userId: userId,
credId: credId,
});
if ((sheets as any)?.success === false) {
return res.status(statusCodes.NOT_FOUND).json({
message: "files not found",
files: sheets,
});
}
return res.status(statusCodes.OK).json({
message: "sheets are fetched successfully",
files: (sheets as any)?.data?.data?.files || [],
});
} catch (e) {
console.log(
"Error Fetching the credentials ",
e instanceof Error ? e.message : "Unkown reason"
);
return res
.status(statusCodes.INTERNAL_SERVER_ERROR)
.json({ message: "Internal server from fetching the credentials" });
}
})
}
);
sheetRouter.get(
"/getDocuments/:cred",
userMiddleware,
async (req: AuthRequest, res: Response) => {
try {
if (!req.user)
return res
.status(statusCodes.BAD_GATEWAY)
.json({ message: "User isnot logged in /not authorized" });
const credId = req.params.cred;
if (!credId) {
return res
.status(statusCodes.BAD_REQUEST)
.json({ message: "credentials id not provided" });
}
const userId = req.user.sub;
console.log("userid from node route: ", userId);
if (!userId)
return res
.status(statusCodes.NOT_FOUND)
.json({ message: "User id not provided" });
const sheets = await sheetExecutor.getSheets({
userId: userId,
credId: credId,
});
if ((sheets as any)?.success === false) {
return res.status(statusCodes.NOT_FOUND).json({
message: "files not found",
files: sheets,
});
}
return res.status(statusCodes.OK).json({
message: "sheets are fetched successfully",
files: (sheets as any)?.data?.data?.files || [],
});
} catch (e) {
console.log(
"Error Fetching the credentials ",
e instanceof Error ? e.message : "Unknown reason"
);
return res
.status(statusCodes.INTERNAL_SERVER_ERROR)
.json({ message: "Internal server from fetching the credentials" });
}
}
);
🤖 Prompt for AI Agents
In apps/http-backend/src/routes/nodes.routes.ts around lines 9 to 54, the catch
block's console.log message contains a typo ("Unkown"); update the string to
"Unknown" so the line reads e.g. e instanceof Error ? e.message : "Unknown
reason". Ensure only the typo is fixed and the rest of the logging/response
remains unchanged.


sheetRouter.get(
"/getSheets/:cred/:sheetId",
userMiddleware,
async (req: AuthRequest, res: Response) => {
try {
const userId = req.user?.sub;
if (!userId)
return res
.status(statusCodes.BAD_GATEWAY)
.json({ message: "User isnot logged in /not authorized" });
const credId = req.params.cred;
const sheetId = req.params.sheetId;
if (!credId || !sheetId) {
return res
.status(statusCodes.BAD_REQUEST)
.json({ message: `credentials id not provided ` });
}
if (!sheetExecutor) {
return res.status(statusCodes.FORBIDDEN).json({
message: "sheet executor not configured well",
});
}
const sheets = await sheetExecutor.getSheetTabs(
{ userId: userId, credId: credId },
sheetId
);

if ((sheets as any)?.success === false)
return res.status(statusCodes.NOT_FOUND).json({
message: "files not found",
files: sheets,
});

sheetRouter.get('/getSheets/:cred/:sheetId', userMiddleware, async(req: AuthRequest, res: Response)=>{
try{
const userId = req.user?.sub
if (!userId)
return res
.status(statusCodes.BAD_GATEWAY)
.json({ message: "User isnot logged in /not authorized" });
const credId = req.params.cred
const sheetId = req.params.sheetId
if(!credId || !sheetId){
return res
.status(statusCodes.BAD_REQUEST)
.json({message: `credentials id not provided `})
}
if(!sheetExecutor){
return res.status(statusCodes.FORBIDDEN).json({
message: "sheet executor not configured well"
})
}
const sheets = await sheetExecutor.getSheetTabs({userId: userId, credId: credId}, sheetId)

if((sheets as any)?.success === false) return res.status(statusCodes.NOT_FOUND).json({
message: "files not found",
files: sheets
});

return res.status(statusCodes.OK).json({
message: "sheets are fetched successfully",
files: sheets
})
}catch(e){
console.log("Error Fetching the credentials ", e instanceof Error ? e.message : "Unkown reason");
return res.status(statusCodes.OK).json({
message: "sheets are fetched successfully",
files: sheets,
});
} catch (e) {
console.log(
"Error Fetching the credentials ",
e instanceof Error ? e.message : "Unkown reason"
);
return res
.status(statusCodes.INTERNAL_SERVER_ERROR)
.json({ message: "Internal server from fetching the credentials" });
}
})
}
);
Comment on lines +56 to +103

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove unnecessary executor check and fix typo.

Two issues in this new route:

  1. Lines 73-77: The check if (!sheetExecutor) is unnecessary. The executor is instantiated at Line 7 as a const, so it will never be falsy.

  2. Line 96: Typo "Unkown" should be "Unknown".

🔎 Proposed fixes

Remove the unnecessary check:

       const sheetId = req.params.sheetId;
       if (!credId || !sheetId) {
         return res
           .status(statusCodes.BAD_REQUEST)
           .json({ message: `credentials id not provided ` });
       }
-      if (!sheetExecutor) {
-        return res.status(statusCodes.FORBIDDEN).json({
-          message: "sheet executor not configured well",
-        });
-      }
       const sheets = await sheetExecutor.getSheetTabs(

Fix the typo:

         "Error Fetching the credentials ",
-        e instanceof Error ? e.message : "Unkown reason"
+        e instanceof Error ? e.message : "Unknown reason"
       );
🤖 Prompt for AI Agents
In apps/http-backend/src/routes/nodes.routes.ts around lines 56 to 103, remove
the unnecessary runtime check for sheetExecutor (delete lines 73-77) since
sheetExecutor is a const instantiated at module load and cannot be falsy, and
fix the typo on the error log at line 96 by changing "Unkown" to "Unknown" so
the catch block logs correct spelling.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function userMiddleware(
next: NextFunction
) {
try {
console.log(req.cookies);
// console.log(req.cookies);
const payload = await getToken({ req, secret: SECRET });

if (!payload) {
Expand Down
119 changes: 48 additions & 71 deletions apps/http-backend/src/routes/userRoutes/userRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ router.post("/createAvaliableNode", async (req: AuthRequest, res: Response) => {
}
});

router.get("/getAvailableNodes",
router.get(
"/getAvailableNodes",
userMiddleware,
async (req: AuthRequest, res: Response) => {
if (!req.user) {
Expand All @@ -93,7 +94,8 @@ router.get("/getAvailableNodes",
}
);

router.post("/createAvaliableTriggers",
router.post(
"/createTriggers",
userMiddleware,
async (req: AuthRequest, res: Response) => {
try {
Expand Down Expand Up @@ -127,7 +129,8 @@ router.post("/createAvaliableTriggers",
}
);

router.get("/getAvailableTriggers",
router.get(
"/getAvailableTriggers",
userMiddleware,
async (req: AuthRequest, res: Response) => {
try {
Expand Down Expand Up @@ -155,54 +158,56 @@ router.get("/getAvailableTriggers",

router.get('/getCredentials/:type',
userMiddleware,
async (req: AuthRequest, res) =>{
try{
console.log("user from getcredentials: ",req.user)
if(!req.user){
return res.status(statusCodes.BAD_REQUEST).json({
message: "User is not Loggedin"
})
}
const userId = req.user.sub;
const type = req.params.type
console.log(userId," -userid")
if(!type || !userId){
return res.status(statusCodes.BAD_REQUEST).json({
message: "Incorrect type Input",
});
}
const executor = new GoogleSheetsNodeExecutor()
const response = await executor.getAllCredentials(userId,type)
// console.log( typeof(response));
// console.log("response: ",response)
const authUrl = typeof response === 'string' ? response : null
// console.log(authUrl);

const credentials = response instanceof Object ? response : null
// console.log(credentials)
if(authUrl){
return res.status(statusCodes.OK).json({
message: "Credentials not found create credentials using this auth url",
async (req: AuthRequest, res) => {
try {
console.log("user from getcredentials: ", req.user);
if (!req.user) {
return res.status(statusCodes.BAD_REQUEST).json({
message: "User is not Loggedin",
});
}
const userId = req.user.sub;
const type = req.params.type;
console.log(userId, " -userid");
if (!type || !userId) {
return res.status(statusCodes.BAD_REQUEST).json({
message: "Incorrect type Input",
});
}
const executor = new GoogleSheetsNodeExecutor();
const response = await executor.getAllCredentials(userId, type);
// console.log( typeof(response));
// console.log("response: ",response)
const authUrl = typeof response === "string" ? response : null;
// console.log(authUrl);

const credentials = response instanceof Object ? response : null;
// console.log(credentials)
if (authUrl) {
return res.status(statusCodes.OK).json({
message:
"Credentials not found create credentials using this auth url",
Data: authUrl,
});
}
else return res.status(statusCodes.OK).json({
} else
return res.status(statusCodes.OK).json({
message: "Credentials Fetched succesfully",
Data: credentials,
});
}
catch(e){
console.log("Error Fetching the credentials ", e instanceof Error ? e.message : "Unkown reason");
} catch (e) {
console.log(
"Error Fetching the credentials ",
e instanceof Error ? e.message : "Unkown reason"
);
return res
.status(statusCodes.INTERNAL_SERVER_ERROR)
.json({ message: "Internal server from fetching the credentials" });
}
}
);

// ----------------------------------- CREATE WORKFLOW ---------------------------------

router.post("/create/workflow",
router.post(
"/create/workflow",
userMiddleware,
async (req: AuthRequest, res) => {
try {
Expand Down Expand Up @@ -252,9 +257,8 @@ router.post("/create/workflow",
}
);

// ------------------------------------ FETCHING WORKFLOWS -----------------------------------

router.get("/workflows",
router.get(
"/workflows",
userMiddleware,
async (req: AuthRequest, res: Response) => {
try {
Expand Down Expand Up @@ -282,35 +286,8 @@ router.get("/workflows",
}
);

router.get('/empty/workflow', userMiddleware, async(req:AuthRequest, res: Response)=>{
try{
if (!req.user)
return res
.status(statusCodes.UNAUTHORIZED)
.json({ message: "User is not logged in /not authorized" });
const userId = req.user.id;
const workflow = await prismaClient.workflow.findFirst({
where:{
userId: userId,
isEmpty: true
},
orderBy: {
createdAt: 'desc'
}
})
return res
.status(statusCodes.OK)
.json({ message: "Workflow fetched succesful", Data: workflow });

}catch(e){
console.log("The error is from getting wrkflows", e instanceof Error ? e.message : "UNKNOWN ERROR");

return res.status(statusCodes.INTERNAL_SERVER_ERROR).json({
meesage: "Internal Server Error From getting workflows for the user",
});
}
})
router.get("/workflow/:workflowId",
router.get(
"/workflow/:workflowId",
userMiddleware,
async (req: AuthRequest, res: Response) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion apps/http-backend/tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"root":["./src/index.ts","./src/routes/google_callback.ts","./src/routes/nodes.routes.ts","./src/routes/userroutes/usermiddleware.ts","./src/routes/userroutes/userroutes.ts"],"version":"5.7.3"}
{"root":["./src/index.ts","./src/routes/google_callback.ts","./src/routes/nodes.routes.ts","./src/routes/userRoutes/userMiddleware.ts","./src/routes/userRoutes/userRoutes.ts"],"version":"5.7.3"}
Loading