better-auth-studio 1.0.59-beta.5 → 1.0.59-beta.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAOA,OAAO,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;AAa9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA8D9C,wBAAsB,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAyLhG;AAwBD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAilLR"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;AAS9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA8D9C,wBAAsB,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAyLhG;AAwBD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAqlLR"}
package/dist/routes.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createHmac, randomBytes } from 'node:crypto';
2
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { existsSync, readFileSync, writeFileSync, } from 'node:fs';
3
3
  import { dirname, join } from 'node:path';
4
4
  import { fileURLToPath, pathToFileURL } from 'node:url';
5
5
  // @ts-expect-error
@@ -7,10 +7,6 @@ import { hex } from '@better-auth/utils/hex';
7
7
  import { scryptAsync } from '@noble/hashes/scrypt.js';
8
8
  import { Router } from 'express';
9
9
  import { createJiti } from 'jiti';
10
- import { execSync } from 'node:child_process';
11
- import { writeFileSync as writeFile, unlinkSync, readFileSync as readFile } from 'node:fs';
12
- import { tmpdir } from 'node:os';
13
- import { join as pathJoin } from 'node:path';
14
10
  import { createMockAccount, createMockSession, createMockUser, createMockVerification, getAuthAdapter, } from './auth-adapter.js';
15
11
  import { getAuthData } from './data.js';
16
12
  import { initializeGeoService, resolveIPLocation, setGeoDbPath } from './geo-service.js';
@@ -4380,6 +4376,29 @@ ${fields}
4380
4376
  })
4381
4377
  .join(',\n')
4382
4378
  : '';
4379
+ const preserveIndentation = (code, baseIndent) => {
4380
+ if (!code.trim())
4381
+ return '';
4382
+ const lines = code.split('\n');
4383
+ const nonEmptyLines = lines.filter(line => line.trim());
4384
+ if (nonEmptyLines.length === 0)
4385
+ return '';
4386
+ const minIndent = Math.min(...nonEmptyLines.map(line => {
4387
+ const match = line.match(/^(\s*)/);
4388
+ return match ? match[1].length : 0;
4389
+ }));
4390
+ return lines
4391
+ .map(line => {
4392
+ if (!line.trim())
4393
+ return '';
4394
+ const currentIndent = line.match(/^(\s*)/)?.[1] || '';
4395
+ const relativeIndent = Math.max(0, currentIndent.length - minIndent);
4396
+ const content = line.trim();
4397
+ return baseIndent + ' '.repeat(relativeIndent) + content;
4398
+ })
4399
+ .filter(Boolean)
4400
+ .join('\n');
4401
+ };
4383
4402
  const beforeHooks = hooks
4384
4403
  .filter((h) => h.timing === 'before')
4385
4404
  .map((hook) => {
@@ -4399,10 +4418,11 @@ ${fields}
4399
4418
  else {
4400
4419
  matcher = `(ctx) => true`;
4401
4420
  }
4421
+ const formattedHookLogic = preserveIndentation(hook.hookLogic || '// Hook logic here', ' ');
4402
4422
  return ` {
4403
4423
  matcher: ${matcher},
4404
4424
  handler: createAuthMiddleware(async (ctx) => {
4405
- ${hook.hookLogic || '// Hook logic here'}
4425
+ ${formattedHookLogic}
4406
4426
  }),
4407
4427
  }`;
4408
4428
  });
@@ -4425,19 +4445,21 @@ ${fields}
4425
4445
  else {
4426
4446
  matcher = `(ctx) => true`;
4427
4447
  }
4448
+ const formattedHookLogic = preserveIndentation(hook.hookLogic || '// Hook logic here', ' ');
4428
4449
  return ` {
4429
4450
  matcher: ${matcher},
4430
4451
  handler: createAuthMiddleware(async (ctx) => {
4431
- ${hook.hookLogic || '// Hook logic here'}
4452
+ ${formattedHookLogic}
4432
4453
  }),
4433
4454
  }`;
4434
4455
  });
4435
4456
  const middlewareCode = middleware
4436
4457
  .map((mw) => {
4458
+ const formattedMiddlewareLogic = preserveIndentation(mw.middlewareLogic || '// Middleware logic here', ' ');
4437
4459
  return ` {
4438
4460
  path: "${mw.path}",
4439
4461
  middleware: createAuthMiddleware(async (ctx) => {
4440
- ${mw.middlewareLogic || '// Middleware logic here'}
4462
+ ${formattedMiddlewareLogic}
4441
4463
  }),
4442
4464
  }`;
4443
4465
  })
@@ -4449,20 +4471,8 @@ ${fields}
4449
4471
  const sanitizedName = endpointName.replace(/[^a-zA-Z0-9]/g, '');
4450
4472
  const endpointPath = endpoint.path?.trim() || `/${camelCaseName}/${sanitizedName}`;
4451
4473
  const handlerLogic = endpoint.handlerLogic ||
