Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

✨ Add support for in-memory rate limiting when kv is not available (#2203)

Luke Vella0db61eec8d26
diff --git a/CLAUDE.md b/CLAUDE.md
index 6d992f5e8..5551691b6 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -160,7 +160,7 @@ Key variables for development:
- `SECRET_PASSWORD` - NextAuth secret
- `GOOGLE_CLIENT_ID/SECRET` - OAuth provider
- `NEXT_PUBLIC_SELF_HOSTED` - Deployment mode toggle
-- `KV_REST_API_URL` - Redis for rate limiting (optional)
+- `KV_REST_API_URL` / `KV_REST_API_TOKEN` - Redis for rate limiting and auth session storage (optional)
See `.env.development` for complete development defaults.
diff --git a/apps/web/.env.test b/apps/web/.env.test
index 8112015e0..485b227f4 100644
--- a/apps/web/.env.test
+++ b/apps/web/.env.test
@@ -1,12 +1,13 @@
+CRON_SECRET=1234567890abcdef1234567890abcdef1234
+DATABASE_URL=postgres://postgres:postgres@localhost:5450/rallly
+NEXT_PUBLIC_BASE_URL=http://localhost:3002
NODE_ENV=test
PORT=3002
-NEXT_PUBLIC_BASE_URL=http://localhost:3002
+QUICK_CREATE_ENABLED=true
+RATE_LIMIT_ENABLED=false
SECRET_PASSWORD=abcdef1234567890abcdef1234567890
-DATABASE_URL=postgres://postgres:postgres@localhost:5450/rallly
SMTP_HOST=localhost
SMTP_PORT=1025
-QUICK_CREATE_ENABLED=true
-CRON_SECRET=1234567890abcdef1234567890abcdef1234
SMTP_REJECT_UNAUTHORIZED=false
diff --git a/apps/web/package.json b/apps/web/package.json
index 01272794e..7b1284042 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -59,8 +59,8 @@
"@trpc/react-query": "^11.8.0",
"@trpc/server": "^11.8.0",
"@upstash/ratelimit": "^1.2.1",
+ "@upstash/redis": "^1.36.2",
"@vercel/functions": "^3.3.6",
- "@vercel/kv": "^3.0.0",
"ai": "^6.0.87",
"arctic": "^3.7.0",
"better-auth": "^1.4.7",
diff --git a/apps/web/src/app/[locale]/(auth)/login/actions.ts b/apps/web/src/app/[locale]/(auth)/login/actions.ts
index 9a93ae910..73fb06437 100644
--- a/apps/web/src/app/[locale]/(auth)/login/actions.ts
+++ b/apps/web/src/app/[locale]/(auth)/login/actions.ts
@@ -1,12 +1,11 @@
"use server";
import { prisma } from "@rallly/database";
-import { cookies } from "next/headers";
+import { cookies, headers } from "next/headers";
import * as z from "zod";
-import {
- actionClient,
- createRateLimitMiddleware,
-} from "@/lib/safe-action/server";
+import { AppError } from "@/lib/errors";
+import { createRatelimit } from "@/lib/rate-limit";
+import { actionClient } from "@/lib/safe-action/server";
export async function setVerificationEmail(email: string) {
const cookieStore = await cookies();
@@ -19,11 +18,28 @@ export async function setVerificationEmail(email: string) {
});
}
+const ratelimit = createRatelimit(10, "1 m");
+
export const getLoginMethodAction = actionClient
.metadata({ actionName: "get_login_method" })
.inputSchema(z.object({ email: z.email() }))
- .use(createRateLimitMiddleware(100, "1m"))
.action(async ({ parsedInput: { email } }) => {
+ if (ratelimit) {
+ const headersList = await headers();
+ const ipAddress = headersList.get("x-forwarded-for");
+
+ const { success } = await ratelimit.limit(
+ `get_login_method:${ipAddress}`,
+ );
+
+ if (!success) {
+ throw new AppError({
+ code: "TOO_MANY_REQUESTS",
+ message: "Too many requests",
+ });
+ }
+ }
+
const user = await prisma.user.findUnique({
where: { email },
select: {
diff --git a/apps/web/src/app/api/licensing/v1/[...route]/route.ts b/apps/web/src/app/api/licensing/v1/[...route]/route.ts
index f85b2f800..6bb7aaa8a 100644
--- a/apps/web/src/app/api/licensing/v1/[...route]/route.ts
+++ b/apps/web/src/app/api/licensing/v1/[...route]/route.ts
@@ -2,12 +2,12 @@ import { zValidator } from "@hono/zod-validator";
import { RedisStore } from "@hono-rate-limiter/redis";
import { prisma } from "@rallly/database";
import { createLogger } from "@rallly/logger";
-import { kv } from "@vercel/kv";
import { Hono } from "hono";
import { bearerAuth } from "hono/bearer-auth";
import { handle } from "hono/vercel";
import { rateLimiter } from "hono-rate-limiter";
import { env } from "@/env";
+import { redis } from "@/lib/kv";
const logger = createLogger("api/licensing");
@@ -22,9 +22,6 @@ import {
} from "@/features/licensing/schema";
import { isSelfHosted } from "@/utils/constants";
-const isKvAvailable =
- process.env.KV_REST_API_URL && process.env.KV_REST_API_TOKEN;
-
const app = new Hono().basePath("/api/licensing/v1");
app.use("*", async (c, next) => {
@@ -40,9 +37,9 @@ if (env.LICENSE_API_AUTH_TOKEN) {
rateLimiter({
windowMs: 60 * 60 * 1000,
limit: 10,
- store: isKvAvailable
+ store: redis
? new RedisStore({
- client: kv,
+ client: redis,
})
: undefined,
}),
@@ -85,9 +82,9 @@ app.post(
},
windowMs: 60 * 1000,
limit: 100,
- store: isKvAvailable
+ store: redis
? new RedisStore({
- client: kv,
+ client: redis,
})
: undefined,
}),
diff --git a/apps/web/src/app/api/private/[...route]/route.test.ts b/apps/web/src/app/api/private/[...route]/route.test.ts
index cf40473c5..fb3e17b11 100644
--- a/apps/web/src/app/api/private/[...route]/route.test.ts
+++ b/apps/web/src/app/api/private/[...route]/route.test.ts
@@ -52,8 +52,7 @@ vi.mock("@vercel/functions", () => ({
}));
vi.mock("@/lib/kv", () => ({
- isKvEnabled: () => false,
- kv: null,
+ redis: null,
}));
import { prisma } from "@rallly/database";
diff --git a/apps/web/src/app/api/private/[...route]/route.ts b/apps/web/src/app/api/private/[...route]/route.ts
index 1522621a3..4e95e661d 100644
--- a/apps/web/src/app/api/private/[...route]/route.ts
+++ b/apps/web/src/app/api/private/[...route]/route.ts
@@ -13,7 +13,7 @@ import {
import { rateLimiter } from "hono-rate-limiter";
import { getPollParticipants, getPollResults } from "@/features/poll/data";
import { createPoll, deletePoll } from "@/features/poll/mutations";
-import { isKvEnabled, kv } from "@/lib/kv";
+import { redis } from "@/lib/kv";
import { isSupportedTimeZone } from "@/utils/supported-time-zones";
import {
createPollInputSchema,
@@ -86,7 +86,7 @@ app.post(
const { apiKeyId } = c.get("apiAuth");
return `private-api:polls-create:${apiKeyId}`;
},
- store: isKvEnabled() ? new RedisStore({ client: kv }) : undefined,
+ store: redis ? new RedisStore({ client: redis }) : undefined,
}),
describeRoute({
tags: ["Polls"],
@@ -329,7 +329,7 @@ app.get(
const { apiKeyId } = c.get("apiAuth");
return `private-api:polls-get:${apiKeyId}`;
},
- store: isKvEnabled() ? new RedisStore({ client: kv }) : undefined,
+ store: redis ? new RedisStore({ client: redis }) : undefined,
}),
describeRoute({
tags: ["Polls"],
@@ -440,7 +440,7 @@ app.get(
const { apiKeyId } = c.get("apiAuth");
return `private-api:polls-results:${apiKeyId}`;
},
- store: isKvEnabled() ? new RedisStore({ client: kv }) : undefined,
+ store: redis ? new RedisStore({ client: redis }) : undefined,
}),
describeRoute({
tags: ["Polls"],
@@ -499,7 +499,7 @@ app.get(
const { apiKeyId } = c.get("apiAuth");
return `private-api:polls-participants:${apiKeyId}`;
},
- store: isKvEnabled() ? new RedisStore({ client: kv }) : undefined,
+ store: redis ? new RedisStore({ client: redis }) : undefined,
}),
describeRoute({
tags: ["Polls"],
@@ -558,7 +558,7 @@ app.delete(
const { apiKeyId } = c.get("apiAuth");
return `private-api:polls-delete:${apiKeyId}`;
},
- store: isKvEnabled() ? new RedisStore({ client: kv }) : undefined,
+ store: redis ? new RedisStore({ client: redis }) : undefined,
}),
describeRoute({
tags: ["Polls"],
diff --git a/apps/web/src/app/api/trpc/[trpc]/route.ts b/apps/web/src/app/api/trpc/[trpc]/route.ts
index a3790ee89..4f8f9a93e 100644
--- a/apps/web/src/app/api/trpc/[trpc]/route.ts
+++ b/apps/web/src/app/api/trpc/[trpc]/route.ts
@@ -61,6 +61,7 @@ const handler = async (req: NextRequest) => {
user,
locale,
identifier,
+ event,
} satisfies TRPCContext;
},
onError: ({ error }) => {
diff --git a/apps/web/src/env.ts b/apps/web/src/env.ts
index 5eb199a2b..b1ba75f0a 100644
--- a/apps/web/src/env.ts
+++ b/apps/web/src/env.ts
@@ -130,11 +130,18 @@ export const env = createEnv({
*/
HIDE_ATTRIBUTION: z.enum(["true", "false"]).default("false"),
/**
- *
+ * Enable or disable rate limiting globally.
+ * @default "true"
+ */
+ RATE_LIMIT_ENABLED: z.enum(["true", "false"]).default("true"),
+
+ /**
+ * Upstash Redis URL and token for rate limiting and auth session storage.
+ * If not set, in-memory rate limiting and db session storage is used.
*/
KV_REST_API_URL: z.url().optional(),
KV_REST_API_TOKEN: z.string().optional(),
- KV_URL: z.url().optional(),
+
/**
* Cloudflare Turnstile secret key for bot protection on registration.
* If not set, Turnstile verification is disabled.
@@ -206,6 +213,8 @@ export const env = createEnv({
NOREPLY_EMAIL_NAME: process.env.NOREPLY_EMAIL_NAME,
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
MODERATION_ENABLED: process.env.MODERATION_ENABLED,
+ KV_REST_API_URL: process.env.KV_REST_API_URL,
+ KV_REST_API_TOKEN: process.env.KV_REST_API_TOKEN,
LICENSE_API_URL: process.env.LICENSE_API_URL,
LICENSE_API_AUTH_TOKEN: process.env.LICENSE_API_AUTH_TOKEN,
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
@@ -220,9 +229,7 @@ export const env = createEnv({
LOGO_ICON_URL: process.env.LOGO_ICON_URL,
APP_NAME: process.env.APP_NAME,
HIDE_ATTRIBUTION: process.env.HIDE_ATTRIBUTION,
- KV_REST_API_URL: process.env.KV_REST_API_URL,
- KV_REST_API_TOKEN: process.env.KV_REST_API_TOKEN,
- KV_URL: process.env.KV_URL,
+ RATE_LIMIT_ENABLED: process.env.RATE_LIMIT_ENABLED,
TURNSTILE_SECRET_KEY: process.env.TURNSTILE_SECRET_KEY,
NEXT_PUBLIC_TURNSTILE_SITE_KEY: process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY,
},
diff --git a/apps/web/src/lib/auth.ts b/apps/web/src/lib/auth.ts
index 0480b12e0..947b6cf57 100644
--- a/apps/web/src/lib/auth.ts
+++ b/apps/web/src/lib/auth.ts
@@ -27,12 +27,13 @@ import { PostHogClient } from "@/features/analytics/posthog";
import { createSpace } from "@/features/space/mutations";
import { getTranslation } from "@/i18n/server";
import { getLocale } from "@/i18n/server/get-locale";
-import { isKvEnabled, kv } from "@/lib/kv";
-import { isRateLimitEnabled } from "@/lib/rate-limit/constants";
+import { redis } from "@/lib/kv";
import { auth as legacyAuth, signOut as legacySignOut } from "@/next-auth";
import { getEmailClient } from "@/utils/emails";
import { getValueByPath } from "@/utils/get-value-by-path";
+const kv = redis;
+
const baseURL = absoluteUrl("/api/better-auth");
const logger = createLogger("auth");
@@ -202,36 +203,32 @@ export const authLib = betterAuth({
},
},
},
- secondaryStorage: isKvEnabled()
+ secondaryStorage: kv
? {
set: async (key: string, value: string, ttl?: number) => {
if (ttl) {
- await kv.set(key, value, {
- ex: ttl,
- });
+ await kv.set(key, value, { ex: ttl });
} else {
await kv.set(key, value);
}
},
- get: async (key: string) => {
- return await kv.get(key);
- },
+ get: async (key: string) => kv.get(key),
delete: async (key: string) => {
await kv.del(key);
},
}
: undefined,
rateLimit: {
- enabled: isRateLimitEnabled,
- storage: isKvEnabled() ? "secondary-storage" : "memory",
+ enabled: env.RATE_LIMIT_ENABLED !== "false",
+ storage: redis ? "secondary-storage" : "memory",
customRules: {
"/sign-up/email": {
window: 60 * 60, // 1 hour
- max: 5,
+ max: 50,
},
"/email-otp/send-verification-otp": {
window: 60 * 60, // 1 hour
- max: 10,
+ max: 100,
},
},
},
diff --git a/apps/web/src/lib/kv.ts b/apps/web/src/lib/kv.ts
index 0dbcd7af3..2263bd583 100644
--- a/apps/web/src/lib/kv.ts
+++ b/apps/web/src/lib/kv.ts
@@ -1,6 +1,21 @@
-import { kv } from "@vercel/kv";
+import { Redis } from "@upstash/redis";
import { env } from "@/env";
-const isKvEnabled = () => !!env.KV_REST_API_URL;
+function createRedis() {
+ if (!env.KV_REST_API_URL || !env.KV_REST_API_TOKEN) {
+ return null;
+ }
-export { kv, isKvEnabled };
+ try {
+ return new Redis({
+ url: env.KV_REST_API_URL,
+ token: env.KV_REST_API_TOKEN,
+ });
+ } catch {
+ return null;
+ }
+}
+
+const redis = createRedis();
+
+export { redis };
diff --git a/apps/web/src/lib/rate-limit/constants.ts b/apps/web/src/lib/rate-limit/constants.ts
index 2157ade9a..d3750c086 100644
--- a/apps/web/src/lib/rate-limit/constants.ts
+++ b/apps/web/src/lib/rate-limit/constants.ts
@@ -1,2 +1,3 @@
-export const isRateLimitEnabled =
- process.env.NODE_ENV !== "test" && !!process.env.KV_REST_API_URL;
+import { env } from "@/env";
+
+export const isRateLimitEnabled = env.RATE_LIMIT_ENABLED !== "false";
diff --git a/apps/web/src/lib/rate-limit/index.ts b/apps/web/src/lib/rate-limit/index.ts
index e100d99fa..96c04e558 100644
--- a/apps/web/src/lib/rate-limit/index.ts
+++ b/apps/web/src/lib/rate-limit/index.ts
@@ -1,47 +1,81 @@
import "server-only";
-
-import { createLogger } from "@rallly/logger";
import { Ratelimit } from "@upstash/ratelimit";
-import { kv } from "@vercel/kv";
-import { headers } from "next/headers";
-
-import { getSession } from "@/lib/auth";
-
+import { redis } from "@/lib/kv";
import { isRateLimitEnabled } from "./constants";
-const logger = createLogger("rate-limit");
-
export type Unit = "ms" | "s" | "m" | "h" | "d";
export type Duration = `${number} ${Unit}` | `${number}${Unit}`;
-async function getIPAddress() {
- return (await headers()).get("x-forwarded-for");
+const unitToMs: Record<Unit, number> = {
+ ms: 1,
+ s: 1000,
+ m: 60_000,
+ h: 3_600_000,
+ d: 86_400_000,
+};
+
+function parseDurationMs(duration: Duration): number {
+ const match = duration.match(/^(\d+)\s?(ms|s|m|h|d)$/);
+ if (!match) {
+ throw new Error(`Invalid duration: ${duration}`);
+ }
+ return Number(match[1]) * unitToMs[match[2] as Unit];
+}
+
+/**
+ * Simple fixed-window in-memory rate limiter.
+ * Entries are evicted after their window expires to prevent unbounded growth.
+ */
+function createMemoryLimiter(maxRequests: number, duration: Duration) {
+ const windowMs = parseDurationMs(duration);
+ const windows = new Map<string, { count: number; resetAt: number }>();
+
+ return {
+ async limit(key: string) {
+ const now = Date.now();
+ const entry = windows.get(key);
+
+ if (!entry || now >= entry.resetAt) {
+ windows.set(key, { count: 1, resetAt: now + windowMs });
+ // Schedule cleanup so the entry doesn't live forever
+ setTimeout(() => windows.delete(key), windowMs).unref?.();
+ return { success: true, remainingPoints: maxRequests - 1 };
+ }
+
+ entry.count++;
+
+ if (entry.count > maxRequests) {
+ return { success: false, remainingPoints: 0 };
+ }
+
+ return { success: true, remainingPoints: maxRequests - entry.count };
+ },
+ name: "memory" as const,
+ };
}
-export async function rateLimit(
- name: string,
- requests: number,
- duration: Duration,
-) {
+export function createRatelimit(requests: number, duration: Duration) {
if (!isRateLimitEnabled) {
- return {
- success: true,
- };
+ return null;
}
- const session = await getSession();
- const identifier = session?.user?.id || (await getIPAddress());
- try {
- const ratelimit = new Ratelimit({
- redis: kv,
- limiter: Ratelimit.slidingWindow(requests, duration),
+ if (redis) {
+ const limiter = new Ratelimit({
+ redis,
+ limiter: Ratelimit.fixedWindow(requests, duration),
});
- return ratelimit.limit(`${identifier}:${name}`);
- } catch (e) {
- logger.error({ error: e, name }, "Rate limit error");
return {
- success: true,
+ async limit(key: string) {
+ const res = await limiter.limit(key);
+ return {
+ success: res.success,
+ remainingPoints: res.remaining,
+ };
+ },
+ name: "redis" as const,
};
}
+
+ return createMemoryLimiter(requests, duration);
}
diff --git a/apps/web/src/lib/safe-action/server.ts b/apps/web/src/lib/safe-action/server.ts
index c9f6a7b6d..35d87fd47 100644
--- a/apps/web/src/lib/safe-action/server.ts
+++ b/apps/web/src/lib/safe-action/server.ts
@@ -11,7 +11,7 @@ import { defineAbilityForMember } from "@/features/space/member/ability";
import { defineAbilityFor } from "@/features/user/ability";
import { AppError } from "@/lib/errors";
import type { Duration } from "@/lib/rate-limit";
-import { rateLimit } from "@/lib/rate-limit";
+import { createRatelimit } from "@/lib/rate-limit";
export const posthogMiddleware = createMiddleware().define(async ({ next }) => {
const posthog = PostHogClient();
@@ -37,12 +37,19 @@ export const createRateLimitMiddleware = (
metadata: {
actionName: string;
};
- }>().define<{
ctx: { user: { id: string } };
- }>(async ({ next, metadata }) => {
- const res = await rateLimit(metadata.actionName, requests, duration);
+ }>().define(async ({ next, metadata, ctx }) => {
+ const ratelimit = createRatelimit(requests, duration);
- if (!res.success) {
+ if (!ratelimit) {
+ return next();
+ }
+
+ const { success } = await ratelimit.limit(
+ `${metadata.actionName}:${ctx.user.id}`,
+ );
+
+ if (!success) {
throw new AppError({
code: "TOO_MANY_REQUESTS",
message: "You are making too many requests.",
diff --git a/apps/web/src/trpc/context.ts b/apps/web/src/trpc/context.ts
index 57568e52c..1b444871a 100644
--- a/apps/web/src/trpc/context.ts
+++ b/apps/web/src/trpc/context.ts
@@ -1,3 +1,5 @@
+import type { WideEvent } from "@rallly/logger";
+
export type User = {
id: string;
isGuest: boolean;
@@ -10,4 +12,5 @@ export type TRPCContext = {
user?: User;
locale?: string;
identifier?: string;
+ event: WideEvent;
};
diff --git a/apps/web/src/trpc/server/create-ssr-helper.ts b/apps/web/src/trpc/server/create-ssr-helper.ts
index c550909c4..e1f51b904 100644
--- a/apps/web/src/trpc/server/create-ssr-helper.ts
+++ b/apps/web/src/trpc/server/create-ssr-helper.ts
@@ -1,8 +1,7 @@
+import { createWideEvent } from "@rallly/logger";
import { createServerSideHelpers } from "@trpc/react-query/server";
import superjson from "superjson";
-
import { getSession } from "@/lib/auth";
-
import type { TRPCContext } from "../context";
import { appRouter } from "../routers";
@@ -16,7 +15,7 @@ import { appRouter } from "../routers";
export const createSSRHelper = () => {
return createServerSideHelpers({
router: appRouter,
- ctx: {} satisfies TRPCContext,
+ ctx: { event: createWideEvent({ service: "trpc" }) } satisfies TRPCContext,
transformer: superjson,
});
};
@@ -29,6 +28,9 @@ export const createSSRHelper = () => {
*/
export const createAuthenticatedSSRHelper = async () => {
const session = await getSession();
+ const event = createWideEvent({
+ service: "trpc",
+ });
return createServerSideHelpers({
router: appRouter,
@@ -42,6 +44,7 @@ export const createAuthenticatedSSRHelper = async () => {
isLegacyGuest: session.legacy && session.user.isGuest,
}
: undefined,
+ event,
} satisfies TRPCContext,
transformer: superjson,
});
diff --git a/apps/web/src/trpc/trpc.ts b/apps/web/src/trpc/trpc.ts
index 12f4dca32..37046e63c 100644
--- a/apps/web/src/trpc/trpc.ts
+++ b/apps/web/src/trpc/trpc.ts
@@ -1,8 +1,6 @@
import { prisma } from "@rallly/database";
import { initTRPC, TRPCError } from "@trpc/server";
-import { Ratelimit } from "@upstash/ratelimit";
import { waitUntil } from "@vercel/functions";
-import { kv } from "@vercel/kv";
import superjson from "superjson";
import { getCurrentUserSpace } from "@/auth/data";
import { PostHogClient } from "@/features/analytics/posthog";
@@ -10,6 +8,7 @@ import { isApiAccessEnabled } from "@/features/developer/data";
import { isQuickCreateEnabled } from "@/features/quick-create";
import { getActiveSpaceForUser } from "@/features/space/data";
import { getUser } from "@/features/user/data";
+import { createRatelimit } from "@/lib/rate-limit";
import { isSelfHosted } from "@/utils/constants";
import type { TRPCContext } from "./context";
@@ -186,8 +185,12 @@ export const createRateLimitMiddleware = (
requests: number,
duration: "1 m" | "1 h",
) => {
+ const ratelimit = createRatelimit(requests, duration);
+
return middleware(async ({ ctx, next }) => {
- if (!process.env.KV_REST_API_URL) {
+ ctx.event.rateLimiter = ratelimit?.name ?? "none";
+
+ if (!ratelimit) {
return next();
}
@@ -198,14 +201,13 @@ export const createRateLimitMiddleware = (
});
}
- const ratelimit = new Ratelimit({
- redis: kv,
- limiter: Ratelimit.slidingWindow(requests, duration),
- });
+ const { success, remainingPoints } = await ratelimit.limit(
+ `${name}:${ctx.identifier}`,
+ );
- const res = await ratelimit.limit(`${name}:${ctx.identifier}`);
+ ctx.event.rateLimiterRemainingPoints = remainingPoints;
- if (!res.success) {
+ if (!success) {
throw new TRPCError({
code: "TOO_MANY_REQUESTS",
message: "Too many requests",
diff --git a/packages/logger/src/wide-event.ts b/packages/logger/src/wide-event.ts
index 040902366..de2437014 100644
--- a/packages/logger/src/wide-event.ts
+++ b/packages/logger/src/wide-event.ts
@@ -87,6 +87,11 @@ export interface WideEvent {
dbQueryCount?: number;
dbQueryDurationMs?: number;
+ // Rate limiting
+ rateLimiter?: string;
+ rateLimiterRemainingPoints?: number;
+ rateLimiterConsumedPoints?: number;
+
// Allow additional fields
[key: string]: unknown;
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d584f2c23..5ab969af4 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -83,7 +83,7 @@ importers:
version: 8.1.0([email protected])
'@vercel/analytics':
specifier: ^1.5.0
dayjs:
specifier: ^1.11.13
version: 1.11.19
@@ -122,7 +122,7 @@ importers:
version: 6.0.0(@types/[email protected])([email protected])
next-seo:
specifier: ^6.1.0
pg:
specifier: ^8.17.1
version: 8.18.0
@@ -301,12 +301,12 @@ importers:
'@upstash/ratelimit':
specifier: ^1.2.1
version: 1.2.1
+ '@upstash/redis':
+ specifier: ^1.36.2
+ version: 1.36.2
'@vercel/functions':
specifier: ^3.3.6
version: 3.4.1(@aws-sdk/[email protected])
- '@vercel/kv':
- specifier: ^3.0.0
- version: 3.0.0
ai:
specifier: ^6.0.87
version: 6.0.87([email protected])
@@ -5270,11 +5270,6 @@ packages:
'@aws-sdk/credential-provider-web-identity':
optional: true
- '@vercel/[email protected]':
- resolution: {integrity: sha512-pKT8fRnfyYk2MgvyB6fn6ipJPCdfZwiKDdw7vB+HL50rjboEBHDVBEcnwfkEpVSp2AjNtoaOUH7zG+bVC/rvSg==}
- engines: {node: '>=14.6'}
- deprecated: 'Vercel KV is deprecated. If you had an existing KV store, it should have moved to Upstash Redis which you will see under Vercel Integrations. For new projects, install a Redis integration from Vercel Marketplace: https://vercel.com/marketplace?category=storage&search=redis'
-
'@vercel/[email protected]':
resolution: {integrity: sha512-Fw28YZpRnA3cAHHDlkt7xQHiJ0fcL+NRcIqsocZQUSmbzeIKRpwttJjik5ZGanXP+vlA4SbTg+AbA3bP363l+w==}
engines: {node: '>= 20'}
@@ -16010,7 +16005,7 @@ snapshots:
dependencies:
uncrypto: 0.1.3
optionalDependencies:
react: 19.2.4
@@ -16021,10 +16016,6 @@ snapshots:
optionalDependencies:
'@aws-sdk/credential-provider-web-identity': 3.972.4
- '@vercel/[email protected]':
- dependencies:
- '@upstash/redis': 1.36.2
-
'@vercel/[email protected]': {}
@@ -19742,7 +19733,7 @@ snapshots:
react: 19.2.4
react-dom: 19.2.4([email protected])
dependencies:
react: 19.2.4
diff --git a/turbo.json b/turbo.json
index ea8edf7ab..bb04c2e43 100644
--- a/turbo.json
+++ b/turbo.json
@@ -77,7 +77,6 @@
"GOOGLE_CLIENT_SECRET",
"KV_REST_API_TOKEN",
"KV_REST_API_URL",
- "KV_URL",
"LICENSE_API_AUTH_TOKEN",
"MAINTENANCE_MODE",
"MICROSOFT_CLIENT_ID",
@@ -99,6 +98,7 @@
"OIDC_PICTURE_CLAIM_PATH",
"OPENAI_API_KEY",
"PORT",
+ "RATE_LIMIT_ENABLED",
"QSTASH_CURRENT_SIGNING_KEY",
"QSTASH_NEXT_SIGNING_KEY",
"QSTASH_TOKEN",