@lovable.dev/email-js 0.1.1-rc.14 → 0.1.1-rc.15

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/index.cjs CHANGED
@@ -1,259 +1,352 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- let _lovable_dev_webhooks_js = require("@lovable.dev/webhooks-js");
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ EmailAPIError: () => EmailAPIError,
34
+ createAuthEmailHandler: () => createAuthEmailHandler,
35
+ createEmailWebhookHandler: () => createEmailWebhookHandler,
36
+ getEmailUnsubscribe: () => getEmailUnsubscribe,
37
+ listEmailLogs: () => listEmailLogs,
38
+ parseEmailWebhookPayload: () => parseEmailWebhookPayload,
39
+ sendLovableEmail: () => sendLovableEmail,
40
+ setEmailUnsubscribe: () => setEmailUnsubscribe
41
+ });
42
+ module.exports = __toCommonJS(src_exports);
43
+
44
+ // src/auth-email-handler.ts
45
+ var import_webhooks_js2 = require("@lovable.dev/webhooks-js");
46
+
47
+ // src/http.ts
48
+ var DEFAULT_AUTH_HEADER = "Authorization";
49
+ var DEFAULT_API_BASE_URL = "https://api.lovable.dev";
3
50
  function resolveApiBaseUrl(apiBaseUrl) {
4
- return (apiBaseUrl ?? "https://api.lovable.dev").replace(/\/$/, "");
51
+ return (apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/$/, "");
5
52
  }
6
53
  var EmailAPIError = class extends Error {
7
- constructor(status, message, retryAfterSeconds, code = null) {
8
- super(message);
9
- this.name = "EmailAPIError";
10
- this.status = status;
11
- this.retryAfterSeconds = retryAfterSeconds;
12
- this.code = code;
13
- }
14
- get retryable() {
15
- return this.status === 429 || this.status >= 500 && this.status < 600;
16
- }
54
+ constructor(status, message, retryAfterSeconds, code = null) {
55
+ super(message);
56
+ this.name = "EmailAPIError";
57
+ this.status = status;
58
+ this.retryAfterSeconds = retryAfterSeconds;
59
+ this.code = code;
60
+ }
61
+ get retryable() {
62
+ return this.status === 429 || this.status >= 500 && this.status < 600;
63
+ }
17
64
  };
18
65
  function parseRetryAfter(header) {
19
- if (!header) return null;
20
- const parsed = Number(header);
21
- if (!Number.isNaN(parsed)) return parsed;
22
- const date = new Date(header);
23
- if (!Number.isNaN(date.getTime())) return Math.max(0, Math.ceil((date.getTime() - Date.now()) / 1e3));
24
- return null;
66
+ if (!header)
67
+ return null;
68
+ const parsed = Number(header);
69
+ if (!Number.isNaN(parsed))
70
+ return parsed;
71
+ const date = new Date(header);
72
+ if (!Number.isNaN(date.getTime())) {
73
+ return Math.max(0, Math.ceil((date.getTime() - Date.now()) / 1e3));
74
+ }
75
+ return null;
25
76
  }
26
77
  function buildAuthHeaderValue(apiKey) {
27
- return `Bearer ${apiKey}`;
78
+ return `Bearer ${apiKey}`;
28
79
  }
29
80
  function parseErrorCode(body) {
30
- try {
31
- const parsed = JSON.parse(body);
32
- if (parsed && typeof parsed === "object" && "type" in parsed && typeof parsed.type === "string") return parsed.type;
33
- } catch {
34
- return null;
35
- }
36
- return null;
81
+ try {
82
+ const parsed = JSON.parse(body);
83
+ if (parsed && typeof parsed === "object" && "type" in parsed && typeof parsed.type === "string") {
84
+ return parsed.type;
85
+ }
86
+ } catch {
87
+ return null;
88
+ }
89
+ return null;
37
90
  }
