-
Notifications
You must be signed in to change notification settings - Fork 0
Added Email Integration and complete worker #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -153,51 +153,105 @@ router.get("/getAvailableTriggers", | |||||
| } | ||||||
| ); | ||||||
|
|
||||||
| // //------------------------------ GET CREDENTIALS ----------------------------- | ||||||
|
|
||||||
| // 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", | ||||||
| // Data: authUrl, | ||||||
| // }); | ||||||
| // } | ||||||
| // 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"); | ||||||
| // return res | ||||||
| // .status(statusCodes.INTERNAL_SERVER_ERROR) | ||||||
| // .json({ message: "Internal server from fetching the credentials" }); | ||||||
| // } | ||||||
| // } | ||||||
| // ); | ||||||
|
|
||||||
| //------------------------------ GET CREDENTIALS ----------------------------- | ||||||
|
|
||||||
| 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", | ||||||
| }); | ||||||
| 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; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent userId extraction may cause authorization issues. This route uses 🔎 Proposed fix to use consistent userId extraction- const userId = req.user.sub;
+ const userId = req.user.id;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| const type = req.params.type | ||||||
| console.log(userId, " -userid") | ||||||
|
|
||||||
| if (!type || !userId) { | ||||||
| return res.status(statusCodes.BAD_REQUEST).json({ | ||||||
| message: "Incorrect type Input", | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| // Check if credentials exist in database | ||||||
| const credentials = await prismaClient.credential.findMany({ | ||||||
| where: { | ||||||
| userId: userId, | ||||||
| type : type | ||||||
| } | ||||||
| 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({ | ||||||
| }); | ||||||
|
|
||||||
| if (credentials.length === 0) { | ||||||
| // No credentials found - return the correct auth URL | ||||||
| const authUrl = `${process.env.BACKEND_URL || 'http://localhost:3002'}/auth/google/initiate`; | ||||||
| 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({ | ||||||
| message: "Credentials Fetched succesfully", | ||||||
| Data: credentials, | ||||||
| }); | ||||||
| } | ||||||
| catch(e){ | ||||||
| console.log("Error Fetching the credentials ", e instanceof Error ? e.message : "Unkown reason"); | ||||||
| } | ||||||
|
|
||||||
| // Credentials found - return them | ||||||
| return res.status(statusCodes.OK).json({ | ||||||
| message: "Credentials Fetched successfully", | ||||||
| Data: credentials, | ||||||
| }); | ||||||
|
|
||||||
| } 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" }); | ||||||
| .json({ message: "Internal server error from fetching the credentials" }); | ||||||
| } | ||||||
| } | ||||||
| ); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,72 @@ | ||||||||||||||||||||||||||||||
| import { prismaClient } from "@repo/db/client"; | ||||||||||||||||||||||||||||||
| import { register } from "./registory.js"; | ||||||||||||||||||||||||||||||
| export async function executeWorkflow( | ||||||||||||||||||||||||||||||
| workflowExecutionId: string | ||||||||||||||||||||||||||||||
| ): Promise<void> { | ||||||||||||||||||||||||||||||
| console.log(`workflowExecutionId is ${workflowExecutionId}`); | ||||||||||||||||||||||||||||||
| const data = await prismaClient.workflowExecution.findUnique({ | ||||||||||||||||||||||||||||||
| where: { id: workflowExecutionId }, | ||||||||||||||||||||||||||||||
| include: { | ||||||||||||||||||||||||||||||
| workflow: { | ||||||||||||||||||||||||||||||
| include: { | ||||||||||||||||||||||||||||||
| nodes: { | ||||||||||||||||||||||||||||||
| include: { | ||||||||||||||||||||||||||||||
| AvailableNode: true, | ||||||||||||||||||||||||||||||
| credentials: true, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| orderBy: { position: "asc" }, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| let currentInputData = data?.metadata; | ||||||||||||||||||||||||||||||
| if (!data) { | ||||||||||||||||||||||||||||||
| console.log(`No workflow execution found for id ${workflowExecutionId}`); | ||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const update = await prismaClient.workflowExecution.update({ | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| const update = await prismaClient.workflowExecution.update({ | |
| await prismaClient.workflowExecution.update({ |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null pointer issue. If no credentials are found for a node (credentials array is empty), this will fail when trying to access 'credentials[0]'. The code should check if credentials exist before accessing them.
| credentialId: node.credentials[0]?.id, | |
| credentialId: node.credentials?.[0]?.id, |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Property name mismatch. The context object uses 'credentialId' but the ExecutionContext interface in types.ts defines it as 'credentialsId' (plural). This inconsistency will cause type errors and runtime issues.
| credentialId: node.credentials[0]?.id, | |
| credentialsId: node.credentials[0]?.id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Field name mismatch - credentialId should be credentialsId.
Line 45 uses credentialId (singular), but the ExecutionContext interface in apps/worker/src/types.ts line 4 defines the field as credentialsId (plural). This breaks the type contract and causes runtime issues when executors try to access the credentials.
🔎 Proposed fix
const context = {
nodeId: node.id,
userId: data.workflow.userId,
- credentialId: node.credentials[0]?.id,
+ credentialsId: node.credentials[0]?.id,
config: node.config as Record<string, any>,
inputData: currentInputData,
};📝 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.
| const context = { | |
| nodeId: node.id, | |
| userId: data.workflow.userId, | |
| credentialId: node.credentials[0]?.id, | |
| config: node.config as Record<string, any>, | |
| inputData: currentInputData, | |
| }; | |
| const context = { | |
| nodeId: node.id, | |
| userId: data.workflow.userId, | |
| credentialsId: node.credentials[0]?.id, | |
| config: node.config as Record<string, any>, | |
| inputData: currentInputData, | |
| }; |
🤖 Prompt for AI Agents
In @apps/worker/src/engine/executor.ts around lines 42-48, The context object in
executor.ts uses the wrong field name `credentialId` (singular) which doesn't
match the `ExecutionContext` interface's `credentialsId` (plural); update the
context literal in the executor (the `context` variable) to use `credentialsId`
and populate it with the same value currently assigned to `credentialId` (e.g.,
node.credentials[0]?.id) so the shape matches the `ExecutionContext` defined in
apps/worker/src/types.ts and executors can access credentials correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add explicit check for authenticated user.
While
userMiddlewareis applied, there's no explicit check ifreq.userexists before usingreq.user?.idas the OAuth state parameter (line 30). Ifreq.useris undefined, the state will be undefined, which could cause the callback flow to fail when associating tokens with the user.🔎 Proposed fix to add explicit authentication check
"/initiate", userMiddleware, async (req: AuthRequest, res: Response) => { - // const userId = req.user?.id || "test_user"; // Get from auth middleware - const userId = req.user?.id; + if (!req.user?.id) { + return res.status(401).json({ + message: "User authentication required" + }); + } + const userId = req.user.id; const oauth2 = new google.auth.OAuth2(📝 Committable suggestion
🤖 Prompt for AI Agents