better-auth-studio 1.0.60-beta.2 → 1.0.61-beta.1

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":"AAeA,OAAO,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;AAS9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA+D9C,wBAAsB,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAqLhG;AAeD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CA0zLR"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAeA,OAAO,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;AAS9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA+D9C,wBAAsB,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAqLhG;AAeD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAg/LR"}
package/dist/routes.js CHANGED
@@ -5302,8 +5302,6 @@ export const authClient = createAuthClient({
5302
5302
  return res.status(404).json({ success: false, message: 'auth.ts not found' });
5303
5303
  }
5304
5304
  let fileContent = readFileSync(authPath, 'utf-8');
5305
- // Escape backticks and ${ for template literals
5306
- // First escape backslashes, then escape backticks and ${ to avoid double-escaping
5307
5305
  const escapedSubject = subject
5308
5306
  .replace(/\\/g, '\\\\')
5309
5307
  .replace(/`/g, '\\`')
@@ -5483,6 +5481,162 @@ export const authClient = createAuthClient({
5483
5481
  });
5484
5482
  }
5485
5483
  });
5484
+ router.get('/api/tools/check-resend-api-key', async (_req, res) => {
5485
+ try {
5486
+ const apiKey = process.env.RESEND_API_KEY;
5487
+ const hasApiKey = !!apiKey && apiKey.trim().length > 0;
5488
+ if (!hasApiKey) {
5489
+ return res.json({
5490
+ success: true,
5491
+ hasApiKey: false,
5492
+ });
5493
+ }
5494
+ const verifiedSenders = [];
5495
+ try {
5496
+ const { createRequire } = await import('node:module');
5497
+ const { resolve } = await import('node:path');
5498
+ const { existsSync } = await import('node:fs');
5499
+ const userRequire = createRequire(resolve(process.cwd(), 'package.json'));
5500
+ let Resend;
5501
+ try {
5502
+ const resendPath = userRequire.resolve('resend');
5503
+ const resendModule = await import(resendPath);
5504
+ Resend = resendModule.Resend || resendModule.default?.Resend || resendModule.default;
5505
+ }
5506
+ catch {
5507
+ const userNodeModules = resolve(process.cwd(), 'node_modules', 'resend');
5508
+ if (existsSync(userNodeModules)) {
5509
+ const resendModule = await import(resolve(userNodeModules, 'index.js'));
5510
+ Resend = resendModule.Resend || resendModule.default?.Resend || resendModule.default;
5511
+ }
5512
+ }
5513
+ if (Resend) {
5514
+ const resend = new Resend(apiKey);
5515
+ try {
5516
+ if (resend.domains && typeof resend.domains.list === 'function') {
5517
+ const domainsResult = await resend.domains.list();
5518
+ if (domainsResult && domainsResult.data && Array.isArray(domainsResult.data)) {
5519
+ domainsResult.data.forEach((domain) => {
5520
+ if (domain && domain.name && domain.status === 'verified') {
5521
+ verifiedSenders.push(`noreply@${domain.name}`);
5522
+ verifiedSenders.push(`hello@${domain.name}`);
5523
+ }
5524
+ });
5525
+ }
5526
+ }
5527
+ }
5528
+ catch (_domainError) {
5529
+ // Domains API might not be available or user doesn't have domains yet
5530
+ // User can manually enter verified email
5531
+ }
5532
+ }
5533
+ }
5534
+ catch (_error) { }
5535
+ res.json({
5536
+ success: true,
5537
+ hasApiKey: true,
5538
+ verifiedSenders: verifiedSenders.length > 0 ? verifiedSenders : undefined,
5539
+ });
5540
+ }
5541
+ catch (error) {
5542
+ res.status(500).json({
5543
+ success: false,
5544
+ hasApiKey: false,
5545
+ message: error?.message || 'Failed to check API key',
5546
+ });
5547
+ }
5548
+ });
5549
+ router.post('/api/tools/send-test-email', async (req, res) => {
5550
+ try {
5551
+ const { templateId, to, subject, html, fieldValues, from } = req.body || {};
5552
+ if (!to || !subject || !html) {
5553
+ return res.status(400).json({
5554
+ success: false,
5555
+ message: 'to, subject, and html are required',
5556
+ });
5557
+ }
5558
+ if (!from) {
5559
+ return res.status(400).json({
5560
+ success: false,
5561
+ message: 'from email address is required. Please use a verified domain/email from your Resend account.',
5562
+ });
5563
+ }
5564
+ const apiKey = process.env.RESEND_API_KEY;
5565
+ if (!apiKey || apiKey.trim().length === 0) {
5566
+ return res.status(400).json({
5567
+ success: false,
5568
+ message: 'RESEND_API_KEY not found in environment variables. Please add it to your .env file.',
5569
+ });
5570
+ }
5571
+ let processedHtml = html;
5572
+ let processedSubject = subject;
5573
+ if (fieldValues) {
5574
+ Object.entries(fieldValues).forEach(([key, value]) => {
5575
+ const placeholder = `{{${key}}}`;
5576
+ processedHtml = processedHtml.replace(new RegExp(placeholder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), String(value));
5577
+ processedSubject = processedSubject.replace(new RegExp(placeholder.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), String(value));
5578
+ });
5579
+ }
5580
+ processedHtml = processedHtml.replace(/\{\{year\}\}/g, new Date().getFullYear().toString());
5581
+ processedSubject = processedSubject.replace(/\{\{year\}\}/g, new Date().getFullYear().toString());
5582
+ let Resend;
5583
+ try {
5584
+ const { createRequire } = await import('node:module');
5585
+ const { resolve } = await import('node:path');
5586
+ const { existsSync } = await import('node:fs');
5587
+ const userRequire = createRequire(resolve(process.cwd(), 'package.json'));
5588
+ try {
5589
+ const resendPath = userRequire.resolve('resend');
5590
+ const resendModule = await import(resendPath);
5591
+ Resend = resendModule.Resend || resendModule.default?.Resend || resendModule.default;
5592
+ }
5593
+ catch (resolveError) {
5594
+ const userNodeModules = resolve(process.cwd(), 'node_modules', 'resend');
5595
+ if (!existsSync(userNodeModules)) {
5596
+ throw new Error('Resend package not found in user project');
5597
+ }
5598
+ const resendModule = await import(resolve(userNodeModules, 'index.js'));
5599
+ Resend = resendModule.Resend || resendModule.default?.Resend || resendModule.default;
5600
+ }
5601
+ }
5602
+ catch (error) {
5603
+ return res.status(400).json({
5604
+ success: false,
5605
+ message: 'Resend package not found. Please install it in your project: npm install resend',
5606
+ });
5607
+ }
5608
+ if (!Resend) {
5609
+ return res.status(400).json({
5610
+ success: false,
5611
+ message: 'Failed to load Resend. Please ensure resend is installed: npm install resend',
5612
+ });
5613
+ }
5614
+ const resend = new Resend(apiKey);
5615
+ const emailResult = await resend.emails.send({
5616
+ from: from,
5617
+ to: to,
5618
+ subject: processedSubject,
5619
+ html: processedHtml,
5620
+ });
5621
+ if (emailResult.error) {
5622
+ return res.status(500).json({
5623
+ success: false,
5624
+ message: emailResult.error.message || 'Failed to send email via Resend',
5625
+ });
5626
+ }
5627
+ res.json({
5628
+ success: true,
5629
+ message: 'Test email sent successfully',
5630
+ emailId: emailResult.data?.id,
5631
+ });
5632
+ }
5633
+ catch (error) {
5634
+ res.status(500).json({
5635
+ success: false,
5636
+ message: error?.message || 'Failed to send test email',
5637
+ });
5638
+ }
5639
+ });
5486
5640
  return router;
5487
5641
  }
5488
5642
  //# sourceMappingURL=routes.js.map