@cms0/transactional 0.2.23 → 0.2.25
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 +1 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +45 -7
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/src/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACf,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAEV,oBAAoB,EACrB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACf,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAEV,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAiPtB,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,oBAAoB,KAC3B,cAWF,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,kBAAkB,KACzB,YAYF,CAAC;AAIF,eAAO,MAAM,sBAAsB,oBAQlC,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,SAAS,YAAY,SAE3D,CAAC;AAEF,eAAO,MAAM,wBAAwB,YAEpC,CAAC"}
|
package/dist/src/client.js
CHANGED
|
@@ -26,6 +26,45 @@ const stringifyRecipients = (value) => {
|
|
|
26
26
|
const normalized = normalizeRecipients(value);
|
|
27
27
|
return Array.isArray(normalized) ? normalized.join(", ") : normalized;
|
|
28
28
|
};
|
|
29
|
+
const normalizePlunkAddress = (value) => {
|
|
30
|
+
if (!value) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (typeof value === "string") {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
const name = value.name?.trim();
|
|
37
|
+
return name ? { email: value.email, name } : value.email;
|
|
38
|
+
};
|
|
39
|
+
const ensurePlunkAddress = (value, label) => {
|
|
40
|
+
const normalized = normalizePlunkAddress(value);
|
|
41
|
+
if (!normalized) {
|
|
42
|
+
throw new Error(`${label} email address is required.`);
|
|
43
|
+
}
|
|
44
|
+
return normalized;
|
|
45
|
+
};
|
|
46
|
+
const normalizePlunkRecipients = (value) => Array.isArray(value)
|
|
47
|
+
? value
|
|
48
|
+
.map((entry) => normalizePlunkAddress(entry))
|
|
49
|
+
.filter((entry) => Boolean(entry))
|
|
50
|
+
: ensurePlunkAddress(value, "Recipient");
|
|
51
|
+
const normalizePlunkReplyAddress = (value) => {
|
|
52
|
+
if (!value) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return typeof value === "string" ? value : value.email;
|
|
56
|
+
};
|
|
57
|
+
const getPlunkErrorMessage = (response, payload) => {
|
|
58
|
+
const baseMessage = (typeof payload?.message === "string" && payload.message.trim()) ||
|
|
59
|
+
(typeof payload?.error === "string" && payload.error.trim()) ||
|
|
60
|
+
(typeof payload?.error === "object" &&
|
|
61
|
+
payload.error?.message?.trim()) ||
|
|
62
|
+
`Failed to send email via Plunk: ${response.status} ${response.statusText}`;
|
|
63
|
+
if (!payload?.errors) {
|
|
64
|
+
return baseMessage;
|
|
65
|
+
}
|
|
66
|
+
return `${baseMessage}: ${JSON.stringify(payload.errors)}`;
|
|
67
|
+
};
|
|
29
68
|
const createLogEmailTransport = () => ({
|
|
30
69
|
kind: "log",
|
|
31
70
|
async send(message) {
|
|
@@ -92,22 +131,21 @@ const createPlunkEmailTransport = (config) => ({
|
|
|
92
131
|
const response = await fetch(`${config.baseUrl ?? DEFAULT_PLUNK_API_BASE_URL}/v1/send`, {
|
|
93
132
|
method: "POST",
|
|
94
133
|
headers: {
|
|
95
|
-
Authorization: `Bearer ${config.
|
|
134
|
+
Authorization: `Bearer ${config.secretKey}`,
|
|
96
135
|
"Content-Type": "application/json",
|
|
97
136
|
},
|
|
98
137
|
body: JSON.stringify({
|
|
99
138
|
body: message.html,
|
|
100
|
-
from:
|
|
139
|
+
from: normalizePlunkAddress(message.from),
|
|
101
140
|
headers: message.headers,
|
|
102
|
-
reply:
|
|
141
|
+
reply: normalizePlunkReplyAddress(message.replyTo),
|
|
103
142
|
subject: message.subject,
|
|
104
|
-
to: message.to,
|
|
143
|
+
to: normalizePlunkRecipients(message.to),
|
|
105
144
|
}),
|
|
106
145
|
});
|
|
107
146
|
const payload = (await response.json().catch(() => null));
|
|
108
|
-
if (!response.ok) {
|
|
109
|
-
throw new Error(payload
|
|
110
|
-
`Failed to send email via Plunk: ${response.status} ${response.statusText}`);
|
|
147
|
+
if (!response.ok || payload?.success === false) {
|
|
148
|
+
throw new Error(getPlunkErrorMessage(response, payload));
|
|
111
149
|
}
|
|
112
150
|
return {
|
|
113
151
|
accepted: Boolean(payload?.data?.emails?.length ?? 0),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cms0/transactional",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.25",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "restricted"
|
|
6
6
|
},
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@react-email/components": "^0.5.7",
|
|
28
28
|
"nodemailer": "^7.0.10",
|
|
29
|
-
"@cms0/shared": "0.2.
|
|
29
|
+
"@cms0/shared": "0.2.25"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": "^19.2.0",
|