Merge branch 'main' into 194-sdk-ci-pipeline-for-publishing-pythonnode-sdk
This commit is contained in:
commit
b234b4be5a
@ -3,9 +3,6 @@ import { withAuth } from "../../lib/withAuth";
|
|||||||
import { Resend } from "resend";
|
import { Resend } from "resend";
|
||||||
import { NotificationType } from "../../types";
|
import { NotificationType } from "../../types";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const emailTemplates: Record<
|
const emailTemplates: Record<
|
||||||
NotificationType,
|
NotificationType,
|
||||||
{ subject: string; html: string }
|
{ subject: string; html: string }
|
||||||
@ -15,12 +12,13 @@ const emailTemplates: Record<
|
|||||||
html: "Hey there,<br/><p>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 <a href='https://firecrawl.dev/pricing'>pricing page</a> for more info.</p><br/>Thanks,<br/>Firecrawl Team<br/>",
|
html: "Hey there,<br/><p>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 <a href='https://firecrawl.dev/pricing'>pricing page</a> for more info.</p><br/>Thanks,<br/>Firecrawl Team<br/>",
|
||||||
},
|
},
|
||||||
[NotificationType.LIMIT_REACHED]: {
|
[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,<br/><p>You have reached your credit limit for this billing period. To resume usage, please upgrade your plan. Check out our <a href='https://firecrawl.dev/pricing'>pricing page</a> for more info.</p><br/>Thanks,<br/>Firecrawl Team<br/>",
|
html: "Hey there,<br/><p>You have reached your credit limit for this billing period. To resume usage, please upgrade your plan. Check out our <a href='https://firecrawl.dev/pricing'>pricing page</a> for more info.</p><br/>Thanks,<br/>Firecrawl Team<br/>",
|
||||||
},
|
},
|
||||||
[NotificationType.RATE_LIMIT_REACHED]: {
|
[NotificationType.RATE_LIMIT_REACHED]: {
|
||||||
subject: "Rate Limit Reached - Firecrawl",
|
subject: "Rate Limit Reached - Firecrawl",
|
||||||
html: "Hey there,<br/><p>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 <a href='https://firecrawl.dev/pricing'>pricing page</a> for more info.</p><p>If you have any questions, feel free to reach out to us at <a href='mailto:hello@firecrawl.com'>hello@firecrawl.com</a></p><br/>Thanks,<br/>Firecrawl Team<br/><br/>Ps. this email is only sent once every 7 days if you reach the limit.",
|
html: "Hey there,<br/><p>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 <a href='https://firecrawl.dev/pricing'>pricing page</a> for more info.</p><p>If you have any questions, feel free to reach out to us at <a href='mailto:hello@firecrawl.com'>hello@firecrawl.com</a></p><br/>Thanks,<br/>Firecrawl Team<br/><br/>Ps. this email is only sent once every 7 days if you reach a rate limit.",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -69,6 +67,9 @@ export async function sendNotificationInternal(
|
|||||||
startDateString: string,
|
startDateString: string,
|
||||||
endDateString: string
|
endDateString: string
|
||||||
): Promise<{ success: boolean }> {
|
): Promise<{ success: boolean }> {
|
||||||
|
if (team_id === "preview") {
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
const { data, error } = await supabase_service
|
const { data, error } = await supabase_service
|
||||||
.from("user_notifications")
|
.from("user_notifications")
|
||||||
.select("*")
|
.select("*")
|
||||||
|
@ -4,6 +4,7 @@ import { RateLimiterMode } from "../../src/types";
|
|||||||
|
|
||||||
const RATE_LIMITS = {
|
const RATE_LIMITS = {
|
||||||
crawl: {
|
crawl: {
|
||||||
|
default: 3,
|
||||||
free: 2,
|
free: 2,
|
||||||
starter: 3,
|
starter: 3,
|
||||||
standard: 5,
|
standard: 5,
|
||||||
@ -14,6 +15,7 @@ const RATE_LIMITS = {
|
|||||||
growth: 50,
|
growth: 50,
|
||||||
},
|
},
|
||||||
scrape: {
|
scrape: {
|
||||||
|
default: 20,
|
||||||
free: 5,
|
free: 5,
|
||||||
starter: 20,
|
starter: 20,
|
||||||
standard: 50,
|
standard: 50,
|
||||||
@ -24,6 +26,7 @@ const RATE_LIMITS = {
|
|||||||
growth: 500,
|
growth: 500,
|
||||||
},
|
},
|
||||||
search: {
|
search: {
|
||||||
|
default: 20,
|
||||||
free: 5,
|
free: 5,
|
||||||
starter: 20,
|
starter: 20,
|
||||||
standard: 40,
|
standard: 40,
|
||||||
@ -33,10 +36,18 @@ const RATE_LIMITS = {
|
|||||||
standardNew: 50,
|
standardNew: 50,
|
||||||
growth: 500,
|
growth: 500,
|
||||||
},
|
},
|
||||||
preview: 5,
|
preview: {
|
||||||
account: 20,
|
default: 5,
|
||||||
crawlStatus: 150,
|
},
|
||||||
testSuite: 10000,
|
account: {
|
||||||
|
default: 20,
|
||||||
|
},
|
||||||
|
crawlStatus: {
|
||||||
|
default: 150,
|
||||||
|
},
|
||||||
|
testSuite: {
|
||||||
|
default: 10000,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const redisClient = redis.createClient({
|
export const redisClient = redis.createClient({
|
||||||
@ -44,30 +55,46 @@ export const redisClient = redis.createClient({
|
|||||||
legacyMode: true,
|
legacyMode: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const createRateLimiter = (keyPrefix, points) => new RateLimiterRedis({
|
const createRateLimiter = (keyPrefix, points) =>
|
||||||
|
new RateLimiterRedis({
|
||||||
storeClient: redisClient,
|
storeClient: redisClient,
|
||||||
keyPrefix,
|
keyPrefix,
|
||||||
points,
|
points,
|
||||||
duration: 60, // Duration in seconds
|
duration: 60, // Duration in seconds
|
||||||
});
|
});
|
||||||
|
|
||||||
export const previewRateLimiter = createRateLimiter("preview", RATE_LIMITS.preview);
|
export const previewRateLimiter = createRateLimiter(
|
||||||
export const serverRateLimiter = createRateLimiter("server", RATE_LIMITS.account);
|
"preview",
|
||||||
export const crawlStatusRateLimiter = createRateLimiter("crawl-status", RATE_LIMITS.crawlStatus);
|
RATE_LIMITS.preview
|
||||||
export const testSuiteRateLimiter = createRateLimiter("test-suite", RATE_LIMITS.testSuite);
|
);
|
||||||
|
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")) {
|
if (token.includes("a01ccae") || token.includes("6254cf9")) {
|
||||||
return testSuiteRateLimiter;
|
return testSuiteRateLimiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rateLimitConfig = RATE_LIMITS[mode]; // {default : 5}
|
||||||
const rateLimitConfig = RATE_LIMITS[mode];
|
|
||||||
if (!rateLimitConfig) return serverRateLimiter;
|
if (!rateLimitConfig) return serverRateLimiter;
|
||||||
|
|
||||||
const planKey = plan ? plan.replace("-", "") : "starter";
|
const planKey = plan ? plan.replace("-", "") : "default"; // "default"
|
||||||
const points = rateLimitConfig[planKey] || rateLimitConfig.preview;
|
const points =
|
||||||
|
rateLimitConfig[planKey] || rateLimitConfig.default || rateLimitConfig; // 5
|
||||||
|
|
||||||
return createRateLimiter(`${mode}-${planKey}`, points);
|
return createRateLimiter(`${mode}-${planKey}`, points);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user