38
91
  async function throwIfNotOk(response) {
39
- if (response.ok) return;
40
- const errorText = await response.text();
41
- const safeErrorText = errorText.length > 500 ? `${errorText.slice(0, 500)}...` : errorText;
42
- const retryAfterSeconds = parseRetryAfter(response.headers.get("Retry-After"));
43
- const code = parseErrorCode(errorText);
44
- if (response.status === 429) console.error("[email-js] rate limited:", {
45
- status: response.status,
46
- code,
47
- retryAfterSeconds
48
- });
49
- throw new EmailAPIError(response.status, `Email API error: ${response.status} ${safeErrorText}`, retryAfterSeconds, code);
92
+ if (response.ok)
93
+ return;
94
+ const errorText = await response.text();
95
+ const safeErrorText = errorText.length > 500 ? `${errorText.slice(0, 500)}...` : errorText;
96
+ const retryAfterSeconds = parseRetryAfter(response.headers.get("Retry-After"));
97
+ const code = parseErrorCode(errorText);
98
+ if (response.status === 429) {
99
+ console.error("[email-js] rate limited:", { status: response.status, code, retryAfterSeconds });
100
+ }
101
+ throw new EmailAPIError(
102
+ response.status,
103
+ `Email API error: ${response.status} ${safeErrorText}`,
104
+ retryAfterSeconds,
105
+ code
106
+ );
50
107
  }
51
108
  async function emailApiRequest(options, path, init = { method: "GET" }) {
52
- if (!options.apiKey) throw new Error("Missing Lovable API key");
53
- const headers = { [options.authHeader ?? "Authorization"]: buildAuthHeaderValue(options.apiKey) };
54
- if (init.body !== void 0) headers["Content-Type"] = "application/json";
55
- const response = await fetch(`${resolveApiBaseUrl(options.apiBaseUrl)}${path}`, {
56
- method: init.method,
57
- headers,
58
- body: init.body === void 0 ? void 0 : JSON.stringify(init.body)
59
- });
60
- await throwIfNotOk(response);
61
- return await response.json();
109
+ if (!options.apiKey) {
110
+ throw new Error("Missing Lovable API key");
111
+ }
112
+ const headers = {
113
+ [options.authHeader ?? DEFAULT_AUTH_HEADER]: buildAuthHeaderValue(options.apiKey)
114
+ };
115
+ if (init.body !== void 0) {
116
+ headers["Content-Type"] = "application/json";
117
+ }
118
+ const response = await fetch(`${resolveApiBaseUrl(options.apiBaseUrl)}${path}`, {
119
+ method: init.method,
120
+ headers,
121
+ body: init.body === void 0 ? void 0 : JSON.stringify(init.body)
122
+ });
123
+ await throwIfNotOk(response);
124
+ return await response.json();
62
125
  }
63
- //#endregion
64
- //#region src/email.ts
65
- const DEFAULT_SEND_PATH = "/v1/messaging/email/send";
126
+
127
+ // src/email.ts
128
+ var DEFAULT_SEND_PATH = "/v1/messaging/email/send";
66
129
  async function sendLovableEmail(payload, options) {
67
- const apiKey = options.apiKey;
68
- if (!apiKey) throw new Error("Missing Lovable API key");
69
- const authHeader = options.authHeader ?? "Authorization";
70
- const url = options.sendUrl || `${resolveApiBaseUrl(options.apiBaseUrl)}${DEFAULT_SEND_PATH}`;
71
- const idempotencyKey = options.idempotencyKey ?? payload.idempotency_key ?? payload.run_id;
72
- const headers = {
73
- [authHeader]: buildAuthHeaderValue(apiKey),
74
- "Content-Type": "application/json"
75
- };
76
- if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;
77
- const response = await fetch(url, {
78
- method: "POST",
79
- headers,
80
- body: JSON.stringify(payload)
81
- });
82
- await throwIfNotOk(response);
83
- return await response.json();
130
+ const apiKey = options.apiKey;
131
+ if (!apiKey) {
132
+ throw new Error("Missing Lovable API key");
133
+ }
134
+ const authHeader = options.authHeader ?? DEFAULT_AUTH_HEADER;
135
+ const sendUrl = options.sendUrl;
136
+ const url = sendUrl || `${resolveApiBaseUrl(options.apiBaseUrl)}${DEFAULT_SEND_PATH}`;
137
+ const idempotencyKey = options.idempotencyKey ?? payload.idempotency_key ?? payload.run_id;
138
+ const headers = {
139
+ [authHeader]: buildAuthHeaderValue(apiKey),
140
+ "Content-Type": "application/json"
141
+ };
142
+ if (idempotencyKey) {
143
+ headers["Idempotency-Key"] = idempotencyKey;
144
+ }
145
+ const response = await fetch(url, {
146
+ method: "POST",
147
+ headers,
148
+ body: JSON.stringify(payload)
149
+ });
150
+ await throwIfNotOk(response);
151
+ return await response.json();
84
152
  }
