feat: add basic webui
This commit is contained in:
26
packages/feature-flags/access.ts
Normal file
26
packages/feature-flags/access.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { type ApiData, verifyAccess } from '@vercel/flags';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import * as flags from './index';
|
||||
|
||||
export const getFlags = async (request: NextRequest) => {
|
||||
const access = await verifyAccess(request.headers.get('Authorization'));
|
||||
|
||||
if (!access) {
|
||||
return NextResponse.json(null, { status: 401 });
|
||||
}
|
||||
|
||||
const definitions = Object.fromEntries(
|
||||
Object.values(flags).map((flag) => [
|
||||
flag.key,
|
||||
{
|
||||
origin: flag.origin,
|
||||
description: flag.description,
|
||||
options: flag.options,
|
||||
},
|
||||
])
|
||||
);
|
||||
|
||||
return NextResponse.json<ApiData>({
|
||||
definitions,
|
||||
});
|
||||
};
|
||||
3
packages/feature-flags/index.ts
Normal file
3
packages/feature-flags/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { createFlag } from './lib/create-flag';
|
||||
|
||||
export const showBetaFeature = createFlag('showBetaFeature');
|
||||
20
packages/feature-flags/lib/create-flag.ts
Normal file
20
packages/feature-flags/lib/create-flag.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { analytics } from '@konobangu/analytics/server';
|
||||
import { getSessionFromHeaders } from '@konobangu/auth/server';
|
||||
import { unstable_flag as flag } from '@vercel/flags/next';
|
||||
|
||||
export const createFlag = (key: string) =>
|
||||
flag({
|
||||
key,
|
||||
defaultValue: false,
|
||||
async decide() {
|
||||
const { userId } = await getSessionFromHeaders();
|
||||
|
||||
if (!userId) {
|
||||
return this.defaultValue as boolean;
|
||||
}
|
||||
|
||||
const isEnabled = await analytics.isFeatureEnabled(key, userId);
|
||||
|
||||
return isEnabled ?? (this.defaultValue as boolean);
|
||||
},
|
||||
});
|
||||
22
packages/feature-flags/package.json
Normal file
22
packages/feature-flags/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "@konobangu/feature-flags",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"clean": "git clean -xdf .cache .turbo dist node_modules",
|
||||
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
|
||||
},
|
||||
"dependencies": {
|
||||
"@konobangu/auth": "workspace:*",
|
||||
"@konobangu/analytics": "workspace:*",
|
||||
"@konobangu/design-system": "workspace:*",
|
||||
"@vercel/flags": "^2.6.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"next": "^15.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.7.2",
|
||||
"@konobangu/typescript-config": "workspace:*"
|
||||
}
|
||||
}
|
||||
8
packages/feature-flags/tsconfig.json
Normal file
8
packages/feature-flags/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@konobangu/typescript-config/react-library.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user