@lovable.dev/email-js 0.1.1-rc.4 → 0.1.1-rc.5
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 +313 -220
- package/dist/index.d.cts +112 -116
- package/dist/index.d.ts +112 -116
- package/dist/index.js +275 -218
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -1,259 +1,352 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
51
|
+
return (apiBaseUrl ?? DEFAULT_API_BASE_URL).replace(/\/$/, "");
|
|
5
52
|
}
|
|
6
53
|
var EmailAPIError = class extends Error {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
78
|
+
return `Bearer ${apiKey}`;
|
|
28
79
|
}
|
|
29
80
|
function parseErrorCode(body) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
126
|
+
|
|
127
|
+
// src/email.ts
|
|
128
|
+
var DEFAULT_SEND_PATH = "/v1/messaging/email/send";
|
|
66
129
|
async function sendLovableEmail(payload, options) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
182
|
+
return parseEmailWebhookPayload(body);
|
|
108
183
|
}
|
|
109
184
|
function createEmailWebhookHandler(options) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
141
|
-
|
|
218
|
+
|
|
219
|
+
// src/auth-email-handler.ts
|
|
142
220
|
function parseAuthEmailWebhookPayload(body) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
229
|
+
const match = /@([^@\s<>]+)>?\s*$/.exec(from.trim());
|
|
230
|
+
return match?.[1];
|
|
150
231
|
}
|
|
151
232
|
function createAuthEmailHandler(options) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
295
|
+
|
|
296
|
+
// src/logs.ts
|
|
297
|
+
var LOGS_PATH = "/v1/messaging/email/logs";
|
|
214
298
|
function buildLogsQuery(filters) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
229
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
323
|
+
|
|
324
|
+
// src/unsubscribe.ts
|
|
325
|
+
var UNSUBSCRIBES_PATH = "/v1/messaging/email/unsubscribes";
|
|
237
326
|
function buildUnsubscribePath(recipient, domain) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
334
|
+
return emailApiRequest(options, buildUnsubscribePath(request.recipient, request.domain));
|
|
244
335
|
}
|
|
245
336
|
async function setEmailUnsubscribe(request, options) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
337
|
+
return emailApiRequest(options, buildUnsubscribePath(request.recipient, request.domain), {
|
|
338
|
+
method: "PUT",
|
|
339
|
+
body: { subscribed: request.subscribed }
|
|
340
|
+
});
|
|
250
341
|
}
|
|
251
|
-
|
|
252
|
-
exports
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
+
});
|