Skip to content
Merged
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/web/app/(app)/[emailAccountId]/onboarding/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Suspense } from "react";
import type { Metadata } from "next";
import { cookies } from "next/headers";
import { after } from "next/server";
import { OnboardingContent } from "@/app/(app)/[emailAccountId]/onboarding/OnboardingContent";
import { fetchUserAndStoreUtms } from "@/app/(landing)/welcome/utms";
Expand All @@ -21,10 +22,11 @@ export default async function OnboardingPage(props: {

const authPromise = auth();

const cookieStore = await cookies();
after(async () => {
const user = await authPromise;
if (!user?.user) return;
await fetchUserAndStoreUtms(user.user.id);
await fetchUserAndStoreUtms(user.user.id, cookieStore);
});

return (
Expand Down
4 changes: 3 additions & 1 deletion apps/web/app/(landing)/welcome/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Suspense } from "react";
import { cookies } from "next/headers";
import type { Metadata } from "next";
import { after } from "next/server";
import { OnboardingForm } from "@/app/(landing)/welcome/form";
Expand All @@ -25,10 +26,11 @@ export default async function WelcomePage(props: {

const authPromise = auth();

const cookieStore = await cookies();
after(async () => {
const user = await authPromise;
if (!user?.user) return;
await fetchUserAndStoreUtms(user.user.id);
await fetchUserAndStoreUtms(user.user.id, cookieStore);
});

return (
Expand Down
39 changes: 22 additions & 17 deletions apps/web/app/(landing)/welcome/utms.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { cookies } from "next/headers";
import prisma from "@/utils/prisma";
import { createScopedLogger } from "@/utils/logger";
import type { ReadonlyRequestCookies } from "next/dist/server/web/spec-extension/adapters/request-cookies";

const logger = createScopedLogger("utms");

export async function fetchUserAndStoreUtms(userId: string) {
export async function fetchUserAndStoreUtms(
userId: string,
cookies: ReadonlyRequestCookies,
) {
Comment on lines +7 to +10
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.

💡 Verification agent

🧩 Analysis chain

Signature change looks good; ensure all call sites pass the cookie store

New param aligns with app router constraints. If you adopt the type change above, update this annotation to CookieStore.

Run to confirm all usages updated to the 2-arg form:


🏁 Script executed:

#!/bin/bash
rg -nP 'fetchUserAndStoreUtms\s*\(' -C2

Length of output: 1173


Update parameter type to CookieStore
All call sites now pass cookieStore. Change the cookies parameter in fetchUserAndStoreUtms from ReadonlyRequestCookies to CookieStore.

🤖 Prompt for AI Agents
In apps/web/app/(landing)/welcome/utms.tsx around lines 7 to 10, the function
parameter type for cookies is declared as ReadonlyRequestCookies but all call
sites now pass cookieStore; change the parameter type to CookieStore, update or
add the appropriate import for CookieStore (from next/headers or your
framework's headers module), and adjust any immediate usages that rely on
ReadonlyRequestCookies APIs to the CookieStore API if there are differences.

const user = await prisma.user
.findUnique({
where: { id: userId },
Expand All @@ -16,21 +19,19 @@ export async function fetchUserAndStoreUtms(userId: string) {
});

if (user && !user.utms) {
await storeUtms(userId).catch((error) => {
logger.error("Failed to store utms", { error, userId });
});
await storeUtms(userId, cookies);
}
}

export async function storeUtms(userId: string) {
// `cookies` passed in as we can't do await cookies() in the `after` hook
async function storeUtms(userId: string, cookies: ReadonlyRequestCookies) {
logger.info("Storing utms", { userId });

const cookieStore = await cookies();
const utmCampaign = cookieStore.get("utm_campaign");
const utmMedium = cookieStore.get("utm_medium");
const utmSource = cookieStore.get("utm_source");
const utmTerm = cookieStore.get("utm_term");
const affiliate = cookieStore.get("affiliate");
const utmCampaign = cookies.get("utm_campaign");
const utmMedium = cookies.get("utm_medium");
const utmSource = cookies.get("utm_source");
const utmTerm = cookies.get("utm_term");
const affiliate = cookies.get("affiliate");

const utms = {
utmCampaign: utmCampaign?.value,
Expand All @@ -40,10 +41,14 @@ export async function storeUtms(userId: string) {
affiliate: affiliate?.value,
};

await prisma.user.update({
where: { id: userId },
data: { utms },
});
try {
await prisma.user.update({
where: { id: userId },
data: { utms },
});

logger.info("Stored utms", { utms, userId });
logger.info("Stored utms", { utms, userId });
} catch (error) {
logger.error("Failed to store utms", { error, userId });
}
}
5 changes: 5 additions & 0 deletions apps/web/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ export const env = createEnv({
.default(false),
NEXT_PUBLIC_AXIOM_DATASET: z.string().optional(),
NEXT_PUBLIC_AXIOM_TOKEN: z.string().optional(),
NEXT_PUBLIC_LOG_SCOPES: z
.string()
.optional()
.transform((value) => value?.split(",")),
NEXT_PUBLIC_BEDROCK_SONNET_MODEL: z
.string()
.default("us.anthropic.claude-3-7-sonnet-20250219-v1:0"),
Expand Down Expand Up @@ -218,6 +222,7 @@ export const env = createEnv({
process.env.NEXT_PUBLIC_WELCOME_UPGRADE_ENABLED,
NEXT_PUBLIC_AXIOM_DATASET: process.env.NEXT_PUBLIC_AXIOM_DATASET,
NEXT_PUBLIC_AXIOM_TOKEN: process.env.NEXT_PUBLIC_AXIOM_TOKEN,
NEXT_PUBLIC_LOG_SCOPES: process.env.NEXT_PUBLIC_LOG_SCOPES,
NEXT_PUBLIC_BEDROCK_SONNET_MODEL:
process.env.NEXT_PUBLIC_BEDROCK_SONNET_MODEL,
NEXT_PUBLIC_OLLAMA_MODEL: process.env.NEXT_PUBLIC_OLLAMA_MODEL,
Expand Down
25 changes: 11 additions & 14 deletions apps/web/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ const colors = {
reset: "\x1b[0m",
} as const;

// const logScopes = new Map<string, boolean>();
// logScopes.set("reply-tracker/outbound", true);
// logScopes.set("outlook/webhook", true);

export function createScopedLogger(scope: string) {
if (env.NEXT_PUBLIC_AXIOM_TOKEN) return createAxiomLogger(scope);
// if (!logScopes.has(scope)) return createNullLogger();
if (env.NEXT_PUBLIC_LOG_SCOPES && !env.NEXT_PUBLIC_LOG_SCOPES.includes(scope))
return createNullLogger();

const createLogger = (fields: Record<string, unknown> = {}) => {
const formatMessage = (
Expand Down Expand Up @@ -89,15 +86,15 @@ function createAxiomLogger(scope: string) {
return createLogger();
}

// function createNullLogger() {
// return {
// info: () => {},
// error: () => {},
// warn: () => {},
// trace: () => {},
// with: () => createNullLogger(),
// };
// }
function createNullLogger() {
return {
info: () => {},
error: () => {},
warn: () => {},
trace: () => {},
with: () => createNullLogger(),
};
}

function formatError(args?: Record<string, unknown>) {
if (env.NODE_ENV !== "production") return args;
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.8.7
v2.8.8
Loading