@fufulog/brevomorphic-cms-sdk 1.0.3 → 1.0.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/.kilo/worktrees/chip-sputter/INTEGRATION.md +147 -0
- package/.kilo/worktrees/chip-sputter/LICENSE +192 -0
- package/.kilo/worktrees/chip-sputter/README.md +354 -0
- package/.kilo/worktrees/chip-sputter/env.example +25 -0
- package/.kilo/worktrees/chip-sputter/prd.md +135 -0
- package/.kilo/worktrees/chip-sputter/react/BrevoWysiwyg.css +233 -0
- package/.kilo/worktrees/chip-sputter/react/BrevoWysiwyg.d.ts +16 -0
- package/.kilo/worktrees/chip-sputter/react/BrevoWysiwyg.tsx +387 -0
- package/.kilo/worktrees/chip-sputter/src/brevoClient.ts +183 -0
- package/.kilo/worktrees/chip-sputter/src/controller.ts +186 -0
- package/.kilo/worktrees/chip-sputter/src/index.ts +5 -0
- package/.kilo/worktrees/chip-sputter/src/repository.ts +244 -0
- package/.kilo/worktrees/chip-sputter/src/service.ts +221 -0
- package/.kilo/worktrees/chip-sputter/src/types.ts +77 -0
- package/.kilo/worktrees/chip-sputter/svelte/BrevoWysiwyg.svelte +639 -0
- package/.kilo/worktrees/chip-sputter/svelte/BrevoWysiwyg.svelte.d.ts +10 -0
- package/.kilo/worktrees/chip-sputter/tests/sdk.test.ts +239 -0
- package/.kilo/worktrees/chip-sputter/tsconfig.json +16 -0
- package/dist/controller.d.ts +2 -2
- package/dist/controller.js +17 -3
- package/package.json +39 -3
- package/react/BrevoWysiwyg.d.ts +16 -0
- package/src/controller.ts +20 -3
- package/svelte/BrevoWysiwyg.svelte.d.ts +10 -0
- package/tests/sdk.test.ts +14 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Brevo CMS SDK - Host Integration Reference Notes
|
|
2
|
+
|
|
3
|
+
These integration notes document the implementation patterns, ESM target configurations, and routing setups utilized when embedding the `brevoCMS` SDK into a React/Vite/Express workspace.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Environment Configurations
|
|
8
|
+
|
|
9
|
+
Make sure to define these keys in the host environment (`.env`):
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Brevo SMTP Configuration
|
|
13
|
+
BREVO_API_KEY="xkeysib-..."
|
|
14
|
+
BREVO_DEFAULT_SENDER_EMAIL="info@yourdomain.com"
|
|
15
|
+
BREVO_DEFAULT_SENDER_NAME="Your Brand Name"
|
|
16
|
+
DB_TYPE="firestore" # or 'postgres' | 'mysql'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 2. ESM Target Module Fixes
|
|
22
|
+
|
|
23
|
+
If your host application is configured to run as an ES Module (`"type": "module"` in `package.json`), you must build the `@fufulog/brevomorphic-cms-sdk` to match ESM:
|
|
24
|
+
|
|
25
|
+
1. Add `"type": "module"` to `brevoCMS/package.json` so TypeScript compiles native ES imports/exports.
|
|
26
|
+
2. Compile/rebuild the package:
|
|
27
|
+
```bash
|
|
28
|
+
npm run build
|
|
29
|
+
```
|
|
30
|
+
This ensures the output in `dist/` is compiled with standard `export` and `import` syntax instead of CommonJS `require`/`exports`, preventing `"exports is not defined"` errors in Vite SSR environments.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 3. Dev Server Proxy Routing
|
|
35
|
+
|
|
36
|
+
In Vite environments using Express API middlewares, Vite must be explicitly instructed to forward the CMS endpoints to the Express instance.
|
|
37
|
+
|
|
38
|
+
Update the API routing middleware check in `vite.config.ts` to intercept `/api/cms`:
|
|
39
|
+
```typescript
|
|
40
|
+
if (req.url && (
|
|
41
|
+
req.url.startsWith('/api/payments') ||
|
|
42
|
+
req.url.startsWith('/api/scanner') ||
|
|
43
|
+
req.url.startsWith('/api/cms') // Ensure this is captured
|
|
44
|
+
)) {
|
|
45
|
+
// Forward to Express server module...
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
Failing to include this causes Vite to fall back to serving the SPA's `index.html` (returning `<!doctype html...`), resulting in JSON parse errors.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 4. API Response Mapping Guardrails
|
|
53
|
+
|
|
54
|
+
The SDK returns templates matching Brevo's naming conventions, returning properties `templateId` and `templateName`.
|
|
55
|
+
When listing and selecting templates in your React dashboard UI, ensure you map these keys to local frontend properties:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const handleSelectTemplate = async (template) => {
|
|
59
|
+
const res = await fetch(`/api/cms/templates/${template.id}`);
|
|
60
|
+
const json = await res.json();
|
|
61
|
+
if (json.success) {
|
|
62
|
+
const t = json.data;
|
|
63
|
+
setEditingTemplate({
|
|
64
|
+
id: t.templateId, // Map templateId -> id
|
|
65
|
+
name: t.templateName, // Map templateName -> name
|
|
66
|
+
subject: t.subject,
|
|
67
|
+
htmlContent: t.htmlContent,
|
|
68
|
+
isActive: t.isActive,
|
|
69
|
+
eventName: t.eventName,
|
|
70
|
+
sender: t.sender,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 5. Event Trigger Implementation
|
|
79
|
+
|
|
80
|
+
Trigger outbound event-driven transactional mailings by passing a recipient email and variables context:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { cmsService } from './server/cms.js';
|
|
84
|
+
|
|
85
|
+
// Inside Checkout / Payment Success Handlers:
|
|
86
|
+
await cmsService.sendEventEmail('order.completed', email, {
|
|
87
|
+
customerName: profile.name,
|
|
88
|
+
orderId: order.id,
|
|
89
|
+
totalAmount: order.total,
|
|
90
|
+
currency: order.currency,
|
|
91
|
+
itemsCount: order.items.length,
|
|
92
|
+
appUrl: 'https://yourdomain.com'
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Inside User Registration Handlers:
|
|
96
|
+
await cmsService.sendEventEmail('user.welcome', email, {
|
|
97
|
+
customerName: profile.name,
|
|
98
|
+
signupDate: new Date().toLocaleDateString()
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
The SDK runs outbound event-check safety checks. If the template is unassigned, missing, or inactive (`isActive` is false), the send is safely ignored without breaking transaction flows.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 6. Brevo Template Loops & Object Decomposition
|
|
106
|
+
|
|
107
|
+
When passing arrays of objects (like tickets or shopping cart items) to Brevo transactional templates, use **Brevo's native template language** (based on Django/Jinja syntax):
|
|
108
|
+
|
|
109
|
+
### Loop Syntax & Decomposing Properties
|
|
110
|
+
* **Root Scope**: All variables passed via `sendEventEmail` reside under the `params` object (e.g. `params.tickets`).
|
|
111
|
+
* **Loop Declaration**: Loop through the array using `{% for %}` tags:
|
|
112
|
+
```django
|
|
113
|
+
{% for item in params.tickets %}
|
|
114
|
+
<!-- Decompose attributes directly from the loop item -->
|
|
115
|
+
<h3>{{ item.name }}</h3>
|
|
116
|
+
<p>Ticket ID: {{ item.ticketId }}</p>
|
|
117
|
+
<p>Attendee: {{ item.attendeeName }}</p>
|
|
118
|
+
<!-- Render QR code dynamically using the standard image tag -->
|
|
119
|
+
<img src="{{ item.qrCodeUrl }}" width="110" height="110" alt="QR Code" />
|
|
120
|
+
{% endfor %}
|
|
121
|
+
```
|
|
122
|
+
* **Gmail/Email Client Compatibility Warning**: Gmail strips inline `<svg>` blocks and inline base64-encoded images. To guarantee delivery across all devices, pass a hosted/generated PNG dynamic URL (such as GoQR/QRServer) and render it inside a standard `<img />` tag.
|
|
123
|
+
|
|
124
|
+
### Example Transactional Dispatch (Tickets)
|
|
125
|
+
```typescript
|
|
126
|
+
await cmsService.sendEventEmail('order.tickets', email, {
|
|
127
|
+
customerName: profile.name,
|
|
128
|
+
orderId: order.id,
|
|
129
|
+
appUrl: 'https://yourdomain.com',
|
|
130
|
+
tickets: [
|
|
131
|
+
{
|
|
132
|
+
name: 'VIP Admission Pass',
|
|
133
|
+
ticketId: 'tkt_VIP123',
|
|
134
|
+
orderIdShort: 'ORD-1234',
|
|
135
|
+
dateRange: 'Oct 15 - 17, 2026',
|
|
136
|
+
timeRange: '10am to 4pm',
|
|
137
|
+
location: 'Design Center, NY',
|
|
138
|
+
entryType: 'Multi Entry',
|
|
139
|
+
isMultiDay: true,
|
|
140
|
+
purchasedDate: '2026-05-28',
|
|
141
|
+
attendeeName: 'Jane Doe',
|
|
142
|
+
qrCodeUrl: 'https://api.qrserver.com/v1/create-qr-code/?size=220x220&margin=0&data=tkt_VIP123'
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, be controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf
|
|
54
|
+
of the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if distributed along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
LIABLE to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
Copyright [2026] [Joseph Quesnel / TicketHouse LLC]
|
|
181
|
+
|
|
182
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
183
|
+
you may not use this file except in compliance with the License.
|
|
184
|
+
You may obtain a copy of the License at
|
|
185
|
+
|
|
186
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
187
|
+
|
|
188
|
+
Unless required by applicable law or agreed to in writing, software
|
|
189
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
190
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
191
|
+
See the License for the specific language governing permissions and
|
|
192
|
+
limitations under the License.
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
# Brevo CMS Email Bootstrap SDK
|
|
2
|
+
|
|
3
|
+
A modular, lightweight, and robust Node.js SDK to synchronize and bootstrap Brevo email templates directly with local application backend events.
|
|
4
|
+
|
|
5
|
+
It provides an out-of-the-box system that syncs metadata from Brevo SMTP templates, saves target-event routing parameters in a local mapping database, runs Just-In-Time (JIT) sync, enforces visual guardrails, and exports plug-and-play Express controllers.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## How to Install
|
|
10
|
+
|
|
11
|
+
### 1. Install the SDK
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @fufulog/brevomorphic-cms-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 2. Set Environment Variables
|
|
18
|
+
|
|
19
|
+
Copy the example env and fill in your credentials:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cp node_modules/@fufulog/brevomorphic-cms-sdk/env.example .env
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Required variables:
|
|
26
|
+
|
|
27
|
+
| Variable | Description |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| `BREVO_API_KEY` | Your Brevo API key (`xkeysib-...`) |
|
|
30
|
+
| `DEFAULT_SENDER_EMAIL` | Verified sender email address |
|
|
31
|
+
| `DB_TYPE` | `postgres`, `mysql`, or `firestore` |
|
|
32
|
+
| `DATABASE_URL` | Connection string (SQL) or Firebase credentials (Firestore) |
|
|
33
|
+
|
|
34
|
+
### 3. Create the Mapping Table
|
|
35
|
+
|
|
36
|
+
Run the appropriate schema migration for your database (see [Database Setup](#1-database-setup) below).
|
|
37
|
+
|
|
38
|
+
### 4. Bootstrap in Your App
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
import { EmailTemplateService, EmailTemplateController } from '@fufulog/brevomorphic-cms-sdk';
|
|
42
|
+
import express from 'express';
|
|
43
|
+
|
|
44
|
+
const emailService = new EmailTemplateService({
|
|
45
|
+
brevoApiKey: process.env.BREVO_API_KEY,
|
|
46
|
+
defaultSender: { email: process.env.DEFAULT_SENDER_EMAIL },
|
|
47
|
+
dbType: 'postgres', // or 'mysql' | 'firestore'
|
|
48
|
+
dbClient: yourDbClient,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const app = express();
|
|
52
|
+
app.use(express.json());
|
|
53
|
+
app.use('/api/cms', new EmailTemplateController(emailService).getRouter());
|
|
54
|
+
|
|
55
|
+
app.listen(3000);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 5. (Optional) Add the WYSIWYG Editor Component
|
|
59
|
+
|
|
60
|
+
The SDK ships drop-in WYSIWYG editor components for **Svelte** and **React**. Copy the component files from the SDK into your frontend project:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Svelte
|
|
64
|
+
cp node_modules/@fufulog/brevomorphic-cms-sdk/svelte/BrevoWysiwyg.svelte src/components/
|
|
65
|
+
|
|
66
|
+
# React
|
|
67
|
+
cp node_modules/@fufulog/brevomorphic-cms-sdk/react/BrevoWysiwyg.tsx src/components/
|
|
68
|
+
cp node_modules/@fufulog/brevomorphic-cms-sdk/react/BrevoWysiwyg.css src/components/
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
See [WYSIWYG Editor Components](#6-wysiwyg-editor-components) for full usage details.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Features
|
|
76
|
+
|
|
77
|
+
- **JIT Local Mapping Engine:** Automatic initialization of local routing templates if a new template is created directly on Brevo.
|
|
78
|
+
- **Outbound Send Guardrail:** Built-in safeguards that silently ignore disabled templates to protect transaction processing systems.
|
|
79
|
+
- **Multi-Database Support:** Native integration with **PostgreSQL**, **MySQL**, and **Google Cloud Firestore NoSQL** with zero code changes.
|
|
80
|
+
- **Plug-and-Play Routing:** Ready-to-mount Express Router exposing CRUD, activation toggles, verified sender lookups, and webhook routes.
|
|
81
|
+
- **WYSIWYG Editor Components:** Bundled Svelte and React editor components with source toggle, formatting toolbar, and Brevo variable injection.
|
|
82
|
+
- **Type Safety:** Full TypeScript declarations (`.d.ts`) included out of the box.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## 1. Database Setup
|
|
87
|
+
|
|
88
|
+
### SQL (PostgreSQL & MySQL)
|
|
89
|
+
Create the mapping ledger table using the appropriate schema block. By default, the SDK looks for the `email_event_templates` table.
|
|
90
|
+
|
|
91
|
+
#### **PostgreSQL**
|
|
92
|
+
```sql
|
|
93
|
+
CREATE TABLE email_event_templates (
|
|
94
|
+
id SERIAL PRIMARY KEY,
|
|
95
|
+
template_id INT NOT NULL UNIQUE, -- Bridges to Brevo template ID
|
|
96
|
+
event_name VARCHAR(255) DEFAULT '', -- Links backend trigger key (e.g., ticket.preapproved)
|
|
97
|
+
is_active BOOLEAN DEFAULT false, -- Master toggle for active sends
|
|
98
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
99
|
+
);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### **MySQL**
|
|
103
|
+
```sql
|
|
104
|
+
CREATE TABLE email_event_templates (
|
|
105
|
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
106
|
+
template_id INT NOT NULL UNIQUE,
|
|
107
|
+
event_name VARCHAR(255) DEFAULT '',
|
|
108
|
+
is_active TINYINT(1) DEFAULT 0,
|
|
109
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
110
|
+
);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### NoSQL (Firestore)
|
|
114
|
+
No collection schema is required. Simply create a document collection named `email_event_templates` (customizable) in your Firestore database. The SDK will automatically structure documents with:
|
|
115
|
+
- **Document ID:** Stringified template ID (e.g. `"42"`)
|
|
116
|
+
- **Fields:**
|
|
117
|
+
- `template_id`: `number`
|
|
118
|
+
- `event_name`: `string`
|
|
119
|
+
- `is_active`: `boolean`
|
|
120
|
+
- `updated_at`: `timestamp`
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 2. Bootstrapping the SDK
|
|
125
|
+
|
|
126
|
+
To bootstrap the SDK in your application, instantiate `EmailTemplateService` by supplying a database driver instance (Postgres Pool, MySQL connection, or Firestore client instance) and the Brevo configuration.
|
|
127
|
+
|
|
128
|
+
### **Recipe A: PostgreSQL (using `pg` Pool)**
|
|
129
|
+
```javascript
|
|
130
|
+
import pg from 'pg';
|
|
131
|
+
import { EmailTemplateService } from '@fufulog/brevomorphic-cms-sdk';
|
|
132
|
+
|
|
133
|
+
const pgPool = new pg.Pool({
|
|
134
|
+
connectionString: process.env.DATABASE_URL
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Configure the SDK using a wrapper matching { query: (sql, params) => Promise<any> }
|
|
138
|
+
const emailService = new EmailTemplateService({
|
|
139
|
+
brevoApiKey: process.env.BREVO_API_KEY,
|
|
140
|
+
defaultSender: {
|
|
141
|
+
name: "Billing Desk",
|
|
142
|
+
email: "billing@yourdomain.com"
|
|
143
|
+
},
|
|
144
|
+
dbType: 'postgres',
|
|
145
|
+
dbClient: pgPool, // Standard pg Pool works natively
|
|
146
|
+
tableNameOrCollection: 'email_event_templates'
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### **Recipe B: MySQL (using `mysql2/promise` Pool)**
|
|
151
|
+
```javascript
|
|
152
|
+
import mysql from 'mysql2/promise';
|
|
153
|
+
import { EmailTemplateService } from '@fufulog/brevomorphic-cms-sdk';
|
|
154
|
+
|
|
155
|
+
const mysqlPool = await mysql.createPool({
|
|
156
|
+
host: process.env.DB_HOST,
|
|
157
|
+
user: process.env.DB_USER,
|
|
158
|
+
password: process.env.DB_PASSWORD,
|
|
159
|
+
database: process.env.DB_NAME
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const emailService = new EmailTemplateService({
|
|
163
|
+
brevoApiKey: process.env.BREVO_API_KEY,
|
|
164
|
+
defaultSender: {
|
|
165
|
+
name: "Customer Support",
|
|
166
|
+
email: "support@yourdomain.com"
|
|
167
|
+
},
|
|
168
|
+
dbType: 'mysql',
|
|
169
|
+
dbClient: mysqlPool, // Standard mysql2 promise pool works natively
|
|
170
|
+
tableNameOrCollection: 'email_event_templates'
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### **Recipe C: Firestore NoSQL (using `firebase-admin/firestore`)**
|
|
175
|
+
```javascript
|
|
176
|
+
import { initializeApp, cert } from 'firebase-admin/app';
|
|
177
|
+
import { getFirestore } from 'firebase-admin/firestore';
|
|
178
|
+
import { EmailTemplateService } from '@fufulog/brevomorphic-cms-sdk';
|
|
179
|
+
|
|
180
|
+
// Initialize Firebase SDK
|
|
181
|
+
initializeApp({
|
|
182
|
+
credential: cert(JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT_JSON))
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const firestoreDb = getFirestore();
|
|
186
|
+
|
|
187
|
+
const emailService = new EmailTemplateService({
|
|
188
|
+
brevoApiKey: process.env.BREVO_API_KEY,
|
|
189
|
+
defaultSender: {
|
|
190
|
+
name: "System Gateway",
|
|
191
|
+
email: "noreply@yourdomain.com"
|
|
192
|
+
},
|
|
193
|
+
dbType: 'firestore',
|
|
194
|
+
dbClient: firestoreDb, // Standard Firestore client works natively
|
|
195
|
+
tableNameOrCollection: 'email_event_templates'
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## 3. Mounting the Routing Layer (Express Server)
|
|
202
|
+
|
|
203
|
+
Instantiate `EmailTemplateController` by passing your bootstrapped `EmailTemplateService` and mounting the routes directly inside your Express router.
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
import express from 'express';
|
|
207
|
+
import { EmailTemplateController } from '@fufulog/brevomorphic-cms-sdk';
|
|
208
|
+
|
|
209
|
+
const app = express();
|
|
210
|
+
app.use(express.json());
|
|
211
|
+
|
|
212
|
+
// Create and mount CMS routes
|
|
213
|
+
const emailController = new EmailTemplateController(emailService);
|
|
214
|
+
app.use('/api/cms', emailController.getRouter());
|
|
215
|
+
|
|
216
|
+
// Start Server
|
|
217
|
+
app.listen(3000, () => {
|
|
218
|
+
console.log('🚀 Brevo CMS mounting on http://localhost:3000/api/cms');
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### **Exposed Routes**
|
|
223
|
+
| Method | Route | Description |
|
|
224
|
+
| --- | --- | --- |
|
|
225
|
+
| **GET** | `/api/cms/templates` | Lists templates with combined remote + local database JIT synchronization. |
|
|
226
|
+
| **GET** | `/api/cms/templates/:id` | Returns visual parameters, subject, HTML code block, and links for a specific template. |
|
|
227
|
+
| **POST** | `/api/cms/templates` | Creates a new draft template on Brevo & hooks up blank local DB mappings. |
|
|
228
|
+
| **PUT** | `/api/cms/templates/:id` | Updates name, subject, HTML markup body, and local target event assignment. |
|
|
229
|
+
| **POST** | `/api/cms/templates/:id/toggle` | Activates/deactivates template remotely on Brevo and locally inside DB mapping. |
|
|
230
|
+
| **GET** | `/api/cms/senders` | Pulls verified sender dropdown configurations from Brevo. |
|
|
231
|
+
| **POST** | `/api/cms/send` | Triggers test sends for a specific mapping. |
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## 4. Operational Workflows (Outbound Sends)
|
|
236
|
+
|
|
237
|
+
In your application code, whenever a business operation completes (e.g. user welcome, ticket pre-approval), call the SDK directly to send an event email.
|
|
238
|
+
|
|
239
|
+
The SDK automatically runs event guardrails: if no active template is associated with the event, or if it has been deactivated on the dashboard, it is ignored safely.
|
|
240
|
+
|
|
241
|
+
```javascript
|
|
242
|
+
// Welcome Event Trigger
|
|
243
|
+
app.post('/api/users/signup', async (req, res) => {
|
|
244
|
+
const newUser = await createUser(req.body);
|
|
245
|
+
|
|
246
|
+
// Trigger event-driven outbound send.
|
|
247
|
+
// If template is inactive (is_active = false) or event mapping doesn't exist, it skips it.
|
|
248
|
+
const outcome = await emailService.sendEventEmail('user.welcome', newUser.email, {
|
|
249
|
+
customer_name: newUser.name,
|
|
250
|
+
signup_date: new Date().toLocaleDateString()
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
console.log(outcome.message); // Logs status outcome safely
|
|
254
|
+
res.status(201).json({ success: true, user: newUser });
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## 5. Visual Form Validation Guards
|
|
261
|
+
|
|
262
|
+
When calling `emailService.updateTemplate(id, data)` or hitting `PUT /api/cms/templates/:id`, the SDK automatically protects Brevo's API by enforcing boundary conditions:
|
|
263
|
+
- **Blank Names:** Rejected. Form fields require unique template name keys.
|
|
264
|
+
- **Short HTML:** Brevo servers reject payloads with missing layouts. The SDK validates that raw HTML blocks must be longer than 10 characters before transmitting.
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## 6. WYSIWYG Editor Components
|
|
269
|
+
|
|
270
|
+
The SDK ships drop-in WYSIWYG editor components for **Svelte** and **React**. These are zero-dependency source files you copy into your frontend project — no extra `npm install` required.
|
|
271
|
+
|
|
272
|
+
### Key Features
|
|
273
|
+
|
|
274
|
+
- **Formatting Toolbar:** Bold, Italic, Underline, Strikethrough, Headings, Lists, Alignment, Links
|
|
275
|
+
- **Source Toggle:** Switch between rich-text and raw HTML editing
|
|
276
|
+
- **Variable Injector:** Insert Brevo Twig expressions (`{{ params.name }}`) at cursor position
|
|
277
|
+
- **Twig Bracket Protection:** Does **not** escape `{`, `}`, or `%` — safe for Brevo's template engine
|
|
278
|
+
|
|
279
|
+
### Svelte Usage
|
|
280
|
+
|
|
281
|
+
```svelte
|
|
282
|
+
<script>
|
|
283
|
+
import BrevoWysiwyg from './BrevoWysiwyg.svelte';
|
|
284
|
+
|
|
285
|
+
let htmlContent = '';
|
|
286
|
+
|
|
287
|
+
const variables = [
|
|
288
|
+
{ label: 'Customer Name', key: 'params.name' },
|
|
289
|
+
{ label: 'Ticket Code', key: 'params.ticket_code' },
|
|
290
|
+
{ label: 'Signup Date', key: 'params.signup_date' }
|
|
291
|
+
];
|
|
292
|
+
</script>
|
|
293
|
+
|
|
294
|
+
<BrevoWysiwyg
|
|
295
|
+
bind:value={htmlContent}
|
|
296
|
+
{variables}
|
|
297
|
+
placeholder="Design your email layout..."
|
|
298
|
+
on:change={(e) => console.log('HTML changed:', e.detail)}
|
|
299
|
+
/>
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### React Usage
|
|
303
|
+
|
|
304
|
+
```tsx
|
|
305
|
+
import { useState } from 'react';
|
|
306
|
+
import BrevoWysiwyg from './BrevoWysiwyg';
|
|
307
|
+
|
|
308
|
+
function TemplateEditor() {
|
|
309
|
+
const [htmlContent, setHtmlContent] = useState('');
|
|
310
|
+
|
|
311
|
+
const variables = [
|
|
312
|
+
{ label: 'Customer Name', key: 'params.name' },
|
|
313
|
+
{ label: 'Ticket Code', key: 'params.ticket_code' },
|
|
314
|
+
{ label: 'Signup Date', key: 'params.signup_date' }
|
|
315
|
+
];
|
|
316
|
+
|
|
317
|
+
return (
|
|
318
|
+
<BrevoWysiwyg
|
|
319
|
+
value={htmlContent}
|
|
320
|
+
onChange={setHtmlContent}
|
|
321
|
+
variables={variables}
|
|
322
|
+
placeholder="Design your email layout..."
|
|
323
|
+
/>
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Props
|
|
329
|
+
|
|
330
|
+
| Prop | Type | Default | Description |
|
|
331
|
+
| --- | --- | --- | --- |
|
|
332
|
+
| `value` | `string` | `''` | Raw HTML content (two-way bind in Svelte, controlled in React) |
|
|
333
|
+
| `onChange` | `(html: string) => void` | — | Callback when content changes (React only) |
|
|
334
|
+
| `variables` | `{ label: string, key: string }[]` | `[]` | Available Brevo template variables |
|
|
335
|
+
| `placeholder` | `string` | `'Start designing...'` | Placeholder text |
|
|
336
|
+
| `disabled` | `boolean` | `false` | Disables editing |
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## License
|
|
341
|
+
|
|
342
|
+
Copyright [2026] [Joseph Quesnel / TicketHouse LLC]
|
|
343
|
+
|
|
344
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
345
|
+
you may not use this file except in compliance with the License.
|
|
346
|
+
You may obtain a copy of the License at
|
|
347
|
+
|
|
348
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
349
|
+
|
|
350
|
+
Unless required by applicable law or agreed to in writing, software
|
|
351
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
352
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
353
|
+
See the License for the specific language governing permissions and
|
|
354
|
+
limitations under the License.
|