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

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 (84) hide show
  1. package/README.md +36 -23
  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/routes/api-router.d.ts +2 -2
  41. package/dist/routes/api-router.js +3 -3
  42. package/dist/routes.d.ts +4 -4
  43. package/dist/routes.d.ts.map +1 -1
  44. package/dist/routes.js +1272 -1272
  45. package/dist/routes.js.map +1 -1
  46. package/dist/studio.d.ts +3 -3
  47. package/dist/studio.js +64 -64
  48. package/dist/types/events.d.ts +7 -7
  49. package/dist/types/events.js +165 -165
  50. package/dist/types/handler.d.ts +5 -5
  51. package/dist/utils/auth-callbacks-injector.d.ts +2 -2
  52. package/dist/utils/auth-callbacks-injector.js +27 -27
  53. package/dist/utils/auth-callbacks-wrapper.d.ts +3 -3
  54. package/dist/utils/auth-callbacks-wrapper.js +117 -107
  55. package/dist/utils/database-detection.d.ts +1 -1
  56. package/dist/utils/database-detection.js +44 -44
  57. package/dist/utils/database-hook-injector.d.ts +3 -3
  58. package/dist/utils/database-hook-injector.js +135 -131
  59. package/dist/utils/email-otp-hooks-injector.d.ts +28 -12
  60. package/dist/utils/email-otp-hooks-injector.js +104 -97
  61. package/dist/utils/event-ingestion.d.ts +5 -5
  62. package/dist/utils/event-ingestion.d.ts.map +1 -1
  63. package/dist/utils/event-ingestion.js +14 -16
  64. package/dist/utils/event-ingestion.js.map +1 -1
  65. package/dist/utils/hook-injector.d.ts +2 -2
  66. package/dist/utils/hook-injector.js +199 -199
  67. package/dist/utils/html-injector.d.ts +3 -3
  68. package/dist/utils/html-injector.js +37 -37
  69. package/dist/utils/org-hooks-injector.d.ts +3 -3
  70. package/dist/utils/org-hooks-injector.js +63 -63
  71. package/dist/utils/org-hooks-wrapper.d.ts +41 -35
  72. package/dist/utils/org-hooks-wrapper.js +778 -658
  73. package/dist/utils/organization-hooks-wrapper.d.ts +23 -17
  74. package/dist/utils/organization-hooks-wrapper.js +325 -277
  75. package/dist/utils/package-json.js +11 -11
  76. package/dist/utils/paths.js +1 -1
  77. package/dist/utils/server-init.d.ts +1 -1
  78. package/dist/utils/server-init.js +25 -25
  79. package/dist/utils/session.js +12 -12
  80. package/dist/utils.js +24 -24
  81. package/package.json +26 -26
  82. package/scripts/download-geolite2.js +8 -8
  83. package/scripts/generate-default-db.js +324 -324
  84. 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.16",
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",
@@ -33,9 +50,9 @@
33
50
  "frontend:dev": "cd frontend && pnpm run dev",
34
51
  "frontend:build": "cd frontend && pnpm run build",
35
52
  "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 .",
53
+ "lint": "oxfmt --check .",
54
+ "lint:fix": "oxfmt .",
55
+ "format": "oxfmt format --write .",
39
56
  "type-check": "tsc --noEmit",
40
57
  "test": "vitest",
41
58
  "test:watch": "vitest --watch",
@@ -47,16 +64,6 @@
47
64
  "release:canary": "pnpm build && bumpp --preid canary --no-commit --no-tag --no-push && pnpm publish --access public --tag canary --no-git-checks",
48
65
  "bump": "bumpp"
49
66
  },
50
- "keywords": [
51
- "better-auth",
52
- "studio",
53
- "dashboard",
54
- "authentication",
55
- "gui",
56
- "admin"
57
- ],
58
- "author": "kinfish",
59
- "license": "MIT",
60
67
  "dependencies": {
61
68
  "@babel/preset-react": "^7.27.1",
62
69
  "@babel/preset-typescript": "^7.27.1",
@@ -81,12 +88,12 @@
81
88
  "ws": "^8.14.2"
82
89
  },
83
90
  "devDependencies": {
84
- "@biomejs/biome": "^2.2.4",
85
91
  "@types/cors": "^2.8.17",
86
92
  "@types/express": "^4.17.21",
87
93
  "@types/node": "^20.10.0",
88
94
  "@types/supertest": "^6.0.2",
89
95
  "@types/ws": "^8.5.10",
96
+ "oxfmt": "^0.26.0",
90
97
  "supertest": "^7.1.4",
91
98
  "tsx": "^4.6.0",
92
99
  "typescript": "^5.3.2",
@@ -102,12 +109,5 @@
102
109
  "devalue": ">=5.6.2",
103
110
  "@sveltejs/kit": ">=2.49.5"
104
111
  }
105
- },
106
- "files": [
107
- "dist/",
108
- "public/",
109
- "data/default-geo.json",
110
- "scripts/",
111
- "README.md"
112
- ]
113
- }
112
+ }
113
+ }
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const https = require('node:https');
4
- const fs = require('node:fs');
5
- const path = require('node:path');
3
+ const https = require("node:https");
4
+ const fs = require("node:fs");
5
+ const path = require("node:path");
6
6
 
7
7
  const GEO_DB_URL =
8
- 'https://github.com/P3TERX/GeoLite.mmdb/releases/download/2024.08.13/GeoLite2-City.mmdb';
9
- const OUTPUT_PATH = path.join(__dirname, '..', 'data', 'GeoLite2-City.mmdb');
8
+ "https://github.com/P3TERX/GeoLite.mmdb/releases/download/2024.08.13/GeoLite2-City.mmdb";
9
+ const OUTPUT_PATH = path.join(__dirname, "..", "data", "GeoLite2-City.mmdb");
10
10
 
11
11
  const dataDir = path.dirname(OUTPUT_PATH);
12
12
  if (!fs.existsSync(dataDir)) {
@@ -20,16 +20,16 @@ https
20
20
  if (response.statusCode === 200) {
21
21
  response.pipe(file);
22
22
 
23
- file.on('finish', () => {
23
+ file.on("finish", () => {
24
24
  file.close();
25
25
 
26
26
  const _stats = fs.statSync(OUTPUT_PATH);
27
27
  });
28
28
 
29
- file.on('error', (_err) => {
29
+ file.on("error", (_err) => {
30
30
  fs.unlink(OUTPUT_PATH, () => {}); // Delete the file on error
31
31
  });
32
32
  } else {
33
33
  }
34
34
  })
35
- .on('error', (_err) => {});
35
+ .on("error", (_err) => {});