@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 +3 -2
- package/dist/index.cjs +11 -7
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -7
- package/package.json +1 -1
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
|
|
224
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
217
|
+
const { subject, element } = typeof definition === "function" ? await definition(data) : {
|
|
214
218
|
subject: definition.subject,
|
|
215
|
-
element: await definition.render(
|
|
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:
|
|
225
|
+
to: data.email,
|
|
222
226
|
from,
|
|
223
227
|
sender_domain: senderDomain,
|
|
224
228
|
reply_to: replyTo,
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
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
|
-
|
|
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
|
|
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(
|
|
216
|
+
const { subject, element } = typeof definition === "function" ? await definition(data) : {
|
|
213
217
|
subject: definition.subject,
|
|
214
|
-
element: await definition.render(
|
|
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:
|
|
224
|
+
to: data.email,
|
|
221
225
|
from,
|
|
222
226
|
sender_domain: senderDomain,
|
|
223
227
|
reply_to: replyTo,
|