resend 6.8.0 → 6.9.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/dist/index.cjs +130 -16
- package/dist/index.d.cts +226 -143
- package/dist/index.d.mts +226 -143
- package/dist/index.mjs +130 -16
- package/package.json +8 -6
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
let mailparser = require("mailparser");
|
|
1
2
|
let svix = require("svix");
|
|
2
3
|
|
|
3
4
|
//#region package.json
|
|
4
|
-
var version = "6.
|
|
5
|
+
var version = "6.9.0";
|
|
5
6
|
|
|
6
7
|
//#endregion
|
|
7
8
|
//#region src/common/utils/build-pagination-query.ts
|
|
@@ -73,13 +74,13 @@ function parseEmailToApiOptions(email) {
|
|
|
73
74
|
//#endregion
|
|
74
75
|
//#region src/render.ts
|
|
75
76
|
async function render(node) {
|
|
76
|
-
let render
|
|
77
|
+
let render;
|
|
77
78
|
try {
|
|
78
|
-
({render
|
|
79
|
+
({render} = await import("@react-email/render"));
|
|
79
80
|
} catch {
|
|
80
81
|
throw new Error("Failed to render React component. Make sure to install `@react-email/render` or `@react-email/components`.");
|
|
81
82
|
}
|
|
82
|
-
return render
|
|
83
|
+
return render(node);
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
//#endregion
|
|
@@ -350,27 +351,40 @@ var Contacts = class {
|
|
|
350
351
|
this.segments = new ContactSegments(this.resend);
|
|
351
352
|
}
|
|
352
353
|
async create(payload, options = {}) {
|
|
353
|
-
if (
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
354
|
+
if ("audienceId" in payload) {
|
|
355
|
+
if ("segments" in payload || "topics" in payload) return {
|
|
356
|
+
data: null,
|
|
357
|
+
headers: null,
|
|
358
|
+
error: {
|
|
359
|
+
message: "`audienceId` is deprecated, and cannot be used together with `segments` or `topics`. Use `segments` instead to add one or more segments to the new contact.",
|
|
360
|
+
statusCode: null,
|
|
361
|
+
name: "invalid_parameter"
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
return await this.resend.post(`/audiences/${payload.audienceId}/contacts`, {
|
|
365
|
+
unsubscribed: payload.unsubscribed,
|
|
366
|
+
email: payload.email,
|
|
367
|
+
first_name: payload.firstName,
|
|
368
|
+
last_name: payload.lastName,
|
|
369
|
+
properties: payload.properties
|
|
370
|
+
}, options);
|
|
371
|
+
}
|
|
372
|
+
return await this.resend.post("/contacts", {
|
|
361
373
|
unsubscribed: payload.unsubscribed,
|
|
362
374
|
email: payload.email,
|
|
363
375
|
first_name: payload.firstName,
|
|
364
376
|
last_name: payload.lastName,
|
|
365
|
-
properties: payload.properties
|
|
377
|
+
properties: payload.properties,
|
|
378
|
+
segments: payload.segments,
|
|
379
|
+
topics: payload.topics
|
|
366
380
|
}, options);
|
|
367
381
|
}
|
|
368
382
|
async list(options = {}) {
|
|
369
383
|
const segmentId = options.segmentId ?? options.audienceId;
|
|
370
384
|
if (!segmentId) {
|
|
371
|
-
const queryString
|
|
372
|
-
const url
|
|
373
|
-
return await this.resend.get(url
|
|
385
|
+
const queryString = buildPaginationQuery(options);
|
|
386
|
+
const url = queryString ? `/contacts?${queryString}` : "/contacts";
|
|
387
|
+
return await this.resend.get(url);
|
|
374
388
|
}
|
|
375
389
|
const queryString = buildPaginationQuery(options);
|
|
376
390
|
const url = queryString ? `/segments/${segmentId}/contacts?${queryString}` : `/segments/${segmentId}/contacts`;
|
|
@@ -527,6 +541,106 @@ var Receiving = class {
|
|
|
527
541
|
const url = queryString ? `/emails/receiving?${queryString}` : "/emails/receiving";
|
|
528
542
|
return await this.resend.get(url);
|
|
529
543
|
}
|
|
544
|
+
async forward(options) {
|
|
545
|
+
const { emailId, to, from } = options;
|
|
546
|
+
const passthrough = options.passthrough !== false;
|
|
547
|
+
const emailResponse = await this.get(emailId);
|
|
548
|
+
if (emailResponse.error) return {
|
|
549
|
+
data: null,
|
|
550
|
+
error: emailResponse.error,
|
|
551
|
+
headers: emailResponse.headers
|
|
552
|
+
};
|
|
553
|
+
const email = emailResponse.data;
|
|
554
|
+
const originalSubject = email.subject || "(no subject)";
|
|
555
|
+
if (passthrough) return this.forwardPassthrough(email, {
|
|
556
|
+
to,
|
|
557
|
+
from,
|
|
558
|
+
subject: originalSubject
|
|
559
|
+
});
|
|
560
|
+
const forwardSubject = originalSubject.startsWith("Fwd:") ? originalSubject : `Fwd: ${originalSubject}`;
|
|
561
|
+
return this.forwardWrapped(email, {
|
|
562
|
+
to,
|
|
563
|
+
from,
|
|
564
|
+
subject: forwardSubject,
|
|
565
|
+
text: "text" in options ? options.text : void 0,
|
|
566
|
+
html: "html" in options ? options.html : void 0
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
async forwardPassthrough(email, options) {
|
|
570
|
+
const { to, from, subject } = options;
|
|
571
|
+
if (!email.raw?.download_url) return {
|
|
572
|
+
data: null,
|
|
573
|
+
error: {
|
|
574
|
+
name: "validation_error",
|
|
575
|
+
message: "Raw email content is not available for this email",
|
|
576
|
+
statusCode: 400
|
|
577
|
+
},
|
|
578
|
+
headers: null
|
|
579
|
+
};
|
|
580
|
+
const rawResponse = await fetch(email.raw.download_url);
|
|
581
|
+
if (!rawResponse.ok) return {
|
|
582
|
+
data: null,
|
|
583
|
+
error: {
|
|
584
|
+
name: "application_error",
|
|
585
|
+
message: "Failed to download raw email content",
|
|
586
|
+
statusCode: rawResponse.status
|
|
587
|
+
},
|
|
588
|
+
headers: null
|
|
589
|
+
};
|
|
590
|
+
const parsed = await (0, mailparser.simpleParser)(await rawResponse.text(), { skipImageLinks: true });
|
|
591
|
+
const attachments = parsed.attachments.map((attachment) => {
|
|
592
|
+
const contentId = attachment.contentId ? attachment.contentId.replace(/^<|>$/g, "") : void 0;
|
|
593
|
+
return {
|
|
594
|
+
filename: attachment.filename,
|
|
595
|
+
content: attachment.content.toString("base64"),
|
|
596
|
+
content_type: attachment.contentType,
|
|
597
|
+
content_id: contentId || void 0
|
|
598
|
+
};
|
|
599
|
+
});
|
|
600
|
+
return await this.resend.post("/emails", {
|
|
601
|
+
from,
|
|
602
|
+
to,
|
|
603
|
+
subject,
|
|
604
|
+
text: parsed.text || void 0,
|
|
605
|
+
html: parsed.html || void 0,
|
|
606
|
+
attachments: attachments.length > 0 ? attachments : void 0
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
async forwardWrapped(email, options) {
|
|
610
|
+
const { to, from, subject, text, html } = options;
|
|
611
|
+
if (!email.raw?.download_url) return {
|
|
612
|
+
data: null,
|
|
613
|
+
error: {
|
|
614
|
+
name: "validation_error",
|
|
615
|
+
message: "Raw email content is not available for this email",
|
|
616
|
+
statusCode: 400
|
|
617
|
+
},
|
|
618
|
+
headers: null
|
|
619
|
+
};
|
|
620
|
+
const rawResponse = await fetch(email.raw.download_url);
|
|
621
|
+
if (!rawResponse.ok) return {
|
|
622
|
+
data: null,
|
|
623
|
+
error: {
|
|
624
|
+
name: "application_error",
|
|
625
|
+
message: "Failed to download raw email content",
|
|
626
|
+
statusCode: rawResponse.status
|
|
627
|
+
},
|
|
628
|
+
headers: null
|
|
629
|
+
};
|
|
630
|
+
const rawEmailContent = await rawResponse.text();
|
|
631
|
+
return await this.resend.post("/emails", {
|
|
632
|
+
from,
|
|
633
|
+
to,
|
|
634
|
+
subject,
|
|
635
|
+
text,
|
|
636
|
+
html,
|
|
637
|
+
attachments: [{
|
|
638
|
+
filename: "forwarded_message.eml",
|
|
639
|
+
content: Buffer.from(rawEmailContent).toString("base64"),
|
|
640
|
+
content_type: "message/rfc822"
|
|
641
|
+
}]
|
|
642
|
+
});
|
|
643
|
+
}
|
|
530
644
|
};
|
|
531
645
|
|
|
532
646
|
//#endregion
|