@ever-works/mailgun-plugin 1.0.5 → 1.0.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.
- package/README.md +2 -2
- package/dist/index.cjs +270 -3
- package/dist/index.js +270 -3
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -13,11 +13,11 @@ Mailgun email provider plugin for Ever Works (Notifications v2, EW-650).
|
|
|
13
13
|
| `apiKey` | yes | `MAILGUN_API_KEY` | yes |
|
|
14
14
|
| `domain` | no | `MAILGUN_DOMAIN` | yes |
|
|
15
15
|
| `region` | no | `MAILGUN_REGION` (`us`/`eu`) | no (us) |
|
|
16
|
-
| `webhookSigningKey` | yes | `MAILGUN_WEBHOOK_SIGNING_KEY` |
|
|
16
|
+
| `webhookSigningKey` | yes | `MAILGUN_WEBHOOK_SIGNING_KEY` | inbound |
|
|
17
17
|
|
|
18
18
|
## Notes
|
|
19
19
|
|
|
20
20
|
- Outbound is built on the official **`mailgun.js`** SDK (`messages.create`); metadata is forwarded as Mailgun `v:` custom variables.
|
|
21
21
|
- Inbound HMAC verification uses Node `crypto` — Mailgun ships no SDK helper for inbound-route signature checking.
|
|
22
|
-
- Inbound verifies the Mailgun **HMAC-SHA256** signature — `HMAC(signingKey, timestamp + token)` compared in constant time — and decodes both JSON and form-urlencoded webhook shapes. When no signing key is set,
|
|
22
|
+
- Inbound verifies the Mailgun **HMAC-SHA256** signature — `HMAC(signingKey, timestamp + token)` compared in constant time — and decodes both JSON and form-urlencoded webhook shapes. When no signing key is set, inbound webhooks are **refused** (`401`); only `EMAIL_INBOUND_ALLOW_UNSIGNED=true` (that exact string, for a local stack with no public webhook URL) accepts them unsigned.
|
|
23
23
|
- `parseInboundWebhook` maps Mailgun's parsed fields (`sender`/`recipient`/`subject`/`body-plain`/`body-html`). Multipart attachment extraction requires a multipart parser at the controller layer and is left empty here.
|
package/dist/index.cjs
CHANGED
|
@@ -103,10 +103,14 @@ var USER_SELECTABLE_WORK_KINDS = [
|
|
|
103
103
|
"repo",
|
|
104
104
|
"app"
|
|
105
105
|
];
|
|
106
|
-
var WORK_KINDS = [...USER_SELECTABLE_WORK_KINDS, "company", "campaign", "default"];
|
|
106
|
+
var WORK_KINDS = [...USER_SELECTABLE_WORK_KINDS, "company", "campaign", "project", "default"];
|
|
107
107
|
new Set(WORK_KINDS);
|
|
108
108
|
var GOAL_KINDS = ["metric", "delivery"];
|
|
109
109
|
new Set(GOAL_KINDS);
|
|
110
|
+
var RECORD_VISIBILITIES = ["private", "team", "organization"];
|
|
111
|
+
new Set(RECORD_VISIBILITIES);
|
|
112
|
+
var RECORD_LIST_VIEWS = ["mine", "shared", "organization"];
|
|
113
|
+
new Set(RECORD_LIST_VIEWS);
|
|
110
114
|
var VERSION = "1.0.0";
|
|
111
115
|
var GTM_SKILLS = [
|
|
112
116
|
// ── research ────────────────────────────────────────────────────────
|
|
@@ -670,6 +674,49 @@ var FLEET_AGENT_CREDENTIAL_FAMILIES = [
|
|
|
670
674
|
FLEET_AGENT_CREDENTIAL_FAMILIES.flatMap(
|
|
671
675
|
(family) => family.envNames
|
|
672
676
|
);
|
|
677
|
+
var FLEET_LINK_FRAME_KINDS = {
|
|
678
|
+
/** Raw bytes: terminal output/input, log lines, file chunks. */
|
|
679
|
+
DATA: 1,
|
|
680
|
+
/** `[cols u16][rows u16]`. */
|
|
681
|
+
RESIZE: 2,
|
|
682
|
+
/** `[code i32]`. */
|
|
683
|
+
EXIT: 3,
|
|
684
|
+
/** UTF-8 JSON control message. */
|
|
685
|
+
JSON: 10,
|
|
686
|
+
/** UTF-8 reason code. */
|
|
687
|
+
CLOSE: 11,
|
|
688
|
+
/** A full picture (the existing computer-frame encoding). */
|
|
689
|
+
FRAME: 20,
|
|
690
|
+
/** A pointer / key / text event (the existing computer input encoding). */
|
|
691
|
+
INPUT: 21,
|
|
692
|
+
/** Changed tiles `[w][h][count]{x,y,w,h,len,jpeg}`. */
|
|
693
|
+
TILES: 23,
|
|
694
|
+
/** `[bytes u32]` credit. */
|
|
695
|
+
ACK: 30,
|
|
696
|
+
/** End of a stream. */
|
|
697
|
+
END: 31,
|
|
698
|
+
/** UTF-8 text ≤ 256 KiB, pasted into a desktop. */
|
|
699
|
+
CLIP: 40
|
|
700
|
+
};
|
|
701
|
+
new Set(Object.values(FLEET_LINK_FRAME_KINDS));
|
|
702
|
+
var FLEET_LINK_CONTROL_TYPES = [
|
|
703
|
+
"link.hello",
|
|
704
|
+
"link.ready",
|
|
705
|
+
"link.ping",
|
|
706
|
+
"link.pong",
|
|
707
|
+
"link.pause",
|
|
708
|
+
"link.resume",
|
|
709
|
+
"link.drain",
|
|
710
|
+
"channel.open",
|
|
711
|
+
"channel.ready",
|
|
712
|
+
"channel.refused",
|
|
713
|
+
"channel.close",
|
|
714
|
+
"operation.progress",
|
|
715
|
+
"operation.done",
|
|
716
|
+
"operation.cancel"
|
|
717
|
+
];
|
|
718
|
+
new Set(FLEET_LINK_CONTROL_TYPES);
|
|
719
|
+
new TextEncoder();
|
|
673
720
|
var EMAIL_INBOX_CAP_FIELDS = [
|
|
674
721
|
"inboxDailySends",
|
|
675
722
|
"inboxBurstSends",
|
|
@@ -812,6 +859,155 @@ var ACTION_CATEGORIES = Object.freeze([
|
|
|
812
859
|
Object.freeze(
|
|
813
860
|
ACTION_CATEGORIES.filter((c) => c !== "read.internal")
|
|
814
861
|
);
|
|
862
|
+
var DOMAIN_EVENT_CATALOG = [
|
|
863
|
+
// EW-P2-6 — `org:write` (and the app) create Organizations.
|
|
864
|
+
{ type: "organization.created", domain: "organization", aggregateType: "organization", phase: "P2" },
|
|
865
|
+
{ type: "organization.updated", domain: "organization", aggregateType: "organization", phase: "P1" },
|
|
866
|
+
{
|
|
867
|
+
type: "organization.member.added",
|
|
868
|
+
domain: "organization",
|
|
869
|
+
aggregateType: "organization",
|
|
870
|
+
phase: "P1",
|
|
871
|
+
child: "member"
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
type: "organization.member.updated",
|
|
875
|
+
domain: "organization",
|
|
876
|
+
aggregateType: "organization",
|
|
877
|
+
phase: "P1",
|
|
878
|
+
child: "member"
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
type: "organization.member.removed",
|
|
882
|
+
domain: "organization",
|
|
883
|
+
aggregateType: "organization",
|
|
884
|
+
phase: "P1",
|
|
885
|
+
child: "member"
|
|
886
|
+
},
|
|
887
|
+
{ type: "agent.created", domain: "agents", aggregateType: "agent", phase: "P1" },
|
|
888
|
+
{ type: "agent.updated", domain: "agents", aggregateType: "agent", phase: "P1" },
|
|
889
|
+
{ type: "agent.status_changed", domain: "agents", aggregateType: "agent", phase: "P1" },
|
|
890
|
+
{ type: "agent.archived", domain: "agents", aggregateType: "agent", phase: "P1" },
|
|
891
|
+
{ type: "agent.deleted", domain: "agents", aggregateType: "agent", phase: "P1" },
|
|
892
|
+
{ type: "team.created", domain: "teams", aggregateType: "team", phase: "P1" },
|
|
893
|
+
{ type: "team.updated", domain: "teams", aggregateType: "team", phase: "P1" },
|
|
894
|
+
{ type: "team.deleted", domain: "teams", aggregateType: "team", phase: "P1" },
|
|
895
|
+
{ type: "team.member.added", domain: "teams", aggregateType: "team", phase: "P1", child: "member" },
|
|
896
|
+
{ type: "team.member.updated", domain: "teams", aggregateType: "team", phase: "P1", child: "member" },
|
|
897
|
+
{ type: "team.member.removed", domain: "teams", aggregateType: "team", phase: "P1", child: "member" },
|
|
898
|
+
{ type: "team.resource.added", domain: "teams", aggregateType: "team", phase: "P1", child: "resource" },
|
|
899
|
+
{ type: "team.resource.removed", domain: "teams", aggregateType: "team", phase: "P1", child: "resource" },
|
|
900
|
+
{ type: "work.created", domain: "works", aggregateType: "work", phase: "P1" },
|
|
901
|
+
{ type: "work.updated", domain: "works", aggregateType: "work", phase: "P1" },
|
|
902
|
+
{ type: "work.archived", domain: "works", aggregateType: "work", phase: "P1" },
|
|
903
|
+
{ type: "work.deleted", domain: "works", aggregateType: "work", phase: "P1" },
|
|
904
|
+
{ type: "work.member.added", domain: "works", aggregateType: "work", phase: "P1", child: "member" },
|
|
905
|
+
{ type: "work.member.updated", domain: "works", aggregateType: "work", phase: "P1", child: "member" },
|
|
906
|
+
{ type: "work.member.removed", domain: "works", aggregateType: "work", phase: "P1", child: "member" },
|
|
907
|
+
{ type: "mission.created", domain: "missions", aggregateType: "mission", phase: "P2" },
|
|
908
|
+
{ type: "mission.updated", domain: "missions", aggregateType: "mission", phase: "P2" },
|
|
909
|
+
{ type: "mission.status_changed", domain: "missions", aggregateType: "mission", phase: "P2" },
|
|
910
|
+
{ type: "mission.deleted", domain: "missions", aggregateType: "mission", phase: "P2" },
|
|
911
|
+
{ type: "mission.goal.linked", domain: "missions", aggregateType: "mission", phase: "P2", child: "goal" },
|
|
912
|
+
{ type: "mission.goal.unlinked", domain: "missions", aggregateType: "mission", phase: "P2", child: "goal" },
|
|
913
|
+
{ type: "mission.work.linked", domain: "missions", aggregateType: "mission", phase: "P2", child: "work" },
|
|
914
|
+
{ type: "mission.work.unlinked", domain: "missions", aggregateType: "mission", phase: "P2", child: "work" },
|
|
915
|
+
{ type: "goal.created", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
916
|
+
{ type: "goal.updated", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
917
|
+
{ type: "goal.status_changed", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
918
|
+
{ type: "goal.archived", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
919
|
+
{ type: "goal.unarchived", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
920
|
+
{ type: "goal.deleted", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
921
|
+
{ type: "goal.progress_changed", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
922
|
+
{ type: "idea.created", domain: "ideas", aggregateType: "idea", phase: "P2" },
|
|
923
|
+
{ type: "idea.updated", domain: "ideas", aggregateType: "idea", phase: "P2" },
|
|
924
|
+
{ type: "idea.status_changed", domain: "ideas", aggregateType: "idea", phase: "P2" },
|
|
925
|
+
{ type: "idea.deleted", domain: "ideas", aggregateType: "idea", phase: "P2" },
|
|
926
|
+
{ type: "task.created", domain: "tasks", aggregateType: "task", phase: "P1" },
|
|
927
|
+
{ type: "task.updated", domain: "tasks", aggregateType: "task", phase: "P1" },
|
|
928
|
+
{ type: "task.transitioned", domain: "tasks", aggregateType: "task", phase: "P1" },
|
|
929
|
+
{ type: "task.deleted", domain: "tasks", aggregateType: "task", phase: "P1" },
|
|
930
|
+
{ type: "task.assignee.added", domain: "tasks", aggregateType: "task", phase: "P1", child: "assignee" },
|
|
931
|
+
{ type: "task.assignee.removed", domain: "tasks", aggregateType: "task", phase: "P1", child: "assignee" },
|
|
932
|
+
{ type: "task.watcher.added", domain: "tasks", aggregateType: "task", phase: "P1", child: "watcher" },
|
|
933
|
+
{ type: "task.watcher.removed", domain: "tasks", aggregateType: "task", phase: "P1", child: "watcher" },
|
|
934
|
+
{ type: "task.block.added", domain: "tasks", aggregateType: "task", phase: "P1", child: "block" },
|
|
935
|
+
{ type: "task.block.removed", domain: "tasks", aggregateType: "task", phase: "P1", child: "block" },
|
|
936
|
+
{ type: "task.relation.added", domain: "tasks", aggregateType: "task", phase: "P1", child: "relation" },
|
|
937
|
+
{ type: "task.relation.removed", domain: "tasks", aggregateType: "task", phase: "P1", child: "relation" },
|
|
938
|
+
{ type: "task.comment.created", domain: "tasks", aggregateType: "task", phase: "P1", child: "comment" },
|
|
939
|
+
{ type: "task.comment.updated", domain: "tasks", aggregateType: "task", phase: "P1", child: "comment" },
|
|
940
|
+
{ type: "task.comment.deleted", domain: "tasks", aggregateType: "task", phase: "P1", child: "comment" },
|
|
941
|
+
{ type: "task.attachment.added", domain: "tasks", aggregateType: "task", phase: "P3", child: "attachment" },
|
|
942
|
+
{ type: "task.attachment.removed", domain: "tasks", aggregateType: "task", phase: "P3", child: "attachment" },
|
|
943
|
+
{ type: "task.runtime_updated", domain: "tasks", aggregateType: "task", phase: "P1", optIn: true },
|
|
944
|
+
{ type: "inbox.item.created", domain: "inbox", aggregateType: "inbox_item", phase: "P3" },
|
|
945
|
+
{ type: "inbox.item.answered", domain: "inbox", aggregateType: "inbox_item", phase: "P3" },
|
|
946
|
+
{ type: "inbox.item.state_changed", domain: "inbox", aggregateType: "inbox_item", phase: "P3" },
|
|
947
|
+
{ type: "inbox.item.deleted", domain: "inbox", aggregateType: "inbox_item", phase: "P3" },
|
|
948
|
+
{ type: "kb.document.created", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
949
|
+
{ type: "kb.document.updated", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
950
|
+
{ type: "kb.document.moved", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
951
|
+
{ type: "kb.document.archived", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
952
|
+
{ type: "kb.document.unarchived", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
953
|
+
{ type: "kb.document.deleted", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
954
|
+
{ type: "kb.document.review_changed", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
955
|
+
{ type: "kb.folder.created", domain: "kb", aggregateType: "kb_folder", phase: "P3" },
|
|
956
|
+
{ type: "kb.folder.updated", domain: "kb", aggregateType: "kb_folder", phase: "P3" },
|
|
957
|
+
{ type: "kb.folder.deleted", domain: "kb", aggregateType: "kb_folder", phase: "P3" },
|
|
958
|
+
{ type: "email.message.received", domain: "email", aggregateType: "email_message", phase: "P4" },
|
|
959
|
+
{ type: "email.message.sent", domain: "email", aggregateType: "email_message", phase: "P4" },
|
|
960
|
+
{ type: "email.message.status_changed", domain: "email", aggregateType: "email_message", phase: "P4" },
|
|
961
|
+
{ type: "task.visibility_changed", domain: "visibility", aggregateType: "task", phase: "P1" },
|
|
962
|
+
{ type: "agent.visibility_changed", domain: "visibility", aggregateType: "agent", phase: "P1" },
|
|
963
|
+
{ type: "goal.visibility_changed", domain: "visibility", aggregateType: "goal", phase: "P2" },
|
|
964
|
+
{ type: "mission.visibility_changed", domain: "visibility", aggregateType: "mission", phase: "P2" },
|
|
965
|
+
{ type: "idea.visibility_changed", domain: "visibility", aggregateType: "idea", phase: "P2" }
|
|
966
|
+
];
|
|
967
|
+
DOMAIN_EVENT_CATALOG.map((entry) => entry.type);
|
|
968
|
+
new Map(
|
|
969
|
+
DOMAIN_EVENT_CATALOG.map((entry) => [entry.type, entry])
|
|
970
|
+
);
|
|
971
|
+
var EMAIL_MESSAGE_ID_MAX_LENGTH = 255;
|
|
972
|
+
var EMAIL_REFERENCES_MAX_IDS = 50;
|
|
973
|
+
function normalizeMessageId(raw) {
|
|
974
|
+
if (typeof raw !== "string") return void 0;
|
|
975
|
+
let value = raw.trim();
|
|
976
|
+
const open = value.indexOf("<");
|
|
977
|
+
if (open !== -1) {
|
|
978
|
+
const close = value.indexOf(">", open + 1);
|
|
979
|
+
value = close === -1 ? value.slice(open + 1) : value.slice(open + 1, close);
|
|
980
|
+
}
|
|
981
|
+
value = value.trim();
|
|
982
|
+
if (!value || value.length > EMAIL_MESSAGE_ID_MAX_LENGTH) return void 0;
|
|
983
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
984
|
+
const code = value.charCodeAt(i);
|
|
985
|
+
if (code <= 32 || code === 127 || value[i] === "<" || value[i] === ">") return void 0;
|
|
986
|
+
}
|
|
987
|
+
return value;
|
|
988
|
+
}
|
|
989
|
+
function parseMessageIdList(raw) {
|
|
990
|
+
if (raw == null) return [];
|
|
991
|
+
const text = Array.isArray(raw) ? raw.join(" ") : String(raw);
|
|
992
|
+
const ids = [];
|
|
993
|
+
if (text.includes("<")) {
|
|
994
|
+
let open = text.indexOf("<");
|
|
995
|
+
while (open !== -1) {
|
|
996
|
+
const close = text.indexOf(">", open + 1);
|
|
997
|
+
if (close === -1) break;
|
|
998
|
+
const id = normalizeMessageId(text.slice(open + 1, close));
|
|
999
|
+
if (id) ids.push(id);
|
|
1000
|
+
open = text.indexOf("<", close + 1);
|
|
1001
|
+
}
|
|
1002
|
+
} else {
|
|
1003
|
+
for (const part of text.split(/[\s,]+/)) {
|
|
1004
|
+
const id = normalizeMessageId(part);
|
|
1005
|
+
if (id) ids.push(id);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
const unique = [...new Set(ids)];
|
|
1009
|
+
return unique.slice(Math.max(0, unique.length - EMAIL_REFERENCES_MAX_IDS));
|
|
1010
|
+
}
|
|
815
1011
|
var PLUGIN_CAPABILITIES = {
|
|
816
1012
|
// Notifications v2 (EW-650) — Email Providers. Plugins MAY declare
|
|
817
1013
|
// `EMAIL_OUTBOUND`, `EMAIL_INBOUND`, or both. See
|
|
@@ -844,6 +1040,10 @@ function resolveSigningKey(options) {
|
|
|
844
1040
|
const fromEnv = process.env.MAILGUN_WEBHOOK_SIGNING_KEY;
|
|
845
1041
|
return fromEnv && fromEnv.length > 0 ? fromEnv : void 0;
|
|
846
1042
|
}
|
|
1043
|
+
var EMAIL_INBOUND_ALLOW_UNSIGNED_ENV = "EMAIL_INBOUND_ALLOW_UNSIGNED";
|
|
1044
|
+
function unsignedInboundAllowed() {
|
|
1045
|
+
return process.env[EMAIL_INBOUND_ALLOW_UNSIGNED_ENV] === "true";
|
|
1046
|
+
}
|
|
847
1047
|
function decodeBody(rawBody) {
|
|
848
1048
|
const text = rawBody.toString("utf8");
|
|
849
1049
|
try {
|
|
@@ -870,6 +1070,31 @@ function angleAddress(value) {
|
|
|
870
1070
|
}
|
|
871
1071
|
return null;
|
|
872
1072
|
}
|
|
1073
|
+
function splitAddressList(raw) {
|
|
1074
|
+
const parts = [];
|
|
1075
|
+
let current = "";
|
|
1076
|
+
let inQuote = false;
|
|
1077
|
+
let inAngle = false;
|
|
1078
|
+
for (let i = 0; i < raw.length; i += 1) {
|
|
1079
|
+
const ch = raw[i];
|
|
1080
|
+
if (ch === "\\" && inQuote && i + 1 < raw.length) {
|
|
1081
|
+
current += ch + raw[i + 1];
|
|
1082
|
+
i += 1;
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1085
|
+
if (ch === '"' && !inAngle) inQuote = !inQuote;
|
|
1086
|
+
else if (ch === "<" && !inQuote) inAngle = true;
|
|
1087
|
+
else if (ch === ">" && !inQuote) inAngle = false;
|
|
1088
|
+
if (ch === "," && !inQuote && !inAngle) {
|
|
1089
|
+
parts.push(current);
|
|
1090
|
+
current = "";
|
|
1091
|
+
continue;
|
|
1092
|
+
}
|
|
1093
|
+
current += ch;
|
|
1094
|
+
}
|
|
1095
|
+
parts.push(current);
|
|
1096
|
+
return parts;
|
|
1097
|
+
}
|
|
873
1098
|
function extractSignature(body) {
|
|
874
1099
|
const nested = body.signature;
|
|
875
1100
|
if (nested && typeof nested === "object") {
|
|
@@ -922,6 +1147,7 @@ var MailgunPlugin = class {
|
|
|
922
1147
|
const mg = mailgun.client({ username: "api", key: apiKey, url: resolveApiUrl(options) });
|
|
923
1148
|
const customVars = {};
|
|
924
1149
|
for (const [k, v] of Object.entries(input.metadata ?? {})) customVars[`v:${k}`] = v;
|
|
1150
|
+
for (const [k, v] of Object.entries(input.headers ?? {})) customVars[`h:${k}`] = v;
|
|
925
1151
|
let id;
|
|
926
1152
|
try {
|
|
927
1153
|
const res = await mg.messages.create(domain, {
|
|
@@ -965,7 +1191,17 @@ var MailgunPlugin = class {
|
|
|
965
1191
|
}
|
|
966
1192
|
verifyWebhookSignature(rawBody, _headers, options) {
|
|
967
1193
|
const signingKey = resolveSigningKey(options);
|
|
968
|
-
if (!signingKey)
|
|
1194
|
+
if (!signingKey) {
|
|
1195
|
+
if (!unsignedInboundAllowed()) {
|
|
1196
|
+
throw new Error(
|
|
1197
|
+
`Mailgun inbound: no \`webhookSigningKey\`/MAILGUN_WEBHOOK_SIGNING_KEY configured; refusing an unsigned webhook (${EMAIL_INBOUND_ALLOW_UNSIGNED_ENV}=true accepts it on a local stack only).`
|
|
1198
|
+
);
|
|
1199
|
+
}
|
|
1200
|
+
console.warn(
|
|
1201
|
+
`[mailgun] inbound webhook accepted WITHOUT signature verification: no \`webhookSigningKey\`/MAILGUN_WEBHOOK_SIGNING_KEY configured and ${EMAIL_INBOUND_ALLOW_UNSIGNED_ENV}=true. Configure a signing key to authenticate inbound mail.`
|
|
1202
|
+
);
|
|
1203
|
+
return;
|
|
1204
|
+
}
|
|
969
1205
|
const sig = extractSignature(decodeBody(rawBody));
|
|
970
1206
|
if (!sig) {
|
|
971
1207
|
throw new Error("Mailgun inbound: missing timestamp/token/signature.");
|
|
@@ -992,11 +1228,39 @@ var MailgunPlugin = class {
|
|
|
992
1228
|
const recipient = str("recipient") ?? str("To") ?? "";
|
|
993
1229
|
const messageId = (str("Message-Id") ?? str("message-id") ?? `mailgun-${Date.now()}`).replace(/^<|>$/g, "");
|
|
994
1230
|
const tsSeconds = Number(str("timestamp"));
|
|
1231
|
+
const header = (name) => {
|
|
1232
|
+
for (const [key, value] of Object.entries(body)) {
|
|
1233
|
+
if (key.toLowerCase() === name && typeof value === "string") return value;
|
|
1234
|
+
}
|
|
1235
|
+
const raw = body["message-headers"];
|
|
1236
|
+
let pairs = raw;
|
|
1237
|
+
if (typeof raw === "string") {
|
|
1238
|
+
try {
|
|
1239
|
+
pairs = JSON.parse(raw);
|
|
1240
|
+
} catch {
|
|
1241
|
+
pairs = null;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
if (Array.isArray(pairs)) {
|
|
1245
|
+
for (const pair of pairs) {
|
|
1246
|
+
if (Array.isArray(pair) && typeof pair[0] === "string" && typeof pair[1] === "string" && pair[0].toLowerCase() === name) {
|
|
1247
|
+
return pair[1];
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
return void 0;
|
|
1252
|
+
};
|
|
1253
|
+
const messageIdHeader = normalizeMessageId(header("message-id"));
|
|
1254
|
+
const cc = splitAddressList(header("cc") ?? "").map((part) => (angleAddress(part.trim()) ?? part).trim()).filter((address) => address.length > 0 && address.includes("@"));
|
|
1255
|
+
const inReplyTo = parseMessageIdList(header("in-reply-to"))[0];
|
|
1256
|
+
const references = parseMessageIdList(header("references"));
|
|
995
1257
|
return {
|
|
996
1258
|
provider: this.id,
|
|
997
1259
|
providerMessageId: messageId,
|
|
998
1260
|
from: str("sender") ?? str("from") ?? "",
|
|
999
1261
|
to: parseAddressList(recipient),
|
|
1262
|
+
// EW-P4-3 — Cc is recorded (never routed on).
|
|
1263
|
+
...cc.length > 0 ? { cc } : {},
|
|
1000
1264
|
subject: str("subject") ?? "",
|
|
1001
1265
|
bodyText: str("body-plain") ?? str("stripped-text") ?? "",
|
|
1002
1266
|
bodyHtml: str("body-html") ?? str("stripped-html"),
|
|
@@ -1005,7 +1269,10 @@ var MailgunPlugin = class {
|
|
|
1005
1269
|
metadata: {
|
|
1006
1270
|
recipient,
|
|
1007
1271
|
signatureVerified: Boolean(resolveSigningKey(_options))
|
|
1008
|
-
}
|
|
1272
|
+
},
|
|
1273
|
+
...messageIdHeader ? { messageIdHeader } : {},
|
|
1274
|
+
...inReplyTo ? { inReplyTo } : {},
|
|
1275
|
+
...references.length > 0 ? { references } : {}
|
|
1009
1276
|
};
|
|
1010
1277
|
}
|
|
1011
1278
|
};
|
package/dist/index.js
CHANGED
|
@@ -96,10 +96,14 @@ var USER_SELECTABLE_WORK_KINDS = [
|
|
|
96
96
|
"repo",
|
|
97
97
|
"app"
|
|
98
98
|
];
|
|
99
|
-
var WORK_KINDS = [...USER_SELECTABLE_WORK_KINDS, "company", "campaign", "default"];
|
|
99
|
+
var WORK_KINDS = [...USER_SELECTABLE_WORK_KINDS, "company", "campaign", "project", "default"];
|
|
100
100
|
new Set(WORK_KINDS);
|
|
101
101
|
var GOAL_KINDS = ["metric", "delivery"];
|
|
102
102
|
new Set(GOAL_KINDS);
|
|
103
|
+
var RECORD_VISIBILITIES = ["private", "team", "organization"];
|
|
104
|
+
new Set(RECORD_VISIBILITIES);
|
|
105
|
+
var RECORD_LIST_VIEWS = ["mine", "shared", "organization"];
|
|
106
|
+
new Set(RECORD_LIST_VIEWS);
|
|
103
107
|
var VERSION = "1.0.0";
|
|
104
108
|
var GTM_SKILLS = [
|
|
105
109
|
// ── research ────────────────────────────────────────────────────────
|
|
@@ -663,6 +667,49 @@ var FLEET_AGENT_CREDENTIAL_FAMILIES = [
|
|
|
663
667
|
FLEET_AGENT_CREDENTIAL_FAMILIES.flatMap(
|
|
664
668
|
(family) => family.envNames
|
|
665
669
|
);
|
|
670
|
+
var FLEET_LINK_FRAME_KINDS = {
|
|
671
|
+
/** Raw bytes: terminal output/input, log lines, file chunks. */
|
|
672
|
+
DATA: 1,
|
|
673
|
+
/** `[cols u16][rows u16]`. */
|
|
674
|
+
RESIZE: 2,
|
|
675
|
+
/** `[code i32]`. */
|
|
676
|
+
EXIT: 3,
|
|
677
|
+
/** UTF-8 JSON control message. */
|
|
678
|
+
JSON: 10,
|
|
679
|
+
/** UTF-8 reason code. */
|
|
680
|
+
CLOSE: 11,
|
|
681
|
+
/** A full picture (the existing computer-frame encoding). */
|
|
682
|
+
FRAME: 20,
|
|
683
|
+
/** A pointer / key / text event (the existing computer input encoding). */
|
|
684
|
+
INPUT: 21,
|
|
685
|
+
/** Changed tiles `[w][h][count]{x,y,w,h,len,jpeg}`. */
|
|
686
|
+
TILES: 23,
|
|
687
|
+
/** `[bytes u32]` credit. */
|
|
688
|
+
ACK: 30,
|
|
689
|
+
/** End of a stream. */
|
|
690
|
+
END: 31,
|
|
691
|
+
/** UTF-8 text ≤ 256 KiB, pasted into a desktop. */
|
|
692
|
+
CLIP: 40
|
|
693
|
+
};
|
|
694
|
+
new Set(Object.values(FLEET_LINK_FRAME_KINDS));
|
|
695
|
+
var FLEET_LINK_CONTROL_TYPES = [
|
|
696
|
+
"link.hello",
|
|
697
|
+
"link.ready",
|
|
698
|
+
"link.ping",
|
|
699
|
+
"link.pong",
|
|
700
|
+
"link.pause",
|
|
701
|
+
"link.resume",
|
|
702
|
+
"link.drain",
|
|
703
|
+
"channel.open",
|
|
704
|
+
"channel.ready",
|
|
705
|
+
"channel.refused",
|
|
706
|
+
"channel.close",
|
|
707
|
+
"operation.progress",
|
|
708
|
+
"operation.done",
|
|
709
|
+
"operation.cancel"
|
|
710
|
+
];
|
|
711
|
+
new Set(FLEET_LINK_CONTROL_TYPES);
|
|
712
|
+
new TextEncoder();
|
|
666
713
|
var EMAIL_INBOX_CAP_FIELDS = [
|
|
667
714
|
"inboxDailySends",
|
|
668
715
|
"inboxBurstSends",
|
|
@@ -805,6 +852,155 @@ var ACTION_CATEGORIES = Object.freeze([
|
|
|
805
852
|
Object.freeze(
|
|
806
853
|
ACTION_CATEGORIES.filter((c) => c !== "read.internal")
|
|
807
854
|
);
|
|
855
|
+
var DOMAIN_EVENT_CATALOG = [
|
|
856
|
+
// EW-P2-6 — `org:write` (and the app) create Organizations.
|
|
857
|
+
{ type: "organization.created", domain: "organization", aggregateType: "organization", phase: "P2" },
|
|
858
|
+
{ type: "organization.updated", domain: "organization", aggregateType: "organization", phase: "P1" },
|
|
859
|
+
{
|
|
860
|
+
type: "organization.member.added",
|
|
861
|
+
domain: "organization",
|
|
862
|
+
aggregateType: "organization",
|
|
863
|
+
phase: "P1",
|
|
864
|
+
child: "member"
|
|
865
|
+
},
|
|
866
|
+
{
|
|
867
|
+
type: "organization.member.updated",
|
|
868
|
+
domain: "organization",
|
|
869
|
+
aggregateType: "organization",
|
|
870
|
+
phase: "P1",
|
|
871
|
+
child: "member"
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
type: "organization.member.removed",
|
|
875
|
+
domain: "organization",
|
|
876
|
+
aggregateType: "organization",
|
|
877
|
+
phase: "P1",
|
|
878
|
+
child: "member"
|
|
879
|
+
},
|
|
880
|
+
{ type: "agent.created", domain: "agents", aggregateType: "agent", phase: "P1" },
|
|
881
|
+
{ type: "agent.updated", domain: "agents", aggregateType: "agent", phase: "P1" },
|
|
882
|
+
{ type: "agent.status_changed", domain: "agents", aggregateType: "agent", phase: "P1" },
|
|
883
|
+
{ type: "agent.archived", domain: "agents", aggregateType: "agent", phase: "P1" },
|
|
884
|
+
{ type: "agent.deleted", domain: "agents", aggregateType: "agent", phase: "P1" },
|
|
885
|
+
{ type: "team.created", domain: "teams", aggregateType: "team", phase: "P1" },
|
|
886
|
+
{ type: "team.updated", domain: "teams", aggregateType: "team", phase: "P1" },
|
|
887
|
+
{ type: "team.deleted", domain: "teams", aggregateType: "team", phase: "P1" },
|
|
888
|
+
{ type: "team.member.added", domain: "teams", aggregateType: "team", phase: "P1", child: "member" },
|
|
889
|
+
{ type: "team.member.updated", domain: "teams", aggregateType: "team", phase: "P1", child: "member" },
|
|
890
|
+
{ type: "team.member.removed", domain: "teams", aggregateType: "team", phase: "P1", child: "member" },
|
|
891
|
+
{ type: "team.resource.added", domain: "teams", aggregateType: "team", phase: "P1", child: "resource" },
|
|
892
|
+
{ type: "team.resource.removed", domain: "teams", aggregateType: "team", phase: "P1", child: "resource" },
|
|
893
|
+
{ type: "work.created", domain: "works", aggregateType: "work", phase: "P1" },
|
|
894
|
+
{ type: "work.updated", domain: "works", aggregateType: "work", phase: "P1" },
|
|
895
|
+
{ type: "work.archived", domain: "works", aggregateType: "work", phase: "P1" },
|
|
896
|
+
{ type: "work.deleted", domain: "works", aggregateType: "work", phase: "P1" },
|
|
897
|
+
{ type: "work.member.added", domain: "works", aggregateType: "work", phase: "P1", child: "member" },
|
|
898
|
+
{ type: "work.member.updated", domain: "works", aggregateType: "work", phase: "P1", child: "member" },
|
|
899
|
+
{ type: "work.member.removed", domain: "works", aggregateType: "work", phase: "P1", child: "member" },
|
|
900
|
+
{ type: "mission.created", domain: "missions", aggregateType: "mission", phase: "P2" },
|
|
901
|
+
{ type: "mission.updated", domain: "missions", aggregateType: "mission", phase: "P2" },
|
|
902
|
+
{ type: "mission.status_changed", domain: "missions", aggregateType: "mission", phase: "P2" },
|
|
903
|
+
{ type: "mission.deleted", domain: "missions", aggregateType: "mission", phase: "P2" },
|
|
904
|
+
{ type: "mission.goal.linked", domain: "missions", aggregateType: "mission", phase: "P2", child: "goal" },
|
|
905
|
+
{ type: "mission.goal.unlinked", domain: "missions", aggregateType: "mission", phase: "P2", child: "goal" },
|
|
906
|
+
{ type: "mission.work.linked", domain: "missions", aggregateType: "mission", phase: "P2", child: "work" },
|
|
907
|
+
{ type: "mission.work.unlinked", domain: "missions", aggregateType: "mission", phase: "P2", child: "work" },
|
|
908
|
+
{ type: "goal.created", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
909
|
+
{ type: "goal.updated", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
910
|
+
{ type: "goal.status_changed", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
911
|
+
{ type: "goal.archived", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
912
|
+
{ type: "goal.unarchived", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
913
|
+
{ type: "goal.deleted", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
914
|
+
{ type: "goal.progress_changed", domain: "goals", aggregateType: "goal", phase: "P2" },
|
|
915
|
+
{ type: "idea.created", domain: "ideas", aggregateType: "idea", phase: "P2" },
|
|
916
|
+
{ type: "idea.updated", domain: "ideas", aggregateType: "idea", phase: "P2" },
|
|
917
|
+
{ type: "idea.status_changed", domain: "ideas", aggregateType: "idea", phase: "P2" },
|
|
918
|
+
{ type: "idea.deleted", domain: "ideas", aggregateType: "idea", phase: "P2" },
|
|
919
|
+
{ type: "task.created", domain: "tasks", aggregateType: "task", phase: "P1" },
|
|
920
|
+
{ type: "task.updated", domain: "tasks", aggregateType: "task", phase: "P1" },
|
|
921
|
+
{ type: "task.transitioned", domain: "tasks", aggregateType: "task", phase: "P1" },
|
|
922
|
+
{ type: "task.deleted", domain: "tasks", aggregateType: "task", phase: "P1" },
|
|
923
|
+
{ type: "task.assignee.added", domain: "tasks", aggregateType: "task", phase: "P1", child: "assignee" },
|
|
924
|
+
{ type: "task.assignee.removed", domain: "tasks", aggregateType: "task", phase: "P1", child: "assignee" },
|
|
925
|
+
{ type: "task.watcher.added", domain: "tasks", aggregateType: "task", phase: "P1", child: "watcher" },
|
|
926
|
+
{ type: "task.watcher.removed", domain: "tasks", aggregateType: "task", phase: "P1", child: "watcher" },
|
|
927
|
+
{ type: "task.block.added", domain: "tasks", aggregateType: "task", phase: "P1", child: "block" },
|
|
928
|
+
{ type: "task.block.removed", domain: "tasks", aggregateType: "task", phase: "P1", child: "block" },
|
|
929
|
+
{ type: "task.relation.added", domain: "tasks", aggregateType: "task", phase: "P1", child: "relation" },
|
|
930
|
+
{ type: "task.relation.removed", domain: "tasks", aggregateType: "task", phase: "P1", child: "relation" },
|
|
931
|
+
{ type: "task.comment.created", domain: "tasks", aggregateType: "task", phase: "P1", child: "comment" },
|
|
932
|
+
{ type: "task.comment.updated", domain: "tasks", aggregateType: "task", phase: "P1", child: "comment" },
|
|
933
|
+
{ type: "task.comment.deleted", domain: "tasks", aggregateType: "task", phase: "P1", child: "comment" },
|
|
934
|
+
{ type: "task.attachment.added", domain: "tasks", aggregateType: "task", phase: "P3", child: "attachment" },
|
|
935
|
+
{ type: "task.attachment.removed", domain: "tasks", aggregateType: "task", phase: "P3", child: "attachment" },
|
|
936
|
+
{ type: "task.runtime_updated", domain: "tasks", aggregateType: "task", phase: "P1", optIn: true },
|
|
937
|
+
{ type: "inbox.item.created", domain: "inbox", aggregateType: "inbox_item", phase: "P3" },
|
|
938
|
+
{ type: "inbox.item.answered", domain: "inbox", aggregateType: "inbox_item", phase: "P3" },
|
|
939
|
+
{ type: "inbox.item.state_changed", domain: "inbox", aggregateType: "inbox_item", phase: "P3" },
|
|
940
|
+
{ type: "inbox.item.deleted", domain: "inbox", aggregateType: "inbox_item", phase: "P3" },
|
|
941
|
+
{ type: "kb.document.created", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
942
|
+
{ type: "kb.document.updated", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
943
|
+
{ type: "kb.document.moved", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
944
|
+
{ type: "kb.document.archived", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
945
|
+
{ type: "kb.document.unarchived", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
946
|
+
{ type: "kb.document.deleted", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
947
|
+
{ type: "kb.document.review_changed", domain: "kb", aggregateType: "kb_document", phase: "P3" },
|
|
948
|
+
{ type: "kb.folder.created", domain: "kb", aggregateType: "kb_folder", phase: "P3" },
|
|
949
|
+
{ type: "kb.folder.updated", domain: "kb", aggregateType: "kb_folder", phase: "P3" },
|
|
950
|
+
{ type: "kb.folder.deleted", domain: "kb", aggregateType: "kb_folder", phase: "P3" },
|
|
951
|
+
{ type: "email.message.received", domain: "email", aggregateType: "email_message", phase: "P4" },
|
|
952
|
+
{ type: "email.message.sent", domain: "email", aggregateType: "email_message", phase: "P4" },
|
|
953
|
+
{ type: "email.message.status_changed", domain: "email", aggregateType: "email_message", phase: "P4" },
|
|
954
|
+
{ type: "task.visibility_changed", domain: "visibility", aggregateType: "task", phase: "P1" },
|
|
955
|
+
{ type: "agent.visibility_changed", domain: "visibility", aggregateType: "agent", phase: "P1" },
|
|
956
|
+
{ type: "goal.visibility_changed", domain: "visibility", aggregateType: "goal", phase: "P2" },
|
|
957
|
+
{ type: "mission.visibility_changed", domain: "visibility", aggregateType: "mission", phase: "P2" },
|
|
958
|
+
{ type: "idea.visibility_changed", domain: "visibility", aggregateType: "idea", phase: "P2" }
|
|
959
|
+
];
|
|
960
|
+
DOMAIN_EVENT_CATALOG.map((entry) => entry.type);
|
|
961
|
+
new Map(
|
|
962
|
+
DOMAIN_EVENT_CATALOG.map((entry) => [entry.type, entry])
|
|
963
|
+
);
|
|
964
|
+
var EMAIL_MESSAGE_ID_MAX_LENGTH = 255;
|
|
965
|
+
var EMAIL_REFERENCES_MAX_IDS = 50;
|
|
966
|
+
function normalizeMessageId(raw) {
|
|
967
|
+
if (typeof raw !== "string") return void 0;
|
|
968
|
+
let value = raw.trim();
|
|
969
|
+
const open = value.indexOf("<");
|
|
970
|
+
if (open !== -1) {
|
|
971
|
+
const close = value.indexOf(">", open + 1);
|
|
972
|
+
value = close === -1 ? value.slice(open + 1) : value.slice(open + 1, close);
|
|
973
|
+
}
|
|
974
|
+
value = value.trim();
|
|
975
|
+
if (!value || value.length > EMAIL_MESSAGE_ID_MAX_LENGTH) return void 0;
|
|
976
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
977
|
+
const code = value.charCodeAt(i);
|
|
978
|
+
if (code <= 32 || code === 127 || value[i] === "<" || value[i] === ">") return void 0;
|
|
979
|
+
}
|
|
980
|
+
return value;
|
|
981
|
+
}
|
|
982
|
+
function parseMessageIdList(raw) {
|
|
983
|
+
if (raw == null) return [];
|
|
984
|
+
const text = Array.isArray(raw) ? raw.join(" ") : String(raw);
|
|
985
|
+
const ids = [];
|
|
986
|
+
if (text.includes("<")) {
|
|
987
|
+
let open = text.indexOf("<");
|
|
988
|
+
while (open !== -1) {
|
|
989
|
+
const close = text.indexOf(">", open + 1);
|
|
990
|
+
if (close === -1) break;
|
|
991
|
+
const id = normalizeMessageId(text.slice(open + 1, close));
|
|
992
|
+
if (id) ids.push(id);
|
|
993
|
+
open = text.indexOf("<", close + 1);
|
|
994
|
+
}
|
|
995
|
+
} else {
|
|
996
|
+
for (const part of text.split(/[\s,]+/)) {
|
|
997
|
+
const id = normalizeMessageId(part);
|
|
998
|
+
if (id) ids.push(id);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
const unique = [...new Set(ids)];
|
|
1002
|
+
return unique.slice(Math.max(0, unique.length - EMAIL_REFERENCES_MAX_IDS));
|
|
1003
|
+
}
|
|
808
1004
|
var PLUGIN_CAPABILITIES = {
|
|
809
1005
|
// Notifications v2 (EW-650) — Email Providers. Plugins MAY declare
|
|
810
1006
|
// `EMAIL_OUTBOUND`, `EMAIL_INBOUND`, or both. See
|
|
@@ -837,6 +1033,10 @@ function resolveSigningKey(options) {
|
|
|
837
1033
|
const fromEnv = process.env.MAILGUN_WEBHOOK_SIGNING_KEY;
|
|
838
1034
|
return fromEnv && fromEnv.length > 0 ? fromEnv : void 0;
|
|
839
1035
|
}
|
|
1036
|
+
var EMAIL_INBOUND_ALLOW_UNSIGNED_ENV = "EMAIL_INBOUND_ALLOW_UNSIGNED";
|
|
1037
|
+
function unsignedInboundAllowed() {
|
|
1038
|
+
return process.env[EMAIL_INBOUND_ALLOW_UNSIGNED_ENV] === "true";
|
|
1039
|
+
}
|
|
840
1040
|
function decodeBody(rawBody) {
|
|
841
1041
|
const text = rawBody.toString("utf8");
|
|
842
1042
|
try {
|
|
@@ -863,6 +1063,31 @@ function angleAddress(value) {
|
|
|
863
1063
|
}
|
|
864
1064
|
return null;
|
|
865
1065
|
}
|
|
1066
|
+
function splitAddressList(raw) {
|
|
1067
|
+
const parts = [];
|
|
1068
|
+
let current = "";
|
|
1069
|
+
let inQuote = false;
|
|
1070
|
+
let inAngle = false;
|
|
1071
|
+
for (let i = 0; i < raw.length; i += 1) {
|
|
1072
|
+
const ch = raw[i];
|
|
1073
|
+
if (ch === "\\" && inQuote && i + 1 < raw.length) {
|
|
1074
|
+
current += ch + raw[i + 1];
|
|
1075
|
+
i += 1;
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
if (ch === '"' && !inAngle) inQuote = !inQuote;
|
|
1079
|
+
else if (ch === "<" && !inQuote) inAngle = true;
|
|
1080
|
+
else if (ch === ">" && !inQuote) inAngle = false;
|
|
1081
|
+
if (ch === "," && !inQuote && !inAngle) {
|
|
1082
|
+
parts.push(current);
|
|
1083
|
+
current = "";
|
|
1084
|
+
continue;
|
|
1085
|
+
}
|
|
1086
|
+
current += ch;
|
|
1087
|
+
}
|
|
1088
|
+
parts.push(current);
|
|
1089
|
+
return parts;
|
|
1090
|
+
}
|
|
866
1091
|
function extractSignature(body) {
|
|
867
1092
|
const nested = body.signature;
|
|
868
1093
|
if (nested && typeof nested === "object") {
|
|
@@ -915,6 +1140,7 @@ var MailgunPlugin = class {
|
|
|
915
1140
|
const mg = mailgun.client({ username: "api", key: apiKey, url: resolveApiUrl(options) });
|
|
916
1141
|
const customVars = {};
|
|
917
1142
|
for (const [k, v] of Object.entries(input.metadata ?? {})) customVars[`v:${k}`] = v;
|
|
1143
|
+
for (const [k, v] of Object.entries(input.headers ?? {})) customVars[`h:${k}`] = v;
|
|
918
1144
|
let id;
|
|
919
1145
|
try {
|
|
920
1146
|
const res = await mg.messages.create(domain, {
|
|
@@ -958,7 +1184,17 @@ var MailgunPlugin = class {
|
|
|
958
1184
|
}
|
|
959
1185
|
verifyWebhookSignature(rawBody, _headers, options) {
|
|
960
1186
|
const signingKey = resolveSigningKey(options);
|
|
961
|
-
if (!signingKey)
|
|
1187
|
+
if (!signingKey) {
|
|
1188
|
+
if (!unsignedInboundAllowed()) {
|
|
1189
|
+
throw new Error(
|
|
1190
|
+
`Mailgun inbound: no \`webhookSigningKey\`/MAILGUN_WEBHOOK_SIGNING_KEY configured; refusing an unsigned webhook (${EMAIL_INBOUND_ALLOW_UNSIGNED_ENV}=true accepts it on a local stack only).`
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
console.warn(
|
|
1194
|
+
`[mailgun] inbound webhook accepted WITHOUT signature verification: no \`webhookSigningKey\`/MAILGUN_WEBHOOK_SIGNING_KEY configured and ${EMAIL_INBOUND_ALLOW_UNSIGNED_ENV}=true. Configure a signing key to authenticate inbound mail.`
|
|
1195
|
+
);
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
962
1198
|
const sig = extractSignature(decodeBody(rawBody));
|
|
963
1199
|
if (!sig) {
|
|
964
1200
|
throw new Error("Mailgun inbound: missing timestamp/token/signature.");
|
|
@@ -985,11 +1221,39 @@ var MailgunPlugin = class {
|
|
|
985
1221
|
const recipient = str("recipient") ?? str("To") ?? "";
|
|
986
1222
|
const messageId = (str("Message-Id") ?? str("message-id") ?? `mailgun-${Date.now()}`).replace(/^<|>$/g, "");
|
|
987
1223
|
const tsSeconds = Number(str("timestamp"));
|
|
1224
|
+
const header = (name) => {
|
|
1225
|
+
for (const [key, value] of Object.entries(body)) {
|
|
1226
|
+
if (key.toLowerCase() === name && typeof value === "string") return value;
|
|
1227
|
+
}
|
|
1228
|
+
const raw = body["message-headers"];
|
|
1229
|
+
let pairs = raw;
|
|
1230
|
+
if (typeof raw === "string") {
|
|
1231
|
+
try {
|
|
1232
|
+
pairs = JSON.parse(raw);
|
|
1233
|
+
} catch {
|
|
1234
|
+
pairs = null;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
if (Array.isArray(pairs)) {
|
|
1238
|
+
for (const pair of pairs) {
|
|
1239
|
+
if (Array.isArray(pair) && typeof pair[0] === "string" && typeof pair[1] === "string" && pair[0].toLowerCase() === name) {
|
|
1240
|
+
return pair[1];
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
return void 0;
|
|
1245
|
+
};
|
|
1246
|
+
const messageIdHeader = normalizeMessageId(header("message-id"));
|
|
1247
|
+
const cc = splitAddressList(header("cc") ?? "").map((part) => (angleAddress(part.trim()) ?? part).trim()).filter((address) => address.length > 0 && address.includes("@"));
|
|
1248
|
+
const inReplyTo = parseMessageIdList(header("in-reply-to"))[0];
|
|
1249
|
+
const references = parseMessageIdList(header("references"));
|
|
988
1250
|
return {
|
|
989
1251
|
provider: this.id,
|
|
990
1252
|
providerMessageId: messageId,
|
|
991
1253
|
from: str("sender") ?? str("from") ?? "",
|
|
992
1254
|
to: parseAddressList(recipient),
|
|
1255
|
+
// EW-P4-3 — Cc is recorded (never routed on).
|
|
1256
|
+
...cc.length > 0 ? { cc } : {},
|
|
993
1257
|
subject: str("subject") ?? "",
|
|
994
1258
|
bodyText: str("body-plain") ?? str("stripped-text") ?? "",
|
|
995
1259
|
bodyHtml: str("body-html") ?? str("stripped-html"),
|
|
@@ -998,7 +1262,10 @@ var MailgunPlugin = class {
|
|
|
998
1262
|
metadata: {
|
|
999
1263
|
recipient,
|
|
1000
1264
|
signatureVerified: Boolean(resolveSigningKey(_options))
|
|
1001
|
-
}
|
|
1265
|
+
},
|
|
1266
|
+
...messageIdHeader ? { messageIdHeader } : {},
|
|
1267
|
+
...inReplyTo ? { inReplyTo } : {},
|
|
1268
|
+
...references.length > 0 ? { references } : {}
|
|
1002
1269
|
};
|
|
1003
1270
|
}
|
|
1004
1271
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ever-works/mailgun-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
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.
|
|
35
|
+
"@ever-works/plugin": "^1.2.6",
|
|
36
36
|
"form-data": "^4.0.1",
|
|
37
37
|
"mailgun.js": "^10.2.3"
|
|
38
38
|
},
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@types/node": "^26.6.4",
|
|
41
41
|
"tsup": "^8.0.0",
|
|
42
42
|
"typescript": "^5.9.3",
|
|
43
|
-
"vitest": "^
|
|
43
|
+
"vitest": "^5.0.5"
|
|
44
44
|
},
|
|
45
45
|
"everworks": {
|
|
46
46
|
"plugin": {
|
|
@@ -102,8 +102,8 @@
|
|
|
102
102
|
"url": "https://github.com/ever-works/ever-works/issues"
|
|
103
103
|
},
|
|
104
104
|
"everworksRelease": {
|
|
105
|
-
"contentHash": "sha256:
|
|
106
|
-
"commit": "
|
|
107
|
-
"source": "https://github.com/ever-works/ever-works/tree/
|
|
105
|
+
"contentHash": "sha256:4e6ce098205095db4f6003964bbd192d73574d055f83d42349aa85f2ab4a944d",
|
|
106
|
+
"commit": "54552a4d2dcb0e2d5213b0a47fd3ffcbd432f73c",
|
|
107
|
+
"source": "https://github.com/ever-works/ever-works/tree/54552a4d2dcb0e2d5213b0a47fd3ffcbd432f73c/packages/plugins/mailgun"
|
|
108
108
|
}
|
|
109
109
|
}
|