@ever-works/mailgun-plugin 1.0.7 → 1.0.9

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/dist/index.cjs CHANGED
@@ -63,6 +63,7 @@ var PROBLEM_CODES = [
63
63
  "already_connected",
64
64
  "already_linked",
65
65
  "already_claimed",
66
+ "claim_locked",
66
67
  "invalid_client",
67
68
  "public_jwk_invalid",
68
69
  "identifier_claimed",
@@ -88,6 +89,11 @@ var PROBLEM_CODES = [
88
89
  "database_absent",
89
90
  "database_unreachable",
90
91
  "topic_private",
92
+ "realtime_disabled",
93
+ "topic_forbidden",
94
+ "topic_invalid",
95
+ "realtime_busy",
96
+ "too_many_streams",
91
97
  "keys_unavailable",
92
98
  "internal_error"
93
99
  ];
@@ -717,6 +723,110 @@ var FLEET_LINK_CONTROL_TYPES = [
717
723
  ];
718
724
  new Set(FLEET_LINK_CONTROL_TYPES);
719
725
  new TextEncoder();
726
+ var FLEET_RUN_TOKEN_ROUTES = Object.freeze([
727
+ // Works — reads, plus the settings update (its merge / check / command
728
+ // fields are refused for run tokens by the Works controller).
729
+ { method: "GET", pathPattern: "/api/works" },
730
+ { method: "GET", pathPattern: "/api/works/{id}" },
731
+ { method: "PUT", pathPattern: "/api/works/{id}" },
732
+ { method: "GET", pathPattern: "/api/works/{id}/config" },
733
+ { method: "GET", pathPattern: "/api/works/{id}/items" },
734
+ { method: "GET", pathPattern: "/api/works/{id}/categories-tags" },
735
+ { method: "GET", pathPattern: "/api/works/{id}/history" },
736
+ { method: "GET", pathPattern: "/api/works/{id}/generator-form" },
737
+ { method: "GET", pathPattern: "/api/works/{id}/schedule" },
738
+ { method: "GET", pathPattern: "/api/works/{id}/comparisons" },
739
+ { method: "GET", pathPattern: "/api/works/{id}/comparisons/{slug}" },
740
+ // Knowledge Base (`apps/mcp/src/tools/kb`). A document a run token writes
741
+ // lands `proposed` (review-gated), see the KB controller. No unlock.
742
+ { method: "GET", pathPattern: "/api/works/{id}/kb/documents" },
743
+ { method: "POST", pathPattern: "/api/works/{id}/kb/documents" },
744
+ { method: "GET", pathPattern: "/api/works/{id}/kb/documents/{docIdOrPath}" },
745
+ { method: "PATCH", pathPattern: "/api/works/{id}/kb/documents/{docId}" },
746
+ { method: "POST", pathPattern: "/api/works/{id}/kb/documents/{docId}/lock" },
747
+ // Deploy — reads and the capability check only.
748
+ { method: "GET", pathPattern: "/api/deploy/works/{id}/domains" },
749
+ { method: "GET", pathPattern: "/api/deploy/providers" },
750
+ { method: "POST", pathPattern: "/api/deploy/works/{id}/check" },
751
+ // Plugins — read only.
752
+ { method: "GET", pathPattern: "/api/plugins" },
753
+ { method: "GET", pathPattern: "/api/plugins/{pluginId}" },
754
+ // Missions — reads, plus pause (the safe direction).
755
+ { method: "GET", pathPattern: "/api/me/missions" },
756
+ { method: "GET", pathPattern: "/api/me/missions/{id}" },
757
+ { method: "GET", pathPattern: "/api/me/missions/{id}/budget" },
758
+ { method: "GET", pathPattern: "/api/me/missions/{id}/works" },
759
+ { method: "POST", pathPattern: "/api/me/missions/{id}/pause" },
760
+ // Ideas — reads, plus filing a new Idea (a proposal a person builds).
761
+ { method: "POST", pathPattern: "/api/me/work-proposals" },
762
+ { method: "GET", pathPattern: "/api/me/work-proposals" },
763
+ { method: "GET", pathPattern: "/api/me/work-proposals/status" },
764
+ { method: "GET", pathPattern: "/api/me/work-proposals/preferences" },
765
+ { method: "GET", pathPattern: "/api/me/work-proposals/{id}" },
766
+ { method: "GET", pathPattern: "/api/me/work-proposals/{id}/budget" },
767
+ // Account-wide usage.
768
+ { method: "GET", pathPattern: "/api/me/usage/account-wide" },
769
+ // Tasks — reads and collaboration writes. Create / update / transition /
770
+ // assign / chat carry body refusals for run tokens in the Tasks
771
+ // controller (no checks, no schedule, no force, no dispatch, no @agent).
772
+ { method: "GET", pathPattern: "/api/tasks" },
773
+ { method: "POST", pathPattern: "/api/tasks" },
774
+ { method: "GET", pathPattern: "/api/tasks/{id}" },
775
+ { method: "PATCH", pathPattern: "/api/tasks/{id}" },
776
+ { method: "GET", pathPattern: "/api/tasks/{id}/subtasks" },
777
+ { method: "GET", pathPattern: "/api/tasks/{id}/activity" },
778
+ { method: "POST", pathPattern: "/api/tasks/{id}/transition" },
779
+ { method: "GET", pathPattern: "/api/tasks/{id}/run-candidates" },
780
+ { method: "GET", pathPattern: "/api/tasks/{id}/pr-status" },
781
+ { method: "GET", pathPattern: "/api/tasks/{id}/diff" },
782
+ { method: "POST", pathPattern: "/api/tasks/{id}/assignees" },
783
+ { method: "POST", pathPattern: "/api/tasks/{id}/reviewers" },
784
+ { method: "POST", pathPattern: "/api/tasks/{id}/approvers" },
785
+ { method: "POST", pathPattern: "/api/tasks/{id}/relations" },
786
+ { method: "GET", pathPattern: "/api/tasks/{id}/escalations" },
787
+ { method: "GET", pathPattern: "/api/tasks/{id}/chat" },
788
+ { method: "POST", pathPattern: "/api/tasks/{id}/chat" },
789
+ { method: "GET", pathPattern: "/api/tasks/{id}/spend" },
790
+ // Inbox — read only (no reply, no archive / delete / mark-read).
791
+ { method: "GET", pathPattern: "/api/inbox" },
792
+ { method: "GET", pathPattern: "/api/inbox/unread-count" },
793
+ { method: "GET", pathPattern: "/api/inbox/{id}" },
794
+ // Goals — reads, a draft create, field-limited update, pause, and the
795
+ // ASKING side of the definition of done (propose, never approve).
796
+ { method: "GET", pathPattern: "/api/me/goals" },
797
+ { method: "POST", pathPattern: "/api/me/goals" },
798
+ { method: "GET", pathPattern: "/api/me/goals/{id}" },
799
+ { method: "PATCH", pathPattern: "/api/me/goals/{id}" },
800
+ { method: "GET", pathPattern: "/api/me/goals/{id}/samples" },
801
+ { method: "POST", pathPattern: "/api/me/goals/{id}/pause" },
802
+ { method: "POST", pathPattern: "/api/me/goals/{id}/dod/propose" },
803
+ // Fleet — reads only.
804
+ { method: "GET", pathPattern: "/api/fleet/nodes" },
805
+ { method: "GET", pathPattern: "/api/fleet/nodes/{id}" },
806
+ { method: "GET", pathPattern: "/api/fleet/runner-status" },
807
+ { method: "GET", pathPattern: "/api/fleet/execution-preferences" },
808
+ { method: "GET", pathPattern: "/api/fleet/agents/{agentId}/node-affinity" },
809
+ // Agents — reads, plus cancel and pause (the safe direction).
810
+ { method: "GET", pathPattern: "/api/agents" },
811
+ { method: "GET", pathPattern: "/api/agents/{id}" },
812
+ { method: "GET", pathPattern: "/api/agents/{id}/runs" },
813
+ { method: "GET", pathPattern: "/api/agents/{id}/runs/{runId}" },
814
+ { method: "POST", pathPattern: "/api/agents/{id}/runs/{runId}/cancel" },
815
+ { method: "POST", pathPattern: "/api/agents/{id}/pause" },
816
+ { method: "GET", pathPattern: "/api/agents/{id}/budget" },
817
+ // Agent Plugins — read only (installing a package installs instructions).
818
+ { method: "GET", pathPattern: "/api/agent-plugins" },
819
+ { method: "GET", pathPattern: "/api/agent-plugins/findings" },
820
+ { method: "GET", pathPattern: "/api/agent-plugins/catalog" },
821
+ { method: "GET", pathPattern: "/api/agent-plugins/updates" }
822
+ ]);
823
+ function splitSegments(normalizedPath) {
824
+ return normalizedPath.split("/").filter((segment) => segment.length > 0);
825
+ }
826
+ FLEET_RUN_TOKEN_ROUTES.map((route) => ({
827
+ method: route.method.toUpperCase(),
828
+ shape: splitSegments(route.pathPattern).map((part) => /^\{[^}]+\}$/.test(part) ? "*" : part.toLowerCase())
829
+ }));
720
830
  var EMAIL_INBOX_CAP_FIELDS = [
721
831
  "inboxDailySends",
722
832
  "inboxBurstSends",
@@ -1041,6 +1151,9 @@ function resolveSigningKey(options) {
1041
1151
  return fromEnv && fromEnv.length > 0 ? fromEnv : void 0;
1042
1152
  }
1043
1153
  var EMAIL_INBOUND_ALLOW_UNSIGNED_ENV = "EMAIL_INBOUND_ALLOW_UNSIGNED";
1154
+ var MAILGUN_SIGNATURE_MAX_AGE_SECONDS = 15 * 60;
1155
+ var MAILGUN_SIGNATURE_MAX_SKEW_SECONDS = 5 * 60;
1156
+ var MAILGUN_USED_TOKENS_MAX = 1e4;
1044
1157
  function unsignedInboundAllowed() {
1045
1158
  return process.env[EMAIL_INBOUND_ALLOW_UNSIGNED_ENV] === "true";
1046
1159
  }
@@ -1131,6 +1244,8 @@ var MailgunPlugin = class {
1131
1244
  required: ["apiKey", "domain"]
1132
1245
  };
1133
1246
  this.idempotencyCache = /* @__PURE__ */ new Map();
1247
+ /** F56: inbound signature tokens already accepted → when they may be forgotten (ms). */
1248
+ this.usedInboundTokens = /* @__PURE__ */ new Map();
1134
1249
  }
