@technomoron/mail-magic 1.0.32 → 1.0.34

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.
Files changed (43) hide show
  1. package/CHANGES +18 -0
  2. package/README.md +213 -122
  3. package/dist/api/assets.js +9 -56
  4. package/dist/api/auth.js +1 -12
  5. package/dist/api/form-replyto.js +1 -0
  6. package/dist/api/form-submission.js +1 -0
  7. package/dist/api/forms.js +114 -474
  8. package/dist/api/mailer.js +1 -1
  9. package/dist/bin/mail-magic.js +2 -2
  10. package/dist/index.js +30 -18
  11. package/dist/models/db.js +5 -5
  12. package/dist/models/domain.js +16 -8
  13. package/dist/models/form.js +111 -40
  14. package/dist/models/init.js +44 -74
  15. package/dist/models/recipient.js +12 -8
  16. package/dist/models/txmail.js +24 -28
  17. package/dist/models/user.js +14 -10
  18. package/dist/server.js +1 -1
  19. package/dist/store/store.js +53 -22
  20. package/dist/swagger.js +107 -0
  21. package/dist/util/captcha.js +24 -0
  22. package/dist/util/email.js +19 -0
  23. package/dist/util/form-replyto.js +44 -0
  24. package/dist/util/form-submission.js +95 -0
  25. package/dist/util/forms.js +431 -0
  26. package/dist/util/paths.js +41 -0
  27. package/dist/util/ratelimit.js +48 -0
  28. package/dist/util/uploads.js +48 -0
  29. package/dist/util/utils.js +151 -0
  30. package/dist/util.js +7 -127
  31. package/docs/config-example/example.test/assets/files/banner.png +1 -0
  32. package/docs/config-example/example.test/assets/images/logo.png +1 -0
  33. package/docs/config-example/example.test/form-template/base.njk +6 -0
  34. package/docs/config-example/example.test/form-template/contact.njk +9 -0
  35. package/docs/config-example/example.test/form-template/partials/fields.njk +3 -0
  36. package/docs/config-example/example.test/tx-template/base.njk +10 -0
  37. package/docs/config-example/example.test/tx-template/partials/header.njk +1 -0
  38. package/docs/config-example/example.test/tx-template/welcome.njk +10 -0
  39. package/docs/config-example/init-data.json +57 -0
  40. package/docs/form-security.md +194 -0
  41. package/docs/swagger/openapi.json +1321 -0
  42. package/{TUTORIAL.MD → docs/tutorial.md} +24 -15
  43. package/package.json +3 -3
@@ -1,12 +1,15 @@
1
1
  # Mail Magic Configuration Tutorial (MyOrg)
2
2
 
3
- This guide walks through building a standalone configuration tree for the user `myorg` and the domain `myorg.com`. The finished layout adds a contact form template and a transactional welcome template that both reuse partials and embed the MyOrg logo inline so it is shipped as a CID attachment.
3
+ This guide walks through building a standalone configuration tree for the user `myorg` and the domain `myorg.com`. The
4
+ finished layout adds a contact form template and a transactional welcome template that both reuse partials and embed the
5
+ MyOrg logo inline so it is shipped as a CID attachment.
4
6
 
5
7
  ---
6
8
 
7
9
  ## 1. Prepare an external config workspace
8
10
 
9
- Mail Magic loads configuration from the folder referenced by the `CONFIG_PATH` environment variable. Keeping your custom assets outside the application repository makes upgrades easier.
11
+ Mail Magic loads configuration from the folder referenced by the `CONFIG_PATH` environment variable. Keeping your custom
12
+ assets outside the application repository makes upgrades easier.
10
13
 
11
14
  ```bash
12
15
  # run this next to the mail-magic checkout
@@ -56,9 +59,13 @@ myorg-config/
56
59
  └── welcome.njk
57
60
  ```
58
61
 
59
- > **Tip:** If you want to share partials between templates, keep file names aligned (e.g. identical `header.njk` content under both `form-template/partials/` and `tx-template/partials/`).
62
+ > **Tip:** If you want to share partials between templates, keep file names aligned (e.g. identical `header.njk` content
63
+ > under both `form-template/partials/` and `tx-template/partials/`).
60
64
 
61
- > **Assets vs inline:** Any file referenced via `asset('...')` must live under `myorg.com/assets/`. The helper `asset('logo.png')` will become `http://localhost:3776/asset/myorg.com/logo.png` by default. You can change the base via `ASSET_PUBLIC_BASE` (or `API_URL`) and the route via `ASSET_ROUTE`. Use `asset('logo.png', true)` when you need the file embedded as a CID attachment instead.
65
+ > **Assets vs inline:** Any file referenced via `asset('...')` must live under `myorg.com/assets/`. The helper
66
+ > `asset('logo.png')` will become `http://localhost:3776/asset/myorg.com/logo.png` by default. You can change the base
67
+ > via `ASSET_PUBLIC_BASE` (or `API_URL`) and the route via `ASSET_ROUTE`. Use `asset('logo.png', true)` when you need
68
+ > the file embedded as a CID attachment instead.
62
69
 
