Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🔥 Remove the developer-tools flag and open API access to Pro spaces (#3268)
Luke Vella7f19b4d8950f
diff --git a/apps/web/src/app/[locale]/(space)/settings/api-keys/page.tsx b/apps/web/src/app/[locale]/(space)/settings/api-keys/page.tsxindex 7f4f5716e..46ac86b11 100644--- a/apps/web/src/app/[locale]/(space)/settings/api-keys/page.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/api-keys/page.tsx@@ -30,7 +30,7 @@ export default async function ApiKeysSettingsPage() {const enabled = await isApiAccessEnabled(user, space);// "Needs to upgrade" (hobby tier) gets its own screen; every other reason- // access is blocked (feature flag off, not the owner) is a 404.+ // access is blocked (self-hosted, not the owner) is a 404.if (!enabled && space.tier !== "hobby") {notFound();}diff --git a/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx b/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsxindex 580300275..ac04c1e1a 100644--- a/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx+++ b/apps/web/src/app/[locale]/(space)/settings/components/sidebar.tsx@@ -1,6 +1,6 @@"use client";-import { posthog, useFeatureFlagEnabled } from "@rallly/posthog/client";+import { posthog } from "@rallly/posthog/client";import {SidebarGroup,SidebarGroupContent,@@ -26,6 +26,7 @@ import {import { usePathname } from "next/navigation";import type React from "react";import { HoverPrefetchLink } from "@/components/hover-prefetch-link";+import { ProBadge } from "@/features/billing/components/pro-badge";import { useSpace } from "@/features/space/client";import { useAuthedUser } from "@/features/user/client";import { Trans, useTranslation } from "@/i18n/client";@@ -188,9 +189,11 @@ export function DeveloperSidebarMenu() {const user = useAuthedUser();const isSpaceOwner = space.ownerId === user.id;const pathname = usePathname();- const isDeveloperToolsEnabled = useFeatureFlagEnabled("developer-tools");+ const isApiEnabled = useFeatureFlag("api");- if (!isSpaceOwner || !isDeveloperToolsEnabled) {+ // Owner only: a member has no self-serve path to API keys. A free space+ // sees the entry with a Pro badge; the page itself offers the upgrade.+ if (!isSpaceOwner || !isApiEnabled) {return null;}@@ -213,6 +216,7 @@ export function DeveloperSidebarMenu() {><KeyIcon /><Trans i18nKey="apiKeys" defaults="API keys" />+ {space.tier !== "pro" ? <ProBadge className="ml-auto" /> : null}</SidebarMenuButton></SidebarMenuItem></SidebarMenu>diff --git a/apps/web/src/features/api-keys/data.ts b/apps/web/src/features/api-keys/data.tsindex 9073c733c..86793683b 100644--- a/apps/web/src/features/api-keys/data.ts+++ b/apps/web/src/features/api-keys/data.ts@@ -3,8 +3,7 @@ import "server-only";import { prisma } from "@rallly/database";import type { SpaceTier } from "@/features/space/schema";import type { AuthorizedSpaceId } from "@/features/space/types";-import { isSelfHosted } from "@/lib/constants";-import { posthog } from "@/lib/posthog";+import { isFeatureEnabled } from "@/lib/feature-flags/server";export function getSpaceApiKeys({ spaceId }: { spaceId: AuthorizedSpaceId }) {return prisma.spaceApiKey.findMany({@@ -27,12 +26,10 @@ export function getSpaceApiKeys({ spaceId }: { spaceId: AuthorizedSpaceId }) {}/**- * Determines if a user has access to API features (API keys, developer tools)- * @param user - The user to check access for- * @param space - The space to check access for- * @returns True if the user can access API features+ * API access is a Pro capability of cloud hosted spaces, managed by the+ * space owner.*/-export async function isApiAccessEnabled(+export function isApiAccessEnabled(user: {id: string;},@@ -40,27 +37,14 @@ export async function isApiAccessEnabled(tier: SpaceTier;ownerId: string;},-): Promise<boolean> {- // Block self-hosted deployments- if (isSelfHosted) {+) {+ if (!isFeatureEnabled("api")) {return false;}- // Require pro tierif (space.tier !== "pro") {return false;}- // Require space owner- if (space.ownerId !== user.id) {- return false;- }-- // Check PostHog feature flag- const isFeatureFlagEnabled = await posthog()?.isFeatureEnabled(- "developer-tools",- user.id,- );-- return isFeatureFlagEnabled ?? false;+ return space.ownerId === user.id;}diff --git a/apps/web/src/lib/feature-flags/config.ts b/apps/web/src/lib/feature-flags/config.tsindex acd5b2474..64ecb2550 100644--- a/apps/web/src/lib/feature-flags/config.ts+++ b/apps/web/src/lib/feature-flags/config.ts@@ -35,4 +35,7 @@ export const featureFlagConfig: FeatureFlagConfig = {// The discount is a Stripe coupon, so it needs billing; applying needs// storage for the verification documents the reviewer reads.nonprofitDiscount: isBillingEnabled && isStorageEnabled,+ // The API launches cloud first; self-hosted gets it once the release+ // channel carries the API host and its docs.+ api: !isSelfHosted,};diff --git a/apps/web/src/lib/feature-flags/types.ts b/apps/web/src/lib/feature-flags/types.tsindex 2f80a1d27..926a62a7c 100644--- a/apps/web/src/lib/feature-flags/types.ts+++ b/apps/web/src/lib/feature-flags/types.ts@@ -11,6 +11,7 @@ export interface FeatureFlagConfig {quickCreate: boolean;inProcessRateLimit: boolean;nonprofitDiscount: boolean;+ api: boolean;}export type Feature = keyof FeatureFlagConfig;diff --git a/packages/posthog/src/client.ts b/packages/posthog/src/client.tsindex 1d7561315..7418c418b 100644--- a/packages/posthog/src/client.ts+++ b/packages/posthog/src/client.ts@@ -2,8 +2,6 @@import posthog from "posthog-js";import type React from "react";-export { useFeatureFlagEnabled } from "posthog-js/react";-import { getPostHogInitOptions } from "./client-config";import {isAbortError,