better-auth-studio 1.1.2-beta.2 → 1.1.2-beta.21

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 (109) hide show
  1. package/README.md +48 -78
  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 +116 -115
  32. package/dist/core/handler.js.map +1 -1
  33. package/dist/data.d.ts +2 -2
  34. package/dist/data.js +60 -60
  35. package/dist/geo-service.js +78 -78
  36. package/dist/get-tsconfig-info.js +4 -4
  37. package/dist/index.d.ts +8 -8
  38. package/dist/index.js +6 -6
  39. package/dist/providers/events/helpers.d.ts +2 -2
  40. package/dist/providers/events/helpers.d.ts.map +1 -1
  41. package/dist/providers/events/helpers.js +178 -154
  42. package/dist/providers/events/helpers.js.map +1 -1
  43. package/dist/public/assets/{main-BDJUrMKx.js → main-BeCk6LUx.js} +133 -133
  44. package/dist/public/assets/main-w2bJSKlF.css +1 -0
  45. package/dist/public/index.html +2 -2
  46. package/dist/routes/api-router.d.ts +3 -1
  47. package/dist/routes/api-router.d.ts.map +1 -1
  48. package/dist/routes/api-router.js +3 -3
  49. package/dist/routes/api-router.js.map +1 -1
  50. package/dist/routes.d.ts +6 -4
  51. package/dist/routes.d.ts.map +1 -1
  52. package/dist/routes.js +1333 -1277
  53. package/dist/routes.js.map +1 -1
  54. package/dist/studio.d.ts +3 -3
  55. package/dist/studio.d.ts.map +1 -1
  56. package/dist/studio.js +64 -65
  57. package/dist/studio.js.map +1 -1
  58. package/dist/types/events.d.ts +8 -7
  59. package/dist/types/events.d.ts.map +1 -1
  60. package/dist/types/events.js +165 -165
  61. package/dist/types/events.js.map +1 -1
  62. package/dist/types/handler.d.ts +14 -4
  63. package/dist/types/handler.d.ts.map +1 -1
  64. package/dist/types/handler.js.map +1 -1
  65. package/dist/utils/auth-callbacks-injector.d.ts +2 -2
  66. package/dist/utils/auth-callbacks-injector.js +27 -27
  67. package/dist/utils/auth-callbacks-wrapper.d.ts +3 -3
  68. package/dist/utils/auth-callbacks-wrapper.js +117 -107
  69. package/dist/utils/database-detection.d.ts +1 -1
  70. package/dist/utils/database-detection.js +44 -44
  71. package/dist/utils/database-hook-injector.d.ts +3 -3
  72. package/dist/utils/database-hook-injector.js +135 -131
  73. package/dist/utils/email-otp-hooks-injector.d.ts +28 -12
  74. package/dist/utils/email-otp-hooks-injector.js +104 -97
  75. package/dist/utils/event-ingestion.d.ts +5 -5
  76. package/dist/utils/event-ingestion.d.ts.map +1 -1
  77. package/dist/utils/event-ingestion.js +32 -12
  78. package/dist/utils/event-ingestion.js.map +1 -1
  79. package/dist/utils/hook-injector.d.ts +2 -2
  80. package/dist/utils/hook-injector.js +199 -199
  81. package/dist/utils/hook-injector.js.map +1 -1
  82. package/dist/utils/html-injector.d.ts +11 -2
  83. package/dist/utils/html-injector.d.ts.map +1 -1
  84. package/dist/utils/html-injector.js +40 -39
  85. package/dist/utils/html-injector.js.map +1 -1
  86. package/dist/utils/org-hooks-injector.d.ts +3 -3
  87. package/dist/utils/org-hooks-injector.js +63 -63
  88. package/dist/utils/org-hooks-wrapper.d.ts +41 -35
  89. package/dist/utils/org-hooks-wrapper.js +778 -658
  90. package/dist/utils/organization-hooks-wrapper.d.ts +23 -17
  91. package/dist/utils/organization-hooks-wrapper.js +325 -277
  92. package/dist/utils/package-json.js +11 -11
  93. package/dist/utils/paths.js +1 -1
  94. package/dist/utils/server-init.d.ts +1 -1
  95. package/dist/utils/server-init.js +25 -25
  96. package/dist/utils/session.d.ts +0 -1
  97. package/dist/utils/session.d.ts.map +1 -1
  98. package/dist/utils/session.js +19 -12
  99. package/dist/utils/session.js.map +1 -1
  100. package/dist/utils.js +24 -24
  101. package/package.json +56 -47
  102. package/public/assets/{main-BDJUrMKx.js → main-BeCk6LUx.js} +133 -133
  103. package/public/assets/main-w2bJSKlF.css +1 -0
  104. package/public/index.html +2 -2
  105. package/scripts/download-geolite2.js +8 -8
  106. package/scripts/generate-default-db.js +324 -324
  107. package/scripts/postinstall.js +25 -25
  108. package/dist/public/assets/main-CBA9bZ-w.css +0 -1
  109. package/public/assets/main-CBA9bZ-w.css +0 -1
