Skip to content

Commit 031a82e

Browse files
committed
feat(analytics): updated experiment analytics
1 parent 908ff50 commit 031a82e

39 files changed

Lines changed: 700 additions & 775 deletions

.cursorrules

Lines changed: 0 additions & 374 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
"source.fixAll.biome": "explicit",
3838
"source.organizeImports.biome": "explicit"
3939
}
40-
}
40+
}

apps/api/src/config/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "dotenv/config";
22

33
export const env = {
44
PORT: process.env.PORT,
5+
APP_URL: process.env.APP_URL,
56
FRONTEND_URL: process.env.FRONTEND_URL,
67
API_URL: process.env.API_URL,
78
RESEND_API_KEY: process.env.RESEND_API_KEY,

apps/api/src/lib/actions/email.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Resend } from "resend";
2+
import { env } from "@/config/env";
23
import { WelcomeEmail } from "@/lib/emails/WelcomeEmail";
34

4-
const resendApiKey = process.env.RESEND_API_KEY;
5+
const resendApiKey = env.RESEND_API_KEY;
56
const resend = resendApiKey ? new Resend(resendApiKey) : null;
67

78
export async function sendWelcomeEmail({ userEmail }: { userEmail: string }) {

apps/api/src/lib/emails/WelcomeEmail.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import {
1212
Tailwind,
1313
Text,
1414
} from "@react-email/components";
15+
import { env } from "@/config/env";
1516

1617
type WelcomeEmailProps = {
1718
userEmail: string;
1819
};
1920

20-
const appBaseUrl = process.env.APP_URL;
21+
const appBaseUrl = env.APP_URL;
2122

2223
export const WelcomeEmail = ({ userEmail }: WelcomeEmailProps) => {
2324
const previewText = "Flagix is ready. Start shipping features with control!";

apps/api/src/routes/flag/route.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,8 @@ router.get(
301301
targetVariation: rule.variation?.name, // Target variation for 'targeting' rules
302302
rolloutPercentage: rule.rolloutPercentage,
303303
variationSplits: // Distribution for 'experiment' rules
304-
rule.type === "experiment"
305-
? JSON.parse(rule.distribution as string)
306-
: undefined,
307-
conditions: rule.conditions
308-
? JSON.parse(rule.conditions as string)
309-
: [],
304+
rule.type === "experiment" ? rule.distribution : undefined,
305+
conditions: rule.conditions ? rule.conditions : [],
310306
}));
311307

312308
// Format the final output structure
@@ -316,8 +312,9 @@ router.get(
316312
description: flagData.description,
317313
createdAt: flagData.createdAt.toISOString().split("T")[0],
318314
variations: flagData.variations.map((variation) => ({
315+
id: variation.id,
319316
name: variation.name,
320-
value: JSON.parse(variation.value as string),
317+
value: variation.value,
321318
type: variation.type,
322319
})),
323320

@@ -708,7 +705,7 @@ router.post(
708705
rolloutPercentage = rule.rolloutPercentage;
709706
} else {
710707
// experiment
711-
distributionJson = JSON.stringify(rule.variationSplits);
708+
distributionJson = rule.variationSplits;
712709
}
713710

714711
const newRule = await tx.environmentRule.create({
@@ -719,9 +716,7 @@ router.post(
719716
type: rule.ruleType,
720717
description: rule.description,
721718
conditions:
722-
rule.conditions.length > 0
723-
? JSON.stringify(rule.conditions)
724-
: Prisma.JsonNull,
719+
rule.conditions.length > 0 ? rule.conditions : Prisma.JsonNull,
725720
rolloutPercentage,
726721
variationId,
727722
distribution: distributionJson,
@@ -922,17 +917,15 @@ router.put(
922917
rolloutPercentage = rule.rolloutPercentage;
923918
} else {
924919
// experiment
925-
distributionData = JSON.stringify(rule.variationSplits);
920+
distributionData = rule.variationSplits;
926921
}
927922

928923
await db.environmentRule.update({
929924
where: { id: ruleId },
930925
data: {
931926
description: rule.description,
932927
conditions:
933-
rule.conditions.length > 0
934-
? JSON.stringify(rule.conditions)
935-
: Prisma.JsonNull,
928+
rule.conditions.length > 0 ? rule.conditions : Prisma.JsonNull,
936929
rolloutPercentage: rolloutPercentage ?? null,
937930
variationId: variationId ?? null,
938931
distribution: distributionData,

0 commit comments

Comments
 (0)