Skip to content

Commit dd2b09e

Browse files
committed
fix: include project name in DB select for dynamic email fromAddress
1 parent 999721b commit dd2b09e

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

apps/public-api/src/__tests__/mail.controller.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jest.mock('@urbackend/common', () => {
5858
})),
5959
},
6060
decrypt: jest.fn(),
61+
generateDynamicFromAddress: jest.fn((name) => `mock <mock@apps.bitbros.in>`),
6162
redis: redisMock,
6263
getPlanLimits: jest.fn(() => ({ mailPerMonth: 100 })),
6364
publicEmailQueue: {

apps/public-api/src/controllers/mail.controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const getMailCountKey = (projectId, monthKey) =>
1313

1414
const loadProjectMailConfig = async (projectId) => {
1515
return Project.findById(projectId)
16-
.select("+resendApiKey.encrypted +resendApiKey.iv +resendApiKey.tag resendFromEmail +mailTemplates")
16+
.select("+resendApiKey.encrypted +resendApiKey.iv +resendApiKey.tag resendFromEmail +mailTemplates name")
1717
.lean();
1818
};
1919

@@ -342,7 +342,7 @@ const resolveResendClient = async (req) => {
342342
throw err;
343343
}
344344

345-
const project = await Project.findById(projectId).select("+resendApiKey.encrypted +resendApiKey.iv +resendApiKey.tag resendFromEmail").lean();
345+
const project = await Project.findById(projectId).select("+resendApiKey.encrypted +resendApiKey.iv +resendApiKey.tag resendFromEmail name").lean();
346346
const encryptedByokKey = project?.resendApiKey && Object.keys(project.resendApiKey).length > 0 ? project.resendApiKey : null;
347347
const decryptedByokKey = encryptedByokKey ? decrypt(encryptedByokKey) : null;
348348
const usingByok = typeof decryptedByokKey === "string" && decryptedByokKey.trim().length > 0;
@@ -356,8 +356,8 @@ const resolveResendClient = async (req) => {
356356

357357
let fromAddress = project?.resendFromEmail?.trim();
358358
if (!fromAddress) {
359-
const { generateDynamicFromAddress } = require("@urbackend/common/src/utils/emailService");
360-
fromAddress = generateDynamicFromAddress(project.name);
359+
const { generateDynamicFromAddress } = require("@urbackend/common");
360+
fromAddress = generateDynamicFromAddress(project?.name);
361361
}
362362

363363
return {

packages/common/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ const {
7070
sendReleaseEmail,
7171
sendAuthOtpEmail,
7272
sendProRequestConfirmationEmail,
73+
formatFromAddress,
74+
generateDynamicFromAddress,
7375
} = require("./utils/emailService");
7476
const {
7577
loginSchema,
@@ -161,6 +163,8 @@ module.exports = {
161163
sendReleaseEmail,
162164
sendAuthOtpEmail,
163165
sendProRequestConfirmationEmail,
166+
formatFromAddress,
167+
generateDynamicFromAddress,
164168
loginSchema,
165169
signupSchema,
166170
changePasswordSchema,

0 commit comments

Comments
 (0)