Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Remove rateLimit column from RestrictedToken

Kiran Kec39d0e8f442
diff --git a/apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts b/apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts
index f20d1a95df..802a9a8228 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/checkout-session-completed.ts
@@ -122,15 +122,6 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
variant: "marketing",
})),
),
- // update rate limits for restricted tokens for the workspace
- prisma.restrictedToken.updateMany({
- where: {
- projectId: workspaceId,
- },
- data: {
- rateLimit: plan.limits.api,
- },
- }),
// enable dub.link premium default domain for the workspace
prisma.defaultDomains.update({
where: {
diff --git a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts
index a1694521c5..fd2882e695 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/customer-subscription-deleted.ts
@@ -125,16 +125,6 @@ export async function customerSubscriptionDeleted(event: Stripe.Event) {
},
}),
- // update rate limit for all restricted tokens for the workspace
- prisma.restrictedToken.updateMany({
- where: {
- projectId: workspace.id,
- },
- data: {
- rateLimit: FREE_PLAN.limits.api,
- },
- }),
-
// disable dub.link premium default domain for the workspace
prisma.defaultDomains.update({
where: {
diff --git a/apps/web/app/(ee)/api/stripe/webhook/utils/update-workspace-plan.ts b/apps/web/app/(ee)/api/stripe/webhook/utils/update-workspace-plan.ts
index 0b89c58ff5..b26cd1f2c6 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/utils/update-workspace-plan.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/utils/update-workspace-plan.ts
@@ -67,15 +67,6 @@ export async function updateWorkspacePlan({
},
}),
- prisma.restrictedToken.updateMany({
- where: {
- projectId: workspace.id,
- },
- data: {
- rateLimit: plan.limits.api,
- },
- }),
-
// expire tokens cache
tokenCache.expireMany({
hashedKeys: workspace.restrictedTokens.map(
diff --git a/apps/web/app/api/oauth/token/exchange-code-for-token.ts b/apps/web/app/api/oauth/token/exchange-code-for-token.ts
index 4f854d0c25..e5e0ae59b5 100644
--- a/apps/web/app/api/oauth/token/exchange-code-for-token.ts
+++ b/apps/web/app/api/oauth/token/exchange-code-for-token.ts
@@ -6,7 +6,6 @@ import { installIntegration } from "@/lib/integrations/install";
import { generateRandomName } from "@/lib/names";
import { authCodeExchangeSchema } from "@/lib/zod/schemas/oauth";
import { prisma } from "@dub/prisma";
-import { getCurrentPlan } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { NextRequest } from "next/server";
import { z } from "zod";
@@ -205,6 +204,7 @@ export const exchangeAuthCodeForToken = async (
code,
},
}),
+
// Remove all existing tokens for this client
prisma.restrictedToken.deleteMany({
where: {
@@ -214,28 +214,6 @@ export const exchangeAuthCodeForToken = async (
},
},
}),
- // Update restricted token rate limit to the plan limit
- prisma.project
- .findUnique({
- where: {
- id: projectId,
- },
- select: {
- plan: true,
- },
- })
- .then(async (project) => {
- if (!project?.plan) {
- return;
- }
-
- await prisma.restrictedToken.update({
- where: { id: restrictedToken.id },
- data: {
- rateLimit: getCurrentPlan(project.plan).limits.api,
- },
- });
- }),
]),
);
diff --git a/apps/web/app/api/oauth/token/refresh-access-token.ts b/apps/web/app/api/oauth/token/refresh-access-token.ts
index 260090bc7f..927007c9fd 100644
--- a/apps/web/app/api/oauth/token/refresh-access-token.ts
+++ b/apps/web/app/api/oauth/token/refresh-access-token.ts
@@ -5,7 +5,6 @@ import { hashToken } from "@/lib/auth";
import { generateRandomName } from "@/lib/names";
import { refreshTokenSchema } from "@/lib/zod/schemas/oauth";
import { prisma } from "@dub/prisma";
-import { getCurrentPlan } from "@dub/utils";
import { NextRequest } from "next/server";
import { z } from "zod";
@@ -180,8 +179,6 @@ export const refreshAccessToken = async (
partialKey: `${newAccessToken.slice(0, 3)}...${newAccessToken.slice(-4)}`,
scopes: accessToken.scopes,
expires: accessTokenExpires,
- rateLimit: getCurrentPlan(authorizedApp.project.plan as string).limits
- .api,
userId: authorizedApp.userId,
projectId: authorizedApp.projectId,
installationId: authorizedApp.id,
diff --git a/apps/web/app/api/tokens/route.ts b/apps/web/app/api/tokens/route.ts
index 35262582f9..2c98a2be5e 100644
--- a/apps/web/app/api/tokens/route.ts
+++ b/apps/web/app/api/tokens/route.ts
@@ -10,7 +10,7 @@ import { sendEmail } from "@dub/email";
import APIKeyCreated from "@dub/email/templates/api-key-created";
import { prisma } from "@dub/prisma";
import { Prisma, User } from "@dub/prisma/client";
-import { getCurrentPlan, nanoid } from "@dub/utils";
+import { nanoid } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
@@ -150,7 +150,6 @@ export const POST = withWorkspace(
partialKey,
userId: isMachine ? machineUser?.id! : session.user.id,
projectId: workspace.id,
- rateLimit: getCurrentPlan(workspace.plan).limits.api,
scopes:
scopes && scopes.length > 0
? [...new Set(scopes)].join(" ")
diff --git a/apps/web/scripts/update-api-rate-limits.ts b/apps/web/scripts/update-api-rate-limits.ts
deleted file mode 100644
index e45c74d019..0000000000
--- a/apps/web/scripts/update-api-rate-limits.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import { prisma } from "@dub/prisma";
-import { getCurrentPlan } from "@dub/utils";
-import "dotenv-flow/config";
-
-async function main() {
- const tokens = await prisma.restrictedToken.findMany({
- select: {
- id: true,
- project: {
- select: {
- plan: true,
- },
- },
- },
- take: 500,
- });
-
- for (const token of tokens) {
- const plan = getCurrentPlan(token.project.plan);
-
- await prisma.restrictedToken.update({
- where: {
- id: token.id,
- },
- data: {
- rateLimit: plan.limits.api,
- },
- });
- }
-}
-
-main();