Skip to content

Commit d5d0118

Browse files
author
Manus AI
committed
feat: Add registry developer account registration command
- Add 'flb register' command for creating Registry Developer Accounts - Interactive prompts for username, email, password, and name - Input validation for username format and password length - Calls /~registry/v1/developer-account/register API endpoint - Provides clear success/error messages - Guides users to login after successful registration
1 parent 1afcb97 commit d5d0118

1 file changed

Lines changed: 105 additions & 1 deletion

File tree

index.js

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,102 @@ async function versionBump (options) {
721721
}
722722
}
723723

724-
// Command to handle login
724+
// Command to handle registration
725+
async function registerCommand(options) {
726+
const registrationApi = 'https://api.fleetbase.io/~registry/v1/developer-account/register';
727+
728+
try {
729+
// Collect registration information
730+
const answers = await prompt([
731+
{
732+
type: 'input',
733+
name: 'username',
734+
message: 'Username:',
735+
initial: options.username,
736+
skip: !!options.username,
737+
validate: (value) => {
738+
if (!value || value.length < 3) {
739+
return 'Username must be at least 3 characters';
740+
}
741+
if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
742+
return 'Username can only contain letters, numbers, hyphens, and underscores';
743+
}
744+
return true;
745+
}
746+
},
747+
{
748+
type: 'input',
749+
name: 'email',
750+
message: 'Email:',
751+
initial: options.email,
752+
skip: !!options.email,
753+
validate: (value) => {
754+
if (!value || !value.includes('@')) {
755+
return 'Please enter a valid email address';
756+
}
757+
return true;
758+
}
759+
},
760+
{
761+
type: 'password',
762+
name: 'password',
763+
message: 'Password:',
764+
skip: !!options.password,
765+
validate: (value) => {
766+
if (!value || value.length < 8) {
767+
return 'Password must be at least 8 characters';
768+
}
769+
return true;
770+
}
771+
},
772+
{
773+
type: 'input',
774+
name: 'name',
775+
message: 'Full Name (optional):',
776+
initial: options.name
777+
}
778+
]);
779+
780+
const registrationData = {
781+
username: options.username || answers.username,
782+
email: options.email || answers.email,
783+
password: options.password || answers.password,
784+
name: options.name || answers.name || undefined
785+
};
786+
787+
console.log('\nRegistering account...');
788+
789+
// Make API call to register
790+
const response = await axios.post(registrationApi, registrationData);
791+
792+
if (response.data.status === 'success') {
793+
console.log('\n✓ Account created successfully!');
794+
console.log('✓ Please check your email to verify your account.');
795+
console.log(`\n✓ Once verified, you can login with: flb login -u ${registrationData.username}`);
796+
} else {
797+
console.error('Registration failed:', response.data.message || 'Unknown error');
798+
process.exit(1);
799+
}
800+
} catch (error) {
801+
if (error.response && error.response.data) {
802+
const errorData = error.response.data;
803+
if (errorData.errors) {
804+
console.error('\nRegistration failed with the following errors:');
805+
Object.keys(errorData.errors).forEach(field => {
806+
errorData.errors[field].forEach(message => {
807+
console.error(` - ${field}: ${message}`);
808+
});
809+
});
810+
} else {
811+
console.error('Registration failed:', errorData.message || 'Unknown error');
812+
}
813+
} else {
814+
console.error('Registration failed:', error.message);
815+
}
816+
process.exit(1);
817+
}
818+
}
819+
725820
function loginCommand (options) {
726821
const npmLogin = require('npm-cli-login');
727822
const username = options.username;
@@ -875,6 +970,15 @@ program
875970
.option('--pre-release [identifier]', 'Add pre-release identifier')
876971
.action(versionBump);
877972

973+
program
974+
.command('register')
975+
.description('Register a new Registry Developer Account')
976+
.option('-u, --username <username>', 'Username for the registry')
977+
.option('-e, --email <email>', 'Email address')
978+
.option('-p, --password <password>', 'Password')
979+
.option('-n, --name <name>', 'Your full name (optional)')
980+
.action(registerCommand);
981+
878982
program
879983
.command('login')
880984
.description('Log in to the Fleetbase registry')

0 commit comments

Comments
 (0)