Skip to content

Commit d9ebf26

Browse files
emrysaljoeauyeungdevin-ai-integration[bot]
authored
chore: standarize rate limit structure (calcom#25736)
* feat: add toggle to opt out of booking title translation in instant meetings (calcom#25547) * feat: add toggle to opt out of booking title translation in instant meetings Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: add autoTranslateTitleEnabled to test builder Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: respect autoTranslateTitleEnabled toggle in InstantBookingCreateService Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: fetch autoTranslateTitleEnabled directly in InstantBookingCreateService Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * refactor: rename autoTranslateTitleEnabled to autoTranslateInstantMeetingTitleEnabled - Renamed field to clarify it only applies to instant meeting title translation - Moved Prisma query to EventTypeRepository.findInstantMeetingConfigById() - Removed title translation logic from update.handler.ts (flag only controls instant meeting title) - Updated all references across the codebase - Added new i18n translation keys for the renamed field Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: add autoTranslateInstantMeetingTitleEnabled to test destructuring patterns Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: use Prisma.TeamCreateInput type for metadata in test helper Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: add autoTranslateInstantMeetingTitleEnabled to mockUpdatedEventType in test Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * refactor: use generic findByIdMinimal instead of business-specific method - Add autoTranslateInstantMeetingTitleEnabled to eventTypeSelect constant - Remove findInstantMeetingConfigById from EventTypeRepository - Update InstantBookingCreateService to use findByIdMinimal Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * refactor: remove autoTranslateInstantMeetingTitleEnabled from eventTypeSelect (not needed for findByIdMinimal) Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * feat: add autoTranslateInstantMeetingTitleEnabled to event type form defaults - Rename shouldTranslateTitle to shouldAutoTranslateInstantMeetingTitle for clarity - Add autoTranslateInstantMeetingTitleEnabled to findById and findByIdForOrgAdmin selects - Add autoTranslateInstantMeetingTitleEnabled to useEventTypeForm defaultValues Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> * fix: only update autoTranslateInstantMeetingTitleEnabled when explicitly provided Fixes issue where omitting the field in update requests would overwrite the saved opt-out setting with the default value (true). Now the field is only included in the update payload when explicitly provided. Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * chore: Create standard for rate limits --------- Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent cb13874 commit d9ebf26

15 files changed

Lines changed: 20 additions & 20 deletions

File tree

apps/web/app/api/auth/forgot-password/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function handler(req: NextRequest) {
2929

3030
await checkRateLimitAndThrowError({
3131
rateLimitingType: "core",
32-
identifier: piiHasher.hash(ip),
32+
identifier: `forgotPassword:${piiHasher.hash(ip)}`,
3333
});
3434

3535
try {

apps/web/pages/api/book/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function handler(req: NextApiRequest & { userId?: number; traceContext: Tr
3636

3737
await checkRateLimitAndThrowError({
3838
rateLimitingType: "core",
39-
identifier: piiHasher.hash(userIp),
39+
identifier: `createBooking:${piiHasher.hash(userIp)}`,
4040
});
4141

4242
const session = await getServerSession({ req });

apps/web/pages/api/book/recurring-event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function handler(req: NextApiRequest & RequestMeta) {
3838

3939
await checkRateLimitAndThrowError({
4040
rateLimitingType: "core",
41-
identifier: piiHasher.hash(userIp),
41+
identifier: `createRecurringBooking:${piiHasher.hash(userIp)}`,
4242
});
4343
const session = await getServerSession({ req });
4444
/* To mimic API behavior and comply with types */

packages/features/auth/lib/verifyEmail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const sendEmailVerification = async ({
5656

5757
await checkRateLimitAndThrowError({
5858
rateLimitingType: "core",
59-
identifier: hashEmail(email),
59+
identifier: `sendEmailVerification:${hashEmail(email)}`,
6060
});
6161

6262
await prisma.verificationToken.create({

packages/features/calAIPhone/providers/retellAI/RetellAIService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ describe("RetellAIService", () => {
917917

918918
expect(vi.mocked(checkRateLimitAndThrowError)).toHaveBeenCalledWith({
919919
rateLimitingType: "core",
920-
identifier: "test-call:1",
920+
identifier: "createTestCall:1",
921921
});
922922
expect(result).toEqual({
923923
callId: "call-123",

packages/features/calAIPhone/providers/retellAI/services/CallService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class CallService {
9797

9898
await checkRateLimitAndThrowError({
9999
rateLimitingType: "core",
100-
identifier: `test-call:${userId}`,
100+
identifier: `createTestCall:${userId}`,
101101
});
102102

103103
const toNumber = phoneNumber?.trim();
@@ -192,7 +192,7 @@ export class CallService {
192192

193193
await checkRateLimitAndThrowError({
194194
rateLimitingType: "core",
195-
identifier: `web-call:${userId}`,
195+
identifier: `createWebCall:${userId}`,
196196
});
197197

198198
const agent = await this.deps.agentRepository.findByIdWithCallAccess({

packages/features/calAIPhone/providers/retellAI/services/__tests__/CallService.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ describe("CallService", () => {
207207

208208
expect(checkRateLimitAndThrowError).toHaveBeenCalledWith({
209209
rateLimitingType: "core",
210-
identifier: "test-call:1",
210+
identifier: "createTestCall:1",
211211
});
212212
});
213213

@@ -224,7 +224,7 @@ describe("CallService", () => {
224224

225225
expect(checkRateLimitAndThrowError).toHaveBeenCalledWith({
226226
rateLimitingType: "core",
227-
identifier: "test-call:42",
227+
identifier: "createTestCall:42",
228228
});
229229
});
230230

packages/features/ee/workflows/lib/reminders/aiPhoneCallManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ const scheduleAIPhoneCallTask = async (args: ScheduleAIPhoneCallTaskArgs) => {
400400
if (userId) {
401401
await checkRateLimitAndThrowError({
402402
rateLimitingType: "core",
403-
identifier: `ai-phone-call:${userId}`,
403+
identifier: `executeAIPhoneCall:${userId}`,
404404
});
405405
}
406406

packages/features/tasker/tasks/executeAIPhoneCall.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ export async function executeAIPhoneCall(payload: string) {
174174
}
175175

176176
const rateLimitIdentifier = data.teamId
177-
? `ai-phone-call:team:${data.teamId}`
177+
? `executeAIPhoneCall:team-${data.teamId}`
178178
: data.userId
179-
? `ai-phone-call:user:${data.userId}`
179+
? `executeAIPhoneCall:user-${data.userId}`
180180
: null;
181181

182182
if (!rateLimitIdentifier) {

packages/sms/sms-manager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ const handleSendingSMS = async ({
3131
// If neither is provided(Just in case), we check the rate limit for the reminderPhone.
3232
await checkSMSRateLimit({
3333
identifier: teamId
34-
? `handleSendingSMS:team:${teamId}`
34+
? `handleSendingSMS:team-${teamId}`
3535
: organizerUserId
36-
? `handleSendingSMS:user:${organizerUserId}`
37-
: `handleSendingSMS:user:${piiHasher.hash(reminderPhone)}`,
36+
? `handleSendingSMS:org-user-${organizerUserId}`
37+
: `handleSendingSMS:user-${piiHasher.hash(reminderPhone)}`,
3838
rateLimitingType: "sms",
3939
});
4040

0 commit comments

Comments
 (0)