@lovable.dev/email-js 0.5.0 → 0.6.0

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/README.md CHANGED
@@ -220,8 +220,9 @@ const handler = createAuthEmailHandler({
220
220
  Projects on Lovable Auth pass `provider: "lovable_auth"`. Lovable Auth sends
221
221
  one-time codes rather than links, so the `emails` map is total over
222
222
  `signup_confirmation`, `sign_in_otp` and `recovery_otp`, and `render` receives
223
- `code` and `expires_at` (ISO 8601) instead of `url` and `token`. The default
224
- provider is `"lovable_cloud"`, the handler shown above.
223
+ `code`, `expires_at` (ISO 8601) and `locale` (the BCP 47 tag of the language the
224
+ user saw on the hosted sign-in page, `en` when unknown) instead of `url` and
225
+ `token`. The default provider is `"lovable_cloud"`, the handler shown above.
225
226
 
226
227
  ```tsx
227
228
  const handler = createAuthEmailHandler({
package/dist/index.cjs CHANGED
@@ -170,10 +170,13 @@ function domainOfAddress(from) {
170
170
  return /@([^@\s<>]+)>?\s*$/.exec(from.trim())?.[1];
171
171
  }
172
172
  function createAuthEmailHandler(options) {
173
- if (options.provider === "lovable_auth") return createHandler(options, options.emails, (data) => typeof data.code === "string" && data.code !== "" ? void 0 : "Missing code");
174
- return createHandler(options, options.emails, () => void 0);
173
+ if (options.provider === "lovable_auth") return createHandler(options, options.emails, (data) => typeof data.code === "string" && data.code !== "" ? void 0 : "Missing code", (data) => ({
174
+ ...data,
175
+ locale: typeof data.locale === "string" && data.locale !== "" ? data.locale : "en"
176
+ }));
177
+ return createHandler(options, options.emails, () => void 0, (data) => data);
175
178
  }
176
- function createHandler(options, emails, rejectReason) {
179
+ function createHandler(options, emails, rejectReason, normalize) {
177
180
  const { apiKey } = options;
178
181
  if (!apiKey) throw new Error("Missing Lovable API key");
179
182
  const from = formatEmailFrom(options.from);
@@ -206,19 +209,20 @@ function createHandler(options, emails, rejectReason) {
206
209
  action_type: actionType,
207
210
  supported_action_types: Object.keys(emails)
208
211
  }, { status: 400 });
209
- const reason = rejectReason(event.data);
212
+ const data = normalize(event.data);
213
+ const reason = rejectReason(data);
210
214
  if (reason) return Response.json({ error: reason }, { status: 400 });
211
215
  try {
212
216
  const { render } = await import("@react-email/render");
213
- const { subject, element } = typeof definition === "function" ? await definition(event.data) : {
217
+ const { subject, element } = typeof definition === "function" ? await definition(data) : {
214
218
  subject: definition.subject,
215
- element: await definition.render(event.data)
219
+ element: await definition.render(data)
216
220
  };
217
221
  const html = await render(element);
218
222
  const text = await render(element, { plainText: true });
219
223
  await sendLovableEmail({
220
224
  run_id: event.run_id,
221
- to: event.data.email,
225
+ to: data.email,
222
226
  from,
223
227
  sender_domain: senderDomain,
224
228
  reply_to: replyTo,
package/dist/index.d.cts CHANGED
@@ -138,6 +138,7 @@ interface LovableAuthEmailHookData {
138
138
  email: string;
139
139
  code: string;
140
140
  expires_at: string;
141
+ locale: string;
141
142
  url: string | null;
142
143
  site_url: string | null;
143
144
  callback_url?: string;
package/dist/index.d.ts CHANGED
@@ -138,6 +138,7 @@ interface LovableAuthEmailHookData {
138
138
  email: string;
139
139
  code: string;
140
140
  expires_at: string;
141
+ locale: string;
141
142
  url: string | null;
142
143
  site_url: string | null;
143
144
  callback_url?: string;
package/dist/index.js CHANGED
@@ -169,10 +169,13 @@ function domainOfAddress(from) {
169
169
  return /@([^@\s<>]+)>?\s*$/.exec(from.trim())?.[1];
170
170
  }
171
171
  function createAuthEmailHandler(options) {
172
- if (options.provider === "lovable_auth") return createHandler(options, options.emails, (data) => typeof data.code === "string" && data.code !== "" ? void 0 : "Missing code");
173
- return createHandler(options, options.emails, () => void 0);
172
+ if (options.provider === "lovable_auth") return createHandler(options, options.emails, (data) => typeof data.code === "string" && data.code !== "" ? void 0 : "Missing code", (data) => ({
173
+ ...data,
174
+ locale: typeof data.locale === "string" && data.locale !== "" ? data.locale : "en"
175
+ }));
176
+ return createHandler(options, options.emails, () => void 0, (data) => data);
174
177
  }
175
- function createHandler(options, emails, rejectReason) {
178
+ function createHandler(options, emails, rejectReason, normalize) {
176
179
  const { apiKey } = options;
177
180
  if (!apiKey) throw new Error("Missing Lovable API key");
178
181
  const from = formatEmailFrom(options.from);
@@ -205,19 +208,20 @@ function createHandler(options, emails, rejectReason) {
205
208
  action_type: actionType,
206
209
  supported_action_types: Object.keys(emails)
207
210
  }, { status: 400 });
208
- const reason = rejectReason(event.data);
211
+ const data = normalize(event.data);
212
+ const reason = rejectReason(data);
209
213
  if (reason) return Response.json({ error: reason }, { status: 400 });
210
214
  try {
211
215
  const { render } = await import("@react-email/render");
212
- const { subject, element } = typeof definition === "function" ? await definition(event.data) : {
216
+ const { subject, element } = typeof definition === "function" ? await definition(data) : {
213
217
  subject: definition.subject,
214
- element: await definition.render(event.data)
218
+ element: await definition.render(data)
215
219
  };
216
220
  const html = await render(element);
217
221
  const text = await render(element, { plainText: true });
218
222
  await sendLovableEmail({
219
223
  run_id: event.run_id,
220
- to: event.data.email,
224
+ to: data.email,
221
225
  from,
222
226
  sender_domain: senderDomain,
223
227
  reply_to: replyTo,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovable.dev/email-js",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Lovable Email JS",
5
5
  "repository": {
6
6
  "type": "git",