@better-auth/infra 0.1.6 → 0.1.8

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/dist/client.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as _better_fetch_fetch0 from "@better-fetch/fetch";
1
+ import * as better_auth_client0 from "better-auth/client";
2
2
 
3
3
  //#region src/client.d.ts
4
4
  interface DashAuditLog {
@@ -49,7 +49,7 @@ interface DashClientOptions {
49
49
  }
50
50
  declare const dashClient: (options?: DashClientOptions) => {
51
51
  id: "dash";
52
- getActions: ($fetch: _better_fetch_fetch0.BetterFetch) => {
52
+ getActions: ($fetch: better_auth_client0.BetterFetch) => {
53
53
  dash: {
54
54
  getAuditLogs: (input?: DashGetAuditLogsInput) => Promise<{
55
55
  data: DashAuditLogsResponse;
@@ -97,15 +97,15 @@ declare const sentinelClient: (options?: SentinelClientOptions) => {
97
97
  id: string;
98
98
  name: string;
99
99
  hooks: {
100
- onRequest<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>): Promise<_better_fetch_fetch0.RequestContext<T>>;
100
+ onRequest<T extends Record<string, any>>(context: better_auth_client0.RequestContext<T>): Promise<better_auth_client0.RequestContext<T>>;
101
101
  onResponse?: undefined;
102
102
  };
103
103
  } | {
104
104
  id: string;
105
105
  name: string;
106
106
  hooks: {
107
- onResponse(context: _better_fetch_fetch0.ResponseContext): Promise<_better_fetch_fetch0.ResponseContext>;
108
- onRequest<T extends Record<string, any>>(context: _better_fetch_fetch0.RequestContext<T>): Promise<_better_fetch_fetch0.RequestContext<T>>;
107
+ onResponse(context: better_auth_client0.ResponseContext): Promise<better_auth_client0.ResponseContext>;
108
+ onRequest<T extends Record<string, any>>(context: better_auth_client0.RequestContext<T>): Promise<better_auth_client0.RequestContext<T>>;
109
109
  };
110
110
  })[];
111
111
  };
package/dist/client.mjs CHANGED
@@ -417,7 +417,9 @@ async function sendIdentify(identifyUrl) {
417
417
  headers: { "Content-Type": "application/json" },
418
418
  body: JSON.stringify(payload)
419
419
  });
420
- } catch {} finally {
420
+ } catch (error) {
421
+ console.warn("[Dash] Identify request failed:", error);
422
+ } finally {
421
423
  identifyCompleteResolve?.();
422
424
  }
423
425
  }
@@ -78,6 +78,7 @@ function createEmailSender(config) {
78
78
  messageId: (await response.json()).messageId
79
79
  };
80
80
  } catch (error) {
81
+ logger.warn("[Dash] Email send failed:", error);
81
82
  return {
82
83
  success: false,
83
84
  error: error instanceof Error ? error.message : "Failed to send email"
@@ -85,6 +86,51 @@ function createEmailSender(config) {
85
86
  }
86
87
  }
87
88
  /**
89
+ * Send bulk emails using a template from Better Auth Infra
90
+ */
91
+ async function sendBulk(options) {
92
+ if (!apiKey) return {
93
+ success: false,
94
+ failures: Object.fromEntries(options.emails.map((e) => [e.to, [{ error: "API key not configured" }]]))
95
+ };
96
+ try {
97
+ const response = await fetch(`${apiUrl}/v1/email/send-bulk`, {
98
+ method: "POST",
99
+ headers: {
100
+ "Content-Type": "application/json",
101
+ Authorization: `Bearer ${apiKey}`
102
+ },
103
+ body: JSON.stringify({
104
+ template: options.template,
105
+ emails: options.emails.map((e) => ({
106
+ to: e.to,
107
+ variables: e.variables || {}
108
+ })),
109
+ subject: options.subject,
110
+ variables: options.variables || {}
111
+ })
112
+ });
113
+ if (!response.ok) {
114
+ const error = await response.json().catch(() => ({ message: "Unknown error" }));
115
+ return {
116
+ success: false,
117
+ failures: Object.fromEntries(options.emails.map((e) => [e.to, [{ error: error.message || `HTTP ${response.status}` }]]))
118
+ };
119
+ }
120
+ const result = await response.json();
121
+ return {
122
+ success: result.success,
123
+ failures: result.failures
124
+ };
125
+ } catch (error) {
126
+ logger.warn("[Dash] Bulk email send failed:", error);
127
+ return {
128
+ success: false,
129
+ failures: Object.fromEntries(options.emails.map((e) => [e.to, [{ error: error instanceof Error ? error.message : "Failed to send bulk emails" }]]))
130
+ };
131
+ }
132
+ }
133
+ /**
88
134
  * Get available email templates
89
135
  */
90
136
  async function getTemplates() {
@@ -93,12 +139,14 @@ function createEmailSender(config) {
93
139
  const response = await fetch(`${apiUrl}/v1/email/templates`, { headers: { Authorization: `Bearer ${apiKey}` } });
94
140
  if (!response.ok) return [];
95
141
  return response.json();
96
- } catch {
142
+ } catch (error) {
143
+ logger.warn("[Dash] Failed to fetch email templates:", error);
97
144
  return [];
98
145
  }
99
146
  }
100
147
  return {
101
148
  send,
149
+ sendBulk,
102
150
  getTemplates
103
151
  };
104
152
  }
