From 3850b000f06baf5302a2a16a4b99448c0c48f90b Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 27 Aug 2024 11:14:04 -0300 Subject: [PATCH 1/4] Nick: removing credit notification for now --- .../src/services/billing/credit_billing.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/api/src/services/billing/credit_billing.ts b/apps/api/src/services/billing/credit_billing.ts index 2ad07318..19c17b48 100644 --- a/apps/api/src/services/billing/credit_billing.ts +++ b/apps/api/src/services/billing/credit_billing.ts @@ -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 if (adjustedCreditsUsed + credits > price.credits) { - await sendNotification( - team_id, - NotificationType.LIMIT_REACHED, - subscription.current_period_start, - subscription.current_period_end - ); + // await sendNotification( + // team_id, + // NotificationType.LIMIT_REACHED, + // subscription.current_period_start, + // subscription.current_period_end + // ); return { success: false, message: "Insufficient credits, please upgrade!", remainingCredits: creditLimit - adjustedCreditsUsed }; } else if (creditUsagePercentage >= 0.8) { // Send email notification for approaching credit limit - await sendNotification( - team_id, - NotificationType.APPROACHING_LIMIT, - subscription.current_period_start, - subscription.current_period_end - ); + // await sendNotification( + // team_id, + // NotificationType.APPROACHING_LIMIT, + // subscription.current_period_start, + // subscription.current_period_end + // ); } return { success: true, message: "Sufficient credits available", remainingCredits: creditLimit - adjustedCreditsUsed }; From 861e2ebdf1f4f38cec6c2f3b1b6e599647469128 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 27 Aug 2024 12:08:50 -0300 Subject: [PATCH 2/4] Nick: 2x rate limits --- apps/api/src/services/rate-limiter.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/api/src/services/rate-limiter.ts b/apps/api/src/services/rate-limiter.ts index 84078894..8e4e9fc9 100644 --- a/apps/api/src/services/rate-limiter.ts +++ b/apps/api/src/services/rate-limiter.ts @@ -17,10 +17,23 @@ const RATE_LIMITS = { growthdouble: 50, }, scrape: { + default: 20, + free: 10, + starter: 20, + standard: 100, + standardOld: 40, + scale: 500, + hobby: 20, + standardNew: 100, + standardnew: 100, + growth: 1000, + growthdouble: 1000, + }, + search: { default: 20, free: 5, starter: 20, - standard: 50, + standard: 40, standardOld: 40, scale: 500, hobby: 10, @@ -29,7 +42,7 @@ const RATE_LIMITS = { growth: 500, growthdouble: 500, }, - search: { + map:{ default: 20, free: 5, starter: 20, From bd84e49a77493dc7a79afe1a5290a8bea2d60b63 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 27 Aug 2024 15:37:36 -0300 Subject: [PATCH 3/4] Update rate-limiter.ts --- apps/api/src/services/rate-limiter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/src/services/rate-limiter.ts b/apps/api/src/services/rate-limiter.ts index 8e4e9fc9..75c4d6af 100644 --- a/apps/api/src/services/rate-limiter.ts +++ b/apps/api/src/services/rate-limiter.ts @@ -115,7 +115,7 @@ export function getRateLimiter( return testSuiteRateLimiter; } - if(teamId === process.env.DEV_B_TEAM_ID) { + if(teamId && teamId === process.env.DEV_B_TEAM_ID) { return devBRateLimiter; } From 8c8d0602bb8800f18b12ab89fdcfcbe95c06ded3 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 27 Aug 2024 15:38:01 -0300 Subject: [PATCH 4/4] Update rate-limiter.test.ts --- apps/api/src/services/rate-limiter.test.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/api/src/services/rate-limiter.test.ts b/apps/api/src/services/rate-limiter.test.ts index c49c85d9..e1c81e08 100644 --- a/apps/api/src/services/rate-limiter.test.ts +++ b/apps/api/src/services/rate-limiter.test.ts @@ -65,7 +65,7 @@ describe("Rate Limiter Service", () => { "test-prefix:someToken", "standard" ); - expect(limiter2.points).toBe(50); + expect(limiter2.points).toBe(100); const limiter3 = getRateLimiter( "search" as RateLimiterMode, @@ -188,14 +188,13 @@ describe("Rate Limiter Service", () => { "test-prefix:someTokenXY", "hobby" ); - // expect hobby to have 100 points - expect(limiter.points).toBe(10); + expect(limiter.points).toBe(20); const consumePoints = 5; const res = await limiter.consume("test-prefix:someTokenXY", consumePoints); 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", () => { @@ -227,7 +226,7 @@ describe("Rate Limiter Service", () => { "test-prefix:someToken", "free" ); - expect(limiter.points).toBe(5); + expect(limiter.points).toBe(10); const limiter2 = getRateLimiter( "scrape" as RateLimiterMode, @@ -241,7 +240,14 @@ describe("Rate Limiter Service", () => { "test-prefix:someToken", "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", () => {