emailengine-app 2.80.0 → 2.81.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.
Files changed (178) hide show
  1. package/.dockerignore +44 -0
  2. package/.github/docker-smoke-test.sh +16 -0
  3. package/.github/workflows/deploy.yml +4 -0
  4. package/.github/workflows/release.yaml +4 -0
  5. package/.github/workflows/test.yml +2 -0
  6. package/.release-please-manifest.json +1 -1
  7. package/CHANGELOG.md +56 -0
  8. package/Dockerfile +17 -9
  9. package/README.md +6 -0
  10. package/data/google-crawlers.json +1 -1
  11. package/docker-compose.yml +7 -1
  12. package/lib/api-routes/account-routes.js +239 -73
  13. package/lib/api-routes/blocklist-routes.js +24 -0
  14. package/lib/api-routes/delivery-test-routes.js +6 -0
  15. package/lib/api-routes/gateway-routes.js +30 -0
  16. package/lib/api-routes/license-routes.js +10 -0
  17. package/lib/api-routes/mcp-oauth-routes.js +3 -3
  18. package/lib/api-routes/mcp-routes.js +39 -21
  19. package/lib/api-routes/oauth2-app-routes.js +38 -1
  20. package/lib/api-routes/outbox-routes.js +6 -0
  21. package/lib/api-routes/permission-map.js +212 -42
  22. package/lib/api-routes/pubsub-routes.js +8 -0
  23. package/lib/api-routes/route-helpers.js +58 -11
  24. package/lib/api-routes/settings-routes.js +50 -4
  25. package/lib/api-routes/stats-routes.js +6 -0
  26. package/lib/api-routes/template-routes.js +21 -0
  27. package/lib/api-routes/token-routes.js +34 -2
  28. package/lib/api-routes/webhook-route-routes.js +13 -0
  29. package/lib/autodetect-imap-settings.js +4 -4
  30. package/lib/email-client/base-client.js +6 -3
  31. package/lib/email-client/credential-errors.js +4 -0
  32. package/lib/email-client/imap/login-failure.js +52 -0
  33. package/lib/email-client/imap/subconnection.js +2 -1
  34. package/lib/email-client/imap-client.js +3 -6
  35. package/lib/enum-descriptions.js +12 -2
  36. package/lib/imapproxy/imap-server.js +1 -1
  37. package/lib/mcp/oauth.js +46 -8
  38. package/lib/mcp/protocol.js +78 -35
  39. package/lib/mcp/tools.js +53 -17
  40. package/lib/privileged-settings.js +147 -0
  41. package/lib/schemas.js +60 -16
  42. package/lib/sentry.js +13 -2
  43. package/lib/settings.js +13 -0
  44. package/lib/tls/catalog.js +428 -0
  45. package/lib/tls/context.js +87 -161
  46. package/lib/tls/listeners.js +62 -0
  47. package/lib/tls/provision.js +1 -1
  48. package/lib/tls/status.js +128 -79
  49. package/lib/tls/store.js +3 -2
  50. package/lib/token-permission-view.js +253 -102
  51. package/lib/token-permissions.js +176 -26
  52. package/lib/tokens.js +7 -6
  53. package/lib/tools.js +5 -3
  54. package/lib/ui-routes/account-routes.js +195 -61
  55. package/lib/ui-routes/admin-config-routes.js +41 -21
  56. package/lib/ui-routes/admin-entities-routes.js +32 -22
  57. package/lib/ui-routes/mcp-consent-routes.js +72 -31
  58. package/lib/ui-routes/tls-config-routes.js +121 -74
  59. package/package.json +16 -16
  60. package/sbom.json +1 -1
  61. package/server.js +7 -1
  62. package/static/css/flyonui.css +1 -1
  63. package/static/css/public.css +41 -0
  64. package/static/css/src/app.tailwind.css +135 -4
  65. package/static/js/public.js +218 -0
  66. package/static/js/ui.js +89 -36
  67. package/static/licenses.html +55 -37
  68. package/translations/README.md +4 -3
  69. package/translations/de.mo +0 -0
  70. package/translations/de.po +296 -185
  71. package/translations/en.po +220 -128
  72. package/translations/es.mo +0 -0
  73. package/translations/es.po +558 -0
  74. package/translations/et.mo +0 -0
  75. package/translations/et.po +288 -181
  76. package/translations/fr.mo +0 -0
  77. package/translations/fr.po +295 -183
  78. package/translations/it.mo +0 -0
  79. package/translations/it.po +558 -0
  80. package/translations/ja.mo +0 -0
  81. package/translations/ja.po +268 -192
  82. package/translations/locales.json +24 -0
  83. package/translations/messages.pot +179 -127
  84. package/translations/nl.mo +0 -0
  85. package/translations/nl.po +288 -175
  86. package/translations/pl.mo +0 -0
  87. package/translations/pl.po +294 -181
  88. package/translations/sv.mo +0 -0
  89. package/translations/sv.po +555 -0
  90. package/translations/tr.mo +0 -0
  91. package/translations/tr.po +555 -0
  92. package/update-info.sh +12 -6
  93. package/views/account/login-redirect.hbs +6 -5
  94. package/views/account/passkeys.hbs +8 -8
  95. package/views/account/security.hbs +2 -2
  96. package/views/accounts/account.hbs +19 -21
  97. package/views/accounts/browse.hbs +1 -1
  98. package/views/accounts/edit.hbs +15 -15
  99. package/views/accounts/index.hbs +3 -3
  100. package/views/accounts/register/imap-server.hbs +27 -173
  101. package/views/accounts/register/validating.hbs +139 -0
  102. package/views/config/ai.hbs +15 -17
  103. package/views/config/branding.hbs +7 -7
  104. package/views/config/document-store/chat.hbs +9 -8
  105. package/views/config/document-store/index.hbs +14 -15
  106. package/views/config/document-store/mappings/index.hbs +5 -6
  107. package/views/config/document-store/mappings/new.hbs +1 -2
  108. package/views/config/document-store/pre-processing/index.hbs +4 -4
  109. package/views/config/email-processing.hbs +6 -6
  110. package/views/config/imap-proxy.hbs +7 -8
  111. package/views/config/license.hbs +9 -9
  112. package/views/config/logging.hbs +5 -7
  113. package/views/config/mcp.hbs +90 -58
  114. package/views/config/network.hbs +4 -4
  115. package/views/config/oauth/app.hbs +12 -12
  116. package/views/config/oauth/index.hbs +6 -6
  117. package/views/config/oauth/subscriptions.hbs +9 -9
  118. package/views/config/security.hbs +5 -7
  119. package/views/config/service.hbs +11 -10
  120. package/views/config/smtp.hbs +9 -12
  121. package/views/config/tls-upload.hbs +3 -3
  122. package/views/config/tls.hbs +281 -182
  123. package/views/config/webhooks.hbs +12 -15
  124. package/views/dashboard.hbs +9 -8
  125. package/views/gateways/edit.hbs +3 -3
  126. package/views/gateways/gateway.hbs +3 -3
  127. package/views/gateways/index.hbs +6 -6
  128. package/views/gateways/new.hbs +3 -3
  129. package/views/internals/index.hbs +15 -13
  130. package/views/layout/app.hbs +6 -6
  131. package/views/layout/login.hbs +32 -19
  132. package/views/layout/main.hbs +2 -2
  133. package/views/layout/prompt.hbs +15 -18
  134. package/views/layout/public.hbs +1 -1
  135. package/views/mcp/authorize.hbs +47 -45
  136. package/views/partials/accounts_table.hbs +5 -5
  137. package/views/partials/ace_assets.hbs +1 -1
  138. package/views/partials/add_account_modal.hbs +4 -4
  139. package/views/partials/address_list.hbs +4 -4
  140. package/views/partials/filter_editor_js.hbs +2 -2
  141. package/views/partials/gateway_form.hbs +5 -5
  142. package/views/partials/gateway_js.hbs +1 -1
  143. package/views/partials/mcp_access_levels.hbs +16 -9
  144. package/views/partials/mcp_account_limit.hbs +2 -2
  145. package/views/partials/mcp_tool_count.hbs +15 -14
  146. package/views/partials/oauth_config_header.hbs +2 -2
  147. package/views/partials/oauth_form.hbs +37 -42
  148. package/views/partials/public_alerts.hbs +1 -1
  149. package/views/partials/public_test_labels.hbs +15 -0
  150. package/views/partials/public_theme_init.hbs +1 -1
  151. package/views/partials/security_header.hbs +2 -2
  152. package/views/partials/template_form.hbs +4 -4
  153. package/views/partials/theme_init.hbs +1 -1
  154. package/views/partials/tls_security_card.hbs +4 -1
  155. package/views/partials/ui/form-field.hbs +6 -1
  156. package/views/partials/ui/setting-ref.hbs +12 -7
  157. package/views/partials/ui/stat-card.hbs +4 -1
  158. package/views/partials/ui/tabs.hbs +3 -7
  159. package/views/partials/webhook_form.hbs +9 -12
  160. package/views/partials/webhooks_editor_functions.hbs +1 -1
  161. package/views/reference/index.hbs +3 -3
  162. package/views/reference/redirect.hbs +1 -1
  163. package/views/reference/tag.hbs +1 -1
  164. package/views/reference/token.hbs +4 -4
  165. package/views/suppression-lists/index.hbs +8 -6
  166. package/views/suppression-lists/list.hbs +13 -8
  167. package/views/templates/edit.hbs +1 -1
  168. package/views/templates/index.hbs +10 -11
  169. package/views/templates/template.hbs +5 -5
  170. package/views/tokens/index.hbs +17 -17
  171. package/views/tokens/new.hbs +190 -93
  172. package/views/unsubscribe.hbs +1 -1
  173. package/views/webhooks/edit.hbs +1 -1
  174. package/views/webhooks/index.hbs +10 -11
  175. package/views/webhooks/new.hbs +1 -1
  176. package/views/webhooks/webhook.hbs +5 -6
  177. package/workers/api.js +9 -8
  178. package/workers/smtp.js +1 -1