@@ -123,6 +171,25 @@ function createEmailSender(config) {
123
171
  async function sendEmail(options, config) {
124
172
  return createEmailSender(config).send(options);
125
173
  }
174
+ /**
175
+ * Send bulk emails using the Better Auth dashboard's email templates.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * import { sendBulkEmails } from "@better-auth/infra";
180
+ *
181
+ * const result = await sendBulkEmails({
182
+ * template: "reset-password",
183
+ * emails: [
184
+ * { to: "user1@example.com", variables: { resetLink: "...", userEmail: "user1@example.com" } },
185
+ * { to: "user2@example.com", variables: { resetLink: "...", userEmail: "user2@example.com" } },
186
+ * ],
187
+ * });
188
+ * ```
189
+ */
190
+ async function sendBulkEmails(options, config) {
191
+ return createEmailSender(config).sendBulk(options);
192
+ }
126
193
 
127
194
  //#endregion
128
- export { INFRA_KV_URL as a, INFRA_API_URL as i, createEmailSender as n, sendEmail as r, EMAIL_TEMPLATES as t };
195
+ export { INFRA_API_URL as a, sendEmail as i, createEmailSender as n, INFRA_KV_URL as o, sendBulkEmails as r, EMAIL_TEMPLATES as t };
package/dist/email.d.mts CHANGED
@@ -168,11 +168,46 @@ type SendEmailOptions<T extends EmailTemplateId = EmailTemplateId> = {
168
168
  */
169
169
  subject?: string;
170
170
  };
171
+ /**
172
+ * Options for sending bulk emails
173
+ */
174
+ type SendBulkEmailsOptions<T extends EmailTemplateId = EmailTemplateId> = {
175
+ /**
176
+ * The template ID to use for all emails
177
+ */
178
+ template: T;
179
+ /**
180
+ * Array of recipients with their template variables
181
+ */
182
+ emails: Array<{
183
+ to: string;
184
+ variables?: EmailTemplateVariables<T>;
185
+ }>;
186
+ /**
187
+ * Optional subject override (shared across all emails)
188
+ */
189
+ subject?: string;
190
+ /**
191
+ * Optional shared variables applied to all emails (per-recipient variables override these)
192
+ */
193
+ variables?: Record<string, string>;
194
+ };
195
+ /**
196
+ * Result of a bulk email send operation
197
+ */
198
+ interface SendBulkEmailsResult {
199
+ success: boolean;
200
+ failures?: Record<string, {
201
+ error?: string;
202
+ messageId?: string;
203
+ }[]>;
204
+ }
171
205
  /**
172
206
  * Create an email sender instance
173
207
  */
174
208
  declare function createEmailSender(config?: EmailConfig): {
175
209
  send: <T extends EmailTemplateId>(options: SendEmailOptions<T>) => Promise<SendEmailResult>;
210
+ sendBulk: <T extends EmailTemplateId>(options: SendBulkEmailsOptions<T>) => Promise<SendBulkEmailsResult>;
176
211
  getTemplates: () => Promise<{
177
212
  id: string;
178
213
  name: string;
@@ -198,5 +233,22 @@ declare function createEmailSender(config?: EmailConfig): {
198
233
  * ```
199
234
  */
200
235
  declare function sendEmail<T extends EmailTemplateId>(options: SendEmailOptions<T>, config?: EmailConfig): Promise<SendEmailResult>;
236
+ /**
237
+ * Send bulk emails using the Better Auth dashboard's email templates.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * import { sendBulkEmails } from "@better-auth/infra";
242
+ *
243
+ * const result = await sendBulkEmails({
244
+ * template: "reset-password",
245
+ * emails: [
246
+ * { to: "user1@example.com", variables: { resetLink: "...", userEmail: "user1@example.com" } },
247
+ * { to: "user2@example.com", variables: { resetLink: "...", userEmail: "user2@example.com" } },
248
+ * ],
249
+ * });
250
+ * ```
251
+ */
252
+ declare function sendBulkEmails<T extends EmailTemplateId>(options: SendBulkEmailsOptions<T>, config?: EmailConfig): Promise<SendBulkEmailsResult>;
201
253
  //#endregion
202
- export { EMAIL_TEMPLATES, EmailConfig, EmailTemplateId, EmailTemplateVariables, SendEmailOptions, SendEmailResult, createEmailSender, sendEmail };
254
+ export { EMAIL_TEMPLATES, EmailConfig, EmailTemplateId, EmailTemplateVariables, SendBulkEmailsOptions, SendBulkEmailsResult, SendEmailOptions, SendEmailResult, createEmailSender, sendBulkEmails, sendEmail };
package/dist/email.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as createEmailSender, r as sendEmail, t as EMAIL_TEMPLATES } from "./email-BGxJ96Ky.mjs";
1
+ import { i as sendEmail, n as createEmailSender, r as sendBulkEmails, t as EMAIL_TEMPLATES } from "./email-D2dL1i3c.mjs";
2
2
 
3
- export { EMAIL_TEMPLATES, createEmailSender, sendEmail };
3
+ export { EMAIL_TEMPLATES, createEmailSender, sendBulkEmails, sendEmail };