emailengine-app 2.79.6 → 2.79.7

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.
@@ -79,6 +79,8 @@
79
79
  files are not scanned, so the classes are safelisted here */
80
80
  @source inline('icon-[tabler--send] icon-[tabler--arrow-right-circle] icon-[tabler--brand-google] icon-[tabler--brand-windows]');
81
81
  @source inline('icon-[tabler--lock-open] icon-[tabler--link] icon-[tabler--key] icon-[tabler--database] icon-[tabler--brand-docker]');
82
+ /* server-driven passkey device icons (describePasskeyDevice in lib/ui-routes/auth-routes.js) */
83
+ @source inline('icon-[tabler--fingerprint] icon-[tabler--device-mobile] icon-[tabler--usb]');
82
84
 
83
85
  @theme {
84
86
  --font-sans: 'PT Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
@@ -234,6 +236,59 @@
234
236
  * and emailengine.css; colors converted to theme tokens for light+dark)
235
237
  * ------------------------------------------------------------------------- */
236
238
  @layer components {
239
+ /* Settings row on the account security page: label / value / action. Three columns from
240
+ * the sm breakpoint up, stacked below it - the row used a bare grid-cols-3 at every
241
+ * width, and at 390px each column is ~110px, narrow enough that every multi-word button
242
+ * label wrapped out of its own fixed-height box. Stacked, the action goes full width the
243
+ * way a form button does on a phone.
244
+ *
245
+ * The action buttons share one width so the right-hand column reads as a column: with
246
+ * natural widths the labels here run 108px to 174px, and right-aligning them left a
247
+ * ragged staircase of left edges. A class rather than utilities because the rule is one
248
+ * definition for every row, and the min-width has to be lifted again for the one row
249
+ * that carries a pair of buttons. */
250
+ .ee-setting-row {
251
+ display: grid;
252
+ gap: 0.5rem;
253
+ }
254
+
255
+ /* Stacked: a column, so a row carrying two buttons keeps them apart instead of letting
256
+ * them touch */
257
+ .ee-setting-action {
258
+ display: flex;
259
+ flex-direction: column;
260
+ gap: 0.5rem;
261
+ }
262
+
263
+ .ee-setting-action .btn {
264
+ width: 100%;
265
+ }
266
+
267
+ @media (width >= 40rem) {
268
+ .ee-setting-row {
269
+ grid-template-columns: repeat(3, minmax(0, 1fr));
270
+ align-items: center;
271
+ gap: 1rem;
272
+ }
273
+
274
+ .ee-setting-action {
275
+ flex-direction: row;
276
+ flex-wrap: wrap;
277
+ justify-content: flex-end;
278
+ }
279
+
280
+ .ee-setting-action .btn {
281
+ width: auto;
282
+ min-width: 12.5rem;
283
+ }
284
+
285
+ /* A row whose action is a pair of dialogs shares the width between them instead of
286
+ * claiming the single-action width twice */
287
+ .ee-setting-action-pair .btn {
288
+ min-width: 0;
289
+ }
290
+ }
291
+
237
292
  /* FlyonUI ships no badge-neutral variant (the base .badge already uses
238
293
  * neutral tokens); define it explicitly so the SSE badge updater's
239
294
  * class swaps (badge-${type} with type "neutral") stay meaningful */
package/static/js/app.js CHANGED
@@ -138,7 +138,10 @@ document.addEventListener('DOMContentLoaded', () => {
138
138
  let updateRelativeTimes = () => {
139
139
  document.querySelectorAll('.relative-time').forEach(entry => {
140
140
  let time = new Date(entry.dataset.time);
141
- if (time) {
141
+ // NaN, not falsy, is what an unparsable stamp yields - a Date object is always
142
+ // truthy. formatTimeAgo runs off the end of DIVISIONS for one and throws, which
143
+ // used to take out the .local-time and drop-target wiring set up below it.
144
+ if (!isNaN(time)) {
142
145
  entry.textContent = formatTimeAgo(time);
143
146
  }
144
147
  });
@@ -408,38 +411,4 @@ document.addEventListener('DOMContentLoaded', () => {
408
411
  }
409
412
  }
410
413
 
411
- for (let f of document.querySelectorAll('form.pending-form')) {
412
- f.addEventListener('submit', () => {
413
- for (let b of f.querySelectorAll('button[type="submit"], button:not([type])')) {
414
- b.disabled = true;
415
- b.classList.add('disabled');
416
- let icon = b.querySelector('span[class*="icon-["]');
417
- if (icon) {
418
- for (let [, className] of icon.classList.entries()) {
419
- if (/^icon-\[/.test(className)) {
420
- icon.classList.remove(className);
421
- icon.dataset.oldIcon = className;
422
- icon.classList.add('icon-updated');
423
- }
424
- }
425
- icon.classList.add('icon-[tabler--loader-2]', 'animate-spin');
426
- }
427
- }
428
- });
429
- }
430
- });
431
-
432
- window.addEventListener('pageshow', () => {
433
- for (let icon of document.querySelectorAll('.icon-updated')) {
434
- icon.classList.remove('icon-[tabler--loader-2]', 'animate-spin', 'icon-updated');
435
- if (icon.dataset.oldIcon) {
436
- icon.classList.add(icon.dataset.oldIcon);
437
- icon.dataset.oldIcon = '';
438
- }
439
- }
440
-
441
- for (let b of document.querySelectorAll('.disabled')) {
442
- b.classList.remove('disabled');
443
- b.disabled = false;
444
- }
445
414
  });
@@ -1,5 +1,51 @@
1
1
  'use strict';
2
2
 
3
+ // A passkey is only tellable apart in the security-page list by the name given here, and the
4
+ // field defaults to "Unnamed passkey" when left empty, so the modal opens with the current
5
+ // browser and platform filled in. It stays fully editable - this is a starting point, not a
6
+ // claim about the authenticator, which may well be a phone or a security key.
7
+ // Lookup tables rather than if/else ladders: a new Chromium fork is then a row, not a branch.
8
+ // Order matters - the Chromium-based browsers all keep "Chrome" in the string, and Chrome itself
9
+ // keeps "Safari".
10
+ var PASSKEY_PLATFORMS = [
11
+ [/iPhone|iPad|iPod/, 'iOS'],
12
+ [/Android/, 'Android'],
13
+ [/Mac OS X|Macintosh/, 'macOS'],
14
+ [/Windows/, 'Windows'],
15
+ [/Linux/, 'Linux']
16
+ ];
17
+
18
+ var PASSKEY_BROWSERS = [
19
+ [/Edg\//, 'Edge'],
20
+ [/OPR\/|Opera/, 'Opera'],
21
+ [/Firefox\//, 'Firefox'],
22
+ [/Chrome\//, 'Chrome'],
23
+ [/Safari\//, 'Safari']
24
+ ];
25
+
26
+ function matchUserAgent(table, ua) {
27
+ for (var i = 0; i < table.length; i++) {
28
+ if (table[i][0].test(ua)) {
29
+ return table[i][1];
30
+ }
31
+ }
32
+ return '';
33
+ }
34
+
35
+ function suggestPasskeyName() {
36
+ var ua = navigator.userAgent || '';
37
+
38
+ // userAgentData.platform first, the way static/js/ui.js reads it: it is the value that
39
+ // survives the user-agent string reduction browsers are rolling out
40
+ var platform = (navigator.userAgentData && navigator.userAgentData.platform) || matchUserAgent(PASSKEY_PLATFORMS, ua);
41
+ var browser = matchUserAgent(PASSKEY_BROWSERS, ua);
42
+
43
+ if (browser && platform) {
44
+ return browser + ' on ' + platform;
45
+ }
46
+ return browser || platform || '';
47
+ }
48
+
3
49
  document.addEventListener('DOMContentLoaded', function () {
4
50
  var registerBtn = document.getElementById('register-passkey-btn');
5
51
  if (!registerBtn) {
@@ -15,7 +61,7 @@ document.addEventListener('DOMContentLoaded', function () {
15
61
  registerBtn.addEventListener('click', function () {
16
62
  var nameInput = document.getElementById('passkey-name');
17
63
  if (nameInput) {
18
- nameInput.value = '';
64
+ nameInput.value = suggestPasskeyName();
19
65
  }
20
66
  var passwordInput = document.getElementById('passkey-current-password');
21
67
  if (passwordInput) {
@@ -79,6 +125,9 @@ document.addEventListener('DOMContentLoaded', function () {
79
125
  body: JSON.stringify({
80
126
  crumb: crumbValue,
81
127
  challengeId: optionsData.challengeId,
128
+ // resent because the server confirms it again where the credential is
129
+ // actually stored, not only when it issued the options
130
+ password: password,
82
131
  name: name,
83
132
  credential: regResponse
84
133
  })
@@ -84,3 +84,131 @@ document.addEventListener('DOMContentLoaded', () => {
84
84
  }
85
85
  }, 15 * 1000);
86
86
  });
87
+
88
+ /*
89
+ * Double-submit guard for the public POST forms (the hosted authentication
90
+ * steps and the unsubscribe pages).
91
+ *
92
+ * These are the slow ones: choosing a provider mints an account and hands the
93
+ * browser to an OAuth provider, and the email/name step runs autodiscovery
94
+ * against DNS and the provider's autoconfig endpoints. Nothing on the page
95
+ * moves while that happens, so the button gets pressed again - and the second
96
+ * POST loses the race against the single-use nonce the first one consumed,
97
+ * which shows the visitor an error for a step that succeeded.
98
+ *
99
+ * Same mechanism as the admin guard in static/js/ui.js, which carries the full
100
+ * reasoning; it is written out again here because the public pages share no
101
+ * code with the admin UI.
102
+ */
103
+ const eeSubmittedForms = new Map();
104
+
105
+ // Toggle a public-page button's busy state: unclickable, with its leading icon
106
+ // swapped for the spinner (or one added when the button has no icon).
107
+ window.eeButtonBusy = (btn, busy) => {
108
+ btn.disabled = !!busy;
109
+
110
+ if (btn.tagName === 'INPUT') {
111
+ // <input type="image"> provider buttons - no children to spin
112
+ return;
113
+ }
114
+
115
+ let icon = btn.querySelector('.ee-icon');
116
+ if (!icon) {
117
+ if (!busy) {
118
+ return;
119
+ }
120
+ icon = document.createElement('span');
121
+ icon.className = 'ee-icon';
122
+ icon.dataset.busySpinner = 'true';
123
+ btn.prepend(icon);
124
+ }
125
+
126
+ if (busy) {
127
+ if (!('idleIcon' in icon.dataset)) {
128
+ icon.dataset.idleIcon = Array.from(icon.classList).find(c => c.startsWith('ee-icon-')) || '';
129
+ }
130
+ if (icon.dataset.idleIcon) {
131
+ icon.classList.remove(icon.dataset.idleIcon);
132
+ }
133
+ icon.classList.add('ee-icon-loader', 'ee-spin');
134
+ } else if (icon.dataset.busySpinner) {
135
+ icon.remove();
136
+ } else {
137
+ icon.classList.remove('ee-icon-loader', 'ee-spin');
138
+ if (icon.dataset.idleIcon) {
139
+ icon.classList.add(icon.dataset.idleIcon);
140
+ }
141
+ }
142
+ };
143
+
144
+ // Bubble phase on document, so a page that runs its own submit handling (the
145
+ // IMAP server settings step tests the connection first) has already cancelled
146
+ // the event by the time this sees it.
147
+ document.addEventListener('submit', e => {
148
+ let form = e.target;
149
+ if (e.defaultPrevented || !form || form.method !== 'post') {
150
+ return;
151
+ }
152
+
153
+ let target = form.target.trim().toLowerCase();
154
+ if (target && target !== '_self') {
155
+ return;
156
+ }
157
+
158
+ if (eeSubmittedForms.has(form)) {
159
+ // Already submitted once; covers implicit submission (Enter in a field)
160
+ e.preventDefault();
161
+ return;
162
+ }
163
+
164
+ let submitter = e.submitter;
165
+ let buttons = form.querySelectorAll('button[type="submit"], button:not([type]), input[type="submit"], input[type="image"]');
166
+ let submitterField = null;
167
+
168
+ // The form data set is built after this event and skips disabled controls,
169
+ // the submitter included - so a submit button that carries a name/value
170
+ // would stop posting it. Move it into a hidden input first.
171
+ if (submitter && submitter.name) {
172
+ submitterField = document.createElement('input');
173
+ submitterField.type = 'hidden';
174
+ submitterField.name = submitter.name;
175
+ submitterField.value = submitter.value;
176
+ form.appendChild(submitterField);
177
+ }
178
+
179
+ eeSubmittedForms.set(form, { buttons, submitter, submitterField });
180
+
181
+ for (let btn of buttons) {
182
+ // A browser that reports no event.submitter leaves us unable to tell which button was
183
+ // pressed, and disabling one that carries a name would drop the value the server branches
184
+ // on - so those keep working and the latch alone does the guarding.
185
+ if (btn === submitter || (!submitter && btn.name)) {
186
+ continue;
187
+ }
188
+ btn.disabled = true;
189
+ }
190
+ if (submitter) {
191
+ window.eeButtonBusy(submitter, true);
192
+ }
193
+ });
194
+
195
+ // Back to a submitted form through the bfcache: the page comes back with the
196
+ // latch set and the buttons disabled, so clear both.
197
+ window.addEventListener('pageshow', e => {
198
+ if (!e.persisted) {
199
+ return;
200
+ }
201
+ for (let state of eeSubmittedForms.values()) {
202
+ if (state.submitterField) {
203
+ state.submitterField.remove();
204
+ }
205
+ for (let btn of state.buttons) {
206
+ if (btn === state.submitter) {
207
+ window.eeButtonBusy(btn, false);
208
+ } else {
209
+ btn.disabled = false;
210
+ }
211
+ }
212
+ }
213
+ eeSubmittedForms.clear();
214
+ });
package/static/js/ui.js CHANGED
@@ -1,4 +1,4 @@
1
- /* global document, window, navigator, localStorage, fetch, Event, AbortController, HSStaticMethods, HSOverlay */
1
+ /* global document, window, navigator, localStorage, fetch, Event, KeyboardEvent, AbortController, HSStaticMethods, HSOverlay */
2
2
 
3
3
  'use strict';
4
4
 
@@ -79,6 +79,29 @@ window.uiModal = {
79
79
  }
80
80
  };
81
81
 
82
+ // FlyonUI picks the component that handles a keypress from the event target, and a tab strip
83
+ // reports itself as opened while defining no Escape handler - so it swallows the key instead of
84
+ // letting it reach the dialog around it, and a modal containing tabs stops closing on Escape the
85
+ // moment the reader switches tab, while every other modal in the app still closes. Re-aim the key
86
+ // at the dialog rather than closing it here: HSOverlay defers parts of its close to timers and to
87
+ // transitionend, and driving it from outside strands the dialog (see the note on uiConfirm below).
88
+ // Capture phase, so this runs before the strip sees the event. The re-dispatched event targets the
89
+ // modal, which matches no [data-tab], so it cannot come back round.
90
+ document.addEventListener(
91
+ 'keydown',
92
+ e => {
93
+ if (e.key !== 'Escape' || !e.target || !e.target.closest) {
94
+ return;
95
+ }
96
+ let tab = e.target.closest('[data-tab]');
97
+ let modal = tab && tab.closest('.modal.open');
98
+ if (modal) {
99
+ modal.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
100
+ }
101
+ },
102
+ true
103
+ );
104
+
82
105
  // Promise-returning confirmation over a ui/modal. Resolves true only when the element matching
83
106
  // `okSelector` was clicked before the dialog closed; every other way out - Cancel, the corner
84
107
  // close, Escape, a backdrop click - resolves false, which is the safe answer for a
@@ -514,14 +537,44 @@ window.uiToastResult = (data, okMessage, failMessage) => {
514
537
  window.showToast(data.error ? status + data.error : failMessage, 'alert-triangle');
515
538
  };
516
539
 
517
- // Toggle an async action button's busy state: disable the button and swap its
518
- // icon span to a spinner while busy, restoring the original icon after
540
+ // Toggle an async action button's busy state: make the control unclickable and
541
+ // swap its icon span to a spinner while busy, restoring it after. Works on both
542
+ // <button> (disabled) and the action links in dropdown menus (<a> takes no
543
+ // disabled attribute, so it gets aria-disabled plus the pointer-events class).
544
+ // A control rendered without a leading icon gets a spinner span for the
545
+ // duration - the busy state has to be visible on those too.
519
546
  window.uiButtonBusy = (btn, busy) => {
520
- btn.disabled = !!busy;
521
- const icon = btn.querySelector('[class*="icon-["]');
522
- if (!icon) {
547
+ if (btn.tagName === 'A') {
548
+ btn.classList.toggle('pointer-events-none', !!busy);
549
+ btn.classList.toggle('opacity-60', !!busy);
550
+ if (busy) {
551
+ btn.setAttribute('aria-disabled', 'true');
552
+ } else if (!btn.classList.contains('dropdown-disabled')) {
553
+ // The reset owns the busy window, not the control's own state: an action that
554
+ // switches its entry off for good (clearing an account's stored logs empties the
555
+ // download and clear entries) keeps the disabled marker it just set.
556
+ btn.removeAttribute('aria-disabled');
557
+ }
558
+ } else {
559
+ btn.disabled = !!busy;
560
+ }
561
+
562
+ if (btn.tagName === 'INPUT') {
563
+ // void element - nothing to put a spinner inside
523
564
  return;
524
565
  }
566
+
567
+ let icon = btn.querySelector('[class*="icon-["]');
568
+ if (!icon) {
569
+ if (!busy) {
570
+ return;
571
+ }
572
+ icon = document.createElement('span');
573
+ icon.className = 'size-4 shrink-0';
574
+ icon.dataset.busySpinner = 'true';
575
+ btn.prepend(icon);
576
+ }
577
+
525
578
  if (busy) {
526
579
  if (!('idleIcon' in icon.dataset)) {
527
580
  icon.dataset.idleIcon = Array.from(icon.classList).find(c => c.startsWith('icon-[')) || '';
@@ -530,6 +583,8 @@ window.uiButtonBusy = (btn, busy) => {
530
583
  icon.classList.remove(icon.dataset.idleIcon);
531
584
  }
532
585
  icon.classList.add('icon-[tabler--loader-2]', 'animate-spin');
586
+ } else if (icon.dataset.busySpinner) {
587
+ icon.remove();
533
588
  } else {
534
589
  icon.classList.remove('icon-[tabler--loader-2]', 'animate-spin');
535
590
  if (icon.dataset.idleIcon) {
@@ -538,6 +593,128 @@ window.uiButtonBusy = (btn, busy) => {
538
593
  }
539
594
  };
540
595
 
596
+ /*
597
+ * Double-submit guard for the admin POST forms.
598
+ *
599
+ * A plain form POST gives no feedback while it is in flight, and the actions
600
+ * behind these forms are slow in the ways an operator cannot see: they talk to
601
+ * a mail server, an OAuth provider or the license server, or they rewrite a lot
602
+ * of Redis. Without feedback the button gets clicked again, and the second
603
+ * request either duplicates the work (a second account, a second delete) or
604
+ * loses a race against a single-use nonce and reports an error for an operation
605
+ * that actually succeeded. So the first submit latches the form: later submits
606
+ * are cancelled, and the button that was pressed spins until the navigation
607
+ * lands.
608
+ *
609
+ * Global rather than opt-in per form (it replaces a `pending-form` class that
610
+ * three forms out of forty carried): on this surface a POST that takes a while
611
+ * is the normal case, and a page that wants to own its submission cancels the
612
+ * event - which is exactly what the listener skips on.
613
+ */
614
+ const uiFormBusy = new Map();
615
+
616
+ // Bubble phase on document, so every listener the form itself installed has
617
+ // already run and event.defaultPrevented tells us whether the page took over.
618
+ // (A page that delegates from `document` instead registers after this file and
619
+ // so is not seen - the API reference's "Try it" forms do that, and stay clear of
620
+ // this guard by not being POST forms.)
621
+ document.addEventListener('submit', event => {
622
+ const form = event.target;
623
+ if (event.defaultPrevented || !form || form.method !== 'post') {
624
+ return;
625
+ }
626
+
627
+ // A form aimed at another browsing context leaves this page in place, so
628
+ // there is no navigation to end the busy state and nothing to latch.
629
+ const target = form.target.trim().toLowerCase();
630
+ if (target && target !== '_self') {
631
+ return;
632
+ }
633
+
634
+ if (uiFormBusy.has(form)) {
635
+ // Already submitted once. Covers implicit submission (Enter in a text
636
+ // field), which a disabled default button does not always stop.
637
+ event.preventDefault();
638
+ return;
639
+ }
640
+
641
+ const submitter = event.submitter;
642
+ // Static NodeList, so it stays usable as the record of what to re-enable.
643
+ // input[type="submit"] is not used on the admin pages today; it is in the
644
+ // selector because this guard applies to whatever form a page adds next.
645
+ const buttons = form.querySelectorAll('button[type="submit"], button:not([type]), input[type="submit"]');
646
+ let submitterField = null;
647
+
648
+ // The form data set is built AFTER this event and skips disabled controls,
649
+ // the submitter included - so disabling it would stop its name/value from
650
+ // posting, and that value is what picks the branch the server takes (the
651
+ // MCP consent page posts its decision that way). Move it into a hidden
652
+ // input first.
653
+ if (submitter && submitter.name) {
654
+ submitterField = document.createElement('input');
655
+ submitterField.type = 'hidden';
656
+ submitterField.name = submitter.name;
657
+ submitterField.value = submitter.value;
658
+ form.appendChild(submitterField);
659
+ }
660
+
661
+ uiFormBusy.set(form, { buttons, submitter, submitterField });
662
+
663
+ for (const btn of buttons) {
664
+ // A browser that reports no event.submitter leaves us unable to tell which button was
665
+ // pressed, and disabling one that carries a name would drop the value the server branches
666
+ // on - so those keep working and the latch alone does the guarding.
667
+ if (btn === submitter || (!submitter && btn.name)) {
668
+ continue;
669
+ }
670
+ btn.disabled = true;
671
+ }
672
+ if (submitter) {
673
+ window.uiButtonBusy(submitter, true);
674
+ }
675
+ });
676
+
677
+ // Back from a submitted form: the bfcache restores the page with the latch
678
+ // still set and the buttons still disabled, which would leave the form dead.
679
+ // (An aborted submit - Esc or Stop while the page stays - is deliberately not
680
+ // recovered: a reload fixes it, and a timer that guessed wrong would re-arm the
681
+ // buttons underneath a request that is still running.)
682
+ window.addEventListener('pageshow', event => {
683
+ if (!event.persisted) {
684
+ return;
685
+ }
686
+ for (const state of uiFormBusy.values()) {
687
+ if (state.submitterField) {
688
+ state.submitterField.remove();
689
+ }
690
+ for (const btn of state.buttons) {
691
+ if (btn === state.submitter) {
692
+ window.uiButtonBusy(btn, false);
693
+ } else {
694
+ btn.disabled = false;
695
+ }
696
+ }
697
+ }
698
+ uiFormBusy.clear();
699
+ });
700
+
701
+ // Run an async action from a button, with the button busy for its duration.
702
+ // The busy button is the re-entrancy guard, so the action cannot be started
703
+ // twice, and the reset runs however the action ends - the shape every action
704
+ // button that posts with fetch() needs, and the one that used to be spelled
705
+ // out (and occasionally forgotten) per page. `run` returns a promise; a
706
+ // rejection it does not handle itself is reported as a toast.
707
+ window.uiBusyAction = (btn, run) => {
708
+ if (btn.disabled || btn.getAttribute('aria-disabled') === 'true') {
709
+ return;
710
+ }
711
+ window.uiButtonBusy(btn, true);
712
+ Promise.resolve()
713
+ .then(run)
714
+ .catch(err => window.showToast('Request failed\n' + err.message, 'alert-triangle'))
715
+ .finally(() => window.uiButtonBusy(btn, false));
716
+ };
717
+
541
718
  // ACE editor theming: light and dark variants per editor kind, applied on
542
719
  // creation and re-applied whenever the admin theme changes. The theme files
543
720
  // must exist under static/js/ace/ - they are copied from ace-builds by