Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/desktop/src/routes/teleprompter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,11 @@ export default function Teleprompter() {
return;
}

resizeEditor();
const element = scrollElement;
if (!element || !hasScript()) return;
const currentScrollTop = element.scrollTop;
resizeEditor();
element.scrollTop = currentScrollTop;
const maximumScroll = Math.max(
0,
element.scrollHeight - element.clientHeight,
Expand Down
10 changes: 7 additions & 3 deletions apps/mobile/src/recording/TeleprompterOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ export function TeleprompterOverlay({
};

const onTextLayout = (event: LayoutChangeEvent) => {
cancelAnimation(progress);
progress.value = 0;
setTextHeight(event.nativeEvent.layout.height);
const newHeight = event.nativeEvent.layout.height;
setTextHeight((prev) => {
if (prev === 0) {
progress.value = 0;
}
return newHeight;
});
};

return (
Expand Down
65 changes: 65 additions & 0 deletions apps/web/__tests__/unit/rate-limit-ids.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { readFileSync, readdirSync, statSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { RATE_LIMIT_IDS } from "../../lib/rate-limit";

// Rate limit IDs declared in advance for firewall rules or separate app packages
// that are intentionally not yet wired in apps/web endpoints.
Comment on lines +6 to +7

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant descriptive comment

This comment restates the purpose already conveyed by UNWIRED_RATE_LIMIT_IDS, adding maintenance noise contrary to the repository's explicit comment policy.

Suggested change
// Rate limit IDs declared in advance for firewall rules or separate app packages
// that are intentionally not yet wired in apps/web endpoints.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/__tests__/unit/rate-limit-ids.test.ts
Line: 6-7

Comment:
**Redundant descriptive comment**

This comment restates the purpose already conveyed by `UNWIRED_RATE_LIMIT_IDS`, adding maintenance noise contrary to the repository's explicit comment policy.

```suggestion

```

**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

const UNWIRED_RATE_LIMIT_IDS = new Set([
"AUTH_OTP_VERIFY",
"AUTH_OTP_SEND",
"LOOM_DOWNLOAD",
"MESSENGER_MESSAGE",
"DESKTOP_LOGS",
]);

function getAllTsFiles(dir: string): string[] {
let results: string[] = [];
const list = readdirSync(dir);
for (const file of list) {
const filePath = join(dir, file);
const stat = statSync(filePath);
if (stat && stat.isDirectory()) {
if (file !== "node_modules" && file !== ".next" && file !== "dist") {
results = results.concat(getAllTsFiles(filePath));
}
} else if (file.endsWith(".ts") || file.endsWith(".tsx")) {
if (!filePath.endsWith("lib/rate-limit.ts") && !filePath.endsWith("rate-limit-ids.test.ts")) {
results.push(filePath);
}
}
}
return results;
}

describe("RATE_LIMIT_IDS reference contract", () => {
it("ensures every active declared RATE_LIMIT_ID is referenced outside lib/rate-limit.ts", () => {
const webAppDir = join(process.cwd());
const tsFiles = getAllTsFiles(webAppDir);

let combinedSource = "";
for (const file of tsFiles) {
combinedSource += readFileSync(file, "utf8") + "\n";
}

const unreferencedKeys: string[] = [];

for (const [key, value] of Object.entries(RATE_LIMIT_IDS)) {
if (UNWIRED_RATE_LIMIT_IDS.has(key)) {
continue;
}

const hasKeyRef = combinedSource.includes(`RATE_LIMIT_IDS.${key}`);
const hasValueRef = combinedSource.includes(`"${value}"`) || combinedSource.includes(`'${value}'`);

if (!hasKeyRef && !hasValueRef) {
unreferencedKeys.push(key);
}
}

expect(
unreferencedKeys,
`The following RATE_LIMIT_IDS are declared but never referenced: ${unreferencedKeys.join(", ")}`,
).toEqual([]);
});
});
12 changes: 12 additions & 0 deletions apps/web/app/api/analytics/track/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
createAnonymousViewNotification,
sendFirstViewEmail,
} from "@/lib/Notification";
import { isRateLimited, RATE_LIMIT_IDS } from "@/lib/rate-limit";
import { runPromise } from "@/lib/server";

interface TrackPayload {
Expand Down Expand Up @@ -42,6 +43,17 @@ const decodeUrlEncodedHeaderValue = (value?: string | null) => {
};

export async function POST(request: NextRequest) {
if (
await isRateLimited(RATE_LIMIT_IDS.ANALYTICS_TRACK, {
headers: request.headers,
})
) {
return Response.json(
{ error: "Too many tracking requests. Please try again later." },
{ status: 429 },
);
}

let body: TrackPayload;
try {
body = (await request.json()) as TrackPayload;
Expand Down
13 changes: 13 additions & 0 deletions apps/web/app/api/settings/billing/guest-checkout/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@ import { serverEnv } from "@cap/env";
import { stripe } from "@cap/utils";
import type { NextRequest } from "next/server";
import { getCheckoutRedirectUrls } from "@/lib/mobile-checkout";

import { isRateLimited, RATE_LIMIT_IDS } from "@/lib/rate-limit";
import { trackServerEvent } from "@/lib/server-analytics";

export async function POST(request: NextRequest) {
if (
await isRateLimited(RATE_LIMIT_IDS.GUEST_CHECKOUT, {
headers: request.headers,
})
) {
return Response.json(
{ error: "Too many checkout attempts. Please try again later." },
{ status: 429 },
);
}

console.log("Starting guest checkout process");
const { priceId, quantity, platform } = await request.json();
const checkoutPlatform = platform === "mobile" ? "mobile" : "web";
Expand Down