Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/lib/posthog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,20 @@ export const isFeatureEnabled = async (feature: FeatureFlags) => {
return cachedFlag.value;
}

// If not in cache or expired, fetch from PostHog
const result = await postHogClient.isFeatureEnabled(
feature,
exchangeAccountId,
);
// Fetch from the v2/feature_flags API
let finalResult = false;
try {
const client = await apiClient(config.auth_token);
const { data, response } = await client.GET(
"/v2/feature_flags/{feature_flag_id}",
{ params: { path: { feature_flag_id: feature } } },
);
// 404 means the flag doesn't exist → treat as disabled (false)
finalResult = response.ok ? (data?.enabled ?? false) : false;
} catch {
// Network or parse error → default to false
}

// Cache the result (PostHog returns undefined if there's an error, default to false)
const finalResult = result ?? false;
await cacheFeatureFlag(feature, exchangeAccountId, finalResult);

return finalResult;
Expand Down
46 changes: 46 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,23 @@ export interface paths {
patch?: never;
trace?: never;
};
"/v2/feature_flags/{feature_flag_id}": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/** Get feature flag status for the authenticated user */
get: operations["get_feature_flag"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/v1/inference/batches": {
parameters: {
query?: never;
Expand Down Expand Up @@ -9223,6 +9240,35 @@ export interface operations {
};
};
};
get_feature_flag: {
parameters: {
query?: never;
header?: never;
path: {
feature_flag_id: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Feature flag status */
200: {
headers: { [name: string]: unknown };
content: {
"application/json": {
enabled: boolean;
};
};
};
/** @description Feature flag not found */
404: {
headers: { [name: string]: unknown };
content: {
"application/json": unknown;
};
};
};
};
handle_quote: {
parameters: {
query: {
Expand Down
Loading