1135
1250
  async onLoad() {
1136
1251
  }
@@ -1212,6 +1327,27 @@ var MailgunPlugin = class {
1212
1327
  if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
1213
1328
  throw new Error("Mailgun inbound: signature mismatch.");
1214
1329
  }
1330
+ const nowMs = Date.now();
1331
+ const signedAt = Number(sig.timestamp);
1332
+ if (!Number.isFinite(signedAt) || signedAt < nowMs / 1e3 - MAILGUN_SIGNATURE_MAX_AGE_SECONDS || signedAt > nowMs / 1e3 + MAILGUN_SIGNATURE_MAX_SKEW_SECONDS) {
1333
+ throw new Error("Mailgun inbound: signature timestamp is outside the accepted window.");
1334
+ }
1335
+ for (const [token, forgetAt] of this.usedInboundTokens) {
1336
+ if (forgetAt > nowMs) break;
1337
+ this.usedInboundTokens.delete(token);
1338
+ }
1339
+ if (this.usedInboundTokens.has(sig.token)) {
1340
+ throw new Error("Mailgun inbound: signature token already used.");
1341
+ }
1342
+ this.usedInboundTokens.set(
1343
+ sig.token,
1344
+ nowMs + (MAILGUN_SIGNATURE_MAX_AGE_SECONDS + MAILGUN_SIGNATURE_MAX_SKEW_SECONDS) * 1e3
1345
+ );
1346
+ while (this.usedInboundTokens.size > MAILGUN_USED_TOKENS_MAX) {
1347
+ const oldest = this.usedInboundTokens.keys().next().value;
1348
+ if (oldest === void 0) break;
1349
+ this.usedInboundTokens.delete(oldest);
1350
+ }
1215
1351
  }
