Skip to content
Open
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
8 changes: 4 additions & 4 deletions BUILDER_IMAGES/build-image-backend/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const sns = new SNSClient({

const TOPIC_ARN = process.env.DOMAIN_EVENTS_TOPIC_ARN;

async function publilishEvent(type, projectId, deploymentId, payload) {
async function publishEvent(type, projectId, deploymentId, payload) {
await sns.send(
new PublishCommand({
TopicArn: TOPIC_ARN,
Expand All @@ -27,9 +27,9 @@ async function publilishEvent(type, projectId, deploymentId, payload) {
);
}

module.exports = { publilishEvent };
module.exports = { publishEvent };


console.log("publilishEvent type:", typeof publilishEvent);
console.log("publishEvent type:", typeof publishEvent);

module.exports = { publilishEvent };
module.exports = { publishEvent };
Comment on lines +30 to +35
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

module.exports is assigned twice and there's a top-level console.log that will run on every require/import. This creates noisy logs in production and makes the module harder to reason about; keep a single export assignment and remove the debug log (or gate it behind an explicit debug flag).

Copilot uses AI. Check for mistakes.
8 changes: 4 additions & 4 deletions BUILDER_IMAGES/build-image-backend/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { spawn } = require("child_process")
const path = require("path");
const fs = require("fs")
const { Kafka } = require("kafkajs");
const { publilishEvent } = require("./publisher");
const { publishEvent } = require("./publisher");

const PROJECT_ID = process.env.PROJECT_ID;
const ECR_URI = process.env.ECR_URI;
Expand Down Expand Up @@ -85,7 +85,7 @@ async function init() {
throw new Error(`Build context path does not exist: ${buildContext}`);
}

publilishEvent("BACKEND_PROCESSING", PROJECT_ID, DEPLOYMENTID, { backendDir: BACKEND_DIR })
publishEvent("BACKEND_PROCESSING", PROJECT_ID, DEPLOYMENTID, { backendDir: BACKEND_DIR })


if (!NODE_VERSION) {
Expand Down Expand Up @@ -154,7 +154,7 @@ async function init() {
"BUILD",
`Image build failed with code: ${code}`
);
publilishEvent("BACKEND_BUILD_FAILED", PROJECT_ID, DEPLOYMENTID, { msg: "Image build failed with code: ${code}" })
publishEvent("BACKEND_BUILD_FAILED", PROJECT_ID, DEPLOYMENTID, { msg: `Image build failed with code: ${code}` })
await safeExit(code, "Build failed");
}
});
Expand All @@ -163,7 +163,7 @@ async function init() {
init().catch(err => {
console.log("INIT ERROR ", err);
publishLog("FAILURE", "INIT", err.message)
publilishEvent("BACKEND_BUILD_FAILED", PROJECT_ID, DEPLOYMENTID, { msg: err.message })
publishEvent("BACKEND_BUILD_FAILED", PROJECT_ID, DEPLOYMENTID, { msg: err.message })
.finally(() => safeExit(1, "Build Init Failed"));
});;

Expand Down
4 changes: 2 additions & 2 deletions BUILDER_IMAGES/builder-image-frontend/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const sns = new SNSClient({

const TOPIC_ARN = process.env.DOMAIN_EVENTS_TOPIC_ARN;

async function publilishEvent(type, projectId, deploymentId, payload) {
async function publishEvent(type, projectId, deploymentId, payload) {
await sns.send(
new PublishCommand({
TopicArn: TOPIC_ARN,
Expand All @@ -23,4 +23,4 @@ async function publilishEvent(type, projectId, deploymentId, payload) {
)
}

module.exports = { publilishEvent };
module.exports = { publishEvent };
20 changes: 10 additions & 10 deletions BUILDER_IMAGES/builder-image-frontend/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const mime = require("mime-types");
const readDirRecursive = require("./utils/readDirRecursive");
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
const { Kafka } = require("kafkajs");
const { publilishEvent } = require("./publisher");
const { publishEvent } = require("./publisher");

/* ---------------- ENV ---------------- */

Expand Down Expand Up @@ -75,7 +75,7 @@ async function publishLog(level, stage, message) {
}),
},
],
}).catch(() => {});
}).catch(() => { });
}

/* ---------------- SAFE EXIT ---------------- */
Expand All @@ -90,7 +90,7 @@ async function safeExit(code, reason) {
await publishLog("INFO", "SHUTDOWN", reason);
}
await producer.disconnect();
} catch (_) {}
} catch (_) { }
finally {
process.exit(code);
}
Expand All @@ -104,7 +104,7 @@ process.on("SIGTERM", () => safeExit(143, "SIGTERM"));
async function init() {
await producer.connect();

await publilishEvent(
await publishEvent(
"FRONTEND_PROCESSING",
PROJECT_ID,
DEPLOYMENTID,
Expand All @@ -117,7 +117,7 @@ async function init() {
const frontendPath = path.join(outputDir, FRONTENDPATH || ".");

if (!fs.existsSync(frontendPath)) {
await publilishEvent(
await publishEvent(
"FRONTEND_BUILT_FAILED",
PROJECT_ID,
DEPLOYMENTID,
Expand All @@ -138,7 +138,7 @@ async function init() {

build.on("close", async (code) => {
if (code !== 0) {
await publilishEvent(
await publishEvent(
"FRONTEND_BUILT_FAILED",
PROJECT_ID,
DEPLOYMENTID,
Expand Down Expand Up @@ -168,7 +168,7 @@ async function init() {
}));
}

await publilishEvent(
await publishEvent(
"FRONTEND_BUILT_SUCCESS",
PROJECT_ID,
DEPLOYMENTID,
Expand All @@ -179,7 +179,7 @@ async function init() {
await safeExit(0, "Success");

} catch (err) {
await publilishEvent(
await publishEvent(
"FRONTEND_BUILT_FAILED",
PROJECT_ID,
DEPLOYMENTID,
Expand All @@ -191,7 +191,7 @@ async function init() {
}

init().catch(async (err) => {
await publilishEvent(
await publishEvent(
"FRONTEND_BUILT_FAILED",
PROJECT_ID,
DEPLOYMENTID,
Expand All @@ -203,7 +203,7 @@ init().catch(async (err) => {
/* ---------------- TIMEOUT ---------------- */

setTimeout(async () => {
await publilishEvent(
await publishEvent(
"FRONTEND_BUILT_FAILED",
PROJECT_ID,
DEPLOYMENTID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dotenv from 'dotenv';
import { AwsCredentialIdentity } from "@aws-sdk/types";
import { ECSClient, RunTaskCommand } from "@aws-sdk/client-ecs";
import { backendECSConfig } from "../../config/ECSconfig.js"
import { DeploymentStatus, publilishEvent } from "@veren/domain";
import { DeploymentStatus, publishEvent } from "@veren/domain";

dotenv.config({
path: '../../../.env'
Expand Down Expand Up @@ -90,7 +90,7 @@ export async function buildBackend(

const resp = await ecsClient.send(backendCommand)
if (resp.failures && resp.failures.length > 0) {
publilishEvent({
publishEvent({
type: DeploymentStatus.INTERNAL_ERROR,
projectId,
deploymentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AwsCredentialIdentity } from "@aws-sdk/types";

import dotenv from "dotenv";
import logger from "../../logger/logger.js";
import { DeploymentStatus, publilishEvent } from '@veren/domain';
import { DeploymentStatus, publishEvent } from '@veren/domain';

dotenv.config({
path: '../../../.env'
Expand Down Expand Up @@ -119,7 +119,7 @@ export async function buildFrontend(

const resp = await ecsClient.send(command18)
if (resp.failures && resp.failures.length > 0) {
publilishEvent({
publishEvent({
type: DeploymentStatus.INTERNAL_ERROR,
projectId,
deploymentId,
Expand Down Expand Up @@ -161,7 +161,7 @@ export async function buildFrontend(

const resp = await ecsClient.send(command20)
if (resp.failures && resp.failures.length > 0) {
publilishEvent({
publishEvent({
type: DeploymentStatus.INTERNAL_ERROR,
projectId,
deploymentId,
Expand Down
12 changes: 6 additions & 6 deletions WORKERS/build-worker/src/workers/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { buildFrontend } from "../services/distributionHandler/buildFrontend.js"
import { buildBackend } from "../services/distributionHandler/buildBackend.js"
import { safeExecute } from "../types/index.js";

import { DeploymentStatus, publilishEvent } from '@veren/domain'
import { DeploymentStatus, publishEvent } from '@veren/domain'
import { BuildJobError } from "../utils/buildError.js";

dotenv.config({ path: "../../.env" });
Expand Down Expand Up @@ -129,7 +129,7 @@ const worker = new Worker<BuildJobData, BuildJobResult>('buildQueue',
worker.on('completed', async (job, result) => {
const { projectId, deploymentId, FrontendtaskArn, BackendtaskArn } = result;

publilishEvent({
publishEvent({
type: DeploymentStatus.BUILD_QUEUE_SUCCESS,
projectId: result.projectId,
deploymentId: result.deploymentId,
Expand All @@ -147,29 +147,29 @@ worker.on('failed', async (job: any, err: any) => {
});
if (err instanceof BuildJobError) {
if (err.message == "BACKEND_BUILT_FAILED") {
publilishEvent({
publishEvent({
type: DeploymentStatus.BACKEND_QUEUE_FAILED,
projectId: job?.data?.projectId!,
deploymentId: job?.data?.deploymentId!,
payload: err.payload,
});
} else if (err.message == "FRONTEND_BUILT_FAILED") {
publilishEvent({
publishEvent({
type: DeploymentStatus.FRONTEND_QUEUE_FAILED,
projectId: job?.data?.projectId!,
deploymentId: job?.data?.deploymentId!,
payload: err.payload,
});
} else {
publilishEvent({
publishEvent({
type: DeploymentStatus.BUILD_UNKNOWN_FAILURE,
projectId: job?.data?.projectId!,
deploymentId: job?.data?.deploymentId!,
payload: err.payload,
});
}
} else {
publilishEvent({
publishEvent({
type: DeploymentStatus.INTERNAL_ERROR,
projectId: job?.data?.projectId!,
deploymentId: job?.data?.deploymentId!,
Expand Down
14 changes: 7 additions & 7 deletions WORKERS/clone-worker/src/workers/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from "fs/promises";
import logger from "../logger/logger.js";
import { cloneRepo } from "../GitHandler/gitHandler.js";
import repoConfigGenerator, { IBuild } from "../services/repoConfigGenerator.js";
import { DeploymentStatus, publilishEvent } from "@veren/domain";
import { DeploymentStatus, publishEvent } from "@veren/domain";
import { CloneJobError } from "../utils/JobError.js";

/* ---------------- TYPES ---------------- */
Expand All @@ -19,7 +19,7 @@ interface CloneJobData {
backendDirPath: string;
frontendDirPath: string;
};
build:IBuild;
build: IBuild;
}

interface CloneJobResult {
Expand Down Expand Up @@ -128,8 +128,8 @@ export const worker = new Worker<CloneJobData, CloneJobResult>(
};
} finally {

/* ---------- CLEAN FOLDER SPACE ---------- */
/* ---------- CLEAN FOLDER SPACE ---------- */

if (baseDir) {
try {
await fs.rm(baseDir, { recursive: true, force: true });
Expand All @@ -154,7 +154,7 @@ worker.on("completed", async (job, result) => {
deploymentId: result.deploymentId,
});

publilishEvent({
publishEvent({
type: DeploymentStatus.REPO_ANALYSIS_SUCCESS,
projectId: result.projectId,
deploymentId: result.deploymentId,
Expand All @@ -173,14 +173,14 @@ worker.on("failed", async (job, err) => {
});

if (err instanceof CloneJobError) {
publilishEvent({
publishEvent({
type: DeploymentStatus.REPO_ANALYSIS_FAILED,
projectId: job?.data?.projectId!,
deploymentId: job?.data?.deploymentId!,
payload: err.payload,
});
} else {
publilishEvent({
publishEvent({
type: DeploymentStatus.INTERNAL_ERROR,
projectId: job?.data?.projectId!,
deploymentId: job?.data?.deploymentId!,
Expand Down
22 changes: 10 additions & 12 deletions api-gateway/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ const getMe = asyncHandler(async (req: Request, res: Response) => {
}
let user = await User.findById(req.user.id).select(
"name userName email avatar provider createdAt"
);;
);

if (!user) {
return res.status(404).json(
new ApiResponse(404, null, "User not found")
Expand All @@ -133,35 +133,33 @@ const getMe = asyncHandler(async (req: Request, res: Response) => {
);
});

const refreshAccessToken = asyncHandler(async (req:Request, res: Response)=>{
let incomingRefreshToken =req.cookies.refreshToken;
if(!incomingRefreshToken){
const refreshAccessToken = asyncHandler(async (req: Request, res: Response) => {
let incomingRefreshToken = req.cookies.refreshToken;
if (!incomingRefreshToken) {
throw new ApiError(401, "Refresh Token is required");
}

try {
const decodedToken = jwt.verify(
incomingRefreshToken,
incomingRefreshToken,
process.env.REFRESH_TOKEN_SECRET!
) as {tokenVersion: number, sub: string};
) as { tokenVersion: number, sub: string };

const user = await User.findById(decodedToken?.sub);
if(!user){
if (!user) {
throw new ApiError(404, "Invalid refresh Token");
}

if(decodedToken?.tokenVersion! != user?.tokenVersion){
if (decodedToken?.tokenVersion! != user?.tokenVersion) {
throw new ApiError(404, "Invalid Refresh Token");
Comment on lines +146 to 154
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

decodedToken.tokenVersion and user.tokenVersion are numbers; using != introduces type coercion and can mask unexpected types. Prefer a strict comparison (!==) (and you likely don’t need the optional chaining / non-null assertion here since jwt.verify is typed to return the required fields).

Copilot uses AI. Check for mistakes.
}

const options = {

}
const newRefreshToken = user.generateRefreshToken();
const newAccessToken = user.generateAccessToken();

setAuthCookies(res, newAccessToken, newRefreshToken);
res.status(200).json(new ApiResponse(200, {newAccessToken, newRefreshToken}, "Refresh token generated successfully"));
res.status(200).json(new ApiResponse(200, { newAccessToken, newRefreshToken }, "Refresh token generated successfully"));
} catch (error) {
throw new ApiError(404, "Failed to refresh refresh-token");
}
Comment on lines 163 to 165
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The catch-all error path throws a 404 (Not Found) for any refresh failure, including JWT verification errors and server issues. Consider returning a 401/403 for invalid/expired refresh tokens and a 500 for unexpected failures, and avoid the duplicated wording in the message ("refresh refresh-token").

Copilot uses AI. Check for mistakes.
Expand Down
4 changes: 2 additions & 2 deletions api-gateway/src/controllers/deployment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { cloneQueue } from "../Queue/clone-queue.js";

import logger from "../logger/logger.js";

import { Project, DeploymentStatus, publilishEvent } from "@veren/domain";
import { Project, DeploymentStatus, publishEvent } from "@veren/domain";
import { Deployment } from "@veren/domain";


Expand Down Expand Up @@ -84,7 +84,7 @@ const deployProject = asyncHandler(async (req: Request, res: Response) => {

logger.info(`Clone job added for project ${projectId}`);

publilishEvent({
publishEvent({
type: DeploymentStatus.CREATED,
projectId: projectId,
deploymentId: newDeployment._id.toString(),
Expand Down
Loading