@remit/imap-worker 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/imap-worker",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -1,6 +1,11 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { describe, it } from "node:test";
3
- import { MAILBOX_FRESHNESS_MS, mailboxNeedsSync } from "./sync-mailboxes.js";
3
+ import {
4
+ DEFAULT_MAILBOX_FRESHNESS_MS,
5
+ MAILBOX_FRESHNESS_MS,
6
+ mailboxNeedsSync,
7
+ resolveMailboxFreshnessMs,
8
+ } from "./sync-mailboxes.js";
4
9
 
5
10
  const NOW = 1_700_000_000_000;
6
11
 
@@ -45,3 +50,37 @@ describe("mailboxNeedsSync", () => {
45
50
  );
46
51
  });
47
52
  });
53
+
54
+ describe("resolveMailboxFreshnessMs", () => {
55
+ it("defaults to the production window when unset", () => {
56
+ assert.equal(resolveMailboxFreshnessMs({}), DEFAULT_MAILBOX_FRESHNESS_MS);
57
+ assert.equal(DEFAULT_MAILBOX_FRESHNESS_MS, 60_000);
58
+ });
59
+
60
+ it("honors a valid override", () => {
61
+ assert.equal(resolveMailboxFreshnessMs({ MAILBOX_FRESHNESS_MS: "0" }), 0);
62
+ assert.equal(
63
+ resolveMailboxFreshnessMs({ MAILBOX_FRESHNESS_MS: "1000" }),
64
+ 1000,
65
+ );
66
+ });
67
+
68
+ it("falls back to the default for a non-numeric or negative value", () => {
69
+ assert.equal(
70
+ resolveMailboxFreshnessMs({ MAILBOX_FRESHNESS_MS: "" }),
71
+ DEFAULT_MAILBOX_FRESHNESS_MS,
72
+ );
73
+ assert.equal(
74
+ resolveMailboxFreshnessMs({ MAILBOX_FRESHNESS_MS: "abc" }),
75
+ DEFAULT_MAILBOX_FRESHNESS_MS,
76
+ );
77
+ assert.equal(
78
+ resolveMailboxFreshnessMs({ MAILBOX_FRESHNESS_MS: "-5" }),
79
+ DEFAULT_MAILBOX_FRESHNESS_MS,
80
+ );
81
+ assert.equal(
82
+ resolveMailboxFreshnessMs({ MAILBOX_FRESHNESS_MS: "1.5" }),
83
+ DEFAULT_MAILBOX_FRESHNESS_MS,
84
+ );
85
+ });
86
+ });
@@ -35,7 +35,25 @@ const EVENT_EMIT_CONCURRENCY = 20;
35
35
  * (`MIN_POLL_INTERVAL_MS` in useStaleAccountSync), so the one caller that
36
36
  * skips this gate on a timer still cannot drive a fan-out faster than it.
37
37
  */
38
- export const MAILBOX_FRESHNESS_MS = 60_000;
38
+ export const DEFAULT_MAILBOX_FRESHNESS_MS = 60_000;
39
+
40
+ /**
41
+ * Resolve the freshness window from the environment, defaulting to production's
42
+ * {@link DEFAULT_MAILBOX_FRESHNESS_MS}. Deployments that drive sync from a test
43
+ * harness rather than a real client set `MAILBOX_FRESHNESS_MS` low so their
44
+ * explicit nudges are never no-oped by the gate; nothing else touches it, so
45
+ * production keeps the default.
46
+ */
47
+ export const resolveMailboxFreshnessMs = (
48
+ env: NodeJS.ProcessEnv = process.env,
49
+ ): number => {
50
+ const value = env.MAILBOX_FRESHNESS_MS?.trim();
51
+ if (!value) return DEFAULT_MAILBOX_FRESHNESS_MS;
52
+ const raw = Number(value);
53
+ return Number.isInteger(raw) && raw >= 0 ? raw : DEFAULT_MAILBOX_FRESHNESS_MS;
54
+ };
55
+
56
+ export const MAILBOX_FRESHNESS_MS = resolveMailboxFreshnessMs();
39
57
 
40
58
  /**
41
59
  * Whether this fan-out should enqueue a mailbox.