41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import 'reflect-metadata';
|
|
import 'dotenv/config';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import { z } from 'zod';
|
|
import { AppModule } from '../app.module';
|
|
import { BootstrapService } from '../identity/bootstrap.service';
|
|
import { createUserSchema } from '../identity/identity.schemas';
|
|
|
|
async function main() {
|
|
const input = createUserSchema.safeParse({
|
|
email: process.env.OWNER_EMAIL,
|
|
name: process.env.OWNER_NAME,
|
|
password: process.env.OWNER_PASSWORD,
|
|
});
|
|
const name = z
|
|
.string()
|
|
.trim()
|
|
.min(1)
|
|
.max(160)
|
|
.safeParse(process.env.ORGANIZATION_NAME);
|
|
if (!input.success || !name.success)
|
|
throw new Error('Invalid bootstrap configuration');
|
|
const app = await NestFactory.createApplicationContext(AppModule, {
|
|
logger: false,
|
|
});
|
|
try {
|
|
const result = await app
|
|
.get(BootstrapService)
|
|
.createOwner(name.data, input.data);
|
|
console.log(JSON.stringify(result));
|
|
} finally {
|
|
await app.close();
|
|
}
|
|
}
|
|
void main().catch(() => {
|
|
console.error(
|
|
'Bootstrap failed. Check configuration, database availability, and whether an owner already exists.',
|
|
);
|
|
process.exitCode = 1;
|
|
});
|