srs-api/scripts/user.ts
Aswin Biju 61514fb82f
All checks were successful
deploy / test (push) Successful in 1m33s
deploy / deploy (push) Successful in 18s
feat(users): added a wizard to reset a password and supporting services for the srs PWA
2026-11-04 20:44:36 +05:30

52 lines
1.5 KiB
TypeScript

/**
* npm run user create a short wizard: choose Admin or User
* npm run user password set a new password for an admin or a user
* npm run user list show every account
*
*/
import { createWizard, listLines, passwordWizard } from '../src/cli/userWizard';
import { loadConfig } from '../src/config';
import { openDb } from '../src/db';
import { runMigrations } from '../src/db/migrate';
import { makeIo } from './cliIo';
async function main(): Promise<number> {
const command = process.argv[2];
if (command !== 'create' && command !== 'password' && command !== 'list') {
console.log('usage:');
console.log(' npm run user create create an admin or a user (a short wizard)');
console.log(' npm run user password set a new password for an admin or a user');
console.log(' npm run user list show every account');
return command ? 1 : 0;
}
const config = loadConfig();
const db = openDb(config.dbPath);
runMigrations(db);
try {
if (command === 'list') {
for (const line of listLines(db)) console.log(line);
return 0;
}
const { io, close } = makeIo();
try {
return command === 'password'
? await passwordWizard(db, io)
: await createWizard(db, io, config.defaultCountryCode);
} finally {
close();
}
} finally {
db.close();
}
}
main().then(
(code) => process.exit(code),
(err) => {
console.error(String(err));
process.exit(1);
},
);