Enhance API with OIDC support, including login and callback endpoints. Update environment variables for OIDC configuration in .env.example. Add new features to the catalog service for listing software families, Minecraft versions, and deployment regions. Implement server management actions such as kill, delete, and update in the servers module. Integrate feature flags for maintenance mode in server operations. Update pnpm-lock.yaml with new dependencies and versions.
This commit is contained in:
22
packages/feature-flags/package.json
Normal file
22
packages/feature-flags/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "@hexahost/feature-flags",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"lint": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hexahost/database": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.7.3",
|
||||
"vitest": "^3.0.5"
|
||||
}
|
||||
}
|
||||
57
packages/feature-flags/src/index.ts
Normal file
57
packages/feature-flags/src/index.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { PrismaClient } from '@hexahost/database';
|
||||
|
||||
export interface FeatureFlagSnapshot {
|
||||
key: string;
|
||||
enabled: boolean;
|
||||
metadata: Record<string, unknown> | null;
|
||||
}
|
||||
|
||||
export class FeatureFlagService {
|
||||
private cache = new Map<string, FeatureFlagSnapshot>();
|
||||
private loadedAt = 0;
|
||||
private readonly ttlMs: number;
|
||||
|
||||
constructor(
|
||||
private readonly prisma: PrismaClient,
|
||||
ttlMs = 30_000,
|
||||
) {
|
||||
this.ttlMs = ttlMs;
|
||||
}
|
||||
|
||||
async refresh(): Promise<void> {
|
||||
const flags = await this.prisma.featureFlag.findMany();
|
||||
this.cache.clear();
|
||||
for (const flag of flags) {
|
||||
this.cache.set(flag.key, {
|
||||
key: flag.key,
|
||||
enabled: flag.enabled,
|
||||
metadata:
|
||||
flag.metadata && typeof flag.metadata === 'object' && !Array.isArray(flag.metadata)
|
||||
? (flag.metadata as Record<string, unknown>)
|
||||
: null,
|
||||
});
|
||||
}
|
||||
this.loadedAt = Date.now();
|
||||
}
|
||||
|
||||
private async ensureLoaded(): Promise<void> {
|
||||
if (Date.now() - this.loadedAt > this.ttlMs || this.cache.size === 0) {
|
||||
await this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
async isEnabled(key: string, defaultValue = false): Promise<boolean> {
|
||||
await this.ensureLoaded();
|
||||
return this.cache.get(key)?.enabled ?? defaultValue;
|
||||
}
|
||||
|
||||
async getFlag(key: string): Promise<FeatureFlagSnapshot | null> {
|
||||
await this.ensureLoaded();
|
||||
return this.cache.get(key) ?? null;
|
||||
}
|
||||
|
||||
async listFlags(): Promise<FeatureFlagSnapshot[]> {
|
||||
await this.ensureLoaded();
|
||||
return [...this.cache.values()];
|
||||
}
|
||||
}
|
||||
8
packages/feature-flags/tsconfig.json
Normal file
8
packages/feature-flags/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
Reference in New Issue
Block a user