1216
1352
  extractInboundRecipients(rawBody, _headers) {
1217
1353
  try {
package/dist/index.d.cts CHANGED
@@ -19,6 +19,8 @@ declare class MailgunPlugin implements IEmailOutboundPlugin, IEmailInboundPlugin
19
19
  onLoad(): Promise<void>;
20
20
  onUnload(): Promise<void>;
21
21
  private readonly idempotencyCache;
22
+ /** F56: inbound signature tokens already accepted → when they may be forgotten (ms). */
23
+ private readonly usedInboundTokens;
22
24
  sendEmail(input: EmailSendInput, options: EmailOptions): Promise<EmailSendResult>;
23
25
  verifyAddress(address: string, _options: EmailOptions): Promise<EmailVerification>;
24
26
  verifyWebhookSignature(rawBody: Buffer, _headers: Readonly<Record<string, string>>, options: EmailOptions): void;
package/dist/index.d.ts CHANGED
@@ -19,6 +19,8 @@ declare class MailgunPlugin implements IEmailOutboundPlugin, IEmailInboundPlugin
19
19
  onLoad(): Promise<void>;
20
20
  onUnload(): Promise<void>;
21
21
  private readonly idempotencyCache;
22
+ /** F56: inbound signature tokens already accepted → when they may be forgotten (ms). */
23
+ private readonly usedInboundTokens;
22
24
  sendEmail(input: EmailSendInput, options: EmailOptions): Promise<EmailSendResult>;
23
25
  verifyAddress(address: string, _options: EmailOptions): Promise<EmailVerification>;
24
26
  verifyWebhookSignature(rawBody: Buffer, _headers: Readonly<Record<string, string>>, options: EmailOptions): void;
package/dist/index.js CHANGED
@@ -56,6 +56,7 @@ var PROBLEM_CODES = [
56
56
  "already_connected",
57
57
  "already_linked",
58
58
  "already_claimed",
59
+ "claim_locked",
59
60
  "invalid_client",
60
61
  "public_jwk_invalid",
61
62
  "identifier_claimed",
@@ -81,6 +82,11 @@ var PROBLEM_CODES = [
81
82
  "database_absent",
82
83
  "database_unreachable",
83
84
  "topic_private",
85
+ "realtime_disabled",
86
+ "topic_forbidden",
87
+ "topic_invalid",
88
+ "realtime_busy",
89
+ "too_many_streams",
84
90
  "keys_unavailable",
85
91
  "internal_error"
86
92
  ];
@@ -710,6 +716,110 @@ var FLEET_LINK_CONTROL_TYPES = [
710
716
  ];
711
717
  new Set(FLEET_LINK_CONTROL_TYPES);
712
718
  new TextEncoder();
719
+ var FLEET_RUN_TOKEN_ROUTES = Object.freeze([
720
+ // Works — reads, plus the settings update (its merge / check / command
721
+ // fields are refused for run tokens by the Works controller).
722
+ { method: "GET", pathPattern: "/api/works" },
723
+ { method: "GET", pathPattern: "/api/works/{id}" },
724
+ { method: "PUT", pathPattern: "/api/works/{id}" },
725
+ { method: "GET", pathPattern: "/api/works/{id}/config" },
726
+ { method: "GET", pathPattern: "/api/works/{id}/items" },
727
+ { method: "GET", pathPattern: "/api/works/{id}/categories-tags" },
728
+ { method: "GET", pathPattern: "/api/works/{id}/history" },
729
+ { method: "GET", pathPattern: "/api/works/{id}/generator-form" },
730
+ { method: "GET", pathPattern: "/api/works/{id}/schedule" },
731
+ { method: "GET", pathPattern: "/api/works/{id}/comparisons" },
732
+ { method: "GET", pathPattern: "/api/works/{id}/comparisons/{slug}" },
733
+ // Knowledge Base (`apps/mcp/src/tools/kb`). A document a run token writes
734
+ // lands `proposed` (review-gated), see the KB controller. No unlock.
735
+ { method: "GET", pathPattern: "/api/works/{id}/kb/documents" },
736
+ { method: "POST", pathPattern: "/api/works/{id}/kb/documents" },
737
+ { method: "GET", pathPattern: "/api/works/{id}/kb/documents/{docIdOrPath}" },
738
+ { method: "PATCH", pathPattern: "/api/works/{id}/kb/documents/{docId}" },
739
+ { method: "POST", pathPattern: "/api/works/{id}/kb/documents/{docId}/lock" },
740
+ // Deploy — reads and the capability check only.
741
+ { method: "GET", pathPattern: "/api/deploy/works/{id}/domains" },
742
+ { method: "GET", pathPattern: "/api/deploy/providers" },
743
+ { method: "POST", pathPattern: "/api/deploy/works/{id}/check" },
744
+ // Plugins — read only.
745
+ { method: "GET", pathPattern: "/api/plugins" },
746
+ { method: "GET", pathPattern: "/api/plugins/{pluginId}" },
747
+ // Missions — reads, plus pause (the safe direction).
748
+ { method: "GET", pathPattern: "/api/me/missions" },
749
+ { method: "GET", pathPattern: "/api/me/missions/{id}" },
750
+ { method: "GET", pathPattern: "/api/me/missions/{id}/budget" },
751
+ { method: "GET", pathPattern: "/api/me/missions/{id}/works" },
752
+ { method: "POST", pathPattern: "/api/me/missions/{id}/pause" },
753
+ // Ideas — reads, plus filing a new Idea (a proposal a person builds).
754
+ { method: "POST", pathPattern: "/api/me/work-proposals" },
755
+ { method: "GET", pathPattern: "/api/me/work-proposals" },
756
+ { method: "GET", pathPattern: "/api/me/work-proposals/status" },
757
+ { method: "GET", pathPattern: "/api/me/work-proposals/preferences" },
758
+ { method: "GET", pathPattern: "/api/me/work-proposals/{id}" },
759
+ { method: "GET", pathPattern: "/api/me/work-proposals/{id}/budget" },
760
+ // Account-wide usage.
761
+ { method: "GET", pathPattern: "/api/me/usage/account-wide" },
762
+ // Tasks — reads and collaboration writes. Create / update / transition /
763
+ // assign / chat carry body refusals for run tokens in the Tasks
764
+ // controller (no checks, no schedule, no force, no dispatch, no @agent).
765
+ { method: "GET", pathPattern: "/api/tasks" },
766
+ { method: "POST", pathPattern: "/api/tasks" },
767
+ { method: "GET", pathPattern: "/api/tasks/{id}" },
768
+ { method: "PATCH", pathPattern: "/api/tasks/{id}" },
769
+ { method: "GET", pathPattern: "/api/tasks/{id}/subtasks" },
770
+ { method: "GET", pathPattern: "/api/tasks/{id}/activity" },
771
+ { method: "POST", pathPattern: "/api/tasks/{id}/transition" },
772
+ { method: "GET", pathPattern: "/api/tasks/{id}/run-candidates" },
773
+ { method: "GET", pathPattern: "/api/tasks/{id}/pr-status" },
774
+ { method: "GET", pathPattern: "/api/tasks/{id}/diff" },
775
+ { method: "POST", pathPattern: "/api/tasks/{id}/assignees" },
776
+ { method: "POST", pathPattern: "/api/tasks/{id}/reviewers" },
777
+ { method: "POST", pathPattern: "/api/tasks/{id}/approvers" },
778
+ { method: "POST", pathPattern: "/api/tasks/{id}/relations" },
779
+ { method: "GET", pathPattern: "/api/tasks/{id}/escalations" },
780
+ { method: "GET", pathPattern: "/api/tasks/{id}/chat" },
781
+ { method: "POST", pathPattern: "/api/tasks/{id}/chat" },
782
+ { method: "GET", pathPattern: "/api/tasks/{id}/spend" },
783
+ // Inbox — read only (no reply, no archive / delete / mark-read).
784
+ { method: "GET", pathPattern: "/api/inbox" },
785
+ { method: "GET", pathPattern: "/api/inbox/unread-count" },
786
+ { method: "GET", pathPattern: "/api/inbox/{id}" },
787
+ // Goals — reads, a draft create, field-limited update, pause, and the
788
+ // ASKING side of the definition of done (propose, never approve).
789
+ { method: "GET", pathPattern: "/api/me/goals" },
790
+ { method: "POST", pathPattern: "/api/me/goals" },
791
+ { method: "GET", pathPattern: "/api/me/goals/{id}" },
792
+ { method: "PATCH", pathPattern: "/api/me/goals/{id}" },
793
+ { method: "GET", pathPattern: "/api/me/goals/{id}/samples" },
794
+ { method: "POST", pathPattern: "/api/me/goals/{id}/pause" },
795
+ { method: "POST", pathPattern: "/api/me/goals/{id}/dod/propose" },
796
+ // Fleet — reads only.
797
+ { method: "GET", pathPattern: "/api/fleet/nodes" },
798
+ { method: "GET", pathPattern: "/api/fleet/nodes/{id}" },
799
+ { method: "GET", pathPattern: "/api/fleet/runner-status" },
800
+ { method: "GET", pathPattern: "/api/fleet/execution-preferences" },
801
+ { method: "GET", pathPattern: "/api/fleet/agents/{agentId}/node-affinity" },
802
+ // Agents — reads, plus cancel and pause (the safe direction).
803
+ { method: "GET", pathPattern: "/api/agents" },
804
+ { method: "GET", pathPattern: "/api/agents/{id}" },
805
+ { method: "GET", pathPattern: "/api/agents/{id}/runs" },
806
+ { method: "GET", pathPattern: "/api/agents/{id}/runs/{runId}" },
807
+ { method: "POST", pathPattern: "/api/agents/{id}/runs/{runId}/cancel" },
808
+ { method: "POST", pathPattern: "/api/agents/{id}/pause" },
809
+ { method: "GET", pathPattern: "/api/agents/{id}/budget" },
810
+ // Agent Plugins — read only (installing a package installs instructions).
811
+ { method: "GET", pathPattern: "/api/agent-plugins" },
812
+ { method: "GET", pathPattern: "/api/agent-plugins/findings" },
813
+ { method: "GET", pathPattern: "/api/agent-plugins/catalog" },
814
+ { method: "GET", pathPattern: "/api/agent-plugins/updates" }
815
+ ]);
816
+ function splitSegments(normalizedPath) {
817
+ return normalizedPath.split("/").filter((segment) => segment.length > 0);
818
+ }
819
+ FLEET_RUN_TOKEN_ROUTES.map((route) => ({
820
+ method: route.method.toUpperCase(),
821
+ shape: splitSegments(route.pathPattern).map((part) => /^\{[^}]+\}$/.test(part) ? "*" : part.toLowerCase())
822
+ }));
713
823
  var EMAIL_INBOX_CAP_FIELDS = [
714
824
  "inboxDailySends",
715
825
  "inboxBurstSends",
@@ -1034,6 +1144,9 @@ function resolveSigningKey(options) {
1034
1144
  return fromEnv && fromEnv.length > 0 ? fromEnv : void 0;
1035
1145
  }
1036
1146
  var EMAIL_INBOUND_ALLOW_UNSIGNED_ENV = "EMAIL_INBOUND_ALLOW_UNSIGNED";
1147
+ var MAILGUN_SIGNATURE_MAX_AGE_SECONDS = 15 * 60;
1148
+ var MAILGUN_SIGNATURE_MAX_SKEW_SECONDS = 5 * 60;
1149
+ var MAILGUN_USED_TOKENS_MAX = 1e4;
1037
1150
  function unsignedInboundAllowed() {
1038
1151
  return process.env[EMAIL_INBOUND_ALLOW_UNSIGNED_ENV] === "true";
1039
1152
  }
@@ -1124,6 +1237,8 @@ var MailgunPlugin = class {
1124
1237
  required: ["apiKey", "domain"]
1125
1238
  };
1126
1239
  this.idempotencyCache = /* @__PURE__ */ new Map();
1240
+ /** F56: inbound signature tokens already accepted → when they may be forgotten (ms). */
1241
+ this.usedInboundTokens = /* @__PURE__ */ new Map();
1127
1242
  }
1128
1243
  async onLoad() {
1129
1244
  }
@@ -1205,6 +1320,27 @@ var MailgunPlugin = class {
1205
1320
  if (a.length !== b.length || !timingSafeEqual(a, b)) {
1206
1321
  throw new Error("Mailgun inbound: signature mismatch.");
1207
1322
  }
1323
+ const nowMs = Date.now();
1324
+ const signedAt = Number(sig.timestamp);
1325
+ if (!Number.isFinite(signedAt) || signedAt < nowMs / 1e3 - MAILGUN_SIGNATURE_MAX_AGE_SECONDS || signedAt > nowMs / 1e3 + MAILGUN_SIGNATURE_MAX_SKEW_SECONDS) {
1326
+ throw new Error("Mailgun inbound: signature timestamp is outside the accepted window.");
1327
+ }
1328
+ for (const [token, forgetAt] of this.usedInboundTokens) {
1329
+ if (forgetAt > nowMs) break;
1330
+ this.usedInboundTokens.delete(token);
1331
+ }
1332
+ if (this.usedInboundTokens.has(sig.token)) {
1333
+ throw new Error("Mailgun inbound: signature token already used.");
1334
+ }
1335
+ this.usedInboundTokens.set(
1336
+ sig.token,
1337
+ nowMs + (MAILGUN_SIGNATURE_MAX_AGE_SECONDS + MAILGUN_SIGNATURE_MAX_SKEW_SECONDS) * 1e3
1338
+ );
1339
+ while (this.usedInboundTokens.size > MAILGUN_USED_TOKENS_MAX) {
1340
+ const oldest = this.usedInboundTokens.keys().next().value;
1341
+ if (oldest === void 0) break;
1342
+ this.usedInboundTokens.delete(oldest);
1343
+ }
1208
1344
  }
1209
1345
  extractInboundRecipients(rawBody, _headers) {
1210
1346
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ever-works/mailgun-plugin",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Mailgun email provider plugin (outbound + inbound) for Ever Works platform",
5
5
  "author": {
6
6
  "name": "Ever Co. LTD",
@@ -32,7 +32,7 @@
32
32
  "test:watch": "vitest"
33
33
  },
34
34
  "dependencies": {
35
- "@ever-works/plugin": "^1.2.6",
35
+ "@ever-works/plugin": "^1.2.8",
36
36
  "form-data": "^4.0.1",
37
37
  "mailgun.js": "^10.2.3"
38
38
  },
@@ -102,8 +102,8 @@
102
102
  "url": "https://github.com/ever-works/ever-works/issues"
103
103
  },
104
104
  "everworksRelease": {
105
- "contentHash": "sha256:4e6ce098205095db4f6003964bbd192d73574d055f83d42349aa85f2ab4a944d",
106
- "commit": "54552a4d2dcb0e2d5213b0a47fd3ffcbd432f73c",
107
- "source": "https://github.com/ever-works/ever-works/tree/54552a4d2dcb0e2d5213b0a47fd3ffcbd432f73c/packages/plugins/mailgun"
105
+ "contentHash": "sha256:476242a6a45ad445d43d067421a984d3651649a1768cca6ee4d4a9214fbbf086",
106
+ "commit": "efd11a2282ea3e514e93f754b9b008543a7cff60",
107
+ "source": "https://github.com/ever-works/ever-works/tree/efd11a2282ea3e514e93f754b9b008543a7cff60/packages/plugins/mailgun"
108
108
  }
109
109
  }