Refactor environment variable handling in package.json scripts, update .env.example for consistency, and enhance Turbo configuration for environment variable passthrough. Modify API content type parsing and resolve circular dependencies in Auth and Billing modules. Add unique username generation logic in bootstrap-admin script.
This commit is contained in:
@@ -26,6 +26,9 @@ function parseArgs(argv: string[]): CliArgs {
|
||||
|
||||
for (let i = 0; i < argv.length; i += 1) {
|
||||
const key = argv[i];
|
||||
if (key === '--') {
|
||||
continue;
|
||||
}
|
||||
const value = argv[i + 1];
|
||||
if (key?.startsWith('--') && value) {
|
||||
args[key.slice(2)] = value;
|
||||
@@ -63,6 +66,29 @@ async function ensurePlatformRoles(prisma: PrismaClient): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureUniqueUsername(
|
||||
prisma: PrismaClient,
|
||||
baseUsername: string,
|
||||
): Promise<string> {
|
||||
let candidate = baseUsername;
|
||||
let suffix = 0;
|
||||
|
||||
while (true) {
|
||||
const existing = await prisma.user.findUnique({
|
||||
where: { username: candidate },
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
suffix += 1;
|
||||
const suffixText = String(suffix);
|
||||
candidate = `${baseUsername.slice(0, Math.max(1, 32 - suffixText.length))}${suffixText}`;
|
||||
}
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const input = parseArgs(process.argv.slice(2));
|
||||
const prisma = new PrismaClient();
|
||||
@@ -111,6 +137,8 @@ async function main(): Promise<void> {
|
||||
username = generateUsernameFromEmail(input.email);
|
||||
}
|
||||
|
||||
username = await ensureUniqueUsername(prisma, username);
|
||||
|
||||
const passwordHash = await hashPassword(input.password);
|
||||
|
||||
const superAdminRole = await prisma.platformRole.findUniqueOrThrow({
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "./base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user