4452
- '// Endpoint handler logic here\n return ctx.json({ success: true });';
4453
- const formattedHandlerLogic = handlerLogic
4454
- .split('\n')
4455
- .map((line) => {
4456
- const trimmed = line.trim();
4457
- if (!trimmed)
4458
- return '';
4459
- if (!line.startsWith(' ')) {
4460
- return ' ' + trimmed;
4461
- }
4462
- return line;
4463
- })
4464
- .filter(Boolean)
4465
- .join('\n');
4474
+ '// Endpoint handler logic here\nreturn ctx.json({ success: true });';
4475
+ const formattedHandlerLogic = preserveIndentation(handlerLogic, ' ');
4466
4476
  return ` ${sanitizedName}: createAuthEndpoint(
4467
4477
  "${endpointPath}",
4468
4478
  {
@@ -4511,33 +4521,6 @@ ${formattedHandlerLogic}
4511
4521
  .replace(/\n{3,}/g, '\n\n')
4512
4522
  .trim();
4513
4523
  };
4514
- const formatCode = (code) => {
4515
- try {
4516
- const tempFile = pathJoin(tmpdir(), `biome-format-${Date.now()}-${Math.random().toString(36).substring(7)}.ts`);
4517
- writeFile(tempFile, code, 'utf-8');
4518
- try {
4519
- execSync(`npx @biomejs/biome format --write ${tempFile}`, {
4520
- stdio: 'pipe',
4521
- cwd: process.cwd(),
4522
- });
4523
- const formatted = readFile(tempFile, 'utf-8');
4524
- unlinkSync(tempFile);
4525
- return formatted;
4526
- }
4527
- catch (formatError) {
4528
- try {
4529
- unlinkSync(tempFile);
4530
- }
4531
- catch {
4532
- // Ignore cleanup errors
4533
- }
4534
- return code;
4535
- }
4536
- }
4537
- catch (error) {
4538
- return code;
4539
- }
4540
- };
4541
4524
  const pluginParts = [];
4542
4525
  if (schemaCode) {
4543
4526
  pluginParts.push(` schema: {\n${schemaCode}\n }`);
@@ -4568,7 +4551,7 @@ ${formattedHandlerLogic}
4568
4551
  const serverPluginBody = pluginParts.length > 0
4569
4552
  ? ` id: "${camelCaseName}",\n${pluginParts.join(',\n')}`
4570
4553
  : ` id: "${camelCaseName}"`;
4571
- const serverPluginCode = formatCode(cleanCode(`import type { BetterAuthPlugin } from "@better-auth/core";
4554
+ const serverPluginCode = cleanCode(`import type { BetterAuthPlugin } from "@better-auth/core";
4572
4555
  ${imports.join('\n')}
4573
4556
 
4574
4557
  ${description ? `/**\n * ${description.replace(/\n/g, '\n * ')}\n */` : ''}
@@ -4577,7 +4560,7 @@ export const ${camelCaseName} = (options?: Record<string, any>) => {
4577
4560
  ${serverPluginBody}
4578
4561
  } satisfies BetterAuthPlugin;
4579
4562
  };
4580
- `));
4563
+ `);
4581
4564
  const pathMethods = endpoints.length > 0
4582
4565
  ? endpoints
4583
4566
  .map((endpoint) => {
@@ -4602,7 +4585,7 @@ ${serverPluginBody}
4602
4585
  const atomListenersCode = sessionAffectingPaths.length > 0
4603
4586
  ? `\n atomListeners: [\n${sessionAffectingPaths.join(',\n')}\n ],`
4604
4587
  : '';
4605
- const clientPluginCode = formatCode(cleanCode(`import type { BetterAuthClientPlugin } from "@better-auth/core";
4588
+ const clientPluginCode = cleanCode(`import type { BetterAuthClientPlugin } from "@better-auth/core";
4606
4589
  import type { ${camelCaseName} } from "..";
4607
4590
 
4608
4591
  export const ${camelCaseName}Client = () => {
@@ -4611,8 +4594,8 @@ export const ${camelCaseName}Client = () => {
4611
4594
  $InferServerPlugin: {} as ReturnType<typeof ${camelCaseName}>,${pathMethods ? `\n pathMethods: {\n${pathMethods}\n },` : ''}${atomListenersCode}
4612
4595
  } satisfies BetterAuthClientPlugin;
4613
4596
  };
4614
- `));
4615
- const serverSetupCode = formatCode(cleanCode(`import { betterAuth } from "@better-auth/core";
4597
+ `);
4598
+ const serverSetupCode = cleanCode(`import { betterAuth } from "@better-auth/core";
4616
4599
  import { ${camelCaseName} } from "./plugin/${camelCaseName}";
4617
4600
 
4618
4601
  export const auth = betterAuth({
@@ -4621,7 +4604,7 @@ export const auth = betterAuth({
4621
4604
  ${camelCaseName}(),
4622
4605
  ],
4623
4606
  });
4624
- `));
4607
+ `);
4625
4608
  const frameworkImportMap = {
4626
4609
  react: 'better-auth/react',
4627
4610
  svelte: 'better-auth/svelte',
@@ -4637,7 +4620,7 @@ export const auth = betterAuth({
4637
4620
  };
4638
4621
  const baseURL = baseURLMap[clientFramework] ||
4639
4622
  'process.env.NEXT_PUBLIC_BETTER_AUTH_URL || "http://localhost:3000"';
4640
- const clientSetupCode = formatCode(cleanCode(`import { createAuthClient } from "${frameworkImport}";
4623
+ const clientSetupCode = cleanCode(`import { createAuthClient } from "${frameworkImport}";
4641
4624
  import { ${camelCaseName}Client } from "./plugin/${camelCaseName}/client";
4642
4625
 
4643
4626
  export const authClient = createAuthClient({
@@ -4646,7 +4629,7 @@ export const authClient = createAuthClient({
4646
4629
  ${camelCaseName}Client(),
4647
4630
  ],
4648
4631
  });
4649
- `));
4632
+ `);
4650
4633
  return res.json({
4651
4634
  success: true,
4652
4635
  plugin: {