emailengine-app 2.79.2 → 2.79.4

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.
@@ -69,10 +69,12 @@ const {
69
69
  EMAIL_COMPLAINT_NOTIFY,
70
70
  MAX_INLINE_ATTACHMENT_SIZE,
71
71
  DEFAULT_MAX_IMAP_AUTH_FAILURE_TIME,
72
+ AUTH_FAILURE_DISABLED_FIELD,
72
73
  EMAIL_DELIVERY_ERROR_NOTIFY,
73
74
  EMAIL_SENT_NOTIFY
74
75
  } = require('../consts');
75
76
  const { buildRetentionPolicy } = require('../queue-retention');
77
+ const { readImapData } = require('../account/imap-data');
76
78
 
77
79
  // Configure download chunk size from environment or use default
78
80
  const DOWNLOAD_CHUNK_SIZE = getByteSize(readEnvValue('EENGINE_CHUNK_SIZE')) || DEFAULT_DOWNLOAD_CHUNK_SIZE;
@@ -486,9 +488,14 @@ class BaseClient {
486
488
  /**
487
489
  * Sets error state and manages error tracking/notifications
488
490
  * Implements logic to disable IMAP after repeated authentication failures
491
+ *
492
+ * The return value drives whether the caller sends a webhook. That is normally "is this a new
493
+ * error", so a run of identical failures is reported once - but it is also true when this call
494
+ * is the one that switches the account off, which is not a new error and still has to be heard.
495
+ *
489
496
  * @param {string} event - Error event type
490
497
  * @param {Object} data - Error details
491
- * @returns {boolean} Whether this is the first occurrence of this error
498
+ * @returns {boolean} Whether the caller should notify
492
499
  */
493
500
  async setErrorState(event, data) {
494
501
  // Retrieve previous error state for comparison
@@ -504,7 +511,7 @@ class BaseClient {
504
511
  this.state = event;
505
512
  await this.setStateVal();
506
513
 
507
- let isFirstOccurrence = true;
514
+ let shouldNotify = true;
508
515
 
509
516
  // Store current error state
510
517
  await this.redis.hSetExists(this.getAccountKey(), 'lastErrorState', JSON.stringify(data));
@@ -516,12 +523,12 @@ class BaseClient {
516
523
 
517
524
  if (data.serverResponseCode && data.serverResponseCode === prevLastErrorState.serverResponseCode) {
518
525
  // error code did not change, assume it is the same error
519
- isFirstOccurrence = false;
526
+ shouldNotify = false;
520
527
  } else {
521
528
  try {
522
529
  deepEqual(data, prevLastErrorState);
523
530
  // nothing changed
524
- isFirstOccurrence = false;
531
+ shouldNotify = false;
525
532
  } catch (err) {
526
533
  // seems different
527
534
  }
@@ -529,7 +536,7 @@ class BaseClient {
529
536
  }
530
537
 
531
538
  // Track error occurrences
532
- if (isFirstOccurrence) {
539
+ if (shouldNotify) {
533
540
  const txn = createTransaction(this.redis, { logger: this.logger });
534
541
  txn.add('hSetExists', this.getAccountKey(), 'lastError:errorCount', 1);
535
542
  txn.add('hSetExists', this.getAccountKey(), 'lastError:first', new Date().toISOString());
@@ -560,53 +567,124 @@ class BaseClient {
560
567
  switch (event) {
561
568
  case 'authenticationError':
562
569
  if (errorCount > 0 && firstError && Date.now() - firstError.getTime() > MAX_IMAP_AUTH_FAILURE_TIME) {
563
- // disable IMAP
564
- let imapData;
565
- let imapInfo = await this.redis.hget(this.getAccountKey(), 'imap');
566
- if (imapInfo) {
567
- try {
568
- imapData = JSON.parse(imapInfo);
569
- } catch (err) {
570
- this.logger.error({ msg: 'Failed parsing IMAP data', err });
571
- }
572
- }
573
- if (imapData && !imapData.disabled) {
574
- imapData.disabled = true;
575
-
576
- // Disable IMAP and reset error counters
577
- const disableTxn = createTransaction(this.redis, { logger: this.logger });
578
- disableTxn.add('hSetExists', this.getAccountKey(), 'imap', JSON.stringify(imapData));
579
- disableTxn.add('hdel', this.getAccountKey(), 'lastError:errorCount', 'lastError:first');
580
- disableTxn.add(
581
- 'hSetExists',
582
- this.getAccountKey(),
583
- 'lastErrorState',
584
- JSON.stringify({
585
- description: 'IMAP was disabled for the account due to exceeding the authentication error threshold',
586
- response: data.response
587
- })
588
- );
589
- await disableTxn.exec();
590
-
591
- this.logger.warn({
592
- msg: 'IMAP was disabled for the account due to exceeding the authentication error threshold',
593
- errorEvent: event,
594
- firstError: firstError.toISOString(),
595
- timeThreshold: MAX_IMAP_AUTH_FAILURE_TIME,
596
- errorCount
597
- });
598
-
599
- // Close the connection after disabling
600
- setImmediate(() => {
601
- this.close();
602
- });
570
+ const disabled = await this.disableAfterAuthFailures({ event, firstError, errorCount, data });
571
+ if (disabled) {
572
+ // Report it. This branch only runs for a repeat of an error the caller
573
+ // has already been told about, and would normally suppress the webhook
574
+ // as unchanged - but an account going offline until a human
575
+ // re-authenticates it is the one thing here an operator has to hear
576
+ // about, and until now it happened in silence.
577
+ shouldNotify = true;
603
578
  }
604
579
  }
605
580
  break;
606
581
  }
607
582
  }
608
583
 
609
- return isFirstOccurrence;
584
+ return shouldNotify;
585
+ }
586
+
587
+ /**
588
+ * Whether mail sync has been switched off for this account, by the operator or by the
589
+ * auth-failure safety net in setErrorState().
590
+ *
591
+ * Reads the flag straight out of Redis rather than through loadAccountData(), so a client can
592
+ * ask before it does any credential work. That ordering is the point: an account is switched
593
+ * off precisely because that work keeps failing, and for an OAuth2 account the failing work is
594
+ * a token refresh against the provider.
595
+ *
596
+ * @returns {Promise<Boolean>} True when the account must not connect
597
+ */
598
+ async isSyncDisabled() {
599
+ // An unreadable blob is not a disable; readImapData() stays noisy about it and the
600
+ // connection proceeds.
601
+ const { imapData } = await readImapData(this.redis, this.getAccountKey(), this.logger);
602
+ return !!(imapData && imapData.disabled);
603
+ }
604
+
605
+ /**
606
+ * Stops an account retrying after it has failed authentication for longer than
607
+ * MAX_IMAP_AUTH_FAILURE_TIME, until someone re-authenticates it.
608
+ *
609
+ * `imap.disabled` is the flag every gate in the codebase already reads, so an OAuth2 account -
610
+ * which has no `imap` configuration of its own, because getImapConfig() builds its connection
611
+ * from the provider table instead - gets one written holding nothing but the flag. Both kinds
612
+ * of account then take the identical path through the connection gates and the admin UI's
613
+ * disabled-account handling. Writing it cannot disturb an OAuth2 connection config:
614
+ * getImapConfig() branches on `oauth2` first and only reads `accountData.imap` for password
615
+ * accounts.
616
+ *
617
+ * Before this, the whole block was gated on an `imap` blob already being present. OAuth2
618
+ * accounts never have one, so on a deployment that is mostly Gmail and Microsoft the documented
619
+ * three-day safety net was a silent no-op: an account whose refresh token had been revoked kept
620
+ * asking for a new one forever.
621
+ *
622
+ * @param {Object} opts
623
+ * @param {String} opts.event - The error event that tripped the threshold
624
+ * @param {Date} opts.firstError - When the current run of failures started
625
+ * @param {Number} opts.errorCount - How many failures have been counted since
626
+ * @param {Object} opts.data - Error payload for the account's stored error state
627
+ * @returns {Promise<Boolean>} True when this call is what disabled the account
628
+ */
629
+ async disableAfterAuthFailures({ event, firstError, errorCount, data }) {
630
+ const accountKey = this.getAccountKey();
631
+
632
+ let { imapData, invalid } = await readImapData(this.redis, accountKey, this.logger);
633
+ if (invalid) {
634
+ // Leave an unreadable configuration alone rather than replacing it with a bare flag.
635
+ return false;
636
+ }
637
+
638
+ if (!imapData) {
639
+ // No IMAP configuration: an OAuth2 account. Only synthesize the flag when there is an
640
+ // OAuth2 credential for the failures to be about, so an account still being created
641
+ // cannot be marked disabled on its way in.
642
+ const hasOAuth2 = await this.redis.hexists(accountKey, 'oauth2');
643
+ if (!hasOAuth2) {
644
+ return false;
645
+ }
646
+ imapData = {};
647
+ }
648
+
649
+ if (imapData.disabled) {
650
+ return false;
651
+ }
652
+
653
+ imapData.disabled = true;
654
+
655
+ // Disable IMAP and reset error counters
656
+ const disableTxn = createTransaction(this.redis, { logger: this.logger });
657
+ disableTxn.add('hSetExists', accountKey, 'imap', JSON.stringify(imapData));
658
+ // Records that this disable is ours, not the operator's send-only switch. Account
659
+ // re-registration and re-authorization lift the flag only when this marker is present,
660
+ // so re-authorizing a deliberately send-only account never starts syncing its mailbox.
661
+ disableTxn.add('hSetExists', accountKey, AUTH_FAILURE_DISABLED_FIELD, new Date().toISOString());
662
+ disableTxn.add('hdel', accountKey, 'lastError:errorCount', 'lastError:first');
663
+ disableTxn.add(
664
+ 'hSetExists',
665
+ accountKey,
666
+ 'lastErrorState',
667
+ JSON.stringify({
668
+ description: 'IMAP was disabled for the account due to exceeding the authentication error threshold',
669
+ response: data.response
670
+ })
671
+ );
672
+ await disableTxn.exec();
673
+
674
+ this.logger.warn({
675
+ msg: 'IMAP was disabled for the account due to exceeding the authentication error threshold',
676
+ errorEvent: event,
677
+ firstError: firstError.toISOString(),
678
+ timeThreshold: MAX_IMAP_AUTH_FAILURE_TIME,
679
+ errorCount
680
+ });
681
+
682
+ // Close the connection after disabling
683
+ setImmediate(() => {
684
+ this.close();
685
+ });
686
+
687
+ return true;
610
688
  }
611
689
 
612
690
  /**
@@ -313,6 +313,18 @@ class GmailClient extends BaseClient {
313
313
  await this.setStateVal();
314
314
 
315
315
  await this.getAccount();
316
+
317
+ // The auth-failure safety net switches an account off by setting `imap.disabled`, and
318
+ // an API-backed account reaches it the same way an IMAP one does - its failures run
319
+ // through the same setErrorState(). Checked before any credential work, because the
320
+ // work that keeps failing for these accounts is the token refresh below.
321
+ if (await this.isSyncDisabled()) {
322
+ this.logger.info({ msg: 'Skipped connection setup', account: this.account, reason: 'disabled' });
323
+ this.state = 'unset';
324
+ await this.setStateVal();
325
+ return;
326
+ }
327
+
316
328
  await this.getClient(true);
317
329
 
318
330
  // Ensure access token exists to get scopes
@@ -415,19 +415,18 @@ class IMAPClient extends BaseClient {
415
415
  await commandClient.connect();
416
416
  commandClient.log.info({ msg: 'Command channel connected', cid: commandCid, channel: 'command', account: this.account });
417
417
  } catch (err) {
418
- if (this.connections.delete(commandClient)) {
419
- await this.redis.hSetExists(this.getAccountKey(), 'connections', this.connections.size.toString());
420
- }
418
+ // untrackConnection() swallows its own Redis failure, so the connect error is
419
+ // what the caller sees - a hiccup while updating the count must not replace it
420
+ await this.untrackConnection(commandClient);
421
421
  commandClient.log.warn({ msg: 'Failed to connect command client', cid: commandCid, channel: 'command', account: this.account, err });
422
422
  throw err;
423
423
  }
424
424
 
425
- // Clean up when connection closes
425
+ // Clean up when connection closes. EventEmitter never observes what an async listener
426
+ // returns, so nothing in this body may escape - see the primary connection's handler
426
427
  commandClient.on('close', async () => {
427
428
  try {
428
- if (this.connections.delete(commandClient)) {
429
- await this.redis.hSetExists(this.getAccountKey(), 'connections', this.connections.size.toString());
430
- }
429
+ await this.untrackConnection(commandClient);
431
430
  commandClient.log.info({ msg: 'Connection closed', cid: commandCid, channel: 'command', account: this.account });
432
431
  } catch (err) {
433
432
  this.logger.error({ msg: 'Error in command client close handler', cid: commandCid, account: this.account, err });
@@ -1663,81 +1662,88 @@ class IMAPClient extends BaseClient {
1663
1662
  metricsMeta({}, this.logger, 'imapBytesReceived', 'inc', imapStats.received);
1664
1663
  });
1665
1664
 
1666
- // Handle connection close events
1665
+ // Handle connection close events. EventEmitter never observes what an async
1666
+ // listener returns, so anything that escapes this body becomes an unhandled
1667
+ // rejection and takes the whole worker down. The steps below carry their own
1668
+ // catches; this outer one is what keeps that true for an await added outside them.
1667
1669
  imapClient.on('close', async () => {
1668
- await this.untrackConnection(imapClient);
1669
- imapClient?.log.info({ msg: 'Connection closed', type: 'imapClient', account: this.account, disabled: imapClient.disabled });
1670
+ try {
1671
+ await this.untrackConnection(imapClient);
1672
+ imapClient?.log.info({ msg: 'Connection closed', type: 'imapClient', account: this.account, disabled: imapClient.disabled });
1670
1673
 
1671
- // Update state on unexpected disconnect
1672
- if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) {
1673
- this.state = 'disconnected';
1674
- try {
1675
- await this.setStateVal();
1676
- await emitChangeEvent(this.logger, this.account, 'state', this.state);
1677
- } catch (err) {
1678
- this.logger.error({ msg: 'Failed to update state on connection close', account: this.account, err });
1674
+ // Update state on unexpected disconnect
1675
+ if (['init', 'connecting', 'syncing', 'connected'].includes(this.state)) {
1676
+ this.state = 'disconnected';
1677
+ try {
1678
+ await this.setStateVal();
1679
+ await emitChangeEvent(this.logger, this.account, 'state', this.state);
1680
+ } catch (err) {
1681
+ this.logger.error({ msg: 'Failed to update state on connection close', account: this.account, err });
1682
+ }
1679
1683
  }
1680
- }
1681
1684
 
1682
- try {
1683
- // Handle cleanup for all mailboxes
1684
- for (let [, mailbox] of this.mailboxes) {
1685
- if (mailbox.syncing) {
1686
- try {
1687
- // set failure flag
1688
- await this.redis.hSetNew(
1689
- this.getAccountKey(),
1690
- 'syncError',
1691
- JSON.stringify({
1692
- path: mailbox.path,
1693
- time: new Date().toISOString(),
1694
- error: {
1695
- error: 'Connection closed unexpectedly'
1696
- }
1697
- })
1698
- );
1699
- } catch (err) {
1700
- // ignore
1685
+ try {
1686
+ // Handle cleanup for all mailboxes
1687
+ for (let [, mailbox] of this.mailboxes) {
1688
+ if (mailbox.syncing) {
1689
+ try {
1690
+ // set failure flag
1691
+ await this.redis.hSetNew(
1692
+ this.getAccountKey(),
1693
+ 'syncError',
1694
+ JSON.stringify({
1695
+ path: mailbox.path,
1696
+ time: new Date().toISOString(),
1697
+ error: {
1698
+ error: 'Connection closed unexpectedly'
1699
+ }
1700
+ })
1701
+ );
1702
+ } catch (err) {
1703
+ // ignore
1704
+ }
1701
1705
  }
1702
- }
1703
1706
 
1704
- if (mailbox.selected) {
1705
- // should be at most one though
1706
- await mailbox.onClose();
1707
+ if (mailbox.selected) {
1708
+ // should be at most one though
1709
+ await mailbox.onClose();
1710
+ }
1707
1711
  }
1712
+ } catch (err) {
1713
+ imapClient.log.error({ msg: 'Connection close error', err });
1708
1714
  }
1709
- } catch (err) {
1710
- imapClient.log.error({ msg: 'Connection close error', err });
1711
- }
1712
1715
 
1713
- try {
1714
- // Attempt reconnection if this was an unexpected close
1715
- if (!imapClient.disabled && imapClient === this.imapClient && !this._connecting) {
1716
- if (this.validateConnectionAge(imapClient)) {
1717
- // A proven-stable connection dropped - reconnect right away
1718
- if (!this.reconnectTimer) {
1719
- imapClient.log.debug({ msg: 'Requesting reconnection due to unexpected close', type: 'imapClient', account: this.account });
1720
- await this.reconnect();
1716
+ try {
1717
+ // Attempt reconnection if this was an unexpected close
1718
+ if (!imapClient.disabled && imapClient === this.imapClient && !this._connecting) {
1719
+ if (this.validateConnectionAge(imapClient)) {
1720
+ // A proven-stable connection dropped - reconnect right away
1721
+ if (!this.reconnectTimer) {
1722
+ imapClient.log.debug({ msg: 'Requesting reconnection due to unexpected close', type: 'imapClient', account: this.account });
1723
+ await this.reconnect();
1724
+ }
1725
+ } else {
1726
+ // The connection died soon after it was set up. An
1727
+ // immediate retry against a server that drops
1728
+ // connections right after setup turns into an
1729
+ // unthrottled login loop (the setup itself
1730
+ // "succeeds", so the sync-reset backoffs never
1731
+ // grow), so schedule the reconnect with a growing
1732
+ // delay instead
1733
+ this.scheduleReconnect(this.closeReconnectBackoff, 'Throttling reconnection of a short-lived connection');
1721
1734
  }
1722
- } else {
1723
- // The connection died soon after it was set up. An
1724
- // immediate retry against a server that drops
1725
- // connections right after setup turns into an
1726
- // unthrottled login loop (the setup itself
1727
- // "succeeds", so the sync-reset backoffs never
1728
- // grow), so schedule the reconnect with a growing
1729
- // delay instead
1730
- this.scheduleReconnect(this.closeReconnectBackoff, 'Throttling reconnection of a short-lived connection');
1731
1735
  }
1736
+ } catch (err) {
1737
+ // This is the only path that re-arms the connection after an unexpected close.
1738
+ // If it throws, nothing else reconnects the account, so it stays offline until
1739
+ // the worker restarts - never demote this below error.
1740
+ imapClient.log.error({ msg: 'Reconnection error', account: this.account, err });
1732
1741
  }
1733
1742
  } catch (err) {
1734
- // This is the only path that re-arms the connection after an unexpected close.
1735
- // If it throws, nothing else reconnects the account, so it stays offline until
1736
- // the worker restarts - never demote this below error.
1737
- imapClient.log.error({ msg: 'Reconnection error', account: this.account, err });
1743
+ this.logger.error({ msg: 'Failed to process connection close', account: this.account, err });
1744
+ } finally {
1745
+ imapClient = null;
1738
1746
  }
1739
-
1740
- imapClient = null;
1741
1747
  });
1742
1748
 
1743
1749
  try {
@@ -238,6 +238,18 @@ class OutlookClient extends BaseClient {
238
238
  await this.setStateVal();
239
239
 
240
240
  await this.getAccount();
241
+
242
+ // The auth-failure safety net switches an account off by setting `imap.disabled`, and
243
+ // an API-backed account reaches it the same way an IMAP one does - its failures run
244
+ // through the same setErrorState(). Checked before any credential work, because the
245
+ // work that keeps failing for these accounts is the token refresh below.
246
+ if (await this.isSyncDisabled()) {
247
+ this.logger.info({ msg: 'Skipped connection setup', account: this.account, reason: 'disabled' });
248
+ this.state = 'unset';
249
+ await this.setStateVal();
250
+ return;
251
+ }
252
+
241
253
  await this.getClient(true);
242
254
  await this.prepareDelegatedAccount();
243
255
 
@@ -27,7 +27,7 @@ const ENUM_DESCRIPTIONS = {
27
27
  paused: 'Syncing was paused through the API. No connection is maintained',
28
28
  authenticationError: 'The credentials were rejected. Requires re-authentication before syncing resumes',
29
29
  connectError: 'The server could not be reached or the TLS handshake failed. Retried with backoff',
30
- unset: 'No IMAP or OAuth2 configuration is set, so the account is not synced'
30
+ unset: 'The account is not syncing: either no IMAP or OAuth2 configuration is set, or syncing was switched off - by the operator, or automatically after repeated authentication failures'
31
31
  },
32
32
 
33
33
  outboxStatus: {
package/lib/logger.js CHANGED
@@ -59,6 +59,14 @@ const FATAL_EXIT_CODES = {
59
59
  unhandledRejection: 2
60
60
  };
61
61
 
62
+ // How long the process stays alive after a fatal error before the exit lands. This is not the
63
+ // error-tracking delivery window - lib/sentry.js installs notifyError and flushNotifications
64
+ // together, so whenever there is a report to deliver its own Sentry.flush() promise already
65
+ // covers it. What this covers is Node's: a handler that arrives a microtask after a rejection was
66
+ // reported raises 'rejectionHandled' a turn later, and without a timer the exit beats it (see the
67
+ // listener at the bottom of this file). Tune it against event-loop turns, not network latency.
68
+ const FATAL_EXIT_GRACE = 10;
69
+
62
70
  // An error that reaches the global handlers leaves the process in an unknown state,
63
71
  // so the process must always exit. If error tracking is enabled, report the error
64
72
  // first and allow a short flush window for the delivery. The report is tagged with
@@ -70,11 +78,17 @@ function fatalShutdown(handler, err) {
70
78
  logger.notifyError(err, { level: 'fatal', tags: { handler } });
71
79
  }
72
80
 
73
- let exit = () => process.exit(FATAL_EXIT_CODES[handler]);
81
+ // The exit is always taken a timer turn later, never straight off the flush promise. Node
82
+ // decides a rejection went unhandled at the end of the tick it settled in and only emits
83
+ // 'rejectionHandled' once a handler turns up after that, so exiting from a resolved flush's
84
+ // microtask races the event away - and it did, on exactly the installations that have error
85
+ // tracking switched on and therefore report the most crashes.
86
+ let exit = () => setTimeout(() => process.exit(FATAL_EXIT_CODES[handler]), FATAL_EXIT_GRACE);
87
+
74
88
  if (logger.flushNotifications) {
75
89
  logger.flushNotifications().then(exit, exit);
76
90
  } else {
77
- setTimeout(exit, 10);
91
+ exit();
78
92
  }
79
93
  }
80
94
 
@@ -88,14 +102,40 @@ process.on('uncaughtException', err => {
88
102
  fatalShutdown('uncaughtException', err);
89
103
  });
90
104
 
91
- process.on('unhandledRejection', err => {
105
+ // Promises that already reached the handler below, so a late handler can be recognised. Weak
106
+ // keys, because the entry is only ever looked up from the promise Node hands back.
107
+ const reportedRejections = new WeakMap();
108
+
109
+ process.on('unhandledRejection', (err, promise) => {
92
110
  logger.fatal({
93
111
  msg: 'unhandledRejection',
94
112
  _msg: 'unhandledRejection',
95
113
  err
96
114
  });
97
115
 
116
+ reportedRejections.set(promise, Date.now());
117
+
98
118
  fatalShutdown('unhandledRejection', err);
99
119
  });
100
120
 
121
+ // Node decides a rejection is unhandled at the end of the tick it settled in, so a handler that
122
+ // arrives one microtask late still counts as unhandled. Such a handler fires 'rejectionHandled'
123
+ // afterwards, and fatalShutdown() always leaves FATAL_EXIT_GRACE before the exit lands, so the
124
+ // event has time to arrive. The worker still dies either way - a rejection that escaped is a bug
125
+ // wherever it came from - but this line is the difference between a genuinely missing catch and a
126
+ // handler that lost a race, which is otherwise impossible to tell apart from a crash log.
127
+ process.on('rejectionHandled', promise => {
128
+ let reportedAt = reportedRejections.get(promise);
129
+ if (!reportedAt) {
130
+ return;
131
+ }
132
+ reportedRejections.delete(promise);
133
+
134
+ logger.fatal({
135
+ msg: 'unhandledRejection was handled after it was reported',
136
+ _msg: 'unhandledRejection was handled after it was reported',
137
+ delay: Date.now() - reportedAt
138
+ });
139
+ });
140
+
101
141
  module.exports = logger;
package/lib/schemas.js CHANGED
@@ -1635,7 +1635,17 @@ const accountSchemas = {
1635
1635
  .example('full')
1636
1636
  .description('Override the global IMAP indexing strategy for this account')
1637
1637
  .meta({ enumDescriptions: ENUM_DESCRIPTIONS.imapIndexer, usage: FIELD_USAGE.imapIndexer })
1638
- .label('AccountImapIndexer')
1638
+ .label('AccountImapIndexer'),
1639
+
1640
+ // Read-only, and no `.label()`: the generator inlines scalars, so a label here would name a
1641
+ // public type that never appears in the document.
1642
+ authFailureDisabledAt: Joi.date()
1643
+ .iso()
1644
+ .allow(null)
1645
+ .example('2021-03-22T13:13:31.000Z')
1646
+ .description(
1647
+ "When EmailEngine switched syncing off for this account after repeated authentication failures, or `null`. Read-only. Supply working credentials - re-authorize an OAuth2 account, or save new IMAP settings - and syncing resumes. `imap.disabled` is also the operator's own send-only switch, so this is what tells an automatic disable from a deliberate one."
1648
+ )
1639
1649
  };
1640
1650
 
1641
1651
  const googleProjectIdSchema = Joi.string()