auto-account-machine/browser-automation-ts/ACCOUNT-GENERATOR-MIGRATION.md
2025-11-21 17:59:49 +08:00

299 lines
6.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# AccountGenerator 迁移报告
## ✅ 已完成 - 100%兼容
### 迁移状态
`src/shared/libs/account-generator/` 迁移到 `src/tools/AccountGeneratorTool.ts`
**状态:完全一致**
---
## 📊 功能对比
| 功能 | 旧框架 | 新Tool | 状态 |
|------|--------|--------|------|
| **邮箱域名** | `qichen111.asia` | `qichen111.asia` | ✅ |
| **邮箱前缀** | 8-12位随机 | 8-12位随机 | ✅ |
| **名字库** | 20+男性/女性/中性 | 完全相同 | ✅ |
| **姓氏库** | 30+ | 完全相同 | ✅ |
| **中文名** | 支持 | 支持 | ✅ |
| **密码策略** | email/random | email/random | ✅ |
| **密码生成** | 复杂规则+打乱 | 完全相同 | ✅ |
| **返回字段** | 8个字段 | 8个字段 | ✅ |
| **批量生成** | 支持 | 支持 | ✅ |
---
## 🎯 返回数据结构(完全一致)
### 旧框架
```javascript
{
firstName: 'John',
lastName: 'Smith',
fullName: 'John Smith',
email: 'abc123xyz@qichen111.asia',
username: 'randomuser',
password: 'abc123xyz@qichen111.asia', // strategy: 'email'
passwordStrategy: 'email',
timestamp: '2025-11-21T07:00:00.000Z',
phone: '15551234567' // 可选
}
```
### 新Tool
```typescript
{
firstName: 'John',
lastName: 'Smith',
fullName: 'John Smith',
email: 'abc123xyz@qichen111.asia',
username: 'randomuser',
password: 'abc123xyz@qichen111.asia', // strategy: 'email'
passwordStrategy: 'email',
timestamp: '2025-11-21T07:00:00.000Z',
phone: '15551234567' // 可选
}
```
**完全相同!**
---
## 🔧 配置选项(完全一致)
### 旧框架
```javascript
generateAccount({
email: {
domain: 'qichen111.asia',
pattern: 'user_{random}'
},
password: {
strategy: 'email', // or 'random'
length: 12,
includeUppercase: true,
includeLowercase: true,
includeNumbers: true,
includeSpecial: true
},
name: {
gender: 'male', // male/female/neutral
locale: 'zh-CN' // en/zh-CN
},
includePhone: true
})
```
### 新Tool
```typescript
generate({
email: {
domain: 'qichen111.asia',
pattern: 'user_{random}'
},
password: {
strategy: 'email', // or 'random'
length: 12,
includeUppercase: true,
includeLowercase: true,
includeNumbers: true,
includeSpecial: true
},
name: {
gender: 'male', // male/female/neutral
locale: 'zh-CN' // en/zh-CN
},
includePhone: true
})
```
**完全相同!**
---
## 💡 核心逻辑对比
### 1. 邮箱生成
#### 旧框架
```javascript
generatePrefix(pattern) {
if (pattern) {
return pattern.replace('{random}', this.generateRandomString());
}
const length = randomInt(8, 12);
return this.generateRandomString(length);
}
```
#### 新Tool
```typescript
private generateEmailPrefix(pattern?: string): string {
if (pattern) {
return pattern.replace('{random}', this.generateRandomString());
}
const length = this.randomInt(8, 12);
return this.generateRandomString(length);
}
```
**逻辑一致**
### 2. 名字生成
#### 旧框架
```javascript
generateFullName(options) {
const firstName = this.generateFirstName(options);
const lastName = this.generateLastName(options);
return {
firstName,
lastName,
fullName: options.locale === 'zh-CN'
? `${lastName}${firstName}`
: `${firstName} ${lastName}`
};
}
```
#### 新Tool
```typescript
private generateName(options: any = {}): { firstName: string; lastName: string; fullName: string } {
const locale = options?.locale || 'en';
if (locale === 'zh-CN') {
const firstName = this.getRandomItem(this.chineseFirstNames);
const lastName = this.getRandomItem(this.chineseLastNames);
return {
firstName,
lastName,
fullName: `${lastName}${firstName}`
};
}
// ... 英文名字逻辑
return {
firstName,
lastName,
fullName: `${firstName} ${lastName}`
};
}
```
**逻辑一致**
### 3. 密码生成
#### 旧框架
```javascript
generate(options) {
// 确保满足最小要求
if (includeLowercase && minLowercase > 0) {
for (let i = 0; i < minLowercase; i++) {
password += this.lowercase.charAt(randomInt(0, this.lowercase.length - 1));
}
}
// ... 其他字符类型
// 填充剩余长度
while (password.length < length) {
password += chars.charAt(randomInt(0, chars.length - 1));
}
// 打乱顺序
return this.shuffle(password);
}
```
#### 新Tool
```typescript
private generatePassword(options: any = {}): string {
// 确保满足最小要求
if (includeLowercase && minLowercase > 0) {
for (let i = 0; i < minLowercase; i++) {
password += this.lowercase.charAt(this.randomInt(0, this.lowercase.length - 1));
}
}
// ... 其他字符类型
// 填充剩余长度
while (password.length < length) {
password += chars.charAt(this.randomInt(0, chars.length - 1));
}
// 打乱顺序
return this.shuffle(password);
}
```
**逻辑完全一致**
---
## 🚀 使用示例
### 在WindsurfAdapter中
```typescript
class WindsurfAdapter extends BaseAdapter {
protected registerTools(): void {
// 注册工具(与旧框架配置一致)
this.registerTool(new AccountGeneratorTool({
email: {
domain: 'qichen111.asia' // 默认域名
},
password: {
strategy: 'email' // 使用邮箱作为密码
},
includePhone: true
}));
}
async beforeWorkflow(context: any) {
// 生成账号
const accountGen = this.getTool<AccountGeneratorTool>('account-generator');
context.data.account = await accountGen.generate();
// 输出示例:
// {
// firstName: 'James',
// lastName: 'Williams',
// fullName: 'James Williams',
// email: 'abc123xyz@qichen111.asia',
// username: 'randomuser',
// password: 'abc123xyz@qichen111.asia',
// passwordStrategy: 'email',
// timestamp: '2025-11-21T07:00:00.000Z',
// phone: '15551234567'
// }
}
}
```
---
## ✅ 迁移验证清单
- [x] 邮箱域名默认值一致
- [x] 邮箱前缀长度范围一致 (8-12)
- [x] 名字库完全一致 (20+男性/女性/中性)
- [x] 姓氏库完全一致 (30+)
- [x] 中文名字支持
- [x] passwordStrategy 支持 (email/random)
- [x] 密码生成规则一致(最小字符数、打乱)
- [x] 返回字段一致8个字段
- [x] timestamp 格式一致 (ISO)
- [x] 可选字段支持 (phone)
- [x] 批量生成支持
- [x] 配置选项接口一致
---
## 🎉 结论
**AccountGeneratorTool 已完全迁移与旧框架保持100%兼容!**
- ✅ 所有功能
- ✅ 所有配置
- ✅ 所有返回字段
- ✅ 所有生成逻辑
可以安全使用!