UNPKG

supa-seed

Version:

A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support

66 lines 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hashPassword = hashPassword; exports.generateSecurePassword = generateSecurePassword; exports.generateTestEmail = generateTestEmail; exports.generateUsername = generateUsername; exports.generateOutdoorUsername = generateOutdoorUsername; const crypto_1 = require("crypto"); /** * Hash a password for seeding purposes * Note: In production, Supabase handles password hashing automatically */ function hashPassword(password) { const salt = (0, crypto_1.randomBytes)(16).toString('hex'); const hash = (0, crypto_1.createHash)('sha256'); hash.update(password + salt); return hash.digest('hex') + ':' + salt; } /** * Generate a secure random password for test users */ function generateSecurePassword() { const length = 12; const charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*'; let password = ''; for (let i = 0; i < length; i++) { password += charset.charAt(Math.floor(Math.random() * charset.length)); } return password; } /** * Generate a valid email address for seeding with guaranteed uniqueness */ function generateTestEmail(username, domain = 'supaseed.test') { // Add timestamp + random to ensure uniqueness (faker is seeded so usernames repeat) const timestamp = Date.now().toString().slice(-6); const randomId = Math.floor(Math.random() * 10000); const uniqueUsername = `${username.toLowerCase()}_${timestamp}_${randomId}`; return `${uniqueUsername}@${domain}`; } /** * Generate realistic usernames based on domain configuration */ function generateUsername(firstName, lastName, suffixes = ['user', 'member', 'pro', 'fan', 'creator']) { const formats = [ `${firstName.toLowerCase()}_${suffixes[Math.floor(Math.random() * suffixes.length)]}`, `${lastName.toLowerCase()}_${suffixes[Math.floor(Math.random() * suffixes.length)]}`, `${firstName.toLowerCase()}${lastName.charAt(0).toLowerCase()}_${Math.floor(Math.random() * 99)}`, `${firstName.charAt(0).toLowerCase()}${lastName.toLowerCase()}_${suffixes[0]}`, `${firstName.toLowerCase()}_${Math.floor(Math.random() * 999)}`, ]; return formats[Math.floor(Math.random() * formats.length)]; } /** * Legacy function for backward compatibility * @deprecated Use generateUsername instead */ function generateOutdoorUsername(firstName, lastName) { const outdoorSuffixes = [ 'hiker', 'climber', 'explorer', 'wanderer', 'adventurer', 'camper', 'backpacker', 'outdoors', 'trails', 'peaks', 'wild', 'summit', 'trek', 'journey', 'roam' ]; return generateUsername(firstName, lastName, outdoorSuffixes); } //# sourceMappingURL=auth-utils.js.map