@better-auth/infra 0.1.7 → 0.1.9-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.
package/package.json CHANGED
@@ -1,19 +1,12 @@
1
1
  {
2
2
  "name": "@better-auth/infra",
3
- "version": "0.1.7",
3
+ "version": "0.1.9-beta.1",
4
4
  "description": "Dashboard and analytics plugin for Better Auth",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
7
7
  "module": "dist/index.mjs",
8
8
  "types": "dist/index.d.mts",
9
9
  "sideEffects": false,
10
- "scripts": {
11
- "build": "tsdown ",
12
- "dev": "tsdown --watch",
13
- "typecheck": "tsc --noEmit",
14
- "test": "bun test",
15
- "test:watch": "bun test --watch"
16
- },
17
10
  "exports": {
18
11
  ".": {
19
12
  "types": "./dist/index.d.mts",
@@ -57,18 +50,26 @@
57
50
  "better-auth": "beta",
58
51
  "@better-auth/scim": "beta",
59
52
  "tsdown": "^0.19.0-beta.2",
60
- "typescript": "^5.9.2"
53
+ "typescript": "^5.9.2",
54
+ "zod": "beta"
61
55
  },
62
56
  "dependencies": {
63
- "@better-auth/core": "beta",
64
- "@better-auth/sso": "beta",
65
- "@better-fetch/fetch": "beta",
66
- "better-call": "beta",
57
+ "@better-fetch/fetch": "^1.1.21",
58
+ "better-call": "^1.3.3",
67
59
  "jose": "^6.1.0",
68
- "libphonenumber-js": "^1.12.36",
69
- "zod": "beta"
60
+ "libphonenumber-js": "^1.12.36"
70
61
  },
71
62
  "peerDependencies": {
72
- "better-auth": ">=1.4.15"
63
+ "better-auth": ">=1.4.0",
64
+ "zod": ">=4.1.12",
65
+ "@better-auth/core": ">=1.4.0",
66
+ "@better-auth/sso": ">=1.4.0"
67
+ },
68
+ "scripts": {
69
+ "build": "tsdown ",
70
+ "dev": "tsdown --watch",
71
+ "typecheck": "tsc --noEmit",
72
+ "test": "bun test",
73
+ "test:watch": "bun test --watch"
73
74
  }
74
- }
75
+ }
@@ -1,128 +0,0 @@
1
- import { logger } from "better-auth";
2
- import { env } from "@better-auth/core/env";
3
-
4
- //#region src/constants.ts
5
- /**
6
- * Infrastructure API URL
7
- * Can be overridden via plugin config or BETTER_AUTH_API_URL env var for local development
8
- */
9
- const INFRA_API_URL = env.BETTER_AUTH_API_URL || "https://beta.better-auth.com";
10
- /**
11
- * KV Storage URL
12
- * Can be overridden via plugin config or BETTER_AUTH_KV_URL env var for local development
13
- */
14
- const INFRA_KV_URL = env.BETTER_AUTH_KV_URL || "https://kv.better-auth.com";
15
-
16
- //#endregion
17
- //#region src/email.ts
18
- /**
19
- * Email sending module for @better-auth/infra
20
- *
21
- * This module provides email sending functionality that integrates with
22
- * Better Auth Infra's template system.
23
- */
24
- /**
25
- * Email template definitions with their required variables
26
- */
27
- const EMAIL_TEMPLATES = {
28
- "verify-email": { variables: {} },
29
- "reset-password": { variables: {} },
30
- "change-email": { variables: {} },
31
- "sign-in-otp": { variables: {} },
32
- "verify-email-otp": { variables: {} },
33
- "reset-password-otp": { variables: {} },
34
- "magic-link": { variables: {} },
35
- "two-factor": { variables: {} },
36
- invitation: { variables: {} },
37
- "application-invite": { variables: {} },
38
- "delete-account": { variables: {} },
39
- "stale-account-user": { variables: {} },
40
- "stale-account-admin": { variables: {} }
41
- };
42
- /**
43
- * Create an email sender instance
44
- */
45
- function createEmailSender(config) {
46
- const baseUrl = config?.apiUrl || INFRA_API_URL;
47
- const apiUrl = baseUrl.endsWith("/api") ? baseUrl : `${baseUrl}/api`;
48
- const apiKey = config?.apiKey || env.BETTER_AUTH_API_KEY || "";
49
- if (!apiKey) logger.warn("[Dash] No API key provided for email sending. Set BETTER_AUTH_API_KEY environment variable or pass apiKey in config.");
50
- /**
51
- * Send an email using a template from Better Auth Infra
52
- */
53
- async function send(options) {
54
- if (!apiKey) return {
55
- success: false,
56
- error: "API key not configured"
57
- };
58
- try {
59
- const response = await fetch(`${apiUrl}/v1/email/send`, {
60
- method: "POST",
61
- headers: {
62
- "Content-Type": "application/json",
63
- Authorization: `Bearer ${apiKey}`
64
- },
65
- body: JSON.stringify({
66
- template: options.template,
67
- to: options.to,
68
- variables: options.variables || {},
69
- subject: options.subject
70
- })
71
- });
72
- if (!response.ok) return {
73
- success: false,
74
- error: (await response.json().catch(() => ({ message: "Unknown error" }))).message || `HTTP ${response.status}`
75
- };
76
- return {
77
- success: true,
78
- messageId: (await response.json()).messageId
79
- };
80
- } catch (error) {
81
- return {
82
- success: false,
83
- error: error instanceof Error ? error.message : "Failed to send email"
84
- };
85
- }
86
- }
87
- /**
88
- * Get available email templates
89
- */
90
- async function getTemplates() {
91
- if (!apiKey) return [];
92
- try {
93
- const response = await fetch(`${apiUrl}/v1/email/templates`, { headers: { Authorization: `Bearer ${apiKey}` } });
94
- if (!response.ok) return [];
95
- return response.json();
96
- } catch {
97
- return [];
98
- }
99
- }
100
- return {
101
- send,
102
- getTemplates
103
- };
104
- }
105
- /**
106
- * Send an email using the Better Auth dashboard's email templates.
107
- *
108
- * @example
109
- * ```ts
110
- * import { sendEmail } from "@better-auth/infra";
111
- *
112
- * // Type-safe - variables are inferred from template
113
- * await sendEmail({
114
- * template: "reset-password",
115
- * to: "user@example.com",
116
- * variables: {
117
- * resetLink: "https://...",
118
- * userEmail: "user@example.com",
119
- * },
120
- * });
121
- * ```
122
- */
123
- async function sendEmail(options, config) {
124
- return createEmailSender(config).send(options);
125
- }
126
-
127
- //#endregion
128
- export { INFRA_KV_URL as a, INFRA_API_URL as i, createEmailSender as n, sendEmail as r, EMAIL_TEMPLATES as t };