Merge branch 'main' into v1-webscraper

This commit is contained in:
Nicolas 2024-08-27 16:16:40 -03:00
commit 88239d7211
3 changed files with 27 additions and 21 deletions

View File

@ -317,21 +317,21 @@ export async function supaCheckTeamCredits(team_id: string, credits: number) {
// Compare the adjusted total credits used with the credits allowed by the plan // Compare the adjusted total credits used with the credits allowed by the plan
if (adjustedCreditsUsed + credits > price.credits) { if (adjustedCreditsUsed + credits > price.credits) {
await sendNotification( // await sendNotification(
team_id, // team_id,
NotificationType.LIMIT_REACHED, // NotificationType.LIMIT_REACHED,
subscription.current_period_start, // subscription.current_period_start,
subscription.current_period_end // subscription.current_period_end
); // );
return { success: false, message: "Insufficient credits, please upgrade!", remainingCredits: creditLimit - adjustedCreditsUsed }; return { success: false, message: "Insufficient credits, please upgrade!", remainingCredits: creditLimit - adjustedCreditsUsed };
} else if (creditUsagePercentage >= 0.8) { } else if (creditUsagePercentage >= 0.8) {
// Send email notification for approaching credit limit // Send email notification for approaching credit limit
await sendNotification( // await sendNotification(
team_id, // team_id,
NotificationType.APPROACHING_LIMIT, // NotificationType.APPROACHING_LIMIT,
subscription.current_period_start, // subscription.current_period_start,
subscription.current_period_end // subscription.current_period_end
); // );
} }
return { success: true, message: "Sufficient credits available", remainingCredits: creditLimit - adjustedCreditsUsed }; return { success: true, message: "Sufficient credits available", remainingCredits: creditLimit - adjustedCreditsUsed };

View File

@ -65,7 +65,7 @@ describe("Rate Limiter Service", () => {
"test-prefix:someToken", "test-prefix:someToken",
"standard" "standard"
); );
expect(limiter2.points).toBe(50); expect(limiter2.points).toBe(100);
const limiter3 = getRateLimiter( const limiter3 = getRateLimiter(
"search" as RateLimiterMode, "search" as RateLimiterMode,
@ -188,14 +188,13 @@ describe("Rate Limiter Service", () => {
"test-prefix:someTokenXY", "test-prefix:someTokenXY",
"hobby" "hobby"
); );
// expect hobby to have 100 points expect(limiter.points).toBe(20);
expect(limiter.points).toBe(10);
const consumePoints = 5; const consumePoints = 5;
const res = await limiter.consume("test-prefix:someTokenXY", consumePoints); const res = await limiter.consume("test-prefix:someTokenXY", consumePoints);
expect(res.consumedPoints).toBe(5); expect(res.consumedPoints).toBe(5);
expect(res.remainingPoints).toBe(5); expect(res.remainingPoints).toBe(15);
}); });
it("should return the correct rate limiter for 'crawl' mode", () => { it("should return the correct rate limiter for 'crawl' mode", () => {
@ -227,7 +226,7 @@ describe("Rate Limiter Service", () => {
"test-prefix:someToken", "test-prefix:someToken",
"free" "free"
); );
expect(limiter.points).toBe(5); expect(limiter.points).toBe(10);
const limiter2 = getRateLimiter( const limiter2 = getRateLimiter(
"scrape" as RateLimiterMode, "scrape" as RateLimiterMode,
@ -241,7 +240,14 @@ describe("Rate Limiter Service", () => {
"test-prefix:someToken", "test-prefix:someToken",
"standard" "standard"
); );
expect(limiter3.points).toBe(50); expect(limiter3.points).toBe(100);
const limiter4 = getRateLimiter(
"scrape" as RateLimiterMode,
"test-prefix:someToken",
"growth"
);
expect(limiter4.points).toBe(1000);
}); });
it("should return the correct rate limiter for 'search' mode", () => { it("should return the correct rate limiter for 'search' mode", () => {

View File

@ -18,12 +18,12 @@ const RATE_LIMITS = {
}, },
scrape: { scrape: {
default: 20, default: 20,
free: 5, free: 10,
starter: 20, starter: 20,
standard: 100, standard: 100,
standardOld: 40, standardOld: 40,
scale: 500, scale: 500,
hobby: 10, hobby: 20,
standardNew: 100, standardNew: 100,
standardnew: 100, standardnew: 100,
growth: 1000, growth: 1000,
@ -115,7 +115,7 @@ export function getRateLimiter(
return testSuiteRateLimiter; return testSuiteRateLimiter;
} }
if(teamId === process.env.DEV_B_TEAM_ID) { if(teamId && teamId === process.env.DEV_B_TEAM_ID) {
return devBRateLimiter; return devBRateLimiter;
} }