better-auth-studio 1.1.2-beta.15 → 1.1.2-beta.17

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.
Files changed (88) hide show
  1. package/README.md +38 -25
  2. package/data/default-geo.json +1 -1
  3. package/dist/adapters/astro.d.ts +1 -1
  4. package/dist/adapters/astro.js +13 -13
  5. package/dist/adapters/elysia.d.ts +2 -2
  6. package/dist/adapters/elysia.js +13 -13
  7. package/dist/adapters/express.d.ts +2 -2
  8. package/dist/adapters/express.js +4 -4
  9. package/dist/adapters/hono.d.ts +2 -2
  10. package/dist/adapters/hono.js +12 -12
  11. package/dist/adapters/nextjs.d.ts +1 -1
  12. package/dist/adapters/nextjs.js +10 -10
  13. package/dist/adapters/nuxt.d.ts +1 -1
  14. package/dist/adapters/nuxt.js +22 -22
  15. package/dist/adapters/remix.d.ts +1 -1
  16. package/dist/adapters/remix.js +13 -13
  17. package/dist/adapters/solid-start.d.ts +1 -1
  18. package/dist/adapters/solid-start.js +13 -13
  19. package/dist/adapters/svelte-kit.d.ts +2 -2
  20. package/dist/adapters/svelte-kit.js +13 -13
  21. package/dist/adapters/tanstack-start.d.ts +1 -1
  22. package/dist/adapters/tanstack-start.js +13 -13
  23. package/dist/add-svelte-kit-env-modules.js +11 -11
  24. package/dist/auth-adapter.d.ts +1 -1
  25. package/dist/auth-adapter.js +96 -96
  26. package/dist/cli/commands/init.js +57 -57
  27. package/dist/cli.js +75 -75
  28. package/dist/config.d.ts +5 -5
  29. package/dist/config.js +37 -37
  30. package/dist/core/handler.d.ts +1 -1
  31. package/dist/core/handler.js +115 -115
  32. package/dist/data.d.ts +2 -2
  33. package/dist/data.js +60 -60
  34. package/dist/geo-service.js +78 -78
  35. package/dist/get-tsconfig-info.js +4 -4
  36. package/dist/index.d.ts +8 -8
  37. package/dist/index.js +6 -6
  38. package/dist/providers/events/helpers.d.ts +2 -2
  39. package/dist/providers/events/helpers.js +156 -156
  40. package/dist/public/assets/{main-Cu8ik7af.js → main-tA7wDMDp.js} +1 -1
  41. package/dist/public/index.html +1 -1
  42. package/dist/routes/api-router.d.ts +2 -2
  43. package/dist/routes/api-router.js +3 -3
  44. package/dist/routes.d.ts +4 -4
  45. package/dist/routes.d.ts.map +1 -1
  46. package/dist/routes.js +1272 -1272
  47. package/dist/routes.js.map +1 -1
  48. package/dist/studio.d.ts +3 -3
  49. package/dist/studio.js +64 -64
  50. package/dist/types/events.d.ts +7 -7
  51. package/dist/types/events.js +165 -165
  52. package/dist/types/handler.d.ts +5 -5
  53. package/dist/utils/auth-callbacks-injector.d.ts +2 -2
  54. package/dist/utils/auth-callbacks-injector.js +27 -27
  55. package/dist/utils/auth-callbacks-wrapper.d.ts +3 -3
  56. package/dist/utils/auth-callbacks-wrapper.js +117 -107
  57. package/dist/utils/database-detection.d.ts +1 -1
  58. package/dist/utils/database-detection.js +44 -44
  59. package/dist/utils/database-hook-injector.d.ts +3 -3
  60. package/dist/utils/database-hook-injector.js +135 -131
  61. package/dist/utils/email-otp-hooks-injector.d.ts +28 -12
  62. package/dist/utils/email-otp-hooks-injector.js +104 -97
  63. package/dist/utils/event-ingestion.d.ts +5 -5
  64. package/dist/utils/event-ingestion.d.ts.map +1 -1
  65. package/dist/utils/event-ingestion.js +14 -16
  66. package/dist/utils/event-ingestion.js.map +1 -1
  67. package/dist/utils/hook-injector.d.ts +2 -2
  68. package/dist/utils/hook-injector.js +199 -199
  69. package/dist/utils/html-injector.d.ts +3 -3
  70. package/dist/utils/html-injector.js +37 -37
  71. package/dist/utils/org-hooks-injector.d.ts +3 -3
  72. package/dist/utils/org-hooks-injector.js +63 -63
  73. package/dist/utils/org-hooks-wrapper.d.ts +41 -35
  74. package/dist/utils/org-hooks-wrapper.js +778 -658
  75. package/dist/utils/organization-hooks-wrapper.d.ts +23 -17
  76. package/dist/utils/organization-hooks-wrapper.js +325 -277
  77. package/dist/utils/package-json.js +11 -11
  78. package/dist/utils/paths.js +1 -1
  79. package/dist/utils/server-init.d.ts +1 -1
  80. package/dist/utils/server-init.js +25 -25
  81. package/dist/utils/session.js +12 -12
  82. package/dist/utils.js +24 -24
  83. package/package.json +47 -55
  84. package/public/assets/{main-Cu8ik7af.js → main-tA7wDMDp.js} +1 -1
  85. package/public/index.html +1 -1
  86. package/scripts/download-geolite2.js +8 -8
  87. package/scripts/generate-default-db.js +324 -324
  88. package/scripts/postinstall.js +25 -25
