From f725fa5a971b9d4e1b459e4e07d28b70e4c84490 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 6 Jun 2024 10:41:23 -0700 Subject: [PATCH 1/3] Update email_notification.ts --- apps/api/src/services/notification/email_notification.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/services/notification/email_notification.ts b/apps/api/src/services/notification/email_notification.ts index 9343ddf..785f0e4 100644 --- a/apps/api/src/services/notification/email_notification.ts +++ b/apps/api/src/services/notification/email_notification.ts @@ -20,7 +20,7 @@ const emailTemplates: Record< }, [NotificationType.RATE_LIMIT_REACHED]: { subject: "Rate Limit Reached - Firecrawl", - html: "Hey there,

You've hit your Firecrawl rate limit! Take a breather and try again in a few moments. If you need higher rate limits, consider upgrading your plan. Check out our pricing page for more info.

If you have any questions, feel free to reach out to us at hello@firecrawl.com


Thanks,
Firecrawl Team

Ps. this email is only sent once every 7 days if you reach the limit.", + html: "Hey there,

You've hit one of the Firecrawl endpoints rate limit! Take a breather and try again in a few moments. If you need higher rate limits, consider upgrading your plan. Check out our pricing page for more info.

If you have any questions, feel free to reach out to us at hello@firecrawl.com


Thanks,
Firecrawl Team

Ps. this email is only sent once every 7 days if you reach a rate limit.", }, }; From deae7dcd6145f0bfb59bc6c203652125d71a9375 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 6 Jun 2024 10:41:54 -0700 Subject: [PATCH 2/3] Update email_notification.ts --- apps/api/src/services/notification/email_notification.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/services/notification/email_notification.ts b/apps/api/src/services/notification/email_notification.ts index 785f0e4..06bcaa6 100644 --- a/apps/api/src/services/notification/email_notification.ts +++ b/apps/api/src/services/notification/email_notification.ts @@ -20,7 +20,7 @@ const emailTemplates: Record< }, [NotificationType.RATE_LIMIT_REACHED]: { subject: "Rate Limit Reached - Firecrawl", - html: "Hey there,

You've hit one of the Firecrawl endpoints rate limit! Take a breather and try again in a few moments. If you need higher rate limits, consider upgrading your plan. Check out our pricing page for more info.

If you have any questions, feel free to reach out to us at hello@firecrawl.com


Thanks,
Firecrawl Team

Ps. this email is only sent once every 7 days if you reach a rate limit.", + html: "Hey there,

You've hit one of the Firecrawl endpoint's rate limit! Take a breather and try again in a few moments. If you need higher rate limits, consider upgrading your plan. Check out our pricing page for more info.

If you have any questions, feel free to reach out to us at hello@firecrawl.com


Thanks,
Firecrawl Team

Ps. this email is only sent once every 7 days if you reach a rate limit.", }, }; From f1b5ec8517d7d6831ad33787edb01d2ddf3aa681 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 6 Jun 2024 11:23:10 -0700 Subject: [PATCH 3/3] Nick: fixes --- .../notification/email_notification.ts | 11 +-- apps/api/src/services/rate-limiter.ts | 67 +++++++++++++------ 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/apps/api/src/services/notification/email_notification.ts b/apps/api/src/services/notification/email_notification.ts index 06bcaa6..e5102ac 100644 --- a/apps/api/src/services/notification/email_notification.ts +++ b/apps/api/src/services/notification/email_notification.ts @@ -3,9 +3,6 @@ import { withAuth } from "../../lib/withAuth"; import { Resend } from "resend"; import { NotificationType } from "../../types"; - - - const emailTemplates: Record< NotificationType, { subject: string; html: string } @@ -15,7 +12,8 @@ const emailTemplates: Record< html: "Hey there,

You are approaching your credit limit for this billing period. Your usage right now is around 80% of your total credit limit. Consider upgrading your plan to avoid hitting the limit. Check out our pricing page for more info.


Thanks,
Firecrawl Team
", }, [NotificationType.LIMIT_REACHED]: { - subject: "Credit Limit Reached! Take action now to resume usage - Firecrawl", + subject: + "Credit Limit Reached! Take action now to resume usage - Firecrawl", html: "Hey there,

You have reached your credit limit for this billing period. To resume usage, please upgrade your plan. Check out our pricing page for more info.


Thanks,
Firecrawl Team
", }, [NotificationType.RATE_LIMIT_REACHED]: { @@ -42,7 +40,7 @@ async function sendEmailNotification( email: string, notificationType: NotificationType ) { -const resend = new Resend(process.env.RESEND_API_KEY); + const resend = new Resend(process.env.RESEND_API_KEY); try { const { data, error } = await resend.emails.send({ @@ -69,6 +67,9 @@ export async function sendNotificationInternal( startDateString: string, endDateString: string ): Promise<{ success: boolean }> { + if (team_id === "preview") { + return { success: true }; + } const { data, error } = await supabase_service .from("user_notifications") .select("*") diff --git a/apps/api/src/services/rate-limiter.ts b/apps/api/src/services/rate-limiter.ts index 51543a6..d0f937f 100644 --- a/apps/api/src/services/rate-limiter.ts +++ b/apps/api/src/services/rate-limiter.ts @@ -4,6 +4,7 @@ import { RateLimiterMode } from "../../src/types"; const RATE_LIMITS = { crawl: { + default: 3, free: 2, starter: 3, standard: 5, @@ -14,6 +15,7 @@ const RATE_LIMITS = { growth: 50, }, scrape: { + default: 20, free: 5, starter: 20, standard: 50, @@ -24,6 +26,7 @@ const RATE_LIMITS = { growth: 500, }, search: { + default: 20, free: 5, starter: 20, standard: 40, @@ -33,10 +36,18 @@ const RATE_LIMITS = { standardNew: 50, growth: 500, }, - preview: 5, - account: 20, - crawlStatus: 150, - testSuite: 10000, + preview: { + default: 5, + }, + account: { + default: 20, + }, + crawlStatus: { + default: 150, + }, + testSuite: { + default: 10000, + }, }; export const redisClient = redis.createClient({ @@ -44,30 +55,46 @@ export const redisClient = redis.createClient({ legacyMode: true, }); -const createRateLimiter = (keyPrefix, points) => new RateLimiterRedis({ - storeClient: redisClient, - keyPrefix, - points, - duration: 60, // Duration in seconds -}); +const createRateLimiter = (keyPrefix, points) => + new RateLimiterRedis({ + storeClient: redisClient, + keyPrefix, + points, + duration: 60, // Duration in seconds + }); -export const previewRateLimiter = createRateLimiter("preview", RATE_LIMITS.preview); -export const serverRateLimiter = createRateLimiter("server", RATE_LIMITS.account); -export const crawlStatusRateLimiter = createRateLimiter("crawl-status", RATE_LIMITS.crawlStatus); -export const testSuiteRateLimiter = createRateLimiter("test-suite", RATE_LIMITS.testSuite); +export const previewRateLimiter = createRateLimiter( + "preview", + RATE_LIMITS.preview +); +export const serverRateLimiter = createRateLimiter( + "server", + RATE_LIMITS.account +); +export const crawlStatusRateLimiter = createRateLimiter( + "crawl-status", + RATE_LIMITS.crawlStatus +); +export const testSuiteRateLimiter = createRateLimiter( + "test-suite", + RATE_LIMITS.testSuite +); -export function getRateLimiter(mode: RateLimiterMode, token: string, plan?: string) { +export function getRateLimiter( + mode: RateLimiterMode, + token: string, + plan?: string +) { if (token.includes("a01ccae") || token.includes("6254cf9")) { return testSuiteRateLimiter; } - - const rateLimitConfig = RATE_LIMITS[mode]; + const rateLimitConfig = RATE_LIMITS[mode]; // {default : 5} if (!rateLimitConfig) return serverRateLimiter; - const planKey = plan ? plan.replace("-", "") : "starter"; - const points = rateLimitConfig[planKey] || rateLimitConfig.preview; + const planKey = plan ? plan.replace("-", "") : "default"; // "default" + const points = + rateLimitConfig[planKey] || rateLimitConfig.default || rateLimitConfig; // 5 - return createRateLimiter(`${mode}-${planKey}`, points); }