63
70
  ---
64
71
 
@@ -277,7 +284,8 @@ Copy or design a square PNG logo and add it under the domain assets folder so th
277
284
  cp path/to/myorg-logo.png "$CONFIG_ROOT"/myorg.com/assets/logo.png
278
285
  ```
279
286
 
280
- The inline flag (`true`) in `asset('logo.png', true)` tells Mail Magic to attach the image and rewrite the markup to `cid:logo.png` when messages are flattened.
287
+ The inline flag (`true`) in `asset('logo.png', true)` tells Mail Magic to attach the image and rewrite the markup to
288
+ `cid:logo.png` when messages are flattened.
281
289
 
282
290
  ---
283
291
 
@@ -306,13 +314,13 @@ The inline flag (`true`) in `asset('logo.png', true)` tells Mail Magic to attach
306
314
  }
307
315
  }'
308
316
  ```
309
- 5. Submit the contact form the same way your frontend will post (public endpoint). Using `form_key` is preferred:
317
+ 5. Submit the contact form the same way your frontend will post (public endpoint). This endpoint requires
318
+ `_mm_form_key`:
310
319
  ```bash
311
320
  curl -X POST http://localhost:3776/api/v1/form/message \
312
321
  -H 'Content-Type: application/json' \
313
322
  -d '{
314
- "form_key": "<your form_key>",
315
- "secret": "s3cret",
323
+ "_mm_form_key": "<your form_key>",
316
324
  "name": "Kai",
317
325
  "email": "kai@myorg.com",
318
326
  "message": "Hello from the contact form"
@@ -321,11 +329,12 @@ The inline flag (`true`) in `asset('logo.png', true)` tells Mail Magic to attach
321
329
 
322
330
  With `DB_AUTO_RELOAD=1`, editing templates or assets is as simple as saving the file.
323
331
 
324
- You now have a clean, self-contained configuration for MyOrg that inherits Mail Magic behaviour while keeping templates, partials, and assets under version control in a dedicated folder.
332
+ You now have a clean, self-contained configuration for MyOrg that inherits Mail Magic behaviour while keeping templates,
333
+ partials, and assets under version control in a dedicated folder.
325
334
 
326
335
  ---
327
336
 
328
- ## 6. Optional: Recipient allowlist for public forms (`recipient_idname`)
337
+ ## 6. Optional: Recipient allowlist for public forms (`_mm_recipients`)
329
338
 
330
339
  If you have a public form where the frontend must select a recipient (for example "send a message to a journalist"),
331
340
  avoid shipping raw email addresses client-side.
@@ -333,7 +342,7 @@ avoid shipping raw email addresses client-side.
333
342
  Instead:
334
343
 
335
344
  1. Configure recipients (authenticated) with `POST /api/v1/form/recipient`.
336
- 2. Submit public forms with `recipient_idname`.
345
+ 2. Submit public forms with `_mm_recipients`.
337
346
 
338
347
  Example (domain-wide mapping):
339
348
 
@@ -354,8 +363,8 @@ Example (public submit):
354
363
  curl -X POST http://localhost:3776/api/v1/form/message \
355
364
  -H 'Content-Type: application/json' \
356
365
  -d '{
357
- "form_key": "<your form_key>",
358
- "recipient_idname": "desk",
366
+ "_mm_form_key": "<your form_key>",
367
+ "_mm_recipients": ["desk"],
359
368
  "name": "Kai",
360
369
  "email": "kai@myorg.com",
361
370
  "message": "Hello"
@@ -375,5 +384,5 @@ If the public form endpoint is a spam/volume target, enable one or more of these
375
384
  - `FORM_MAX_ATTACHMENTS` and `UPLOAD_MAX`
376
385
  - CAPTCHA: set `FORM_CAPTCHA_SECRET` + `FORM_CAPTCHA_PROVIDER`
377
386
 
378
- Per form, you can also set `captcha_required=true` when storing/updating the form template via the API (`POST
379
- /api/v1/form/template`).
387
+ Per form, you can also set `captcha_required=true` when storing/updating the form template via the API
388
+ (`POST /api/v1/form/template`).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@technomoron/mail-magic",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,9 +8,9 @@
8
8
  },
9
9
  "files": [
10
10
  "dist",
11
+ "docs",
11
12
  "README.md",
12
- "CHANGES",
13
- "TUTORIAL.MD"
13
+ "CHANGES"
14
14
  ],
15
15
  "repository": {
16
16
  "type": "git",