@@ -10,11 +10,9 @@
10
10
  {{#unless canProvision}}
11
11
  {{#> ui/stat-card variant="error" title="Set an admin password first" icon="icon-[tabler--shield-lock]" class="mb-6"}}
12
12
 
13
- <p class="mb-4">Access tokens do not expire on their own, so EmailEngine only issues one to a request
14
- that carries an admin session. This instance has no admin password set, so there is no session to
15
- carry - set one and the form appears here.</p>
13
+ <p class="mb-4">Set an admin password and sign in to create access tokens. Tokens created here remain valid until you delete them.</p>
16
14
  <div>
17
- {{> ui/btn href="/admin/account/password" variant="primary" icon="icon-[tabler--arrow-right]" label="Enable authentication"}}
15
+ {{> ui/btn href="/admin/account/password" variant="primary" icon="icon-[tabler--arrow-right]" label="Set admin password"}}
18
16
  </div>
19
17
 
20
18
  {{/ui/stat-card}}
@@ -26,7 +24,7 @@
26
24
 
27
25
  <div class="card-body space-y-4">
28
26
 
29
- {{> ui/form-field id="description" label="Description" value=values.description error=errors.description required=true hint="This description is shown when listing active tokens."}}
27
+ {{> ui/form-field id="description" label="Description" value=values.description error=errors.description required=true hint="Describe the app or task that will use this token."}}
30
28
 
31
29
  {{!-- A search box rather than a select or free text: an instance can hold far more
32
30
  accounts than a list could usefully carry, and an account id is the one thing
@@ -35,13 +33,12 @@
35
33
  nothing. --}}
36
34
  {{> ui/account-picker id="account" label="Account (optional)" value=values.account selected=selectedAccount error=errors.account
37
35
  placeholder="Leave empty to allow all accounts"
38
- hint="A bound token only works for that one account. Requests made for any other account are refused."}}
36
+ hint="Limit this token to one account. Leave blank to allow access to all accounts within the selected scopes and permissions."}}
39
37
 
40
38
  <div>
41
39
  <h6 class="mb-1 font-bold">Allowed scopes</h6>
42
40
  <p class="text-base-content/60 text-sm mb-3">
43
- Which surfaces this credential opens. Scopes are fixed the moment the token exists, so
44
- a surface left out here cannot be added later.
41
+ Choose which EmailEngine interfaces this token can access. Scopes cannot be changed after creation.
45
42
  </p>
46
43
 
47
44
  {{!-- One line of plain words per row. The bracketed slug beside each was the only
@@ -57,7 +54,7 @@
57
54
  <label class="label-text grow p-0" for="scopesAll">All scopes</label>
58
55
  <div class="text-base-content/60 code-link">["*"]</div>
59
56
  </div>
60
- <p class="helper-text ms-7">Every surface below, including any added in a later release.</p>
57
+ <p class="helper-text ms-7">All interfaces below, including any added in future releases.</p>
61
58
  </li>
62
59
 
63
60
  <li class="p-4">
@@ -100,16 +97,32 @@
100
97
  <p class="helper-text ms-7">Read the Prometheus metrics endpoint and nothing else.</p>
101
98
  </li>
102
99
 
100
+ {{!-- Two MCP scopes, management first: the endpoint is one door with two tool
101
+ sets behind it, and each scope opens one of them. Both rows carry the Beta
102
+ badge the MCP config page carries. --}}
103
+ <li class="p-4">
104
+ <div class="flex items-center gap-2">
105
+ <input type="checkbox" class="checkbox checkbox-sm scope-entry scope-list" id="scopesMcpManage"
106
+ name="scopesMcpManage" data-scope="mcp-manage" {{#if values.scopesMcpManage}}checked{{/if}} />
107
+ <label class="label-text grow p-0" for="scopesMcpManage">MCP management
108
+ {{> ui/badge label="Beta" variant="info" soft=true class="badge-sm align-middle" icon="" elId=""}}</label>
109
+ <div class="text-base-content/60 code-link">["mcp-manage"]</div>
110
+ </div>
111
+ <p class="helper-text ms-7">Let an AI agent manage this instance through the MCP tools at
112
+ <code>/mcp</code>: accounts, settings, OAuth2 applications, gateways, tokens and the license.
113
+ This scope does not grant REST API access.</p>
114
+ </li>
115
+
103
116
  <li class="p-4">
104
117
  <div class="flex items-center gap-2">
105
118
  <input type="checkbox" class="checkbox checkbox-sm scope-entry scope-list" id="scopesMcp"
106
119
  name="scopesMcp" data-scope="mcp" {{#if values.scopesMcp}}checked{{/if}} />
107
- <label class="label-text grow p-0" for="scopesMcp">MCP
120
+ <label class="label-text grow p-0" for="scopesMcp">MCP mail
108
121
  {{> ui/badge label="Beta" variant="info" soft=true class="badge-sm align-middle" icon="" elId=""}}</label>
109
122
  <div class="text-base-content/60 code-link">["mcp"]</div>
110
123
  </div>
111
- <p class="helper-text ms-7">Let an AI agent call MCP tools at <code>/mcp</code>. This is not REST
112
- API access - the same token is refused by <code>/v1</code>.</p>
124
+ <p class="helper-text ms-7">Let an AI agent work with mailbox contents through the MCP tools at
125
+ <code>/mcp</code>: list, read, organize and send mail. This scope does not grant REST API access.</p>
113
126
  {{!-- The endpoint is off by default, so an operator can otherwise mint a
114
127
  credential for something that is not serving and only find out in the
115
128
  client. Both halves of the gate are folded into mcpReady. Revealed by
@@ -118,8 +131,8 @@
118
131
  selection ("All scopes") technically carries the mcp scope too. --}}
119
132
  {{#unless mcpReady}}
120
133
  <p id="mcpDisabledHint" class="helper-text ms-7 text-warning hidden">The MCP endpoint is not
121
- enabled on this instance, so this token would have nothing to talk to. <a
122
- href="/admin/config/mcp" class="link">Turn it on</a> first.</p>
134
+ enabled on this instance. <a href="/admin/config/mcp" class="link">Enable MCP</a>
135
+ before using this token with an MCP client.</p>
123
136
  {{/unless}}
124
137
  </li>
125
138
  </ul>
@@ -138,7 +151,7 @@
138
151
  The record itself stays single: one `permissions` object narrows whatever surface the
139
152
  request arrives on. That is why this is one editor with two modes rather than a tab per
140
153
  scope - separate panes would promise two records that cannot exist. --}}
141
- <div id="accessCard" class="hidden" data-surfaces="{{permissionSurfacesJson}}" data-mcp-presets="{{json mcpAccessPresets}}">
154
+ <div id="accessCard" class="hidden" data-surfaces="{{permissionSurfacesJson}}" data-mcp-sections="{{json mcpSections}}">
142
155
  {{#> ui/card bodyClass="space-y-4"}}
143
156
 
144
157
  <div>
@@ -146,32 +159,42 @@
146
159
  <p id="accessAppliesTo" class="text-base-content/60 text-sm"></p>
147
160
  </div>
148
161
 
149
- {{!-- MCP-only mode. The three levels are the ones the OAuth consent prompt and the MCP config
150
- page already offer, from the same table through the same partial, because the same
151
- credential minted from three places must not mean three different things. A 52-cell
152
- matrix is not how anyone provisions an agent, so it is the fourth option rather than
153
- the only one - and unlike the API editor there is no "restrict?" toggle: read-only is
162
+ {{!-- MCP-only mode. One level per MCP scope, shown while that scope is ticked above: the
163
+ same sections and levels the OAuth consent prompt and the MCP config page offer, from
164
+ the same table through the same partial, because the same credential minted from
165
+ three places must not mean three different things. A 72-cell matrix is not how
166
+ anyone provisions an agent, so it is the opt-in behind the levels rather than the way
167
+ in - and unlike the API editor there is no "restrict?" toggle: the narrowest level is
154
168
  the default, because an agent credential that starts unrestricted is the wrong way
155
169
  round. --}}
156
170
  {{!-- Labelled by the card heading rather than carrying a legend of its own, which would
157
171
  repeat "Access level" directly under itself --}}
158
- <fieldset id="mcpLevelBlock" class="hidden space-y-2" aria-labelledby="accessCardTitle">
159
- {{> mcp_access_levels name="mcpAccess" idPrefix="mcpAccess_" selected="read"}}
160
- {{> ui/radio id="mcpAccess_custom" name="mcpAccess" value="custom" label="Custom permissions"
161
- hint="Choose the exact actions and sections yourself, starting from the level selected above."}}
172
+ <fieldset id="mcpLevelBlock" class="hidden space-y-4" aria-labelledby="accessCardTitle">
173
+ {{!-- One block per section, shown while that section's scope is ticked above; the radio
174
+ group is named mcpLevel_<key>, which is what the script and ui.js read back --}}
175
+ {{#each mcpSections}}
176
+ <div class="space-y-2 mcp-section-block" data-mcp-scope="{{scope}}">
177
+ <div class="label-text font-medium">{{label}}
178
+ <span class="text-base-content/60 code-link font-normal">["{{scope}}"]</span></div>
179
+ {{> mcp_access_levels section=this name=(concat "mcpLevel_" @key) idPrefix=(concat "mcpLevel_" @key) selected=levels.[0].value}}
180
+ </div>
181
+ {{/each}}
182
+
183
+ {{> ui/checkbox id="mcpCustom" label="Custom permissions" noName=true
184
+ hint="Choose the exact actions and sections yourself, starting from the levels selected above."}}
162
185
 
163
186
  {{!-- At the decision point, as on the MCP config page: the level chosen here is what
164
187
  decides whether instructions hidden inside received mail can act --}}
165
- <p class="text-base-content/60 text-sm">Email content flows into whatever model the connected client runs,
166
- and instructions inside received mail can steer it - grant sending and deleting rights deliberately.</p>
188
+ <p class="text-base-content/60 text-sm">The connected client may send email content to its AI model. Instructions in received emails can influence
189
+ the agent. Grant permission to send or delete email only when the agent needs it.</p>
167
190
  </fieldset>
168
191
 
169
192
  {{!-- API mode. Unrestricted by default, because an API token is the general-purpose
170
193
  credential and narrowing it is the exception. --}}
171
194
  <div id="apiLimitBlock" class="hidden">
172
195
  <p class="text-base-content/60 text-sm mb-3">
173
- By default this token can use the whole API. Restrict it to hand out a credential for a
174
- single job: an agent that reads mail but cannot delete it, or a service that can only send.
196
+ Limit this token to the actions its app or service needs, such as reading email or sending messages.
197
+ Without restrictions, it can use all operations allowed by its scopes and account selection.
175
198
  </p>
176
199
  {{> ui/checkbox id="permissionsEnabled" label="Restrict what this token can do" checked=values.permissionsEnabled error=errors.permissions noName=true}}
177
200
  </div>
@@ -201,7 +224,7 @@
201
224
  <div id="permissionPresetRow">
202
225
  <h6 class="mb-1 font-bold">Pick a preset</h6>
203
226
  <p class="text-base-content/60 text-sm mb-2">
204
- These cover the usual shapes. Adjust the details below if you need something else.
227
+ Start with a common set of permissions, then adjust the actions and sections below.
205
228
  </p>
206
229
  <div class="flex flex-wrap gap-2">
207
230
  {{#each permissionPresets}}
@@ -255,8 +278,9 @@
255
278
  <span class="icon-[tabler--lock] size-5 shrink-0"></span>
256
279
  <span>
257
280
  Some endpoints are never available to a restricted token, whatever you select here:
258
- settings, OAuth2 applications, licensing, access tokens and stored account
259
- credentials. A token that could reach those could grant itself more.
281
+ creating access tokens, reading an account's live OAuth2 credential, and the settings
282
+ that would let a token widen itself ({{privilegedSettingsSummary}}). A token that
283
+ could reach those could grant itself more.
260
284
  </span>
261
285
  </div>
262
286
  </div>
@@ -266,20 +290,20 @@
266
290
  </div>
267
291
 
268
292
  <div class="mb-6">
269
- {{> ui/btn label="Generate a token" type="submit" icon="icon-[tabler--key]"}}
293
+ {{> ui/btn label="Create access token" type="submit" icon="icon-[tabler--key]"}}
270
294
  </div>
271
295
  </form>
272
296
 
273
297
  {{!-- Wider than the default: the token is 64 characters and this is the only time it is shown, so
274
298
  it has to be readable in full rather than scrolled through a 32-character window. --}}
275
- {{#> ui/modal id="showToken" title="Access tokens" static=true dialogClass="max-w-2xl"}}
299
+ {{#> ui/modal id="showToken" title="Your access token" static=true dialogClass="max-w-2xl"}}
276
300
  <div class="modal-body">
277
301
  <div id="showTokenLoader" class="py-2 text-center">
278
302
  <span class="loading loading-spinner loading-sm align-middle"></span> Generating token&hellip;
279
303
  </div>
280
304
  <div id="showTokenContent" class="hidden">
281
305
 
282
- <div class="mb-2">Access token:</div>
306
+ <div class="mb-2">Copy and store this token securely. It will only be shown once.</div>
283
307
  {{!-- w-full because ui/copy-field's join wrapper is inline-flex, so the `grow` on the input
284
308
  has nothing to grow inside and the field kept its intrinsic width. text-sm so all 64
285
309
  characters fit: this is the only time the value is ever shown, and a token truncated at
@@ -294,7 +318,7 @@
294
318
  </div>
295
319
  {{/ui/modal}}
296
320
 
297
- <script nonce="{{cspNonce}}">
321
+ <script data-cfasync="false" nonce="{{cspNonce}}">
298
322
  document.addEventListener('DOMContentLoaded', () => {
299
323
 
300
324
  let showTokenValueElm = document.getElementById('showTokenValue');
@@ -334,13 +358,32 @@
334
358
  };
335
359
  }
336
360
 
337
- let mcpAccessPresets = JSON.parse(accessCardElm.dataset.mcpPresets || '{}');
338
- // What the mcp scope can reach at all, which is also what the "Full access" level means:
339
- // that level stores no record, so the surface grant list is its own description.
340
- let mcpCeiling = surfaceRequirements.mcp || { actions: [], groups: [], grants: [] };
361
+ // The two MCP access sections and what each level mints, from the same table the consent
362
+ // prompt and the MCP config page mint from
363
+ let mcpSections = JSON.parse(accessCardElm.dataset.mcpSections || '{}');
364
+ let mcpCustomElm = document.getElementById('mcpCustom');
365
+
366
+ let mcpScopes = Object.values(mcpSections).map(section => section.scope);
341
367
 
342
368
  let scopeElms = Array.from(document.querySelectorAll('.scope-entry'));
343
369
  let selectedScopes = () => scopeElms.filter(elm => elm.checked && !elm.disabled).map(elm => elm.dataset.scope);
370
+ let selectedMcpScopes = () => selectedScopes().filter(scope => mcpScopes.includes(scope));
371
+
372
+ // What the ticked MCP scopes can reach at all: the union of their surface tables. Read per
373
+ // call because it follows the scopes - a token holding only the management scope has no
374
+ // business ticking Messages in the custom editor.
375
+ let mcpCeilingFor = scopes => {
376
+ let ceiling = { actions: [], groups: [] };
377
+ for (let scope of scopes) {
378
+ let need = surfaceRequirements[scope];
379
+ if (!need) {
380
+ continue;
381
+ }
382
+ ceiling.actions = ceiling.actions.concat(need.actions.filter(value => !ceiling.actions.includes(value)));
383
+ ceiling.groups = ceiling.groups.concat(need.groups.filter(value => !ceiling.groups.includes(value)));
384
+ }
385
+ return ceiling;
386
+ };
344
387
 
345
388
  // Permissions are resolved per endpoint on the REST API and per tool call on the MCP
346
389
  // endpoint, so both of those scopes can carry a narrowing. The login-time scopes (SMTP,
@@ -353,7 +396,7 @@
353
396
  // be greyed while this is open. That reads correctly: API access is granted by "All", and
354
397
  // this is how to narrow it.
355
398
  let hasApiScope = () => selectedScopes().some(scope => ['*', 'api'].includes(scope));
356
- let hasMcpScope = () => selectedScopes().some(scope => ['*', 'mcp'].includes(scope));
399
+ let hasMcpScope = () => selectedScopes().some(scope => scope === '*' || mcpScopes.includes(scope));
357
400
  let narrowableScope = () => hasApiScope() || hasMcpScope();
358
401
 
359
402
  // The two editor modes. A token that reaches the MCP endpoint and not the REST API is a
@@ -363,9 +406,18 @@
363
406
  // permissions record covers both surfaces and the API side needs all thirteen sections.
364
407
  let mcpLevelMode = () => hasMcpScope() && !hasApiScope();
365
408
 
366
- let selectedMcpLevel = () => {
367
- let elm = document.querySelector('input[name="mcpAccess"]:checked');
368
- return (elm && elm.value) || 'read';
409
+ // The level per section, read through the shared helper: a section whose scope is not
410
+ // ticked has no radio group on screen and so comes back declined - the scope checkbox is
411
+ // this form's way of switching a section off
412
+ let selectedMcpLevels = () => {
413
+ let ticked = selectedMcpScopes();
414
+ let choice = uiMcpLevelChoice(mcpSections, 'mcpLevel_');
415
+ for (let key of Object.keys(mcpSections)) {
416
+ if (!ticked.includes(mcpSections[key].scope)) {
417
+ choice[key] = 'none';
418
+ }
419
+ }
420
+ return choice;
369
421
  };
370
422
 
371
423
  // Sections the MCP surface can never reach are disabled while the level editor is showing,
@@ -396,29 +448,23 @@
396
448
  // an empty one: it means the scopes are the only bound.
397
449
  let effectiveRecord = () => {
398
450
  if (mcpLevelMode()) {
399
- let level = selectedMcpLevel();
400
- if (level !== 'custom') {
401
- let record = mcpAccessPresets[level];
402
- if (record) {
403
- return { actions: record.actions, groups: record.groups, unrestricted: false };
404
- }
405
- // The full level is the one that legitimately stores no record. Any other level
406
- // missing from the table means the table did not load, and a missing preset must
407
- // not quietly mint a wider credential than the level on screen promises - the
408
- // MCP config page's generator refuses the same way, and the consent route
409
- // defaults the same direction.
410
- return {
411
- actions: mcpCeiling.actions,
412
- groups: mcpCeiling.groups,
413
- unrestricted: true,
414
- unknownLevel: !Object.prototype.hasOwnProperty.call(mcpAccessPresets, level)
415
- };
451
+ if (!mcpCustomElm.checked) {
452
+ // The pair list the selected levels mint, through the shared helper, so a level
453
+ // mints here exactly what it mints on the consent prompt
454
+ return uiMcpLevelRecord(mcpSections, selectedMcpLevels());
416
455
  }
417
456
  } else if (!permissionsEnabledElm.checked) {
418
457
  return { actions: allActions, groups: Object.keys(axisLabels.group), unrestricted: true };
419
458
  }
420
459
 
421
- return { actions: tickedValues('.permission-action'), groups: tickedValues('.permission-group'), unrestricted: false };
460
+ return {
461
+ actions: tickedValues('.permission-action'),
462
+ groups: tickedValues('.permission-group'),
463
+ // The scope bound applies to a custom record too: the count must not promise a
464
+ // management tool to a token that only holds the mail scope
465
+ surfaces: mcpLevelMode() ? selectedMcpScopes() : undefined,
466
+ unrestricted: false
467
+ };
422
468
  };
423
469
 
424
470
  // Applies a permission record to the axes. Shared by the API presets and by the switch into
@@ -434,10 +480,11 @@
434
480
 
435
481
  let syncAxisAvailability = () => {
436
482
  let restrictToMcp = mcpLevelMode();
483
+ let ceiling = mcpCeilingFor(selectedMcpScopes());
437
484
 
438
485
  for (let elm of document.querySelectorAll('.permission-axis')) {
439
486
  let axis = elm.classList.contains('permission-action') ? 'actions' : 'groups';
440
- let reachable = !restrictToMcp || mcpCeiling[axis].includes(elm.dataset.value);
487
+ let reachable = !restrictToMcp || ceiling[axis].includes(elm.dataset.value);
441
488
 
442
489
  // Disabled rather than unticked: flipping the scopes back has to restore the
443
490
  // selection rather than quietly lose it, and a disabled box is skipped by every
@@ -479,6 +526,35 @@
479
526
  // stale count cannot survive a scope change.
480
527
  window.uiMcpToolCount(mcpToolCountElm, hasMcpScope() ? Object.assign({ account: accountElm.value }, record) : null);
481
528
 
529
+ let rest = document.createElement('div');
530
+ rest.className = 'text-base-content/60';
531
+ rest.textContent = 'It cannot reach anything else, create tokens or read stored credentials.';
532
+
533
+ if (record.grants) {
534
+ // A level per section, each read out in the words of the table it came from
535
+ if (!record.grants.length) {
536
+ let line = document.createElement('div');
537
+ line.className = 'text-warning';
538
+ line.textContent = 'No access level is selected, so this token would not be able to do anything.';
539
+ permissionOutcomeTextElm.append(line);
540
+ return;
541
+ }
542
+ let levels = selectedMcpLevels();
543
+ for (let key of Object.keys(mcpSections)) {
544
+ let level = mcpSections[key].levels.find(entry => entry.value === levels[key]);
545
+ if (!level) {
546
+ continue;
547
+ }
548
+ let line = document.createElement('div');
549
+ let label = document.createElement('strong');
550
+ label.textContent = mcpSections[key].label + ' (' + level.label + '): ';
551
+ line.append(label, document.createTextNode('can ' + level.actions + ' across ' + level.groups + '.'));
552
+ permissionOutcomeTextElm.append(line);
553
+ }
554
+ permissionOutcomeTextElm.append(rest);
555
+ return;
556
+ }
557
+
482
558
  if (!record.unrestricted && (!record.actions.length || !record.groups.length)) {
483
559
  let line = document.createElement('div');
484
560
  line.className = 'text-warning';
@@ -504,9 +580,6 @@
504
580
  permissionOutcomeTextElm.append(cannot);
505
581
  }
506
582
 
507
- let rest = document.createElement('div');
508
- rest.className = 'text-base-content/60';
509
- rest.textContent = 'It cannot reach anything else, or read credentials and settings.';
510
583
  permissionOutcomeTextElm.append(rest);
511
584
  };
512
585
 
@@ -525,15 +598,18 @@
525
598
  scopes = Object.keys(surfaceRequirements);
526
599
  }
527
600
 
601
+ let covers = ([action, group]) => uiMcpRecordAllows(record, action, group);
602
+
528
603
  let blocked = scopes
529
604
  .filter(scope => surfaceRequirements[scope])
530
605
  .filter(scope => {
531
606
  let need = surfaceRequirements[scope];
532
607
  if (need.mode === 'any') {
533
608
  // Per-request surface: usable while any one (action, group) pair survives
534
- return !need.grants.some(([action, group]) => record.actions.includes(action) && record.groups.includes(group));
609
+ return !need.grants.some(covers);
535
610
  }
536
- return !need.actions.every(value => record.actions.includes(value)) || !need.groups.every(value => record.groups.includes(value));
611
+ // Login-time surface: every pair it exercises has to survive
612
+ return !need.grants.every(covers);
537
613
  })
538
614
  .map(scope => surfaceRequirements[scope].label);
539
615
 
@@ -582,11 +658,18 @@
582
658
  apiLimitBlockElm.classList.toggle('hidden', levelMode);
583
659
  syncAxisAvailability();
584
660
 
585
- // The matrix is the detail view behind either mode: the "Custom permissions" level on
661
+ // A section is shown while its scope is ticked: the scope checkbox is how this form
662
+ // declines a section, so an unticked scope must not leave a level on screen
663
+ let ticked = selectedMcpScopes();
664
+ for (let block of document.querySelectorAll('.mcp-section-block')) {
665
+ block.classList.toggle('hidden', !ticked.includes(block.dataset.mcpScope));
666
+ }
667
+
668
+ // The matrix is the detail view behind either mode: the "Custom permissions" opt-in on
586
669
  // one side, the restriction toggle on the other. The API presets are shapes for the
587
670
  // REST API, so they stay out of the way in level mode, where the named levels above
588
671
  // are the presets.
589
- permissionSectionElm.classList.toggle('hidden', levelMode ? selectedMcpLevel() !== 'custom' : !permissionsEnabledElm.checked);
672
+ permissionSectionElm.classList.toggle('hidden', levelMode ? !mcpCustomElm.checked : !permissionsEnabledElm.checked);
590
673
  permissionPresetRowElm.classList.toggle('hidden', levelMode);
591
674
  };
592
675
 
@@ -594,7 +677,7 @@
594
677
  // ticked - the default selection carries the mcp scope with everything else, and warning
595
678
  // about a disabled endpoint on a page nobody opened for MCP is noise.
596
679
  let mcpDisabledHintElm = document.getElementById('mcpDisabledHint');
597
- let scopesMcpElm = document.getElementById('scopesMcp');
680
+ let scopesMcpElms = [document.getElementById('scopesMcpManage'), document.getElementById('scopesMcp')];
598
681
 
599
682
  let syncAll = () => {
600
683
  syncAccessCard();
@@ -602,7 +685,7 @@
602
685
  syncPermissionOutcome();
603
686
 
604
687
  if (mcpDisabledHintElm) {
605
- mcpDisabledHintElm.classList.toggle('hidden', !scopesMcpElm.checked || scopesMcpElm.disabled);
688
+ mcpDisabledHintElm.classList.toggle('hidden', !scopesMcpElms.some(elm => elm.checked && !elm.disabled));
606
689
  }
607
690
  };
608
691
 
@@ -618,19 +701,28 @@
618
701
  syncAll();
619
702
  });
620
703
 
621
- // The level the axes are seeded from when "Custom permissions" is picked, which is what its
622
- // hint promises. Starts at the default selection rather than empty.
623
- let lastNamedLevel = selectedMcpLevel();
624
- for (let elm of document.querySelectorAll('input[name="mcpAccess"]')) {
625
- elm.addEventListener('change', () => {
626
- if (elm.value === 'custom') {
627
- let record = mcpAccessPresets[lastNamedLevel];
628
- applyRecord(record ? record.actions : mcpCeiling.actions, record ? record.groups : mcpCeiling.groups);
629
- } else {
630
- lastNamedLevel = elm.value;
704
+ // Custom starts from the levels selected above, which is what its hint promises: the axes
705
+ // are seeded from the pairs those levels mint, which is the two-axis record closest to them
706
+ mcpCustomElm.addEventListener('change', () => {
707
+ if (mcpCustomElm.checked) {
708
+ let record = uiMcpLevelRecord(mcpSections, selectedMcpLevels());
709
+ let actions = [];
710
+ let groups = [];
711
+ for (let grant of record.grants) {
712
+ if (!actions.includes(grant.action)) {
713
+ actions.push(grant.action);
714
+ }
715
+ if (!groups.includes(grant.group)) {
716
+ groups.push(grant.group);
717
+ }
631
718
  }
632
- syncAll();
633
- });
719
+ applyRecord(actions, groups);
720
+ }
721
+ syncAll();
722
+ });
723
+
724
+ for (let elm of document.querySelectorAll('input[name^="mcpLevel_"]')) {
725
+ elm.addEventListener('change', syncAll);
634
726
  }
635
727
 
636
728
  for (let elm of document.querySelectorAll('.permission-axis, .scope-entry')) {
@@ -689,12 +781,12 @@
689
781
  document.getElementById('showTokenError').classList.add('hidden');
690
782
  uiModal.open('#showToken');
691
783
 
692
- // Omitting the field is what "not narrowed" means on the record, so an unchecked toggle -
693
- // and the MCP "Full access" level, which the access table stores as null for exactly that
694
- // reason - must not post an empty object. That is a different answer, and the API refuses
695
- // it.
784
+ // Omitting the field is what "not narrowed" means on the record, so an unchecked toggle
785
+ // must not post an empty object. That is a different answer, and the API refuses it. An
786
+ // MCP token minted by level always carries its pair list explicitly, so what the operator
787
+ // saw is exactly what the credential holds.
696
788
  let record = effectiveRecord();
697
- let permissions = record.unrestricted ? null : { actions: record.actions, groups: record.groups };
789
+ let permissions = record.unrestricted ? null : record.grants ? { grants: record.grants } : { actions: record.actions, groups: record.groups };
698
790
 
699
791
  let refuse = message => {
700
792
  document.getElementById('showTokenLoader').classList.add('hidden');
@@ -704,10 +796,11 @@
704
796
  uiModal.open('#showToken');
705
797
  };
706
798
 
707
- // The access table failed to load, so the level on screen cannot be resolved to the
708
- // record it promises. Refused rather than posted: what would go out is the absence of a
709
- // narrowing, which is the widest answer there is.
710
- if (record.unknownLevel) {
799
+ // The section table failed to load, so the levels on screen cannot be resolved to the
800
+ // record they promise. Refused rather than posted, as the MCP config page's generator
801
+ // refuses: what would go out is a record that grants nothing, which the API refuses
802
+ // too, but with an answer that names the wrong cause.
803
+ if (mcpLevelMode() && !mcpCustomElm.checked && !Object.keys(mcpSections).length) {
711
804
  refuse('The access levels failed to load, so the selected level cannot be applied. Reload the page and try again.');
712
805
  return;
713
806
  }
@@ -715,7 +808,11 @@
715
808
  // Said here rather than left to the schema. tokenPermissionsSchema refuses an empty axis
716
809
  // too, but a joi rejection reaches this page as a bare "HTTP error! status: 400", which
717
810
  // tells the reader nothing about the box they left unticked.
718
- if (permissions && (!permissions.actions.length || !permissions.groups.length)) {
811
+ if (permissions && permissions.grants && !permissions.grants.length) {
812
+ refuse('Select an access level for at least one MCP scope. A token that grants nothing cannot make any request.');
813
+ return;
814
+ }
815
+ if (permissions && permissions.actions && (!permissions.actions.length || !permissions.groups.length)) {
719
816
  let missing = !permissions.actions.length ? 'action' : 'section';
720
817
  refuse(`Select at least one ${missing}. A restriction that allows nothing would create a token that cannot make any request.`);
721
818
  return;
@@ -37,7 +37,7 @@ focus ring on) the corner close button --}}
37
37
  </div>
38
38
  </dialog>
39
39
 
40
- <script nonce="{{cspNonce}}">
40
+ <script data-cfasync="false" nonce="{{cspNonce}}">
41
41
  document.addEventListener('DOMContentLoaded', () => {
42
42
 
43
43
  document.getElementById('resubscribe-link').addEventListener('click', e => {
@@ -11,7 +11,7 @@
11
11
  {{>webhook_form}}
12
12
 
13
13
  <div class="mb-6">
14
- {{> ui/btn label="Update webhook" type="submit" icon="icon-[tabler--device-floppy]"}}
14
+ {{> ui/btn label="Save changes" type="submit" icon="icon-[tabler--device-floppy]"}}
15
15
  </div>
16
16
  </form>
17
17
 
@@ -1,11 +1,11 @@
1
- {{#> ui/page-header title="Webhook Routes" icon="icon-[tabler--webhook]" subtitle="Send HTTP callbacks to custom targets when email events match your filters." badgeLabel=total badgeVariant="neutral" class="mb-6"}}
1
+ {{#> ui/page-header title="Webhook Routes" icon="icon-[tabler--webhook]" subtitle="Filter email events, customize their payloads, and send them to your chosen URLs." badgeLabel=total badgeVariant="neutral" class="mb-6"}}
2
2
  {{> ui/btn href=newLink label="Create webhook route" icon="icon-[tabler--plus]"}}
3
3
  {{/ui/page-header}}
4
4
 
5
5
  {{> ui/search-crumb parentHref="/admin/webhooks" parentLabel="Webhook Routes" query=query}}
6
6
 
7
7
  {{#unless webhooksEnabled}}
8
- <div class="alert alert-soft alert-warning mb-6"><span><strong>Note:</strong> Webhook processing is currently disabled
8
+ <div class="alert alert-soft alert-warning mb-6"><span><strong>Note:</strong> Webhooks are disabled
9
9
  for EmailEngine.
10
10
  <a href="/admin/config/webhooks" class="link link-animated">Enable webhooks in configuration
11
11
  settings</a>.</span></div>
@@ -14,7 +14,7 @@
14
14
  {{#if webhooks}}
15
15
  <div class="card bg-base-100 shadow-md mb-6">
16
16
  <div class="overflow-x-auto">
17
- <table class="table">
17
+ <table class="table ee-table-stack">
18
18
  <thead>
19
19
  <tr>
20
20
  <th>Name</th>
@@ -34,15 +34,15 @@
34
34
  {{> ui/entity-id id=id label="Webhook Route ID"}}
35
35
  </td>
36
36
 
37
- <td class="relative">
37
+ <td class="relative" data-label="Description">
38
38
  {{> ui/row-link href=(concat "/admin/webhooks/webhook/" id)}}{{description}}
39
39
  </td>
40
40
 
41
- <td class="relative">
41
+ <td class="relative" data-label="Triggered">
42
42
  {{> ui/row-link href=(concat "/admin/webhooks/webhook/" id)}}{{tcount}}
43
43
  </td>
44
44
 
45
- <td class="relative">
45
+ <td class="relative" data-label="Status">
46
46
  {{> ui/row-link href=(concat "/admin/webhooks/webhook/" id)}}
47
47
  {{#if enabled}}
48
48
 
@@ -56,7 +56,7 @@
56
56
  {{/if}}
57
57
  </td>
58
58
 
59
- <td class="relative text-end">
59
+ <td class="ee-stack-actions relative text-end">
60
60
  {{> ui/row-actions openHref=(concat "/admin/webhooks/webhook/" id) label="Webhook route actions"
61
61
  deleteModal="#deleteWebhook" deleteId=id deleteName=name}}
62
62
  </td>
@@ -75,10 +75,9 @@
75
75
  {{#> ui/details summary="How webhook routes work" class="card bg-base-100 shadow-md mb-6"}}
76
76
  <div>
77
77
  <p class="mb-2">
78
- EmailEngine tests all events against <em>filter functions</em> of webhook routes. When
79
- a filter matches, EmailEngine sends a webhook to the target URL of that route. If
80
- the webhook target requires a specific payload format, you can define a <em>mapping
81
- function</em> to modify the payload before sending.
78
+ Each enabled route evaluates events with its filter function. When the filter returns <code>true</code>,
79
+ EmailEngine sends the event to the route's target URL. Add a map function to change the payload format.
80
+ Routes run independently of the default webhook target and its event selection.
82
81
  </p>
83
82
  <p class="mb-0"><a href="https://learn.emailengine.app/docs/integrations/low-code" target="_blank"
84
83
  rel="noopener noreferrer" referrerpolicy="no-referrer" class="link link-animated">Learn more about webhook