@@ -1,16 +1,16 @@
1
- import { randomBytes } from 'node:crypto';
2
- import { existsSync } from 'node:fs';
3
- import { dirname, join, parse, resolve } from 'node:path';
1
+ import { randomBytes } from "node:crypto";
2
+ import { existsSync } from "node:fs";
3
+ import { dirname, join, parse, resolve } from "node:path";
4
4
  // @ts-expect-error - No types available
5
- import babelPresetReact from '@babel/preset-react';
5
+ import babelPresetReact from "@babel/preset-react";
6
6
  // @ts-expect-error - No types available
7
- import babelPresetTypeScript from '@babel/preset-typescript';
7
+ import babelPresetTypeScript from "@babel/preset-typescript";
8
8
  // @ts-expect-error - No types available for current moduleResolution and bundler mode
9
- import { hex } from '@better-auth/utils/hex';
10
- import { scryptAsync } from '@noble/hashes/scrypt.js';
11
- import { createJiti } from 'jiti';
12
- import { getPathAliases } from './config.js';
13
- import { possibleConfigFiles } from './utils.js';
9
+ import { hex } from "@better-auth/utils/hex";
10
+ import { scryptAsync } from "@noble/hashes/scrypt.js";
11
+ import { createJiti } from "jiti";
12
+ import { getPathAliases } from "./config.js";
13
+ import { possibleConfigFiles } from "./utils.js";
14
14
  /**
15
15
  * Find tsconfig.json by searching upwards from a starting directory
16
16
  */
@@ -18,7 +18,7 @@ function findTsconfigPath(startDir) {
18
18
  let currentDir = resolve(startDir);
19
19
  const root = parse(currentDir).root;
20
20
  while (currentDir !== root) {
21
- const tsconfigPath = join(currentDir, 'tsconfig.json');
21
+ const tsconfigPath = join(currentDir, "tsconfig.json");
22
22
  if (existsSync(tsconfigPath)) {
23
23
  return currentDir;
24
24
  }
@@ -37,7 +37,7 @@ export async function getAuthAdapter(configPath) {
37
37
  let authModule;
38
38
  try {
39
39
  let importPath = authConfigPath;
40
- if (!authConfigPath.startsWith('/')) {
40
+ if (!authConfigPath.startsWith("/")) {
41
41
  importPath = join(process.cwd(), authConfigPath);
42
42
  }
43
43
  const configDir = dirname(resolve(importPath));
@@ -59,11 +59,11 @@ export async function getAuthAdapter(configPath) {
59
59
  allExtensions: true,
60
60
  },
61
61
  ],
62
- [babelPresetReact, { runtime: 'automatic' }],
62
+ [babelPresetReact, { runtime: "automatic" }],
63
63
  ],
64
64
  },
65
65
  },
66
- extensions: ['.ts', '.js', '.tsx', '.jsx', '.mjs', '.cjs'],
66
+ extensions: [".ts", ".js", ".tsx", ".jsx", ".mjs", ".cjs"],
67
67
  });
