()
| 38 | |
| 39 | // 12 chars grouped as XXXX-XXXX-XXXX — easy to read aloud or paste. |
| 40 | const generateCode = (): string => { |
| 41 | const bytes = randomBytes(12); |
| 42 | const chars = Array.from(bytes, (b) => ALPHABET[b % ALPHABET.length]); |
| 43 | return [chars.slice(0, 4), chars.slice(4, 8), chars.slice(8, 12)] |
| 44 | .map((g) => g.join("")) |
| 45 | .join("-"); |
| 46 | }; |
| 47 | |
| 48 | const toRow = (raw: Row): InviteCodeRow => ({ |
| 49 | id: String(raw.id), |