okta-mcp-server
Version:
Model Context Protocol (MCP) server for Okta API operations with support for bulk operations and caching
171 lines • 5.8 kB
JavaScript
import { faker } from '@faker-js/faker';
export class UserGenerator {
faker;
statusDistribution;
profileFields;
dateRange;
generatedCount = 0;
constructor(options = {}) {
this.faker = faker;
if (options.seed) {
this.faker.seed(options.seed);
}
this.statusDistribution = options.statusDistribution || {
ACTIVE: 0.8,
STAGED: 0.05,
PROVISIONED: 0.05,
RECOVERY: 0.02,
LOCKED_OUT: 0.02,
PASSWORD_EXPIRED: 0.02,
SUSPENDED: 0.02,
DEPROVISIONED: 0.02,
};
this.profileFields = options.profileFields || [
'department',
'title',
'manager',
'employeeNumber',
'costCenter',
'division',
'company',
'office',
'city',
'state',
'zipCode',
'countryCode',
'phoneNumber',
'mobilePhone',
'preferredLanguage',
];
const now = new Date();
this.dateRange = options.dateRange || {
start: new Date(now.getTime() - 365 * 24 * 60 * 60 * 1000), // 1 year ago
end: now,
};
}
generate() {
this.generatedCount++;
const id = this.faker.string.alphanumeric(20);
const firstName = this.faker.person.firstName();
const lastName = this.faker.person.lastName();
const email = this.faker.internet.email({ firstName, lastName }).toLowerCase();
const login = email;
const created = this.faker.date.between({
from: this.dateRange.start,
to: this.dateRange.end,
});
const status = this.selectStatus();
const activated = status === 'ACTIVE'
? this.faker.date.between({ from: created, to: this.dateRange.end })
: undefined;
const lastLogin = activated
? this.faker.date.between({ from: activated, to: this.dateRange.end })
: undefined;
const lastUpdated = this.faker.date.between({
from: created,
to: this.dateRange.end,
});
const passwordChanged = activated
? this.faker.date.between({ from: created, to: lastUpdated })
: undefined;
const profile = {
login,
email,
firstName,
lastName,
};
// Add optional profile fields
this.profileFields.forEach((field) => {
if (this.faker.datatype.boolean({ probability: 0.7 })) {
profile[field] = this.generateProfileField(field);
}
});
const user = {
id,
status,
created: created.toISOString(),
statusChanged: lastUpdated.toISOString(),
lastUpdated: lastUpdated.toISOString(),
profile,
};
// Add optional fields only if they have values
if (activated) {
user.activated = activated.toISOString();
}
if (lastLogin) {
user.lastLogin = lastLogin.toISOString();
}
if (passwordChanged) {
user.passwordChanged = passwordChanged.toISOString();
}
return user;
}
generateBatch(count) {
return Array.from({ length: count }, () => this.generate());
}
selectStatus() {
const random = this.faker.number.float({ min: 0, max: 1 });
let cumulative = 0;
for (const [status, probability] of Object.entries(this.statusDistribution)) {
cumulative += probability;
if (random <= cumulative) {
return status;
}
}
return 'ACTIVE'; // Default fallback
}
generateProfileField(field) {
switch (field) {
case 'department':
return this.faker.commerce.department();
case 'title':
return this.faker.person.jobTitle();
case 'manager':
return this.faker.person.fullName();
case 'employeeNumber':
return this.faker.string.numeric(6);
case 'costCenter':
return this.faker.string.alphanumeric(8).toUpperCase();
case 'division':
return this.faker.helpers.arrayElement([
'Sales',
'Engineering',
'Marketing',
'Operations',
'Finance',
'HR',
]);
case 'company':
return this.faker.company.name();
case 'office':
return this.faker.helpers.arrayElement([
'HQ',
'Remote',
'Branch-' + this.faker.location.city(),
]);
case 'city':
return this.faker.location.city();
case 'state':
return this.faker.location.state({ abbreviated: true });
case 'zipCode':
return this.faker.location.zipCode();
case 'countryCode':
return this.faker.location.countryCode();
case 'phoneNumber':
return this.faker.phone.number();
case 'mobilePhone':
return this.faker.phone.number();
case 'preferredLanguage':
return this.faker.helpers.arrayElement(['en', 'es', 'fr', 'de', 'ja', 'zh']);
default:
return this.faker.lorem.word();
}
}
reset() {
this.generatedCount = 0;
}
getGeneratedCount() {
return this.generatedCount;
}
}
//# sourceMappingURL=user-generator.js.map