diff --git a/src/environment/constants/cache.ts b/src/environment/constants/cache.ts new file mode 100644 index 0000000..e042c47 --- /dev/null +++ b/src/environment/constants/cache.ts @@ -0,0 +1,26 @@ +const cacheKeys = { + session: "session", + mailVerification: "mail-verification", + passwordReset: "password-reset", + emailChange: "email-change", + emailChangeCooldown: "email-change-cooldown", +} as const; + +const cacheTTL = { + passwordReset: 1 * 60 * 60, // 1h + mailVerification: 3 * 60 * 60, // 3h + emailChange: 3 * 60 * 60, // 3h + emailChangeCooldown: 5 * 60, // 5m +} as const; + +const generateCacheKey = { + session: (userId: string, token: string) => + `${cacheKeys.session}:${userId}:${token}`, + mailVerification: (token: string) => `${cacheKeys.mailVerification}:${token}`, + passwordReset: (token: string) => `${cacheKeys.passwordReset}:${token}`, + emailChange: (token: string) => `${cacheKeys.emailChange}:${token}`, + emailChangeCooldown: (userId: string) => + `${cacheKeys.emailChangeCooldown}:${userId}`, +} as const; + +export { cacheKeys, cacheTTL, generateCacheKey }; diff --git a/src/environment/constants/http.ts b/src/environment/constants/http.ts new file mode 100644 index 0000000..fcaa614 --- /dev/null +++ b/src/environment/constants/http.ts @@ -0,0 +1,54 @@ +const httpStatus = { + OK: 200, + CREATED: 201, + BAD_REQUEST: 400, + UNAUTHORIZED: 401, + FORBIDDEN: 403, + NOT_FOUND: 404, + METHOD_NOT_ALLOWED: 405, + NOT_ACCEPTABLE: 406, + CONFLICT: 409, + TOO_MANY_REQUESTS: 429, + INTERNAL_SERVER_ERROR: 500, + SERVICE_UNAVAILABLE: 503, +}; + +const errorMessages = { + NOT_AUTHENTICATED: "Not authenticated", + INVALID_CREDENTIALS: "Invalid credentials", + USER_ALREADY_LOGGED_IN: "User already logged in", + + USER_NOT_FOUND: "User not found", + USERNAME_ALREADY_EXISTS: "Username already exists", + EMAIL_ALREADY_EXISTS: "Email already exists", + + MISSING_REQUIRED_FIELDS: "Missing required fields", + INVALID_TOKEN: "Invalid or expired token", + INVALID_TOKEN_FORMAT: "Invalid token format", + + INTERNAL_SERVER_ERROR: "Internal server error", + DATABASE_QUERY_FAILED: "Database query failed", + NOT_FOUND: "Not Found", + METHOD_NOT_ALLOWED: "Method Not Allowed", + + EMAIL_SEND_FAILED: "Failed to send email. Please try again.", + EMAIL_ALREADY_VERIFIED: "Email is already verified", + + PASSWORD_SAME_AS_CURRENT: + "New password must be different from current password", + CURRENT_PASSWORD_INCORRECT: "Current password is incorrect", +}; + +const successMessages = { + LOGIN_SUCCESSFUL: "Login successful", + LOGOUT_SUCCESSFUL: "Logged out successfully", + EMAIL_VERIFIED: "Email verified successfully", + PASSWORD_UPDATED: "Password updated successfully", + USER_INFO_UPDATED: "User information updated successfully", + PASSWORD_RESET_SENT: + "If the email exists, a password reset link has been sent", + REGISTRATION_SUCCESSFUL: + "User registered successfully - please check your email to verify your account", +}; + +export { httpStatus, errorMessages, successMessages }; diff --git a/src/environment/constants/index.ts b/src/environment/constants/index.ts index 6ca789c..062632b 100644 --- a/src/environment/constants/index.ts +++ b/src/environment/constants/index.ts @@ -32,3 +32,5 @@ export * from "./validation"; export * from "./database"; export * from "./mailer"; export * from "./user"; +export * from "./cache"; +export * from "./http"; diff --git a/src/environment/constants/user/index.ts b/src/environment/constants/user/index.ts index 635be64..082e610 100644 --- a/src/environment/constants/user/index.ts +++ b/src/environment/constants/user/index.ts @@ -1 +1,7 @@ -export * from "./update"; +const passwordHashing = { + algorithm: "argon2id" as const, + memoryCost: 4096, + timeCost: 3, +} as const; + +export { passwordHashing }; diff --git a/src/environment/constants/user/update.ts b/src/environment/constants/user/update.ts deleted file mode 100644 index f69fe57..0000000 --- a/src/environment/constants/user/update.ts +++ /dev/null @@ -1,6 +0,0 @@ -const emailUpdateTimes = { - coolDownMinutes: 5, - tokenExpiryHours: 3, -}; - -export { emailUpdateTimes }; diff --git a/src/environment/mailer/templates/email-change-completed-notification.html b/src/environment/mailer/templates/email-change-completed-notification.html index 87cb9c4..c89439d 100644 --- a/src/environment/mailer/templates/email-change-completed-notification.html +++ b/src/environment/mailer/templates/email-change-completed-notification.html @@ -35,6 +35,6 @@
If this change was not authorized by you: Contact our support team immediately at {{supportEmail}}. Your account may have been compromised and we will help you recover it.
User ID: {{id}} | {{companyName}}
+User ID: {{id}}