@ehven/messaging-form-connector-brevo 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +35 -2
- package/package.json +27 -4
- package/src/send-email.mjs +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gilad Ehven
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Brevo messaging form connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@ehven/messaging-form-connector-brevo` sends an application-composed transactional email through Brevo. The server connector targets Node.js 24 or later and is MIT licensed.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @ehven/messaging-form-connector-brevo
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { sendBrevoEmail } from '@ehven/messaging-form-connector-brevo';
|
|
13
|
+
|
|
14
|
+
const receipt = await sendBrevoEmail({
|
|
15
|
+
apiKey: process.env.BREVO_API_KEY,
|
|
16
|
+
message: {
|
|
17
|
+
sender: { email: 'receipts@example.org' },
|
|
18
|
+
to: [{ email: 'visitor@example.org' }],
|
|
19
|
+
replyTo: { email: 'contact@example.org' },
|
|
20
|
+
subject: 'Message received',
|
|
21
|
+
textContent: 'Thank you for getting in touch.',
|
|
22
|
+
},
|
|
23
|
+
signal: AbortSignal.timeout(10_000),
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- Supply a Brevo account, a configured sender and a server-only API key. Message copy, recipients, reply routing, templates and tags come from the application.
|
|
28
|
+
- Success returns provider JSON or `null` when there is no JSON body. A returned `messageId` identifies Brevo's accepted request. Inbox arrival depends on later delivery. Non-success responses throw `BrevoDeliveryError` with the HTTP status. Transport and cancellation errors propagate.
|
|
29
|
+
- Pass a cancellation signal or inject `fetchImpl` for controlled testing. The connector declines redirects and makes one POST per call. Reconcile an ambiguous timeout before retrying. Keep keys, recipients and provider responses out of normal logs.
|
|
30
|
+
- When composing with core, await `sendBrevoEmail` inside the acknowledgment callback and return `{ ok: true }` after success. An acknowledgment failure still permits acceptance after a confirmed primary operation.
|
|
31
|
+
|
|
32
|
+
The transport tests use synthetic responses. Run `npm ci --ignore-scripts --offline` and `npm run check` to verify the request contract locally.
|
|
33
|
+
|
|
34
|
+
## Support
|
|
35
|
+
|
|
36
|
+
Patch releases within 0.1 are intended to be compatible. Future 0.x minor releases may change APIs. Open an issue for bugs and usage questions. For a security concern, use the contact form to request a private reporting channel and keep credentials, tokens and submissions out of the public tracker. [Issues](https://github.com/ehven-consultants-npm-products/ehven-messaging-form-connector-brevo/issues) · [Contact](https://ehven.com/contact/)
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ehven/messaging-form-connector-brevo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Send application-composed transactional email through Brevo.",
|
|
7
|
+
"exports": "./src/send-email.mjs",
|
|
8
|
+
"files": [
|
|
9
|
+
"src/send-email.mjs"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=24"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"check": "node --test test/*.test.mjs"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/ehven-consultants-npm-products/ehven-messaging-form-connector-brevo.git"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/ehven-consultants-npm-products/ehven-messaging-form-connector-brevo#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/ehven-consultants-npm-products/ehven-messaging-form-connector-brevo/issues"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const BREVO_EMAIL_ENDPOINT = 'https://api.brevo.com/v3/smtp/email';
|
|
2
|
+
|
|
3
|
+
export class BrevoDeliveryError extends Error {
|
|
4
|
+
constructor(status) {
|
|
5
|
+
super(`Brevo rejected the transactional email with status ${status}.`);
|
|
6
|
+
this.name = 'BrevoDeliveryError';
|
|
7
|
+
this.status = status;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function sendBrevoEmail({ apiKey, message, signal, fetchImpl = fetch }) {
|
|
12
|
+
if (typeof apiKey !== 'string' || !apiKey.trim() || /[\r\n]/.test(apiKey)) {
|
|
13
|
+
throw new TypeError('A Brevo API key is required.');
|
|
14
|
+
}
|
|
15
|
+
if (!message || typeof message !== 'object' || Array.isArray(message)) {
|
|
16
|
+
throw new TypeError('A Brevo message object is required.');
|
|
17
|
+
}
|
|
18
|
+
signal?.throwIfAborted();
|
|
19
|
+
|
|
20
|
+
const response = await fetchImpl(BREVO_EMAIL_ENDPOINT, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
redirect: 'manual',
|
|
23
|
+
signal,
|
|
24
|
+
headers: {
|
|
25
|
+
Accept: 'application/json',
|
|
26
|
+
'Content-Type': 'application/json',
|
|
27
|
+
'api-key': apiKey,
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify(message),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new BrevoDeliveryError(response.status);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return response.json().catch(() => null);
|
|
37
|
+
}
|