feat(dashboard): add MeDto, AdminDto, apiKeys + role/password helpers
Extends api.ts with the Phase 3.5 wire types (InstanceRole, Scope, MeDto, AdminDto, ApiKeyDto, MintApiKey*) and the matching apiKeys namespace. AdminUser in auth.ts now carries instance_role and email, so layout/store consumers see the role without a separate fetch. Adds two tiny lib helpers used by the upcoming profile/users pages: RoleChip.svelte for the colored owner/admin/member pill, and password-gen.ts for crypto.getRandomValues-backed temporary passwords used in user-invite + reset-password reveals. AdminUserRecord stays as a deprecated alias until /admins is retired in a follow-up commit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
25
dashboard/src/lib/password-gen.ts
Normal file
25
dashboard/src/lib/password-gen.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// Cryptographically random password generator for the user-create
|
||||
// and reset-password flows. PiCloud has no email yet, so the admin
|
||||
// invites a user by generating a password locally, posting it to the
|
||||
// backend, and copying the cleartext out of the one-time reveal panel
|
||||
// to share through whatever channel they trust.
|
||||
//
|
||||
// Charset is alphanumeric plus a small printable symbol set — enough
|
||||
// entropy at 16 chars (~95 bits) to be uncopyable by hand mistakes,
|
||||
// avoidant of characters that ship awkwardly through chat clients
|
||||
// (no quotes, slashes, or backticks).
|
||||
|
||||
const CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&*+-?@';
|
||||
|
||||
export function generatePassword(length = 16): string {
|
||||
if (length < 8) {
|
||||
throw new Error('password length must be at least 8');
|
||||
}
|
||||
const buf = new Uint32Array(length);
|
||||
crypto.getRandomValues(buf);
|
||||
let out = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
out += CHARSET[buf[i] % CHARSET.length];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user