This commit is contained in:
Rayyan Syahbani Hermanto
2026-09-07 22:57:18 +07:00
parent fdbfb34842
commit 1bba2b518e
101 changed files with 2503 additions and 8 deletions
+14
View File
@@ -21,3 +21,17 @@ model User {
updated_at DateTime @updatedAt
deleted_at DateTime?
}
model ServiceAccount {
id String @id @default(uuid())
client_id String @unique
client_secret_hash String
name String
role String
permissions Json
status String @default("ACTIVE")
metadata Json?
created_at DateTime @default(now())
updated_at DateTime @updatedAt
deleted_at DateTime?
}
+44 -1
View File
@@ -1 +1,44 @@
// prisma seed placeholder
import { PrismaClient } from '@prisma/client';
import * as bcrypt from 'bcrypt';
import crypto from 'crypto';
const prisma = new PrismaClient();
async function main() {
const clientId = 'raylab-telegram-bot';
const clientSecret = crypto.randomBytes(32).toString('hex');
const saltRounds = parseInt(process.env.BCRYPT_SALT_ROUNDS ?? '10', 10);
const clientSecretHash = await bcrypt.hash(clientSecret, saltRounds);
// Create service account only if not exists
const existing = await prisma.serviceAccount.findUnique({ where: { client_id: clientId } });
if (!existing) {
const sa = await prisma.serviceAccount.create({
data: {
client_id: clientId,
client_secret_hash: clientSecretHash,
name: 'Telegram Bot',
role: 'BOT',
permissions: ['DEBT_CREATE', 'DEBT_READ', 'DEBT_SETTLE'],
status: 'ACTIVE',
},
});
console.log('Service account created for development/testing.');
console.log('Client ID:', clientId);
console.log('Client Secret (one-time):', clientSecret);
console.log('Please store the client secret securely.');
} else {
console.log('Service account already exists.');
}
}
main()
.catch(e => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});