68
68
  authModule = await jitiInstance.import(importPath);
69
69
  }
@@ -91,7 +91,7 @@ export async function getAuthAdapter(configPath) {
91
91
  authAdapter = {
92
92
  createUser: async (data) => {
93
93
  const user = await adapter.create({
94
- model: 'user',
94
+ model: "user",
95
95
  data: {
96
96
  createdAt: new Date(),
97
97
  updatedAt: new Date(),
@@ -106,10 +106,10 @@ export async function getAuthAdapter(configPath) {
106
106
  if (data.password) {
107
107
  try {
108
108
  await adapter.create({
109
- model: 'account',
109
+ model: "account",
110
110
  data: {
111
111
  userId: user.id,
112
- providerId: 'credential',
112
+ providerId: "credential",
113
113
  accountId: user.id,
114
114
  password: hashedPassword,
115
115
  createdAt: new Date(),
@@ -123,7 +123,7 @@ export async function getAuthAdapter(configPath) {
123
123
  },
124
124
  createSession: async (data) => {
125
125
  return await adapter.create({
126
- model: 'session',
126
+ model: "session",
127
127
  data: {
128
128
  createdAt: new Date(),
129
129
  updatedAt: new Date(),
@@ -133,7 +133,7 @@ export async function getAuthAdapter(configPath) {
133
133
  },
134
134
  createAccount: async (data) => {
135
135
  return await adapter.create({
136
- model: 'account',
136
+ model: "account",
137
137
  data: {
138
138
  createdAt: new Date(),
139
139
  updatedAt: new Date(),
@@ -143,7 +143,7 @@ export async function getAuthAdapter(configPath) {
143
143
  },
144
144
  createVerification: async (data) => {
145
145
  return await adapter.create({
146
- model: 'verification',
146
+ model: "verification",
147
147
  data: {
148
148
  createdAt: new Date(),
149
149
  updatedAt: new Date(),
@@ -153,7 +153,7 @@ export async function getAuthAdapter(configPath) {
153
153
  },
154
154
  createOrganization: async (data) => {
155
155
  return await adapter.create({
156
- model: 'organization',
156
+ model: "organization",
157
157
  data: {
158
158
  createdAt: new Date(),
159
159
  updatedAt: new Date(),
@@ -163,11 +163,11 @@ export async function getAuthAdapter(configPath) {
163
163
  },
164
164
  getUsers: async () => {
165
165
  try {
166
- if (typeof adapter.findMany === 'function') {
167
- const users = await adapter.findMany({ model: 'user' });
166
+ if (typeof adapter.findMany === "function") {
167
+ const users = await adapter.findMany({ model: "user" });
168
168
  return users || [];
169
169
  }
170
- if (typeof adapter.getUsers === 'function') {
170
+ if (typeof adapter.getUsers === "function") {
171
171
  const users = await adapter.getUsers();
172
172
  return users || [];
173
173
  }
@@ -179,11 +179,11 @@ export async function getAuthAdapter(configPath) {
179
179
  },
180
180
  getSessions: async () => {
181
181
  try {
182
- if (typeof adapter.findMany === 'function') {
183
- const sessions = await adapter.findMany({ model: 'session' });
182
+ if (typeof adapter.findMany === "function") {
183
+ const sessions = await adapter.findMany({ model: "session" });
184
184
  return sessions || [];
185
185
  }
186
- if (typeof adapter.getSessions === 'function') {
186
+ if (typeof adapter.getSessions === "function") {
187
187
  const sessions = await adapter.getSessions();
188
188
  return sessions || [];
189
189
  }
@@ -195,7 +195,7 @@ export async function getAuthAdapter(configPath) {
195
195
  },
196
196
  findMany: async (options) => {
197
197
  try {
198
- if (typeof adapter.findMany === 'function') {
198
+ if (typeof adapter.findMany === "function") {
199
199
  return await adapter.findMany(options);
200
200
  }
201
201
  return [];
@@ -239,7 +239,7 @@ async function hashPassword(password) {
239
239
  dkLen: 64,
240
240
  };
241
241
  const salt = hex.encode(randomBytes(16));
242
- const key = await scryptAsync(password.normalize('NFKC'), salt, {
242
+ const key = await scryptAsync(password.normalize("NFKC"), salt, {
243
243
  N: config.N,
244
244
  p: config.p,
245
245
  r: config.r,
@@ -272,9 +272,9 @@ export async function createMockUser(adapter, index, role) {
272
272
  const _countryIPRanges = [
273
273
  // United States
274
274
  {
275
- country: 'United States',
276
- city: 'New York',
277
- region: 'NY',
275
+ country: "United States",
276
+ city: "New York",
277
+ region: "NY",
278
278
  ranges: [
279
279
  { min: 8, max: 8 },
280
280
  { min: 24, max: 24 },
@@ -284,9 +284,9 @@ const _countryIPRanges = [
284
284
  },
285
285
  // United Kingdom
286
286
  {
287
- country: 'United Kingdom',
288
- city: 'London',
289
- region: 'England',
287
+ country: "United Kingdom",
288
+ city: "London",
289
+ region: "England",
290
290
  ranges: [
291
291
  { min: 51, max: 51 },
292
292
  { min: 77, max: 77 },
@@ -296,9 +296,9 @@ const _countryIPRanges = [
296
296
  },
297
297
  // Germany
298
298
  {
299
- country: 'Germany',
300
- city: 'Berlin',
301
- region: 'Berlin',
299
+ country: "Germany",
300
+ city: "Berlin",
301
+ region: "Berlin",
302
302
  ranges: [
303
303
  { min: 46, max: 46 },
304
304
  { min: 78, max: 78 },
@@ -308,9 +308,9 @@ const _countryIPRanges = [
308
308
  },
309
309
  // Japan
310
310
  {
311
- country: 'Japan',
312
- city: 'Tokyo',
313
- region: 'Tokyo',
311
+ country: "Japan",
312
+ city: "Tokyo",
313
+ region: "Tokyo",
314
314
  ranges: [
315
315
  { min: 126, max: 126 },
316
316
  { min: 157, max: 157 },
@@ -320,9 +320,9 @@ const _countryIPRanges = [
320
320
  },
321
321
  // Australia
322
322
  {
323
- country: 'Australia',
324
- city: 'Sydney',
325
- region: 'NSW',
323
+ country: "Australia",
324
+ city: "Sydney",
325
+ region: "NSW",
326
326
  ranges: [
327
327
  { min: 101, max: 101 },
328
328
  { min: 118, max: 118 },
@@ -332,9 +332,9 @@ const _countryIPRanges = [
332
332
  },
333
333
  // Canada
334
334
  {
335
- country: 'Canada',
336
- city: 'Toronto',
337
- region: 'ON',
335
+ country: "Canada",
336
+ city: "Toronto",
337
+ region: "ON",
338
338
  ranges: [
339
339
  { min: 24, max: 24 },
340
340
  { min: 70, max: 70 },
@@ -344,9 +344,9 @@ const _countryIPRanges = [
344
344
  },
345
345
  // France
346
346
  {
347
- country: 'France',
348
- city: 'Paris',
349
- region: 'Île-de-France',
347
+ country: "France",
348
+ city: "Paris",
349
+ region: "Île-de-France",
350
350
  ranges: [
351
351
  { min: 37, max: 37 },
352
352
  { min: 51, max: 51 },
@@ -356,9 +356,9 @@ const _countryIPRanges = [
356
356
  },
357
357
  // Brazil
358
358
  {
359
- country: 'Brazil',
360
- city: 'São Paulo',
361
- region: 'SP',
359
+ country: "Brazil",
360
+ city: "São Paulo",
361
+ region: "SP",
362
362
  ranges: [
363
363
  { min: 177, max: 177 },
364
364
  { min: 179, max: 179 },
@@ -368,9 +368,9 @@ const _countryIPRanges = [
368
368
  },
369
369
  // India
370
370
  {
371
- country: 'India',
372
- city: 'Mumbai',
373
- region: 'Maharashtra',
371
+ country: "India",
372
+ city: "Mumbai",
373
+ region: "Maharashtra",
374
374
  ranges: [
375
375
  { min: 103, max: 103 },
376
376
  { min: 117, max: 117 },
@@ -380,9 +380,9 @@ const _countryIPRanges = [
380
380
  },
381
381
  // South Korea
382
382
  {
383
- country: 'South Korea',
384
- city: 'Seoul',
385
- region: 'Seoul',
383
+ country: "South Korea",
384
+ city: "Seoul",
385
+ region: "Seoul",
386
386
  ranges: [
387
387
  { min: 112, max: 112 },
388
388
  { min: 114, max: 114 },
@@ -394,27 +394,27 @@ const _countryIPRanges = [
394
394
  function generateRandomIP() {
395
395
  // Generate a random IP address from common ranges
396
396
  const commonRanges = [
397
- { min: '8.0.0.0', max: '8.255.255.255' }, // US
398
- { min: '24.0.0.0', max: '24.255.255.255' }, // US
399
- { min: '2.0.0.0', max: '2.255.255.255' }, // UK
400
- { min: '5.0.0.0', max: '5.255.255.255' }, // UK
401
- { min: '46.0.0.0', max: '46.255.255.255' }, // Germany
402
- { min: '62.0.0.0', max: '62.255.255.255' }, // Germany
403
- { min: '37.0.0.0', max: '37.255.255.255' }, // France
404
- { min: '126.0.0.0', max: '126.255.255.255' }, // Japan
405
- { min: '210.0.0.0', max: '210.255.255.255' }, // Japan
406
- { min: '1.0.0.0', max: '1.255.255.255' }, // Australia
407
- { min: '27.0.0.0', max: '27.255.255.255' }, // Australia
408
- { min: '177.0.0.0', max: '177.255.255.255' }, // Brazil
409
- { min: '201.0.0.0', max: '201.255.255.255' }, // Brazil
410
- { min: '103.0.0.0', max: '103.255.255.255' }, // India
411
- { min: '117.0.0.0', max: '117.255.255.255' }, // India
397
+ { min: "8.0.0.0", max: "8.255.255.255" }, // US
398
+ { min: "24.0.0.0", max: "24.255.255.255" }, // US
399
+ { min: "2.0.0.0", max: "2.255.255.255" }, // UK
400
+ { min: "5.0.0.0", max: "5.255.255.255" }, // UK
401
+ { min: "46.0.0.0", max: "46.255.255.255" }, // Germany
402
+ { min: "62.0.0.0", max: "62.255.255.255" }, // Germany
403
+ { min: "37.0.0.0", max: "37.255.255.255" }, // France
404
+ { min: "126.0.0.0", max: "126.255.255.255" }, // Japan
405
+ { min: "210.0.0.0", max: "210.255.255.255" }, // Japan
406
+ { min: "1.0.0.0", max: "1.255.255.255" }, // Australia
407
+ { min: "27.0.0.0", max: "27.255.255.255" }, // Australia
408
+ { min: "177.0.0.0", max: "177.255.255.255" }, // Brazil
409
+ { min: "201.0.0.0", max: "201.255.255.255" }, // Brazil
410
+ { min: "103.0.0.0", max: "103.255.255.255" }, // India
411
+ { min: "117.0.0.0", max: "117.255.255.255" }, // India
412
412
  ];
413
413
  const range = commonRanges[Math.floor(Math.random() * commonRanges.length)];
414
414
  const secondOctet = Math.floor(Math.random() * 256);
415
415
  const thirdOctet = Math.floor(Math.random() * 256);
416
416
  const fourthOctet = Math.floor(Math.random() * 255) + 1;
417
- return `${range.min.split('.')[0]}.${secondOctet}.${thirdOctet}.${fourthOctet}`;
417
+ return `${range.min.split(".")[0]}.${secondOctet}.${thirdOctet}.${fourthOctet}`;
418
418
  }
419
419
  export async function createMockSession(adapter, userId, index) {
420
420
  // Generate a random IP address
@@ -436,38 +436,38 @@ export async function createMockSession(adapter, userId, index) {
436
436
  export async function createMockAccount(adapter, userId, index, providerId) {
437
437
  // List of common OAuth providers
438
438
  const providers = [
439
- 'github',
440
- 'google',
441
- 'discord',
442
- 'facebook',
443
- 'twitter',
444
- 'linkedin',
445
- 'apple',
446
- 'microsoft',
447
- 'gitlab',
448
- 'bitbucket',
449
- 'spotify',
450
- 'twitch',
451
- 'reddit',
452
- 'slack',
453
- 'notion',
454
- 'tiktok',
455
- 'zoom',
439
+ "github",
440
+ "google",
441
+ "discord",
442
+ "facebook",
443
+ "twitter",
444
+ "linkedin",
445
+ "apple",
446
+ "microsoft",
447
+ "gitlab",
448
+ "bitbucket",
449
+ "spotify",
450
+ "twitch",
451
+ "reddit",
452
+ "slack",
453
+ "notion",
454
+ "tiktok",
455
+ "zoom",
456
456
  ];
457
- const selectedProvider = providerId && providerId !== 'random'
457
+ const selectedProvider = providerId && providerId !== "random"
458
458
  ? providerId
459
459
  : providers[Math.floor(Math.random() * providers.length)];
460
460
  const accountData = {
461
461
  userId: userId,
462
- type: 'oauth',
462
+ type: "oauth",
463
463
  provider: selectedProvider,
464
464
  providerId: selectedProvider,
465
465
  accountId: `${selectedProvider}_${index}_${Date.now()}`,
466
466
  refresh_token: `refresh_token_${index}_${Date.now()}`,
467
467
  access_token: `access_token_${index}_${Date.now()}`,
468
468
  expires_at: Math.floor(Date.now() / 1000) + 3600,
469
- token_type: 'bearer',
470
- scope: 'read:user',
469
+ token_type: "bearer",
470
+ scope: "read:user",
471
471
  id_token: `id_token_${index}_${Date.now()}`,
472
472
  session_state: `session_state_${index}_${Date.now()}`,
473
473
  createdAt: new Date(),
@@ -1,16 +1,16 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
2
- import { join } from 'path';
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
+ import { join } from "path";
3
3
  export async function initCommand(options) {
4
- console.log('🚀 Initializing Better Auth Studio...\n');
4
+ console.log("🚀 Initializing Better Auth Studio...\n");
5
5
  const framework = detectFramework();
6
- console.log('🔍 Detected framework:', framework);
6
+ console.log("🔍 Detected framework:", framework);
7
7
  const configPath = await createStudioConfig(framework);
8
- console.log('✅ Created config:', configPath);
9
- const basePath = '/api/studio';
10
- if (framework === 'nextjs') {
8
+ console.log("✅ Created config:", configPath);
9
+ const basePath = "/api/studio";
10
+ if (framework === "nextjs") {
11
11
  await setupNextJS(basePath, options?.apiDir);
12
12
  }
13
- else if (framework === 'sveltekit') {
13
+ else if (framework === "sveltekit") {
14
14
  await setupSvelteKit(basePath);
15
15
  }
16
16
  else {
@@ -18,17 +18,17 @@ export async function initCommand(options) {
18
18
  }
19
19
  }
20
20
  async function createStudioConfig(framework) {
21
- const configPath = 'studio.config.ts';
21
+ const configPath = "studio.config.ts";
22
22
  if (existsSync(configPath)) {
23
- console.log('⚠️ studio.config.ts already exists, skipping...');
23
+ console.log("⚠️ studio.config.ts already exists, skipping...");
24
24
  return configPath;
25
25
  }
26
- let authImportPath = './src/auth';
27
- if (framework === 'nextjs') {
28
- authImportPath = '@/lib/auth';
26
+ let authImportPath = "./src/auth";
27
+ if (framework === "nextjs") {
28
+ authImportPath = "@/lib/auth";
29
29
  }
30
- else if (framework === 'sveltekit') {
31
- authImportPath = '$lib/auth';
30
+ else if (framework === "sveltekit") {
31
+ authImportPath = "$lib/auth";
32
32
  }
33
33
  const configContent = `import type { StudioConfig } from 'better-auth-studio';
34
34
  import { auth } from '${authImportPath}';
@@ -44,20 +44,20 @@ const config: StudioConfig = {
44
44
 
45
45
  export default config;
46
46
  `;
47
- writeFileSync(configPath, configContent, 'utf-8');
47
+ writeFileSync(configPath, configContent, "utf-8");
48
48
  return configPath;
49
49
  }
50
50
  function detectNextJSAppDir() {
51
- if (existsSync(join(process.cwd(), 'src', 'app'))) {
52
- return 'src/app';
51
+ if (existsSync(join(process.cwd(), "src", "app"))) {
52
+ return "src/app";
53
53
  }
54
- if (existsSync(join(process.cwd(), 'app'))) {
55
- return 'app';
54
+ if (existsSync(join(process.cwd(), "app"))) {
55
+ return "app";
56
56
  }
57
- return 'app';
57
+ return "app";
58
58
  }
59
59
  async function setupNextJS(basePath, customApiDir) {
60
- const segments = basePath.split('/').filter(Boolean);
60
+ const segments = basePath.split("/").filter(Boolean);
61
61
  let appDir;
62
62
  if (customApiDir) {
63
63
  appDir = customApiDir;
@@ -67,16 +67,16 @@ async function setupNextJS(basePath, customApiDir) {
67
67
  appDir = detectNextJSAppDir();
68
68
  console.log(`📂 Auto-detected app directory: ${appDir}`);
69
69
  }
70
- const routeDir = join(process.cwd(), appDir, ...segments, '[[...path]]');
71
- const routeFile = join(routeDir, 'route.ts');
70
+ const routeDir = join(process.cwd(), appDir, ...segments, "[[...path]]");
71
+ const routeFile = join(routeDir, "route.ts");
72
72
  if (existsSync(routeFile)) {
73
- console.log('⚠️ Route file already exists:', routeFile);
73
+ console.log("⚠️ Route file already exists:", routeFile);
74
74
  }
75
75
  else {
76
76
  mkdirSync(routeDir, { recursive: true });
77
77
  const code = generateNextJSRoute();
78
- writeFileSync(routeFile, code, 'utf-8');
79
- console.log('✅ Generated route file:', routeFile);
78
+ writeFileSync(routeFile, code, "utf-8");
79
+ console.log("✅ Generated route file:", routeFile);
80
80
  }
81
81
  const relativePath = `${appDir}${basePath}/[[...path]]/route.ts`;
82
82
  console.log(`
@@ -116,17 +116,17 @@ export {
116
116
  `;
117
117
  }
118
118
  async function setupSvelteKit(basePath) {
119
- const segments = basePath.split('/').filter(Boolean);
120
- const routeDir = join(process.cwd(), 'src', 'routes', ...segments, '[...path]');
121
- const routeFile = join(routeDir, '+server.ts');
119
+ const segments = basePath.split("/").filter(Boolean);
120
+ const routeDir = join(process.cwd(), "src", "routes", ...segments, "[...path]");
121
+ const routeFile = join(routeDir, "+server.ts");
122
122
  if (existsSync(routeFile)) {
123
- console.log('⚠️ Route file already exists:', routeFile);
123
+ console.log("⚠️ Route file already exists:", routeFile);
124
124
  }
125
125
  else {
126
126
  mkdirSync(routeDir, { recursive: true });
127
127
  const code = generateSvelteKitRoute();
128
- writeFileSync(routeFile, code, 'utf-8');
129
- console.log('✅ Generated route file:', routeFile);
128
+ writeFileSync(routeFile, code, "utf-8");
129
+ console.log("✅ Generated route file:", routeFile);
130
130
  }
131
131
  const relativePath = `src/routes${basePath}/[...path]/+server.ts`;
132
132
  console.log(`
@@ -178,7 +178,7 @@ export async function PATCH(event) {
178
178
  `;
179
179
  }
180
180
  function showManualInstructions(framework, basePath) {
181
- const frameworkName = framework === 'express' ? 'Express' : 'your app';
181
+ const frameworkName = framework === "express" ? "Express" : "your app";
182
182
  console.log(`
183
183
  ╔═══════════════════════════════════════════════════════════════╗
184
184
  ║ 📝 Manual Setup Required for ${frameworkName.padEnd(10)} ║
@@ -205,51 +205,51 @@ app.use('${basePath}', betterAuthStudio(studioConfig));
205
205
  }
206
206
  function detectFramework() {
207
207
  // Check for SvelteKit
208
- if (existsSync('svelte.config.js') ||
209
- existsSync('svelte.config.ts') ||
210
- existsSync('src/routes') ||
211
- existsSync('src/hooks.server.ts')) {
208
+ if (existsSync("svelte.config.js") ||
209
+ existsSync("svelte.config.ts") ||
210
+ existsSync("src/routes") ||
211
+ existsSync("src/hooks.server.ts")) {
212
212
  try {
213
- const pkgPath = join(process.cwd(), 'package.json');
213
+ const pkgPath = join(process.cwd(), "package.json");
214
214
  if (existsSync(pkgPath)) {
215
- const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
216
- if (pkg.dependencies?.['@sveltejs/kit'] || pkg.devDependencies?.['@sveltejs/kit']) {
217
- return 'sveltekit';
215
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
216
+ if (pkg.dependencies?.["@sveltejs/kit"] || pkg.devDependencies?.["@sveltejs/kit"]) {
217
+ return "sveltekit";
218
218
  }
219
219
  }
220
220
  }
221
221
  catch { }
222
222
  }
223
223
  // Check for Next.js
224
- if (existsSync('next.config.js') ||
225
- existsSync('next.config.mjs') ||
226
- existsSync('next.config.ts')) {
227
- return 'nextjs';
224
+ if (existsSync("next.config.js") ||
225
+ existsSync("next.config.mjs") ||
226
+ existsSync("next.config.ts")) {
227
+ return "nextjs";
228
228
  }
229
229
  // Check for Express
230
- if (existsSync('src/index.ts') || existsSync('src/app.ts') || existsSync('src/server.ts')) {
231
- return 'express';
230
+ if (existsSync("src/index.ts") || existsSync("src/app.ts") || existsSync("src/server.ts")) {
231
+ return "express";
232
232
  }
233
- if (existsSync('app.js') || existsSync('server.js') || existsSync('index.js')) {
234
- return 'express';
233
+ if (existsSync("app.js") || existsSync("server.js") || existsSync("index.js")) {
234
+ return "express";
235
235
  }
236
236
  // Check package.json for framework dependencies
237
237
  try {
238
- const pkgPath = join(process.cwd(), 'package.json');
238
+ const pkgPath = join(process.cwd(), "package.json");
239
239
  if (existsSync(pkgPath)) {
240
- const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
241
- if (pkg.dependencies?.['@sveltejs/kit'] || pkg.devDependencies?.['@sveltejs/kit']) {
242
- return 'sveltekit';
240
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
241
+ if (pkg.dependencies?.["@sveltejs/kit"] || pkg.devDependencies?.["@sveltejs/kit"]) {
242
+ return "sveltekit";
243
243
  }
244
244
  if (pkg.dependencies?.express || pkg.devDependencies?.express) {
245
- return 'express';
245
+ return "express";
246
246
  }
247
247
  if (pkg.dependencies?.next || pkg.devDependencies?.next) {
248
- return 'nextjs';
248
+ return "nextjs";
249
249
  }
250
250
  }
251
251
  }
252
252
  catch { }
253
- return 'unknown';
253
+ return "unknown";
254
254
  }
255
255
  //# sourceMappingURL=init.js.map