@deenruv/email-plugin 1.0.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 +23 -0
- package/README.md +85 -0
- package/dev-mailbox.html +218 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +30 -0
- package/lib/index.js.map +1 -0
- package/lib/src/attachment-utils.d.ts +3 -0
- package/lib/src/attachment-utils.js +66 -0
- package/lib/src/attachment-utils.js.map +1 -0
- package/lib/src/common.d.ts +4 -0
- package/lib/src/common.js +17 -0
- package/lib/src/common.js.map +1 -0
- package/lib/src/constants.d.ts +2 -0
- package/lib/src/constants.js +6 -0
- package/lib/src/constants.js.map +1 -0
- package/lib/src/dev-mailbox.d.ts +14 -0
- package/lib/src/dev-mailbox.js +116 -0
- package/lib/src/dev-mailbox.js.map +1 -0
- package/lib/src/email-processor.d.ts +21 -0
- package/lib/src/email-processor.js +109 -0
- package/lib/src/email-processor.js.map +1 -0
- package/lib/src/email-send-event.d.ts +18 -0
- package/lib/src/email-send-event.js +24 -0
- package/lib/src/email-send-event.js.map +1 -0
- package/lib/src/event-listener.d.ts +19 -0
- package/lib/src/event-listener.js +25 -0
- package/lib/src/event-listener.js.map +1 -0
- package/lib/src/generator/email-generator.d.ts +25 -0
- package/lib/src/generator/email-generator.js +3 -0
- package/lib/src/generator/email-generator.js.map +1 -0
- package/lib/src/generator/handlebars-mjml-generator.d.ts +19 -0
- package/lib/src/generator/handlebars-mjml-generator.js +78 -0
- package/lib/src/generator/handlebars-mjml-generator.js.map +1 -0
- package/lib/src/generator/noop-email-generator.d.ts +11 -0
- package/lib/src/generator/noop-email-generator.js +13 -0
- package/lib/src/generator/noop-email-generator.js.map +1 -0
- package/lib/src/generator/react-email-generator.d.ts +7 -0
- package/lib/src/generator/react-email-generator.js +40 -0
- package/lib/src/generator/react-email-generator.js.map +1 -0
- package/lib/src/handler/default-email-handlers.d.ts +32 -0
- package/lib/src/handler/default-email-handlers.js +111 -0
- package/lib/src/handler/default-email-handlers.js.map +1 -0
- package/lib/src/handler/event-handler.d.ts +276 -0
- package/lib/src/handler/event-handler.js +396 -0
- package/lib/src/handler/event-handler.js.map +1 -0
- package/lib/src/handler/mock-events.d.ts +5 -0
- package/lib/src/handler/mock-events.js +119 -0
- package/lib/src/handler/mock-events.js.map +1 -0
- package/lib/src/plugin.d.ts +301 -0
- package/lib/src/plugin.js +428 -0
- package/lib/src/plugin.js.map +1 -0
- package/lib/src/sender/email-sender.d.ts +45 -0
- package/lib/src/sender/email-sender.js +3 -0
- package/lib/src/sender/email-sender.js.map +1 -0
- package/lib/src/sender/nodemailer-email-sender.d.ts +37 -0
- package/lib/src/sender/nodemailer-email-sender.js +151 -0
- package/lib/src/sender/nodemailer-email-sender.js.map +1 -0
- package/lib/src/template-loader/file-based-template-loader.d.ts +17 -0
- package/lib/src/template-loader/file-based-template-loader.js +37 -0
- package/lib/src/template-loader/file-based-template-loader.js.map +1 -0
- package/lib/src/template-loader/react-email-template-loader.d.ts +6 -0
- package/lib/src/template-loader/react-email-template-loader.js +14 -0
- package/lib/src/template-loader/react-email-template-loader.js.map +1 -0
- package/lib/src/template-loader/template-loader.d.ts +42 -0
- package/lib/src/template-loader/template-loader.js +3 -0
- package/lib/src/template-loader/template-loader.js.map +1 -0
- package/lib/src/types.d.ts +453 -0
- package/lib/src/types.js +3 -0
- package/lib/src/types.js.map +1 -0
- package/package.json +51 -0
- package/templates/email-address-change/body.hbs +20 -0
- package/templates/email-verification/body.hbs +20 -0
- package/templates/order-confirmation/body.hbs +133 -0
- package/templates/partials/footer.hbs +10 -0
- package/templates/partials/header.hbs +18 -0
- package/templates/password-reset/body.hbs +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# License 1
|
|
2
|
+
|
|
3
|
+
The MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025-present Aexol
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
12
|
+
|
|
13
|
+
# License 2
|
|
14
|
+
|
|
15
|
+
The MIT License
|
|
16
|
+
|
|
17
|
+
Copyright (c) 2018-2025 Michael Bromley
|
|
18
|
+
|
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @deenruv/email-plugin
|
|
2
|
+
|
|
3
|
+
Generates and sends transactional emails based on Deenruv server events, using [MJML](https://mjml.io/) + [Handlebars](https://handlebarsjs.com/) templates (or [React Email](https://react.email/)) and [Nodemailer](https://nodemailer.com/) for delivery.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @deenruv/email-plugin
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { defaultEmailHandlers, EmailPlugin } from '@deenruv/email-plugin';
|
|
15
|
+
import path from 'path';
|
|
16
|
+
|
|
17
|
+
const config = {
|
|
18
|
+
plugins: [
|
|
19
|
+
EmailPlugin.init({
|
|
20
|
+
handlers: defaultEmailHandlers,
|
|
21
|
+
templatePath: path.join(__dirname, 'static/email/templates'),
|
|
22
|
+
transport: {
|
|
23
|
+
type: 'smtp',
|
|
24
|
+
host: 'smtp.example.com',
|
|
25
|
+
port: 587,
|
|
26
|
+
auth: {
|
|
27
|
+
user: 'username',
|
|
28
|
+
pass: 'password',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Dev Mode
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
EmailPlugin.init({
|
|
40
|
+
devMode: true,
|
|
41
|
+
route: 'mailbox',
|
|
42
|
+
handlers: defaultEmailHandlers,
|
|
43
|
+
templatePath: path.join(__dirname, 'static/email/templates'),
|
|
44
|
+
outputPath: path.join(__dirname, 'test-emails'),
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
In dev mode, emails are saved as HTML files and a web-based mailbox UI is available at the configured route (e.g. `http://localhost:3000/mailbox`).
|
|
49
|
+
|
|
50
|
+
**Options:**
|
|
51
|
+
|
|
52
|
+
| Option | Type | Default | Description |
|
|
53
|
+
|--------|------|---------|-------------|
|
|
54
|
+
| `handlers` | `EmailEventHandler[]` | *required* | Event handlers that define which events trigger emails |
|
|
55
|
+
| `templatePath` | `string` | - | Path to MJML/Handlebars email templates (deprecated, use `templateLoader`) |
|
|
56
|
+
| `templateLoader` | `TemplateLoader` | `FileBasedTemplateLoader` | Custom template loader for dynamic template resolution |
|
|
57
|
+
| `transport` | `EmailTransportOptions \| fn` | *required* | Email transport config (SMTP, SES, sendmail, file, none) or dynamic function |
|
|
58
|
+
| `globalTemplateVars` | `object \| fn` | - | Variables available to all templates (static or async function with `RequestContext`) |
|
|
59
|
+
| `emailSender` | `EmailSender` | `NodemailerEmailSender` | Custom email sending implementation |
|
|
60
|
+
| `emailGenerator` | `EmailGenerator` | `HandlebarsMjmlGenerator` | Custom email generation implementation |
|
|
61
|
+
| `useReactEmail` | `boolean` | `false` | Use React Email for template rendering |
|
|
62
|
+
|
|
63
|
+
**Transport types:** `smtp`, `ses` (AWS SES), `sendmail`, `file`, `none`, `testing`
|
|
64
|
+
|
|
65
|
+
## Features
|
|
66
|
+
|
|
67
|
+
- **MJML + Handlebars templates** - Responsive email markup with dynamic data
|
|
68
|
+
- **React Email support** - Alternative template engine using React components
|
|
69
|
+
- **Default event handlers** - Order confirmation, email verification, password reset, email change
|
|
70
|
+
- **Customizable handlers** - Extend/modify default handlers or create entirely new ones
|
|
71
|
+
- **Dynamic SMTP settings** - Channel-aware transport configuration via async function
|
|
72
|
+
- **Job queue integration** - Emails processed via the Deenruv job queue with retry support
|
|
73
|
+
- **Dev mailbox** - Web-based email preview UI for development
|
|
74
|
+
- **Global template variables** - Static or async variables (e.g. storefront URL, theme colors)
|
|
75
|
+
- **Template helpers** - Built-in `formatMoney` and `formatDate` Handlebars helpers
|
|
76
|
+
- **File attachments** - Support for email attachments via Nodemailer
|
|
77
|
+
- **AWS SES support** - Native SES transport option
|
|
78
|
+
|
|
79
|
+
## Admin UI
|
|
80
|
+
|
|
81
|
+
Server-only plugin. No Admin UI extensions.
|
|
82
|
+
|
|
83
|
+
## API Extensions
|
|
84
|
+
|
|
85
|
+
No GraphQL API extensions. Email sending is triggered by internal Deenruv events.
|
package/dev-mailbox.html
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<title>Deenruv Development Inbox</title>
|
|
6
|
+
<style>
|
|
7
|
+
body {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
height: 100vh;
|
|
11
|
+
margin: 0;
|
|
12
|
+
font-family: Helvetica, Arial, sans-serif;
|
|
13
|
+
}
|
|
14
|
+
.top-bar {
|
|
15
|
+
padding: 12px;
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
background-color: #2a2929;
|
|
19
|
+
color: #efefef;
|
|
20
|
+
height: 60px;
|
|
21
|
+
}
|
|
22
|
+
.heading {
|
|
23
|
+
margin: 0;
|
|
24
|
+
font-size: 22px;
|
|
25
|
+
}
|
|
26
|
+
button#refresh {
|
|
27
|
+
margin-left: 12px;
|
|
28
|
+
border-radius: 3px;
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
}
|
|
32
|
+
button#refresh .label {
|
|
33
|
+
margin-left: 6px;
|
|
34
|
+
}
|
|
35
|
+
.generate-controls {
|
|
36
|
+
flex: 1;
|
|
37
|
+
display: flex;
|
|
38
|
+
justify-content: flex-end;
|
|
39
|
+
}
|
|
40
|
+
input,
|
|
41
|
+
select,
|
|
42
|
+
button {
|
|
43
|
+
padding: 6px;
|
|
44
|
+
border-radius: 3px;
|
|
45
|
+
border: 1px solid #0b384b;
|
|
46
|
+
margin-left: 3px;
|
|
47
|
+
}
|
|
48
|
+
button {
|
|
49
|
+
text-transform: uppercase;
|
|
50
|
+
font-size: 12px;
|
|
51
|
+
transition: background-color 0.2s;
|
|
52
|
+
padding: 0 12px;
|
|
53
|
+
height: 32px;
|
|
54
|
+
}
|
|
55
|
+
button:hover {
|
|
56
|
+
background-color: #efefef;
|
|
57
|
+
}
|
|
58
|
+
#language-code {
|
|
59
|
+
width: 32px;
|
|
60
|
+
}
|
|
61
|
+
.content {
|
|
62
|
+
display: flex;
|
|
63
|
+
flex: 1;
|
|
64
|
+
height: calc(100% - 60px);
|
|
65
|
+
}
|
|
66
|
+
.list {
|
|
67
|
+
width: 40vw;
|
|
68
|
+
min-width: 300px;
|
|
69
|
+
overflow: auto;
|
|
70
|
+
}
|
|
71
|
+
.row {
|
|
72
|
+
border-bottom: 1px dashed #ddd;
|
|
73
|
+
padding: 12px 6px;
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
transition: background-color 0.2s;
|
|
76
|
+
}
|
|
77
|
+
.row.selected {
|
|
78
|
+
background-color: #d4e1e7;
|
|
79
|
+
}
|
|
80
|
+
.row:not(.selected):hover {
|
|
81
|
+
background-color: #efefef;
|
|
82
|
+
}
|
|
83
|
+
.meta {
|
|
84
|
+
display: flex;
|
|
85
|
+
justify-content: space-between;
|
|
86
|
+
color: #666;
|
|
87
|
+
}
|
|
88
|
+
.detail {
|
|
89
|
+
flex: 1;
|
|
90
|
+
border: 1px solid #999;
|
|
91
|
+
display: flex;
|
|
92
|
+
flex-direction: column;
|
|
93
|
+
}
|
|
94
|
+
.detail iframe {
|
|
95
|
+
height: 100%;
|
|
96
|
+
border: 1px solid #eee;
|
|
97
|
+
overflow: auto;
|
|
98
|
+
}
|
|
99
|
+
.metadata {
|
|
100
|
+
padding: 6px;
|
|
101
|
+
color: #333;
|
|
102
|
+
background-color: white;
|
|
103
|
+
z-index: 1;
|
|
104
|
+
box-shadow: 0px 5px 8px -7px rgba(0, 0, 0, 0.49);
|
|
105
|
+
}
|
|
106
|
+
</style>
|
|
107
|
+
</head>
|
|
108
|
+
<body>
|
|
109
|
+
<div class="top-bar">
|
|
110
|
+
<h1 class="heading">Deenruv Dev Mailbox</h1>
|
|
111
|
+
<div class="generate-controls">
|
|
112
|
+
<select id="type-selector"></select>
|
|
113
|
+
<input id="language-code" value="en" type="text" />
|
|
114
|
+
<button id="generate-test">Generate test</button>
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
<div class="content">
|
|
118
|
+
<div class="list"></div>
|
|
119
|
+
<div class="detail"></div>
|
|
120
|
+
</div>
|
|
121
|
+
<script>
|
|
122
|
+
let selectedId = '';
|
|
123
|
+
const normalizePath = endpoint => {
|
|
124
|
+
const pathname = location.pathname;
|
|
125
|
+
return pathname.endsWith('/') ? `${pathname}${endpoint}` : `${pathname}/${endpoint}`;
|
|
126
|
+
};
|
|
127
|
+
refreshInbox();
|
|
128
|
+
setInterval(refreshInbox, 5000);
|
|
129
|
+
|
|
130
|
+
const typeSelect = document.querySelector('#type-selector');
|
|
131
|
+
fetch(normalizePath('types'))
|
|
132
|
+
.then(res => res.json())
|
|
133
|
+
.then(res => {
|
|
134
|
+
res.forEach(type => {
|
|
135
|
+
const option = document.createElement('option');
|
|
136
|
+
option.value = type;
|
|
137
|
+
option.text = type;
|
|
138
|
+
typeSelect.appendChild(option);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const languageCodeInput = document.querySelector('#language-code');
|
|
143
|
+
const generateTestButton = document.querySelector('#generate-test');
|
|
144
|
+
generateTestButton.addEventListener('click', e => {
|
|
145
|
+
fetch(normalizePath(`generate/${typeSelect.value}/${languageCodeInput.value}`))
|
|
146
|
+
.then(() => new Promise(resolve => setTimeout(resolve, 500)))
|
|
147
|
+
.then(() => refreshInbox());
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const list = document.querySelector('.list');
|
|
151
|
+
|
|
152
|
+
function refreshInbox() {
|
|
153
|
+
fetch(normalizePath('list'))
|
|
154
|
+
.then(res => res.json())
|
|
155
|
+
.then(res => renderList(res));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function renderList(items) {
|
|
159
|
+
const list = document.querySelector('.list');
|
|
160
|
+
list.innerHTML = '';
|
|
161
|
+
const rows = items.forEach(item => {
|
|
162
|
+
const row = document.createElement('div');
|
|
163
|
+
row.classList.add('row');
|
|
164
|
+
row.dataset.id = item.fileName;
|
|
165
|
+
row.innerHTML = `
|
|
166
|
+
<div class="meta">
|
|
167
|
+
<div class="date">${item.date}</div>
|
|
168
|
+
<div class="recipient">${item.recipient}</div>
|
|
169
|
+
</div>
|
|
170
|
+
<div class="subject">${item.subject}</div>`;
|
|
171
|
+
|
|
172
|
+
row.addEventListener('click', e => {
|
|
173
|
+
selectedId = item.fileName;
|
|
174
|
+
fetch(normalizePath('item/' + item.fileName))
|
|
175
|
+
.then(res => res.json())
|
|
176
|
+
.then(res => renderEmail(res))
|
|
177
|
+
.then(() => highlightSelectedRow());
|
|
178
|
+
});
|
|
179
|
+
list.appendChild(row);
|
|
180
|
+
});
|
|
181
|
+
highlightSelectedRow();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function highlightSelectedRow() {
|
|
185
|
+
document.querySelectorAll('.list .row').forEach(row => {
|
|
186
|
+
row.classList.remove('selected');
|
|
187
|
+
if (row.dataset.id === selectedId) {
|
|
188
|
+
row.classList.add('selected');
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function renderEmail(email) {
|
|
194
|
+
const content = `
|
|
195
|
+
<div class="metadata">
|
|
196
|
+
<table>
|
|
197
|
+
<tr>
|
|
198
|
+
<td>Recipient:</td>
|
|
199
|
+
<td>${email.recipient}</td>
|
|
200
|
+
</tr>
|
|
201
|
+
<tr>
|
|
202
|
+
<td>Subject:</td>
|
|
203
|
+
<td>${email.subject}</td>
|
|
204
|
+
</tr>
|
|
205
|
+
<tr>
|
|
206
|
+
<td>Date:</td>
|
|
207
|
+
<td>${new Date().toLocaleString()}</td>
|
|
208
|
+
</tr>
|
|
209
|
+
</table>
|
|
210
|
+
</div>
|
|
211
|
+
<iframe srcdoc="${email.body.replace(/"/g, '"')}"></iframe>
|
|
212
|
+
`;
|
|
213
|
+
|
|
214
|
+
document.querySelector('.detail').innerHTML = content;
|
|
215
|
+
}
|
|
216
|
+
</script>
|
|
217
|
+
</body>
|
|
218
|
+
</html>
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./src/handler/default-email-handlers";
|
|
2
|
+
export * from "./src/sender/nodemailer-email-sender";
|
|
3
|
+
export * from "./src/handler/event-handler";
|
|
4
|
+
export * from "./src/event-listener";
|
|
5
|
+
export * from "./src/generator/handlebars-mjml-generator";
|
|
6
|
+
export * from "./src/generator/noop-email-generator";
|
|
7
|
+
export * from "./src/plugin";
|
|
8
|
+
export * from "./src/template-loader/template-loader";
|
|
9
|
+
export * from "./src/template-loader/file-based-template-loader";
|
|
10
|
+
export * from "./src/types";
|
|
11
|
+
export * from "./src/email-send-event";
|
|
12
|
+
export * from "./src/generator/email-generator";
|
|
13
|
+
export * from "./src/sender/email-sender";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src/handler/default-email-handlers"), exports);
|
|
18
|
+
__exportStar(require("./src/sender/nodemailer-email-sender"), exports);
|
|
19
|
+
__exportStar(require("./src/handler/event-handler"), exports);
|
|
20
|
+
__exportStar(require("./src/event-listener"), exports);
|
|
21
|
+
__exportStar(require("./src/generator/handlebars-mjml-generator"), exports);
|
|
22
|
+
__exportStar(require("./src/generator/noop-email-generator"), exports);
|
|
23
|
+
__exportStar(require("./src/plugin"), exports);
|
|
24
|
+
__exportStar(require("./src/template-loader/template-loader"), exports);
|
|
25
|
+
__exportStar(require("./src/template-loader/file-based-template-loader"), exports);
|
|
26
|
+
__exportStar(require("./src/types"), exports);
|
|
27
|
+
__exportStar(require("./src/email-send-event"), exports);
|
|
28
|
+
__exportStar(require("./src/generator/email-generator"), exports);
|
|
29
|
+
__exportStar(require("./src/sender/email-sender"), exports);
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uEAAqD;AACrD,uEAAqD;AACrD,8DAA4C;AAC5C,uDAAqC;AACrC,4EAA0D;AAC1D,uEAAqD;AACrD,+CAA6B;AAC7B,wEAAsD;AACtD,mFAAiE;AACjE,8CAA4B;AAC5B,yDAAuC;AACvC,kEAAgD;AAChD,4DAA0C"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { EmailAttachment, SerializedAttachment } from "./types";
|
|
2
|
+
export declare function serializeAttachments(attachments: EmailAttachment[]): Promise<SerializedAttachment[]>;
|
|
3
|
+
export declare function deserializeAttachments(serializedAttachments: SerializedAttachment[]): EmailAttachment[];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deserializeAttachments = exports.serializeAttachments = void 0;
|
|
4
|
+
const core_1 = require("@deenruv/core");
|
|
5
|
+
const stream_1 = require("stream");
|
|
6
|
+
const url_1 = require("url");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
async function serializeAttachments(attachments) {
|
|
9
|
+
const promises = attachments.map(async (a) => {
|
|
10
|
+
const stringPath = (path) => typeof path === "string" ? path : (0, url_1.format)(path);
|
|
11
|
+
const content = a.content instanceof stream_1.Stream ? await streamToBuffer(a.content) : a.content;
|
|
12
|
+
return Object.assign(Object.assign({ filename: null, cid: null, encoding: null, contentType: null, contentTransferEncoding: null, contentDisposition: null, headers: null }, a), { path: a.path ? stringPath(a.path) : null, content: JSON.stringify(content) });
|
|
13
|
+
});
|
|
14
|
+
return Promise.all(promises);
|
|
15
|
+
}
|
|
16
|
+
exports.serializeAttachments = serializeAttachments;
|
|
17
|
+
function deserializeAttachments(serializedAttachments) {
|
|
18
|
+
return serializedAttachments.map((a) => {
|
|
19
|
+
const content = parseContent(a.content);
|
|
20
|
+
if (content instanceof Buffer && 50 * 1024 <= content.length) {
|
|
21
|
+
core_1.Logger.warn(`Email has a large 'content' attachment (${Math.round(content.length / 1024)}k). Consider using the 'path' instead for improved performance.`, constants_1.loggerCtx);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
filename: nullToUndefined(a.filename),
|
|
25
|
+
cid: nullToUndefined(a.cid),
|
|
26
|
+
encoding: nullToUndefined(a.encoding),
|
|
27
|
+
contentType: nullToUndefined(a.contentType),
|
|
28
|
+
contentTransferEncoding: nullToUndefined(a.contentTransferEncoding),
|
|
29
|
+
contentDisposition: nullToUndefined(a.contentDisposition),
|
|
30
|
+
headers: nullToUndefined(a.headers),
|
|
31
|
+
path: nullToUndefined(a.path),
|
|
32
|
+
content,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.deserializeAttachments = deserializeAttachments;
|
|
37
|
+
function parseContent(content) {
|
|
38
|
+
try {
|
|
39
|
+
const parsedContent = content && JSON.parse(content);
|
|
40
|
+
if (typeof parsedContent === "string") {
|
|
41
|
+
return parsedContent;
|
|
42
|
+
}
|
|
43
|
+
else if (parsedContent.hasOwnProperty("data")) {
|
|
44
|
+
return Buffer.from(parsedContent.data);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
// empty
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function streamToBuffer(stream) {
|
|
52
|
+
const chunks = [];
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
stream.on("data", (chunk) => {
|
|
55
|
+
chunks.push(Buffer.from(chunk));
|
|
56
|
+
});
|
|
57
|
+
stream.on("error", (err) => reject(err));
|
|
58
|
+
stream.on("end", () => {
|
|
59
|
+
resolve(Buffer.concat(chunks));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function nullToUndefined(input) {
|
|
64
|
+
return input == null ? undefined : input;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=attachment-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment-utils.js","sourceRoot":"","sources":["../../src/attachment-utils.ts"],"names":[],"mappings":";;;AAAA,wCAAuC;AACvC,mCAA0C;AAC1C,6BAAkC;AAElC,2CAAwC;AAGjC,KAAK,UAAU,oBAAoB,CACxC,WAA8B;IAE9B,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;QAC3C,MAAM,UAAU,GAAG,CAAC,IAAkB,EAAE,EAAE,CACxC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CA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E,CAAC,KAAK,EAAE,GAAG,EAAE;YACpB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CAAI,KAAe;IACzC,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Injector, RequestContext } from "@deenruv/core";
|
|
2
|
+
import { EmailPluginDevModeOptions, EmailPluginOptions, EmailTransportOptions } from "./types";
|
|
3
|
+
export declare function isDevModeOptions(input: EmailPluginOptions | EmailPluginDevModeOptions): input is EmailPluginDevModeOptions;
|
|
4
|
+
export declare function resolveTransportSettings(options: EmailPluginOptions, injector: Injector, ctx?: RequestContext): Promise<EmailTransportOptions>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveTransportSettings = exports.isDevModeOptions = void 0;
|
|
4
|
+
function isDevModeOptions(input) {
|
|
5
|
+
return input.devMode === true;
|
|
6
|
+
}
|
|
7
|
+
exports.isDevModeOptions = isDevModeOptions;
|
|
8
|
+
async function resolveTransportSettings(options, injector, ctx) {
|
|
9
|
+
if (typeof options.transport === "function") {
|
|
10
|
+
return options.transport(injector, ctx);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return options.transport;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.resolveTransportSettings = resolveTransportSettings;
|
|
17
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":";;;AAQA,SAAgB,gBAAgB,CAC9B,KAAqD;IAErD,OAAQ,KAAmC,CAAC,OAAO,KAAK,IAAI,CAAC;AAC/D,CAAC;AAJD,4CAIC;AAEM,KAAK,UAAU,wBAAwB,CAC5C,OAA2B,EAC3B,QAAkB,EAClB,GAAoB;IAEpB,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC,SAAS,CAAC;IAC3B,CAAC;AACH,CAAC;AAVD,4DAUC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loggerCtx = exports.EMAIL_PLUGIN_OPTIONS = void 0;
|
|
4
|
+
exports.EMAIL_PLUGIN_OPTIONS = Symbol("EMAIL_PLUGIN_OPTIONS");
|
|
5
|
+
exports.loggerCtx = "EmailPlugin";
|
|
6
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AACtD,QAAA,SAAS,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { EmailEventHandler } from "./handler/event-handler";
|
|
3
|
+
import { EmailPluginDevModeOptions, EventWithContext } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* An email inbox application that serves the contents of the dev mode `outputPath` directory.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DevMailbox {
|
|
8
|
+
private handleMockEventFn;
|
|
9
|
+
serve(options: EmailPluginDevModeOptions): Router;
|
|
10
|
+
handleMockEvent(handler: (handler: EmailEventHandler<string, any>, event: EventWithContext) => void): void;
|
|
11
|
+
private getEmailList;
|
|
12
|
+
private getEmail;
|
|
13
|
+
private createRequestContext;
|
|
14
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DevMailbox = void 0;
|
|
7
|
+
const core_1 = require("@deenruv/core");
|
|
8
|
+
const express_1 = require("express");
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
/**
|
|
12
|
+
* An email inbox application that serves the contents of the dev mode `outputPath` directory.
|
|
13
|
+
*/
|
|
14
|
+
class DevMailbox {
|
|
15
|
+
serve(options) {
|
|
16
|
+
const { outputPath, handlers } = options;
|
|
17
|
+
const server = (0, express_1.Router)();
|
|
18
|
+
server.get("/", (req, res) => {
|
|
19
|
+
res.sendFile(path_1.default.join(__dirname, "../../dev-mailbox.html"));
|
|
20
|
+
});
|
|
21
|
+
server.get("/list", async (req, res) => {
|
|
22
|
+
const list = await fs_extra_1.default.readdir(outputPath);
|
|
23
|
+
const contents = await this.getEmailList(outputPath);
|
|
24
|
+
res.send(contents);
|
|
25
|
+
});
|
|
26
|
+
server.get("/types", async (req, res) => {
|
|
27
|
+
res.send(handlers.map((h) => h.type));
|
|
28
|
+
});
|
|
29
|
+
server.get("/generate/:type/:languageCode", async (req, res) => {
|
|
30
|
+
const { type, languageCode } = req.params;
|
|
31
|
+
if (this.handleMockEventFn) {
|
|
32
|
+
const handler = handlers.find((h) => h.type === type);
|
|
33
|
+
if (!handler || !handler.mockEvent) {
|
|
34
|
+
res.statusCode = 404;
|
|
35
|
+
res.send({
|
|
36
|
+
success: false,
|
|
37
|
+
error: `No mock event registered for type "${type}"`,
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
this.handleMockEventFn(handler, Object.assign(Object.assign({}, handler.mockEvent), { ctx: this.createRequestContext(languageCode, req) }));
|
|
43
|
+
res.send({ success: true });
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
res.statusCode = 500;
|
|
47
|
+
res.send({ success: false, error: e.message });
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
res.send({
|
|
53
|
+
success: false,
|
|
54
|
+
error: "Mock email generation not set up.",
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
server.get("/item/:id", async (req, res) => {
|
|
59
|
+
const fileName = req.params.id;
|
|
60
|
+
const content = await this.getEmail(outputPath, fileName);
|
|
61
|
+
res.send(content);
|
|
62
|
+
});
|
|
63
|
+
server.get("/placeholder-image", async (req, res) => {
|
|
64
|
+
const img = Buffer.from("/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCADgAO4DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD7VooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACszXNeg0SENJ88rfdjB5NafTrXlPiHUW1PVZpScqDtX2AoGX7jxxqM0m5GWFf7qj/ABqL/hMtU/57/wDjorDooGbn/CZap/z3/wDHRR/wmWqf89//AB0Vh0UAbn/CZap/z3/8dFWLPx1fwSfvgs6Z5BGD+GK5uigD1vSdWg1i1E0J/wB5e6mrtea+DdQNlrCIWxHN8hHbPavSqBBRRRQIKKKKACiiigAooooAKKKKACiiigAooooAKKKKACqepatbaTD5lxIE9F6k/hU17dpY2ss8n3I1ya8p1TVJtWu3nlPU8LnhR6UDOquPiEqswhttwzwWNQ/8LDm/59U/M1x9FAzq7rx9PcW8ka26IXUruyeM965UnJyetJRQAUUUUDCiiigAooooAcjmNwykhgcgiutX4hTKoBtkYgdcmuQooEdh/wALDm/59U/M1Ys/iDG8gFzB5a/3k5rh6KAPYbG/g1GES28gkQ+nb61PXleg61Lo14rg5iY4dM8EV6lFIJY0cdGAIoEOooooEFFFFABRRRQAUUUUAFFFFABRRRQBgeOJDHoLY/idVP615tXo3jz/AJAP/bVf615zQUgooooGFFFLQAlWLXT7m8YCGF5M91HH510/hvwd9oVLq9BC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c3oDSD7sfYe9dazBVJJwB1qOe4jtoy8rrGo7sa4bxN4u+3BrazYrD0aTpu/8ArUBuZ/irWjq2oELxDF8qjPU9zWJRRQUFFFFABXqfhX/kX7L/AHP6mvLK9T8K/wDIv2X+5/U0CZq0UUUEhRRRQAUUUUAFFFFABRRRQAUUUUAYHjiMyaC2P4XVj+tebV7BqFmmoWcsD9HGK8o1Cxl026kgmXDKcZ7H3FBSK1FFFAwooooAKuWerXmnsDBcPHjoucj8jVOigDpY/HmoR7dyxyY67h1ps3jrUZFYL5cZPQqOn51zlFAizdajc3rEzzvJnsTx+VVqKKBhRRRQAUUUUAFeq+GY2i0GzVhhgnT8TXnWh6TJq9/HCo+TOXbsBXqsMSwQpGowqjAoEx9FFFBIUUUUAFFFFABRRRQAUUUUAFFFFABVHVtFttYhCTplh91x1FXqKAOIuPh5Lu/cXSbf+mgP9Ki/4V5d/wDP1D+R/wAK7yigdzg/+FeXf/P1D+R/wo/4V5d/8/UP5H/Cu8ooC5wf/CvLv/n6h/I/4Uf8K8u/+fqH8j/hXeUUBc4P/hXl3/z9Q/kf8KP+FeXf/P1D+R/wrvKKAucH/wAK8u/+fqH8j/hR/wAK8u/+fqH8j/hXeUUBc4P/AIV5d/8AP1D+R/wo/wCFeXf/AD9Q/kf8K7yigLnB/wDCvLv/AJ+ofyP+FWLX4ekMDc3KkZ6Rg12lFAXKmm6VbaVD5dvGEB6nuat0UUCCiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9k=", "base64");
|
|
65
|
+
res.writeHead(200, {
|
|
66
|
+
"Content-Type": "image/png",
|
|
67
|
+
"Content-Length": img.length,
|
|
68
|
+
});
|
|
69
|
+
res.end(img);
|
|
70
|
+
});
|
|
71
|
+
return server;
|
|
72
|
+
}
|
|
73
|
+
handleMockEvent(handler) {
|
|
74
|
+
this.handleMockEventFn = handler;
|
|
75
|
+
}
|
|
76
|
+
async getEmailList(outputPath) {
|
|
77
|
+
const list = await fs_extra_1.default.readdir(outputPath);
|
|
78
|
+
const contents = [];
|
|
79
|
+
for (const fileName of list.filter((name) => name.endsWith(".json"))) {
|
|
80
|
+
const json = await fs_extra_1.default.readFile(path_1.default.join(outputPath, fileName), "utf-8");
|
|
81
|
+
const content = JSON.parse(json);
|
|
82
|
+
contents.push({
|
|
83
|
+
fileName,
|
|
84
|
+
date: content.date,
|
|
85
|
+
subject: content.subject,
|
|
86
|
+
recipient: content.recipient,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
contents.sort((a, b) => {
|
|
90
|
+
return a.fileName < b.fileName ? 1 : -1;
|
|
91
|
+
});
|
|
92
|
+
return contents;
|
|
93
|
+
}
|
|
94
|
+
async getEmail(outputPath, fileName) {
|
|
95
|
+
const safeSuffix = path_1.default
|
|
96
|
+
.normalize(fileName)
|
|
97
|
+
.replace(/^(\.\.(\/|\\|$))+/, "");
|
|
98
|
+
const safeFilePath = path_1.default.join(outputPath, safeSuffix);
|
|
99
|
+
const json = await fs_extra_1.default.readFile(safeFilePath, "utf-8");
|
|
100
|
+
const content = JSON.parse(json);
|
|
101
|
+
return content;
|
|
102
|
+
}
|
|
103
|
+
createRequestContext(languageCode, req) {
|
|
104
|
+
return new core_1.RequestContext({
|
|
105
|
+
languageCode,
|
|
106
|
+
req,
|
|
107
|
+
apiType: "admin",
|
|
108
|
+
session: {},
|
|
109
|
+
isAuthorized: false,
|
|
110
|
+
authorizedAsOwnerOnly: true,
|
|
111
|
+
channel: new core_1.Channel(),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.DevMailbox = DevMailbox;
|
|
116
|
+
//# sourceMappingURL=dev-mailbox.js.map
|
|
@@ -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