@@ -1,6 +1,6 @@
1
- import { existsSync, readFileSync } from 'node:fs';
2
- import { createRequire } from 'node:module';
3
- import { dirname, join, resolve } from 'node:path';
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { dirname, join, resolve } from "node:path";
4
4
  /**
5
5
  * Find the project root by looking for package.json files up the directory tree
6
6
  * @param startDir - Directory to start searching from
@@ -8,9 +8,9 @@ import { dirname, join, resolve } from 'node:path';
8
8
  */
9
9
  function findProjectRoot(startDir) {
10
10
  let currentDir = resolve(startDir);
11
- const root = resolve('/');
11
+ const root = resolve("/");
12
12
  while (currentDir !== root) {
13
- const packageJsonPath = join(currentDir, 'package.json');
13
+ const packageJsonPath = join(currentDir, "package.json");
14
14
  if (existsSync(packageJsonPath)) {
15
15
  return currentDir;
16
16
  }
@@ -28,17 +28,17 @@ export async function getPackageVersion(packageName, cwd) {
28
28
  const searchDir = cwd || process.cwd();
29
29
  try {
30
30
  const projectRoot = findProjectRoot(searchDir);
31
- const packageJsonPath = join(searchDir, 'package.json');
31
+ const packageJsonPath = join(searchDir, "package.json");
32
32
  if (existsSync(packageJsonPath)) {
33
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
33
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
34
34
  if (packageJson.dependencies?.[packageName]) {
35
- return packageJson.dependencies[packageName].replace(/[\^~]/, '');
35
+ return packageJson.dependencies[packageName].replace(/[\^~]/, "");
36
36
  }
37
37
  if (packageJson.devDependencies?.[packageName]) {
38
- return packageJson.devDependencies[packageName].replace(/[\^~]/, '');
38
+ return packageJson.devDependencies[packageName].replace(/[\^~]/, "");
39
39
  }
40
40
  if (packageJson.peerDependencies?.[packageName]) {
41
- return packageJson.peerDependencies[packageName].replace(/[\^~]/, '');
41
+ return packageJson.peerDependencies[packageName].replace(/[\^~]/, "");
42
42
  }
43
43
  }
44
44
  try {
@@ -47,7 +47,7 @@ export async function getPackageVersion(packageName, cwd) {
47
47
  paths: [projectRoot],
48
48
  });
49
49
  if (existsSync(packagePath)) {
50
- const packageJson = JSON.parse(readFileSync(packagePath, 'utf-8'));
50
+ const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
51
51
  return packageJson.version;
52
52
  }
53
53
  }
@@ -1,4 +1,4 @@
1
- const basePaths = ['auth.ts', 'auth.js', 'auth.server.js', 'auth.server.ts'];
1
+ const basePaths = ["auth.ts", "auth.js", "auth.server.js", "auth.server.ts"];
2
2
  export const possiblePaths = [
3
3
  ...basePaths,
4
4
  ...basePaths.map((it) => `lib/server/${it}`),
@@ -7,4 +7,4 @@
7
7
  * This should be called at server startup, before any auth requests
8
8
  */
9
9
  export declare function initializeOnServerStart(baseUrl?: string, basePath?: string): void;
10
- //# sourceMappingURL=server-init.d.ts.map
10
+ //# sourceMappingURL=server-init.d.ts.map
@@ -8,33 +8,33 @@ let initializationAttempted = false;
8
8
  * This should be called at server startup, before any auth requests
9
9
  */
10
10
  export function initializeOnServerStart(baseUrl, basePath) {
11
- console.log("PINGGEDD");
12
- if (initializationAttempted) {
13
- return;
11
+ console.log("PINGGEDD");
12
+ if (initializationAttempted) {
13
+ return;
14
+ }
15
+ initializationAttempted = true;
16
+ // Use setImmediate to ensure this runs after the event loop starts
17
+ // but before any requests are processed
18
+ setImmediate(async () => {
19
+ try {
20
+ const url =
21
+ baseUrl || process.env.BETTER_AUTH_URL || process.env.AUTH_URL || "http://localhost:3000";
22
+ const path = basePath || process.env.BETTER_AUTH_STUDIO_PATH || "/api/studio";
23
+ const fullUrl = `${url}${path}`;
24
+ await fetch(fullUrl, {
25
+ method: "GET",
26
+ headers: { "user-agent": "better-auth-studio-server-init" },
27
+ }).catch(() => {
28
+ // Silently fail - initialization will happen on first real request
29
+ });
30
+ } catch (error) {
31
+ // Silently fail - initialization will happen on first real request
14
32
  }
15
- initializationAttempted = true;
16
- // Use setImmediate to ensure this runs after the event loop starts
17
- // but before any requests are processed
18
- setImmediate(async () => {
19
- try {
20
- const url = baseUrl || process.env.BETTER_AUTH_URL || process.env.AUTH_URL || 'http://localhost:3000';
21
- const path = basePath || process.env.BETTER_AUTH_STUDIO_PATH || '/api/studio';
22
- const fullUrl = `${url}${path}`;
23
- await fetch(fullUrl, {
24
- method: 'GET',
25
- headers: { 'user-agent': 'better-auth-studio-server-init' },
26
- }).catch(() => {
27
- // Silently fail - initialization will happen on first real request
28
- });
29
- }
30
- catch (error) {
31
- // Silently fail - initialization will happen on first real request
32
- }
33
- });
33
+ });
34
34
  }
35
35
  // @ts-ignore
36
36
  // Auto-initialize when module is imported (if in server environment)
37
- if (typeof window === 'undefined' && typeof process !== 'undefined') {
38
- initializeOnServerStart();
37
+ if (typeof window === "undefined" && typeof process !== "undefined") {
38
+ initializeOnServerStart();
39
39
  }
40
- //# sourceMappingURL=server-init.js.map
40
+ //# sourceMappingURL=server-init.js.map
@@ -1,31 +1,31 @@
1
- import { createCipheriv, createDecipheriv, createHmac, randomBytes } from 'crypto';
2
- const ALGORITHM = 'aes-256-gcm';
1
+ import { createCipheriv, createDecipheriv, createHmac, randomBytes } from "crypto";
2
+ const ALGORITHM = "aes-256-gcm";
3
3
  const IV_LENGTH = 16;
4
4
  const AUTH_TAG_LENGTH = 16;
5
5
  function deriveKey(secret) {
6
- return createHmac('sha256', secret).update('studio-session-key').digest();
6
+ return createHmac("sha256", secret).update("studio-session-key").digest();
7
7
  }
8
8
  export function encryptSession(session, secret) {
9
9
  const key = deriveKey(secret);
10
10
  const iv = randomBytes(IV_LENGTH);
11
11
  const cipher = createCipheriv(ALGORITHM, key, iv);
12
12
  const data = JSON.stringify(session);
13
- const encrypted = Buffer.concat([cipher.update(data, 'utf8'), cipher.final()]);
13
+ const encrypted = Buffer.concat([cipher.update(data, "utf8"), cipher.final()]);
14
14
  const authTag = cipher.getAuthTag();
15
15
  const combined = Buffer.concat([iv, authTag, encrypted]);
16
- return combined.toString('base64url');
16
+ return combined.toString("base64url");
17
17
  }
18
18
  export function decryptSession(token, secret) {
19
19
  try {
20
20
  const key = deriveKey(secret);
21
- const combined = Buffer.from(token, 'base64url');
21
+ const combined = Buffer.from(token, "base64url");
22
22
  const iv = combined.subarray(0, IV_LENGTH);
23
23
  const authTag = combined.subarray(IV_LENGTH, IV_LENGTH + AUTH_TAG_LENGTH);
24
24
  const encrypted = combined.subarray(IV_LENGTH + AUTH_TAG_LENGTH);
25
25
  const decipher = createDecipheriv(ALGORITHM, key, iv);
26
26
  decipher.setAuthTag(authTag);
27
27
  const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
28
- return JSON.parse(decrypted.toString('utf8'));
28
+ return JSON.parse(decrypted.toString("utf8"));
29
29
  }
30
30
  catch {
31
31
  return null;
@@ -45,14 +45,14 @@ export function createStudioSession(user, durationMs = 7 * 24 * 60 * 60 * 1000)
45
45
  return {
46
46
  userId: user.id,
47
47
  email: user.email.length > maxEmailLength ? user.email.substring(0, maxEmailLength) : user.email,
48
- name: (user.name || '').length > maxNameLength
49
- ? (user.name || '').substring(0, maxNameLength)
50
- : user.name || '',
51
- role: user.role || 'user',
48
+ name: (user.name || "").length > maxNameLength
49
+ ? (user.name || "").substring(0, maxNameLength)
50
+ : user.name || "",
51
+ role: user.role || "user",
52
52
  // Don't store image in session to reduce cookie size - it can be fetched from user data if needed
53
53
  issuedAt: Date.now(),
54
54
  expiresAt: Date.now() + durationMs,
55
55
  };
56
56
  }
57
- export const STUDIO_COOKIE_NAME = 'better_auth_studio_session';
57
+ export const STUDIO_COOKIE_NAME = "better_auth_studio_session";
58
58
  //# sourceMappingURL=session.js.map
package/dist/utils.js CHANGED
@@ -1,27 +1,27 @@
1
1
  export const possibleConfigFiles = [
2
- 'auth.ts',
3
- 'auth.js',
4
- 'app/auth.ts',
5
- 'app/auth.js',
6
- 'apps/auth.ts',
7
- 'apps/auth.js',
8
- 'server/auth.ts',
9
- 'server/auth.js',
10
- 'src/auth.ts',
11
- 'src/auth.js',
12
- 'lib/auth.ts',
13
- 'utils/auth.ts',
14
- 'utils/auth.js',
15
- 'utils/auth.server.ts',
16
- 'utils/auth.server.js',
17
- 'utils/lib/auth.ts',
18
- 'utils/lib/auth.js',
19
- 'utils/lib/auth.server.ts',
20
- 'utils/lib/auth.server.js',
21
- 'lib/auth.js',
22
- 'better-auth.config.ts',
23
- 'better-auth.config.js',
24
- 'auth.config.ts',
25
- 'auth.config.js',
2
+ "auth.ts",
3
+ "auth.js",
4
+ "app/auth.ts",
5
+ "app/auth.js",
6
+ "apps/auth.ts",
7
+ "apps/auth.js",
8
+ "server/auth.ts",
9
+ "server/auth.js",
10
+ "src/auth.ts",
11
+ "src/auth.js",
12
+ "lib/auth.ts",
13
+ "utils/auth.ts",
14
+ "utils/auth.js",
15
+ "utils/auth.server.ts",
16
+ "utils/auth.server.js",
17
+ "utils/lib/auth.ts",
18
+ "utils/lib/auth.js",
19
+ "utils/lib/auth.server.ts",
20
+ "utils/lib/auth.server.js",
21
+ "lib/auth.js",
22
+ "better-auth.config.ts",
23
+ "better-auth.config.js",
24
+ "auth.config.ts",
25
+ "auth.config.js",
26
26
  ];
27
27
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,12 +1,29 @@
1
1
  {
2
2
  "name": "better-auth-studio",
3
- "version": "1.1.2-beta.15",
3
+ "version": "1.1.2-beta.17",
4
4
  "description": "Studio for Better Auth",
5
- "main": "dist/index.js",
6
- "type": "module",
5
+ "keywords": [
6
+ "admin",
7
+ "authentication",
8
+ "better-auth",
9
+ "dashboard",
10
+ "gui",
11
+ "studio"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "kinfish",
7
15
  "bin": {
8
16
  "better-auth-studio": "./dist/cli.js"
9
17
  },
18
+ "files": [
19
+ "README.md",
20
+ "data/default-geo.json",
21
+ "dist/",
22
+ "public/",
23
+ "scripts/"
24
+ ],
25
+ "type": "module",
26
+ "main": "dist/index.js",
10
27
  "exports": {
11
28
  ".": "./dist/index.js",
12
29
  "./express": "./dist/adapters/express.js",
@@ -21,42 +38,6 @@
21
38
  "./nuxt": "./dist/adapters/nuxt.js",
22
39
  "./config": "./dist/types/handler.js"
23
40
  },
24
- "scripts": {
25
- "build": "tsc && pnpm run frontend:build && pnpm run copy:public && pnpm run verify:public",
26
- "copy:public": "rm -rf dist/public && cp -r public dist/",
27
- "verify:public": "test -f dist/public/index.html && echo '✓ Public directory copied successfully' || (echo '✗ ERROR: Public directory not copied!' && exit 1)",
28
- "postinstall": "node scripts/postinstall.js",
29
- "dev": "tsx src/cli.ts",
30
- "start": "node dist/cli.js",
31
- "studio": "tsx src/cli.ts",
32
- "clean": "rm -rf dist",
33
- "frontend:dev": "cd frontend && pnpm run dev",
34
- "frontend:build": "cd frontend && pnpm run build",
35
- "frontend:preview": "cd frontend && pnpm run preview",
36
- "lint": "biome check . --max-diagnostics=1000",
37
- "lint:fix": "biome check --write .",
38
- "format": "biome format --write .",
39
- "type-check": "tsc --noEmit",
40
- "test": "vitest",
41
- "test:watch": "vitest --watch",
42
- "test:coverage": "vitest --coverage",
43
- "test:ci": "pnpm test --run",
44
- "release": "pnpm build && bumpp && pnpm publish --access public --no-git-checks",
45
- "release:beta": "pnpm build && bumpp --preid beta && pnpm publish --access public --tag beta --no-git-checks",
46
- "release:no-build": "bumpp && pnpm publish --access public --no-git-checks --tag next",
47
- "release:canary": "pnpm build && bumpp --preid canary --no-commit --no-tag --no-push && pnpm publish --access public --tag canary --no-git-checks",
48
- "bump": "bumpp"
49
- },
50
- "keywords": [
51
- "better-auth",
52
- "studio",
53
- "dashboard",
54
- "authentication",
55
- "gui",
56
- "admin"
57
- ],
58
- "author": "kinfish",
59
- "license": "MIT",
60
41
  "dependencies": {
61
42
  "@babel/preset-react": "^7.27.1",
62
43
  "@babel/preset-typescript": "^7.27.1",
@@ -81,12 +62,12 @@
81
62
  "ws": "^8.14.2"
82
63
  },
83
64
  "devDependencies": {
84
- "@biomejs/biome": "^2.2.4",
85
65
  "@types/cors": "^2.8.17",
86
66
  "@types/express": "^4.17.21",
87
67
  "@types/node": "^20.10.0",
88
68
  "@types/supertest": "^6.0.2",
89
69
  "@types/ws": "^8.5.10",
70
+ "oxfmt": "^0.26.0",
90
71
  "supertest": "^7.1.4",
91
72
  "tsx": "^4.6.0",
92
73
  "typescript": "^5.3.2",
@@ -95,19 +76,30 @@
95
76
  "engines": {
96
77
  "node": ">=18.0.0"
97
78
  },
98
- "pnpm": {
99
- "overrides": {
100
- "qs": ">=6.14.1",
101
- "@remix-run/router": ">=1.23.2",
102
- "devalue": ">=5.6.2",
103
- "@sveltejs/kit": ">=2.49.5"
104
- }
105
- },
106
- "files": [
107
- "dist/",
108
- "public/",
109
- "data/default-geo.json",
110
- "scripts/",
111
- "README.md"
112
- ]
79
+ "scripts": {
80
+ "build": "tsc && pnpm run frontend:build && pnpm run copy:public && pnpm run verify:public",
81
+ "copy:public": "rm -rf dist/public && cp -r public dist/",
82
+ "verify:public": "test -f dist/public/index.html && echo '✓ Public directory copied successfully' || (echo '✗ ERROR: Public directory not copied!' && exit 1)",
83
+ "postinstall": "node scripts/postinstall.js",
84
+ "dev": "tsx src/cli.ts",
85
+ "start": "node dist/cli.js",
86
+ "studio": "tsx src/cli.ts",
87
+ "clean": "rm -rf dist",
88
+ "frontend:dev": "cd frontend && pnpm run dev",
89
+ "frontend:build": "cd frontend && pnpm run build",
90
+ "frontend:preview": "cd frontend && pnpm run preview",
91
+ "lint": "oxfmt --check .",
92
+ "lint:fix": "oxfmt .",
93
+ "format": "oxfmt format --write .",
94
+ "type-check": "tsc --noEmit",
95
+ "test": "vitest",
96
+ "test:watch": "vitest --watch",
97
+ "test:coverage": "vitest --coverage",
98
+ "test:ci": "pnpm test --run",
99
+ "release": "pnpm build && bumpp && pnpm publish --access public --no-git-checks",
100
+ "release:beta": "pnpm build && bumpp --preid beta && pnpm publish --access public --tag beta --no-git-checks",
101
+ "release:no-build": "bumpp && pnpm publish --access public --no-git-checks --tag next",
102
+ "release:canary": "pnpm build && bumpp --preid canary --no-commit --no-tag --no-push && pnpm publish --access public --tag canary --no-git-checks",
103
+ "bump": "bumpp"
104
+ }
113
105
  }