Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
π Require explicit PostHog region host for erasure and admin scripts (#3106)
Luke Vellac6cfd7ac880d
diff --git a/apps/web/src/lib/posthog.ts b/apps/web/src/lib/posthog.tsindex a982f941c..c4f377918 100644--- a/apps/web/src/lib/posthog.ts+++ b/apps/web/src/lib/posthog.ts@@ -1,3 +1,4 @@+import { createLogger } from "@rallly/logger";import { PostHog } from "@rallly/posthog/server";import {getPostHogCookieName,@@ -7,6 +8,8 @@ import type { NextRequest } from "next/server";import { after } from "next/server";import { env } from "@/env";+const logger = createLogger("posthog");+let instance: PostHog | undefined;export function posthog() {@@ -139,9 +142,13 @@ export async function flushPostHog() {* Erase a person from PostHog (profile plus their events) so analytics data* keyed to a userId does not outlive the account. PostHog is optional config* that can run in any deployment mode, so this guards on configuration- * presence and no-ops when the personal API key or project id is missing.- * Reads process.env directly (same pattern as features/billing/service.ts);- * the personal API key needs the person:write scope.+ * presence and no-ops when the personal API key or project id is missing β+ * with a warning when analytics is ingesting, since the skipped erasure+ * leaves person data behind. Reads process.env directly (same pattern as+ * features/billing/service.ts); the personal API key needs the person:write+ * scope. POSTHOG_API_HOST is the region app host serving the private+ * management API β not NEXT_PUBLIC_POSTHOG_API_HOST, which is an ingestion+ * host (in production a reverse proxy that does not forward the private API).*/export async function deletePostHogPerson({distinctId,@@ -152,10 +159,22 @@ export async function deletePostHogPerson({const projectId = process.env.POSTHOG_PROJECT_ID;if (!personalApiKey || !projectId) {+ if (env.NEXT_PUBLIC_POSTHOG_API_KEY) {+ logger.warn(+ {+ distinctId,+ missingEnvVars: [+ !personalApiKey && "POSTHOG_PERSONAL_API_KEY",+ !projectId && "POSTHOG_PROJECT_ID",+ ].filter(Boolean),+ },+ "PostHog erasure skipped: analytics data will outlive the account",+ );+ }return;}- const apiHost = process.env.POSTHOG_API_HOST ?? "https://us.posthog.com";+ const apiHost = process.env.POSTHOG_API_HOST ?? "https://eu.posthog.com";const headers = { Authorization: `Bearer ${personalApiKey}` };const lookupRes = await fetch(diff --git a/packages/posthog/.env.sample b/packages/posthog/.env.sampleindex c245e45bc..509b4be54 100644--- a/packages/posthog/.env.sample+++ b/packages/posthog/.env.sample@@ -3,7 +3,7 @@# https://app.posthog.com/settings/user-api-keysPOSTHOG_PERSONAL_API_KEY=POSTHOG_PROJECT_ID=-# Optional β defaults to https://us.posthog.com+# Optional β defaults to https://eu.posthog.com# POSTHOG_API_HOST=# backfill-space-group-properties: project API key (ingestion) + databasediff --git a/packages/posthog/src/scripts/backfill-space-type.ts b/packages/posthog/src/scripts/backfill-space-type.tsindex ee34f555c..de9f7263b 100644--- a/packages/posthog/src/scripts/backfill-space-type.ts+++ b/packages/posthog/src/scripts/backfill-space-type.ts@@ -26,11 +26,11 @@ import { prisma } from "@rallly/database";* Requires in packages/posthog/.env (see .env.sample):* POSTHOG_PERSONAL_API_KEY personal API key with query:read* POSTHOG_PROJECT_ID- * POSTHOG_API_HOST optional, defaults to https://us.posthog.com+ * POSTHOG_API_HOST optional, defaults to https://eu.posthog.com* DATABASE_URL*/-const API_HOST = process.env.POSTHOG_API_HOST ?? "https://us.posthog.com";+const API_HOST = process.env.POSTHOG_API_HOST ?? "https://eu.posthog.com";const PROJECT_ID = process.env.POSTHOG_PROJECT_ID;const API_KEY = process.env.POSTHOG_PERSONAL_API_KEY;diff --git a/packages/posthog/src/scripts/purge-guest-profiles.ts b/packages/posthog/src/scripts/purge-guest-profiles.tsindex 5725bfa32..443661bfe 100644--- a/packages/posthog/src/scripts/purge-guest-profiles.ts+++ b/packages/posthog/src/scripts/purge-guest-profiles.ts@@ -32,10 +32,10 @@* Requires in packages/posthog/.env (see .env.sample):* POSTHOG_PERSONAL_API_KEY personal API key with query:read + person:write* POSTHOG_PROJECT_ID- * POSTHOG_API_HOST optional, defaults to https://us.posthog.com+ * POSTHOG_API_HOST optional, defaults to https://eu.posthog.com*/-const API_HOST = process.env.POSTHOG_API_HOST ?? "https://us.posthog.com";+const API_HOST = process.env.POSTHOG_API_HOST ?? "https://eu.posthog.com";const PROJECT_ID = process.env.POSTHOG_PROJECT_ID;const API_KEY = process.env.POSTHOG_PERSONAL_API_KEY;