85
- //#endregion
86
- //#region src/webhook.ts
153
+
154
+ // src/webhook-handler.ts
155
+ var import_webhooks_js = require("@lovable.dev/webhooks-js");
156
+
157
+ // src/webhook.ts
87
158
  function parseEmailWebhookPayload(body) {
88
- const parsed = JSON.parse(body);
89
- if (!parsed || typeof parsed !== "object") throw new Error("Invalid email webhook payload: missing version or type");
90
- const payload = parsed;
91
- if (typeof payload.version !== "string" || typeof payload.type !== "string") throw new Error("Invalid email webhook payload: missing version or type");
92
- return payload;
159
+ const parsed = JSON.parse(body);
160
+ if (!parsed || typeof parsed !== "object") {
161
+ throw new Error("Invalid email webhook payload: missing version or type");
162
+ }
163
+ const payload = parsed;
164
+ if (typeof payload.version !== "string" || typeof payload.type !== "string") {
165
+ throw new Error("Invalid email webhook payload: missing version or type");
166
+ }
167
+ return payload;
93
168
  }
94
- //#endregion
95
- //#region src/webhook-handler.ts
96
- const WEBHOOK_ERROR_STATUS = {
97
- missing_secret: 401,
98
- missing_timestamp: 401,
99
- invalid_timestamp: 401,
100
- stale_timestamp: 401,
101
- invalid_signature: 401,
102
- body_too_large: 400,
103
- invalid_json: 400,
104
- invalid_payload: 400
169
+
170
+ // src/webhook-handler.ts
171
+ var WEBHOOK_ERROR_STATUS = {
172
+ missing_secret: 401,
173
+ missing_timestamp: 401,
174
+ invalid_timestamp: 401,
175
+ stale_timestamp: 401,
176
+ invalid_signature: 401,
177
+ body_too_large: 400,
178
+ invalid_json: 400,
179
+ invalid_payload: 400
105
180
  };
106
181
  function parseEmailWebhookEvent(body) {
107
- return parseEmailWebhookPayload(body);
182
+ return parseEmailWebhookPayload(body);
108
183
  }
109
184
  function createEmailWebhookHandler(options) {
110
- const { apiKey, on } = options;
111
- if (!apiKey) throw new Error("Missing Lovable API key");
112
- return async (req) => {
113
- if (req.method !== "POST") return Response.json({ error: "Method not allowed" }, {
114
- status: 405,
115
- headers: { Allow: "POST" }
116
- });
117
- let event;
118
- try {
119
- ({payload: event} = await (0, _lovable_dev_webhooks_js.verifyWebhookRequest)({
120
- req,
121
- secret: apiKey,
122
- parser: parseEmailWebhookEvent
123
- }));
124
- } catch (error) {
125
- if (error instanceof _lovable_dev_webhooks_js.WebhookError) return Response.json({ error: error.message }, { status: WEBHOOK_ERROR_STATUS[error.code] });
126
- console.error("[email-js] webhook verification failed:", error);
127
- return Response.json({ error: "Webhook verification failed" }, { status: 500 });
128
- }
129
- if (event.version !== "1") return Response.json({ received: true });
130
- const handler = on[event.type];
131
- if (handler) try {
132
- await handler(event);
133
- } catch (error) {
134
- console.error("[email-js] webhook handler failed:", error);
135
- return Response.json({ error: "Handler failed" }, { status: 500 });
136
- }
137
- return Response.json({ received: true });
138
- };
185
+ const { apiKey, on } = options;
186
+ if (!apiKey) {
187
+ throw new Error("Missing Lovable API key");
188
+ }
189
+ return async (req) => {
190
+ if (req.method !== "POST") {
191
+ return Response.json({ error: "Method not allowed" }, { status: 405, headers: { Allow: "POST" } });
192
+ }
193
+ let event;
194
+ try {
195
+ ({ payload: event } = await (0, import_webhooks_js.verifyWebhookRequest)({ req, secret: apiKey, parser: parseEmailWebhookEvent }));
196
+ } catch (error) {
197
+ if (error instanceof import_webhooks_js.WebhookError) {
198
+ return Response.json({ error: error.message }, { status: WEBHOOK_ERROR_STATUS[error.code] });
199
+ }
200
+ console.error("[email-js] webhook verification failed:", error);
201
+ return Response.json({ error: "Webhook verification failed" }, { status: 500 });
202
+ }
203
+ if (event.version !== "1") {
204
+ return Response.json({ received: true });
205
+ }
206
+ const handler = on[event.type];
207
+ if (handler) {
208
+ try {
209
+ await handler(event);
210
+ } catch (error) {
211
+ console.error("[email-js] webhook handler failed:", error);
212
+ return Response.json({ error: "Handler failed" }, { status: 500 });
213
+ }
214
+ }
215
+ return Response.json({ received: true });
216
+ };
139
217
  }
140
- //#endregion
141
- //#region src/auth-email-handler.ts
218
+
219
+ // src/auth-email-handler.ts
142
220
  function parseAuthEmailWebhookPayload(body) {
143
- const parsed = JSON.parse(body);
144
- const payload = parsed;
145
- if (!parsed || typeof parsed !== "object" || typeof payload.version !== "string" || payload.type !== "auth" || !payload.data || typeof payload.data !== "object" || typeof payload.data.action_type !== "string" || typeof payload.data.email !== "string") throw new Error("Invalid auth email webhook payload");
146
- return payload;
221
+ const parsed = JSON.parse(body);
222
+ const payload = parsed;
223
+ if (!parsed || typeof parsed !== "object" || typeof payload.version !== "string" || payload.type !== "auth" || !payload.data || typeof payload.data !== "object" || typeof payload.data.action_type !== "string" || typeof payload.data.email !== "string") {
224
+ throw new Error("Invalid auth email webhook payload");
225
+ }
226
+ return payload;
147
227
  }
148
228
  function domainOfAddress(from) {
149
- return /@([^@\s<>]+)>?\s*$/.exec(from.trim())?.[1];
229
+ const match = /@([^@\s<>]+)>?\s*$/.exec(from.trim());
230
+ return match?.[1];
150
231
  }
151
232
  function createAuthEmailHandler(options) {
152
- const { apiKey, from, emails } = options;
153
- if (!apiKey) throw new Error("Missing Lovable API key");
154
- const senderDomain = options.senderDomain ?? domainOfAddress(from);
155
- if (!senderDomain) throw new Error(`Cannot derive a sender domain from "${from}"; pass senderDomain`);
156
- return async (req) => {
157
- if (req.method !== "POST") return Response.json({ error: "Method not allowed" }, {
158
- status: 405,
159
- headers: { Allow: "POST" }
160
- });
161
- let event;
162
- try {
163
- ({payload: event} = await (0, _lovable_dev_webhooks_js.verifyWebhookRequest)({
164
- req,
165
- secret: apiKey,
166
- parser: parseAuthEmailWebhookPayload
167
- }));
168
- } catch (error) {
169
- if (error instanceof _lovable_dev_webhooks_js.WebhookError) return Response.json({ error: error.message }, { status: WEBHOOK_ERROR_STATUS[error.code] });
170
- console.error("[email-js] auth webhook verification failed:", error);
171
- return Response.json({ error: "Webhook verification failed" }, { status: 500 });
172
- }
173
- if (!event.run_id) return Response.json({ error: "Missing run_id" }, { status: 400 });
174
- if (event.version !== "1") return Response.json({ error: `Unsupported payload version: ${event.version}` }, { status: 400 });
175
- const actionType = event.data.action_type;
176
- const definition = Object.prototype.hasOwnProperty.call(emails, actionType) ? emails[actionType] : void 0;
177
- if (!definition) return Response.json({ error: `Unknown auth email action type: ${actionType}` }, { status: 400 });
178
- try {
179
- const { render } = await import("@react-email/render");
180
- const { subject, element } = typeof definition === "function" ? await definition(event.data) : {
181
- subject: definition.subject,
182
- element: await definition.render(event.data)
183
- };
184
- const html = await render(element);
185
- const text = await render(element, { plainText: true });
186
- await sendLovableEmail({
187
- run_id: event.run_id,
188
- to: event.data.email,
189
- from,
190
- sender_domain: senderDomain,
191
- subject,
192
- html,
193
- text,
194
- purpose: "transactional",
195
- label: actionType
196
- }, {
197
- apiKey,
198
- sendUrl: options.sendUrl
199
- });
200
- } catch (error) {
201
- console.error("[email-js] auth email send failed:", error);
202
- if (error instanceof EmailAPIError && !error.retryable) return Response.json({ error: "Email send rejected" }, { status: 400 });
203
- return Response.json({ error: "Failed to send email" }, { status: 500 });
204
- }
205
- return Response.json({
206
- success: true,
207
- sent: true
208
- });
209
- };
233
+ const { apiKey, from, emails } = options;
234
+ if (!apiKey) {
235
+ throw new Error("Missing Lovable API key");
236
+ }
237
+ const senderDomain = options.senderDomain ?? domainOfAddress(from);
238
+ if (!senderDomain) {
239
+ throw new Error(`Cannot derive a sender domain from "${from}"; pass senderDomain`);
240
+ }
241
+ return async (req) => {
242
+ if (req.method !== "POST") {
243
+ return Response.json({ error: "Method not allowed" }, { status: 405, headers: { Allow: "POST" } });
244
+ }
245
+ let event;
246
+ try {
247
+ ({ payload: event } = await (0, import_webhooks_js2.verifyWebhookRequest)({ req, secret: apiKey, parser: parseAuthEmailWebhookPayload }));
248
+ } catch (error) {
249
+ if (error instanceof import_webhooks_js2.WebhookError) {
250
+ return Response.json({ error: error.message }, { status: WEBHOOK_ERROR_STATUS[error.code] });
251
+ }
252
+ console.error("[email-js] auth webhook verification failed:", error);
253
+ return Response.json({ error: "Webhook verification failed" }, { status: 500 });
254
+ }
255
+ if (!event.run_id) {
256
+ return Response.json({ error: "Missing run_id" }, { status: 400 });
257
+ }
258
+ if (event.version !== "1") {
259
+ return Response.json({ error: `Unsupported payload version: ${event.version}` }, { status: 400 });
260
+ }
261
+ const actionType = event.data.action_type;
262
+ const definition = Object.prototype.hasOwnProperty.call(emails, actionType) ? emails[actionType] : void 0;
263
+ if (!definition) {
264
+ return Response.json({ error: `Unknown auth email action type: ${actionType}` }, { status: 400 });
265
+ }
266
+ try {
267
+ const { render } = await import("@react-email/render");
268
+ const { subject, element } = typeof definition === "function" ? await definition(event.data) : { subject: definition.subject, element: await definition.render(event.data) };
269
+ const html = await render(element);
270
+ const text = await render(element, { plainText: true });
271
+ await sendLovableEmail(
272
+ {
273
+ run_id: event.run_id,
274
+ to: event.data.email,
275
+ from,
276
+ sender_domain: senderDomain,
277
+ subject,
278
+ html,
279
+ text,
280
+ purpose: "transactional",
281
+ label: actionType
282
+ },
283
+ { apiKey, sendUrl: options.sendUrl }
284
+ );
285
+ } catch (error) {
286
+ console.error("[email-js] auth email send failed:", error);
287
+ if (error instanceof EmailAPIError && !error.retryable) {
288
+ return Response.json({ error: "Email send rejected" }, { status: 400 });
289
+ }
290
+ return Response.json({ error: "Failed to send email" }, { status: 500 });
291
+ }
292
+ return Response.json({ success: true, sent: true });
293
+ };
210
294
  }
211
- //#endregion
212
- //#region src/logs.ts
213
- const LOGS_PATH = "/v1/messaging/email/logs";
295
+
296
+ // src/logs.ts
297
+ var LOGS_PATH = "/v1/messaging/email/logs";
214
298
  function buildLogsQuery(filters) {
215
- const params = new URLSearchParams();
216
- if (filters.recipient) params.set("recipient", filters.recipient);
217
- if (filters.event_type) params.set("event_type", filters.event_type);
218
- if (filters.status) params.set("status", filters.status);
219
- if (filters.tag) params.set("tag", filters.tag);
220
- if (filters.since) params.set("since", filters.since);
221
- if (filters.until) params.set("until", filters.until);
222
- if (filters.limit !== void 0) params.set("limit", String(filters.limit));
223
- if (filters.cursor) params.set("cursor", filters.cursor);
224
- const query = params.toString();
225
- return query ? `?${query}` : "";
299
+ const params = new URLSearchParams();
300
+ if (filters.recipient)
301
+ params.set("recipient", filters.recipient);
302
+ if (filters.event_type)
303
+ params.set("event_type", filters.event_type);
304
+ if (filters.status)
305
+ params.set("status", filters.status);
306
+ if (filters.tag)
307
+ params.set("tag", filters.tag);
308
+ if (filters.since)
309
+ params.set("since", filters.since);
310
+ if (filters.until)
311
+ params.set("until", filters.until);
312
+ if (filters.limit !== void 0)
313
+ params.set("limit", String(filters.limit));
314
+ if (filters.cursor)
315
+ params.set("cursor", filters.cursor);
316
+ const query = params.toString();
317
+ return query ? `?${query}` : "";
226
318
  }
227
319
  async function listEmailLogs(filters, options) {
228
- const body = await emailApiRequest(options, `${LOGS_PATH}${buildLogsQuery(filters)}`);
229
- return {
230
- ...body,
231
- data: body.data ?? []
232
- };
320
+ const body = await emailApiRequest(options, `${LOGS_PATH}${buildLogsQuery(filters)}`);
321
+ return { ...body, data: body.data ?? [] };
233
322
  }
234
- //#endregion
235
- //#region src/unsubscribe.ts
236
- const UNSUBSCRIBES_PATH = "/v1/messaging/email/unsubscribes";
323
+
324
+ // src/unsubscribe.ts
325
+ var UNSUBSCRIBES_PATH = "/v1/messaging/email/unsubscribes";
237
326
  function buildUnsubscribePath(recipient, domain) {
238
- if (!recipient.includes("@")) throw new Error("Invalid recipient");
239
- const query = new URLSearchParams({ domain }).toString();
240
- return `${UNSUBSCRIBES_PATH}/${encodeURIComponent(recipient)}?${query}`;
327
+ if (!recipient.includes("@")) {
328
+ throw new Error("Invalid recipient");
329
+ }
330
+ const query = new URLSearchParams({ domain }).toString();
331
+ return `${UNSUBSCRIBES_PATH}/${encodeURIComponent(recipient)}?${query}`;
241
332
  }
242
333
  async function getEmailUnsubscribe(request, options) {
243
- return emailApiRequest(options, buildUnsubscribePath(request.recipient, request.domain));
334
+ return emailApiRequest(options, buildUnsubscribePath(request.recipient, request.domain));
244
335
  }
245
336
  async function setEmailUnsubscribe(request, options) {
246
- return emailApiRequest(options, buildUnsubscribePath(request.recipient, request.domain), {
247
- method: "PUT",
248
- body: { subscribed: request.subscribed }
249
- });
337
+ return emailApiRequest(options, buildUnsubscribePath(request.recipient, request.domain), {
338
+ method: "PUT",
339
+ body: { subscribed: request.subscribed }
340
+ });
250
341
  }
251
- //#endregion
252
- exports.EmailAPIError = EmailAPIError;
253
- exports.createAuthEmailHandler = createAuthEmailHandler;
254
- exports.createEmailWebhookHandler = createEmailWebhookHandler;
255
- exports.getEmailUnsubscribe = getEmailUnsubscribe;
256
- exports.listEmailLogs = listEmailLogs;
257
- exports.parseEmailWebhookPayload = parseEmailWebhookPayload;
258
- exports.sendLovableEmail = sendLovableEmail;
259
- exports.setEmailUnsubscribe = setEmailUnsubscribe;
342
+ // Annotate the CommonJS export names for ESM import in node:
343
+ 0 && (module.exports = {
344
+ EmailAPIError,
345
+ createAuthEmailHandler,
346
+ createEmailWebhookHandler,
347
+ getEmailUnsubscribe,
348
+ listEmailLogs,
349
+ parseEmailWebhookPayload,
350
+ sendLovableEmail,
351
+ setEmailUnsubscribe
352
+ });