66 lines
1.5 KiB
TypeScript
66 lines
1.5 KiB
TypeScript
import { get } from "@vercel/edge-config";
|
|
|
|
export type BetaFeatures =
|
|
| "tokens"
|
|
| "incomingWebhooks"
|
|
| "roomChangeNotifications"
|
|
| "webhooks"
|
|
| "conversations"
|
|
| "dataroomUpload"
|
|
| "inDocumentLinks"
|
|
| "usStorage"
|
|
| "dataroomIndex"
|
|
| "slack"
|
|
| "annotations"
|
|
| "dataroomInvitations"
|
|
| "workflows"
|
|
| "ai";
|
|
|
|
type BetaFeaturesRecord = Record<BetaFeatures, string[]>;
|
|
|
|
export const getFeatureFlags = async ({ teamId }: { teamId?: string }) => {
|
|
const teamFeatures: Record<BetaFeatures, boolean> = {
|
|
tokens: false,
|
|
incomingWebhooks: false,
|
|
roomChangeNotifications: false,
|
|
webhooks: false,
|
|
conversations: false,
|
|
dataroomUpload: false,
|
|
inDocumentLinks: false,
|
|
usStorage: false,
|
|
dataroomIndex: false,
|
|
slack: false,
|
|
annotations: false,
|
|
dataroomInvitations: false,
|
|
workflows: false,
|
|
ai: false,
|
|
};
|
|
|
|
// Return all features as true if edge config is not available
|
|
if (!process.env.EDGE_CONFIG) {
|
|
return Object.fromEntries(
|
|
Object.entries(teamFeatures).map(([key, _v]) => [key, false]),
|
|
);
|
|
} else if (!teamId) {
|
|
return teamFeatures;
|
|
}
|
|
|
|
let betaFeatures: BetaFeaturesRecord | undefined = undefined;
|
|
|
|
try {
|
|
betaFeatures = await get("betaFeatures");
|
|
} catch (e) {
|
|
console.error(`Error getting beta features: ${e}`);
|
|
}
|
|
|
|
if (betaFeatures) {
|
|
for (const [featureFlag, teamIds] of Object.entries(betaFeatures)) {
|
|
if (teamIds.includes(teamId)) {
|
|
teamFeatures[featureFlag as BetaFeatures] = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
return teamFeatures;
|
|
};
|