@flags-sdk/posthog@1.0.0
Major Changes
-
#436
aec3c03Thanks @dferber90! - Modernize the PostHog adapter. This release is breaking in five ways:- Environment variables were renamed.
NEXT_PUBLIC_POSTHOG_KEY→POSTHOG_PROJECT_API_KEYandNEXT_PUBLIC_POSTHOG_HOST→POSTHOG_HOST. - Local vs. remote evaluation is now an explicit choice. The default adapter evaluates remotely unless you set
POSTHOG_SECRET_KEY. - The three adapter methods collapsed into a single callable adapter.
isFeatureEnabled()/featureFlagValue()/featureFlagPayload()becomepostHogAdapterandpostHogAdapter.payload. - A flag's
keyis used as the PostHog flag key verbatim. The old "read until the first." convention is gone. - The per-call
sendFeatureFlagEventsoption and thefeatureFlagPayloadgetValuemapper are removed.
It also upgrades
posthog-nodefrom v4.11.1 to v5.45.0 (which raises the required
Node.js version), adds bulk evaluation support, dropsposthog-node's runtime
deprecation warnings, and removes the unused@vercel/edge-configdependency.This release requires
flags@^4.2.0, which is where the uninvoked-adapter shorthand
and bulk evaluation landed.Environment variables
The adapter runs server-side only, so its credentials were never meant to be exposed
to the browser. TheNEXT_PUBLIC_prefixed variables are renamed accordingly, and the
project API key variable now says which key it wants:- NEXT_PUBLIC_POSTHOG_KEY=phc_... - NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com + POSTHOG_PROJECT_API_KEY=phc_... + POSTHOG_HOST=https://us.i.posthog.com
POSTHOG_HOSTis also whatgetProviderDataderives the app host from, and
POSTHOG_PERSONAL_API_KEY/POSTHOG_PROJECT_IDare unchanged.Explicit local vs. remote evaluation
Previously the default
postHogAdapterpassedPOSTHOG_PERSONAL_API_KEYinto the
runtimeposthog-nodeclient. When that variable was set, this enabled local
evaluation and started a feature-flag poller in every warm server process — on
serverless that could generate a large, traffic-independent volume of PostHog feature
flag requests, as a side effect of a credential you may only have set for the Flags
Explorer.The default adapter now evaluates flags remotely unless you opt in to local
evaluation by settingPOSTHOG_SECRET_KEY(aphs_...project secret key). When set,
posthog-nodepolls flag definitions and evaluates flags in-process. When using
createPostHogAdapter, control it explicitly viapostHogOptions
(secretKey+enableLocalEvaluation).POSTHOG_PERSONAL_API_KEYcontinues to be used only bygetProviderData(Flags
Explorer discovery) and no longer affects runtime evaluation.Single callable adapter
The three adapter methods (
isFeatureEnabled,featureFlagValue,featureFlagPayload)
are collapsed into a single callable adapter, matching@flags-sdk/vercel. Pass it
uninvoked or invoked, and use.payloadfor a flag's attached payload:// before import { postHogAdapter } from "@flags-sdk/posthog"; flag({ key: "my-flag", adapter: postHogAdapter.isFeatureEnabled() }); flag({ key: "my-flag", adapter: postHogAdapter.featureFlagValue() }); flag({ key: "my-flag", adapter: postHogAdapter.featureFlagPayload((v) => v), }); // after import { postHogAdapter } from "@flags-sdk/posthog"; flag({ key: "my-flag", adapter: postHogAdapter }); // or postHogAdapter() flag({ key: "my-flag", adapter: postHogAdapter.payload }); // or .payload()
isFeatureEnabledandfeatureFlagValuemerged into the value adapter, which returns
whatever PostHog evaluated the flag to: a boolean for a boolean flag, the variant
stringfor a multivariate flag. Type the flag (flag<boolean>,flag<string>) to
describe the value you expect.Note that
isFeatureEnabledused to coerce a multivariate flag's variant totrue.
Nothing coerces now, so a flag that previously readtrueviaisFeatureEnabledwill
read e.g.'variant-a'. Declaringflag<boolean>only changes the TypeScript type —
if you relied on the boolean, narrow the value in your owndecideor at the call site.A flag's
keyis now used as the PostHog feature flag key verbatim. The previous
convention of trimming everything after the first.(somy-flag.variantread the
PostHog flagmy-flag) has been removed; use the exact PostHog flag key as your flag
key.Upgraded
posthog-node, migrated toevaluateFlags, added bulk evaluationposthog-nodeis upgraded from v4.11.1 to v5.45.0. Internally the adapter now uses its
evaluateFlagsinstead of the deprecatedisFeatureEnabled/getFeatureFlag/
getFeatureFlagPayloadmethods, removing the deprecation warnings those log at runtime.The adapter also implements
bulkDecide, so
evaluate()resolves flags
that share anidentifysource through a singleevaluateFlagscall — one/flags
request when evaluating remotely, one in-process evaluation when evaluating locally.
Flag values and flag payloads are batched separately, so a flag and its payload still
resolve through two calls.The per-call
sendFeatureFlagEventsoption and thefeatureFlagPayloadgetValue
mapper are removed (neither has anevaluateFlagsequivalent); map payloads in your
own flag code instead.Node.js version requirement
posthog-node@5.45.0requires Node.js^20.20.0 || >=22.22.0, and this adapter now
declares the sameenginesconstraint.Removed
@vercel/edge-configdependencyThe adapter never used it. It is dropped from
dependencies(and from the package
keywords), so installs no longer pull it in. - Environment variables were renamed.