deesse 0.2.10 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/tsconfig.json CHANGED
@@ -1,12 +1,12 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "composite": false,
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "outDir": "./dist",
8
- "rootDir": "./src"
9
- },
10
- "include": ["src/**/*"],
11
- "exclude": ["node_modules", "dist"]
12
- }
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "composite": false,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "outDir": "./dist",
8
+ "rootDir": "./src"
9
+ },
10
+ "include": ["src/**/*"],
11
+ "exclude": ["node_modules", "dist"]
12
+ }
package/src/lib/admin.ts DELETED
@@ -1,68 +0,0 @@
1
- import type { Auth } from "better-auth";
2
-
3
- /**
4
- * Check if the database has any users.
5
- * Returns true if the database is empty (no users).
6
- */
7
- export async function isDatabaseEmpty(auth: Auth): Promise<boolean> {
8
- try {
9
- const result = await (auth.api as any).listUsers({ limit: 1 });
10
- return !result?.users || result.users.length === 0;
11
- } catch {
12
- // If listUsers fails, assume not empty (safer default)
13
- return false;
14
- }
15
- }
16
-
17
- /**
18
- * Require that the database is NOT empty.
19
- * Throws if no users exist.
20
- */
21
- export async function requireDatabaseNotEmpty(auth: Auth): Promise<void> {
22
- if (await isDatabaseEmpty(auth)) {
23
- throw new Error(
24
- "Database is empty. Cannot proceed with this operation. " +
25
- "Use the First Admin Setup page to create the initial admin account."
26
- );
27
- }
28
- }
29
-
30
- export interface EmailValidationOptions {
31
- allowedDomains?: string[];
32
- blockedDomains?: string[];
33
- requireOrganization?: boolean;
34
- }
35
-
36
- /**
37
- * Validate an admin email against configured rules.
38
- */
39
- export function validateAdminEmail(
40
- email: string,
41
- options: EmailValidationOptions = {}
42
- ): { valid: boolean; error?: string } {
43
- const domain = email.split('@')[1]?.toLowerCase();
44
-
45
- if (!domain) {
46
- return { valid: false, error: "Invalid email format" };
47
- }
48
-
49
- // Check blocked domains
50
- if (options.blockedDomains?.includes(domain)) {
51
- return { valid: false, error: `Email domain ${domain} is blocked` };
52
- }
53
-
54
- // Check allowed domains (if specified)
55
- if (options.allowedDomains?.length && !options.allowedDomains.includes(domain)) {
56
- return { valid: false, error: `Email must be from: ${options.allowedDomains.join(', ')}` };
57
- }
58
-
59
- // Require organization (no public email domains)
60
- if (options.requireOrganization) {
61
- const PUBLIC_DOMAINS = ['gmail.com', 'yahoo.com', 'hotmail.com', 'outlook.com', 'icloud.com'];
62
- if (PUBLIC_DOMAINS.includes(domain)) {
63
- return { valid: false, error: "Personal email domains are not allowed. Use an organizational email." };
64
- }
65
- }
66
-
67
- return { valid: true };
68
- }
@@ -1,89 +0,0 @@
1
- /**
2
- * Email validation utilities for admin email enforcement
3
- */
4
-
5
- export const PUBLIC_EMAIL_DOMAINS = [
6
- 'gmail.com',
7
- 'yahoo.com',
8
- 'hotmail.com',
9
- 'outlook.com',
10
- 'icloud.com',
11
- 'mail.com',
12
- 'aol.com',
13
- 'protonmail.com',
14
- 'zoho.com',
15
- 'yandex.com',
16
- 'gmx.com',
17
- ] as const;
18
-
19
- export type PublicEmailDomain = (typeof PUBLIC_EMAIL_DOMAINS)[number];
20
-
21
- /**
22
- * Check if an email uses a public email domain
23
- */
24
- export function isPublicEmailDomain(email: string): boolean {
25
- const domain = email.split('@')[1]?.toLowerCase();
26
- return PUBLIC_EMAIL_DOMAINS.includes(domain as PublicEmailDomain);
27
- }
28
-
29
- /**
30
- * Get allowed domains from ADMIN_ALLOWED_DOMAINS environment variable.
31
- * Returns empty array if not configured (no restrictions).
32
- */
33
- export function getAllowedDomains(): string[] {
34
- const envValue = process.env['ADMIN_ALLOWED_DOMAINS'];
35
- if (!envValue) return [];
36
- return envValue
37
- .split(',')
38
- .map((d) => d.trim().toLowerCase())
39
- .filter(Boolean);
40
- }
41
-
42
- /**
43
- * Check if an email is from an allowed domain.
44
- * If no allowed domains are configured, all domains are allowed.
45
- */
46
- export function isAllowedAdminEmail(email: string): boolean {
47
- const allowed = getAllowedDomains();
48
- if (!allowed.length) return true; // No restriction configured
49
- const domain = email.split('@')[1]?.toLowerCase();
50
- return allowed.includes(domain);
51
- }
52
-
53
- /**
54
- * Validate admin email against organizational requirements.
55
- * Returns an error message if validation fails.
56
- */
57
- export function validateAdminEmailDomain(
58
- email: string
59
- ): { valid: true } | { valid: false; code: string; message: string; suggestion?: string } {
60
- // Check if email is from a public domain (warning level, not blocking)
61
- const isPublic = isPublicEmailDomain(email);
62
- const allowed = getAllowedDomains();
63
-
64
- // If allowed domains are configured, enforce them strictly
65
- if (allowed.length > 0) {
66
- const domain = email.split('@')[1]?.toLowerCase();
67
- if (!allowed.includes(domain)) {
68
- return {
69
- valid: false,
70
- code: 'INVALID_EMAIL_DOMAIN',
71
- message: `Admin email must be from an allowed domain. Allowed: ${allowed.join(', ')}`,
72
- suggestion: 'Set ADMIN_ALLOWED_DOMAINS environment variable to configure allowed email domains',
73
- };
74
- }
75
- }
76
-
77
- // If email is from a public domain, return warning info (but allow through)
78
- if (isPublic && allowed.length === 0) {
79
- const domain = email.split('@')[1]?.toLowerCase();
80
- return {
81
- valid: false,
82
- code: 'PUBLIC_EMAIL_DOMAIN',
83
- message: `${email} is a public email domain. Admin accounts should use organizational email addresses.`,
84
- suggestion: `Set ADMIN_ALLOWED_DOMAINS environment variable to restrict to organizational domains only (e.g., ADMIN_ALLOWED_DOMAINS=${domain})`,
85
- };
86
- }
87
-
88
- return { valid: true };
89
- }