diff --git a/apps/web/src/app/(dashboard)/settings/billing/page.tsx b/apps/web/src/app/(dashboard)/settings/billing/page.tsx index 8773f1aa8..256f682fb 100644 --- a/apps/web/src/app/(dashboard)/settings/billing/page.tsx +++ b/apps/web/src/app/(dashboard)/settings/billing/page.tsx @@ -8,7 +8,7 @@ import { getServerComponentFlag } from '~/helpers/get-server-component-feature-f export default async function BillingSettingsPage() { const user = await getRequiredServerComponentSession(); - const isBillingEnabled = await getServerComponentFlag('billing'); + const isBillingEnabled = await getServerComponentFlag('app_billing'); // Redirect if subscriptions are not enabled. if (!isBillingEnabled) { diff --git a/apps/web/src/components/(dashboard)/layout/profile-dropdown.tsx b/apps/web/src/components/(dashboard)/layout/profile-dropdown.tsx index fb57beff8..f7d14c39d 100644 --- a/apps/web/src/components/(dashboard)/layout/profile-dropdown.tsx +++ b/apps/web/src/components/(dashboard)/layout/profile-dropdown.tsx @@ -38,7 +38,7 @@ export const ProfileDropdown = ({ user }: ProfileDropdownProps) => { const { getFlag } = useFeatureFlags(); - const isBillingEnabled = getFlag('billing'); + const isBillingEnabled = getFlag('app_billing'); const initials = user.name diff --git a/apps/web/src/components/(dashboard)/settings/layout/desktop-nav.tsx b/apps/web/src/components/(dashboard)/settings/layout/desktop-nav.tsx index 6cce0e62e..5a85680c8 100644 --- a/apps/web/src/components/(dashboard)/settings/layout/desktop-nav.tsx +++ b/apps/web/src/components/(dashboard)/settings/layout/desktop-nav.tsx @@ -19,7 +19,7 @@ export const DesktopNav = ({ className, ...props }: DesktopNavProps) => { const { getFlag } = useFeatureFlags(); - const isBillingEnabled = getFlag('billing'); + const isBillingEnabled = getFlag('app_billing'); return (
diff --git a/apps/web/src/components/(dashboard)/settings/layout/mobile-nav.tsx b/apps/web/src/components/(dashboard)/settings/layout/mobile-nav.tsx index 24fccedaa..19bbefdc9 100644 --- a/apps/web/src/components/(dashboard)/settings/layout/mobile-nav.tsx +++ b/apps/web/src/components/(dashboard)/settings/layout/mobile-nav.tsx @@ -19,7 +19,7 @@ export const MobileNav = ({ className, ...props }: MobileNavProps) => { const { getFlag } = useFeatureFlags(); - const isBillingEnabled = getFlag('billing'); + const isBillingEnabled = getFlag('app_billing'); return (
=> { +): Promise => { const requestHeaders = options?.requestHeaders ?? {}; if (!isFeatureFlagEnabled()) { @@ -47,7 +47,7 @@ export const getFlag = async ( */ export const getAllFlags = async ( options?: GetFlagOptions, -): Promise> => { +): Promise> => { const requestHeaders = options?.requestHeaders ?? {}; if (!isFeatureFlagEnabled()) { diff --git a/apps/web/src/pages/api/feature-flag/get.ts b/apps/web/src/pages/api/feature-flag/get.ts index eab7f9cb8..c3de053cd 100644 --- a/apps/web/src/pages/api/feature-flag/get.ts +++ b/apps/web/src/pages/api/feature-flag/get.ts @@ -92,7 +92,7 @@ export const mapJwtToFlagProperties = ( * * @param jwt The JWT of the current user. * @param request Request potentially containing a PostHog `distinct_id` cookie. - * @returns + * @returns A distinct user ID. */ export const extractDistinctUserId = (jwt: JWT | null, request: NextRequest): string => { const config = extractPostHogConfig(); diff --git a/apps/web/src/providers/feature-flag.tsx b/apps/web/src/providers/feature-flag.tsx index df034abc3..2bd9e1a3e 100644 --- a/apps/web/src/providers/feature-flag.tsx +++ b/apps/web/src/providers/feature-flag.tsx @@ -2,6 +2,8 @@ import { createContext, useCallback, useContext, useEffect, useState } from 'react'; +import { z } from 'zod'; + import { FEATURE_FLAG_POLL_INTERVAL, LOCAL_FEATURE_FLAGS, @@ -10,10 +12,17 @@ import { import { getAllFlags } from '~/helpers/get-feature-flag'; -export type FeatureFlagValue = boolean | string | number | undefined; +export const ZFeatureFlagValueSchema = z.union([ + z.boolean(), + z.string(), + z.number(), + z.undefined(), +]); + +export type TFeatureFlagValue = z.infer; export type FeatureFlagContextValue = { - getFlag: (_key: string) => FeatureFlagValue; + getFlag: (_key: string) => TFeatureFlagValue; }; export const FeatureFlagContext = createContext(null); @@ -33,7 +42,7 @@ export function FeatureFlagProvider({ initialFlags, }: { children: React.ReactNode; - initialFlags: Record; + initialFlags: Record; }) { const [flags, setFlags] = useState(initialFlags); diff --git a/apps/web/src/providers/posthog.tsx b/apps/web/src/providers/posthog.tsx index 792802a38..4bed6960e 100644 --- a/apps/web/src/providers/posthog.tsx +++ b/apps/web/src/providers/posthog.tsx @@ -9,7 +9,7 @@ import posthog from 'posthog-js'; import { extractPostHogConfig } from '@documenso/lib/constants/feature-flags'; -export function PostHogPageview(): JSX.Element { +export function PostHogPageview() { const postHogConfig = extractPostHogConfig(); const pathname = usePathname(); @@ -18,6 +18,7 @@ export function PostHogPageview(): JSX.Element { if (typeof window !== 'undefined' && postHogConfig) { posthog.init(postHogConfig.key, { api_host: postHogConfig.host, + disable_session_recording: true, loaded: () => { getSession() .then((session) => { @@ -48,5 +49,5 @@ export function PostHogPageview(): JSX.Element { }); }, [pathname, searchParams, postHogConfig]); - return <>; + return null; } diff --git a/packages/lib/constants/feature-flags.ts b/packages/lib/constants/feature-flags.ts index 77d89065b..d0004e83b 100644 --- a/packages/lib/constants/feature-flags.ts +++ b/packages/lib/constants/feature-flags.ts @@ -9,7 +9,7 @@ export const FEATURE_FLAG_POLL_INTERVAL = 30000; * Does not take any person or group properties into account. */ export const LOCAL_FEATURE_FLAGS: Record = { - billing: process.env.NEXT_PUBLIC_FEATURE_BILLING_ENABLED === 'true', + app_billing: process.env.NEXT_PUBLIC_FEATURE_BILLING_ENABLED === 'true', } as const; /**