mailery 0.15.0 → 0.16.0
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 +1 -0
- package/dist/index.cjs +1370 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +417 -114
- package/dist/index.d.ts +417 -114
- package/dist/index.js +1356 -10
- package/dist/index.js.map +1 -1
- package/dist/{null-CnhsvKvy.d.cts → null-CDlseQxO.d.cts} +1 -1
- package/dist/{null-CnhsvKvy.d.ts → null-CDlseQxO.d.ts} +1 -1
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -6162,13 +6162,13 @@ function createAdminRouter(mailer, opts = {}) {
|
|
|
6162
6162
|
req.actor = getActor(req);
|
|
6163
6163
|
next();
|
|
6164
6164
|
});
|
|
6165
|
-
router.use("/api",
|
|
6165
|
+
router.use("/api", createAdminApiRouter(mailer, opts));
|
|
6166
6166
|
router.get(/.*/, (_req, res) => {
|
|
6167
6167
|
res.sendFile(path.join(spaDir, "index.html"));
|
|
6168
6168
|
});
|
|
6169
6169
|
return router;
|
|
6170
6170
|
}
|
|
6171
|
-
function
|
|
6171
|
+
function createAdminApiRouter(mailer, opts = {}) {
|
|
6172
6172
|
const r = Router();
|
|
6173
6173
|
const c = mailer.collections;
|
|
6174
6174
|
const varsSchema = mailer.config.varsAdapter ? varsJsonSchema(mailer.config.varsAdapter) : null;
|
|
@@ -6365,7 +6365,11 @@ function apiRouter(mailer, opts = {}) {
|
|
|
6365
6365
|
asyncHandler(async (req, res) => {
|
|
6366
6366
|
const before = await c.flows.findOne({ slug: req.params.slug });
|
|
6367
6367
|
if (!before) return res.status(404).json({ error: "not_found" });
|
|
6368
|
-
|
|
6368
|
+
const now = /* @__PURE__ */ new Date();
|
|
6369
|
+
await c.flows.updateOne(
|
|
6370
|
+
{ _id: before._id },
|
|
6371
|
+
{ $set: { enabled: true, updatedAt: now, ...before.lastTriggerScanAt ? {} : { lastTriggerScanAt: now } } }
|
|
6372
|
+
);
|
|
6369
6373
|
await mailer.audit({
|
|
6370
6374
|
actor: req.actor,
|
|
6371
6375
|
action: "flow.resume",
|
|
@@ -6946,6 +6950,7 @@ function apiRouter(mailer, opts = {}) {
|
|
|
6946
6950
|
if (!Array.isArray(draftSteps) || draftSteps.length === 0) {
|
|
6947
6951
|
return res.status(400).json({ error: "empty_flow", message: "flow has no steps to publish" });
|
|
6948
6952
|
}
|
|
6953
|
+
const enable = req.body?.enable !== false;
|
|
6949
6954
|
const nextVersion = (flow.version ?? 0) + 1;
|
|
6950
6955
|
const now = /* @__PURE__ */ new Date();
|
|
6951
6956
|
await c.flowVersions.insertOne({
|
|
@@ -6962,11 +6967,14 @@ function apiRouter(mailer, opts = {}) {
|
|
|
6962
6967
|
$set: {
|
|
6963
6968
|
steps: draftSteps,
|
|
6964
6969
|
version: nextVersion,
|
|
6965
|
-
enabled: true,
|
|
6970
|
+
enabled: enable ? true : flow.enabled,
|
|
6966
6971
|
draft: null,
|
|
6967
6972
|
publishedAt: now,
|
|
6968
6973
|
publishedBy: req.actor,
|
|
6969
|
-
updatedAt: now
|
|
6974
|
+
updatedAt: now,
|
|
6975
|
+
// First enable: stamp the trigger watermark so the scan does not
|
|
6976
|
+
// replay every event since the flow document was created.
|
|
6977
|
+
...enable && !flow.lastTriggerScanAt ? { lastTriggerScanAt: now } : {}
|
|
6970
6978
|
}
|
|
6971
6979
|
}
|
|
6972
6980
|
);
|
|
@@ -6974,9 +6982,9 @@ function apiRouter(mailer, opts = {}) {
|
|
|
6974
6982
|
actor: req.actor,
|
|
6975
6983
|
action: "flow.publish",
|
|
6976
6984
|
resource: { collection: "mailer_flows", id: flow._id, slug: flow.slug },
|
|
6977
|
-
diffSummary: `Published v${nextVersion}`
|
|
6985
|
+
diffSummary: `Published v${nextVersion}${enable ? "" : " (left disabled)"}`
|
|
6978
6986
|
});
|
|
6979
|
-
return res.json({ ok: true, version: nextVersion });
|
|
6987
|
+
return res.json({ ok: true, version: nextVersion, enabled: enable ? true : flow.enabled });
|
|
6980
6988
|
})
|
|
6981
6989
|
);
|
|
6982
6990
|
r.delete(
|
|
@@ -7847,7 +7855,1345 @@ function wrap(logger, handler) {
|
|
|
7847
7855
|
};
|
|
7848
7856
|
}
|
|
7849
7857
|
|
|
7850
|
-
// src/server/api/
|
|
7858
|
+
// src/server/api/agent.ts
|
|
7859
|
+
init_vars();
|
|
7860
|
+
|
|
7861
|
+
// src/server/runner/arm.ts
|
|
7862
|
+
var FlowOperationError = class extends Error {
|
|
7863
|
+
constructor(code, message, status = 400) {
|
|
7864
|
+
super(message);
|
|
7865
|
+
this.code = code;
|
|
7866
|
+
this.status = status;
|
|
7867
|
+
this.name = "FlowOperationError";
|
|
7868
|
+
}
|
|
7869
|
+
code;
|
|
7870
|
+
status;
|
|
7871
|
+
};
|
|
7872
|
+
async function stampWatermarkIfNull(collections, flow, now = /* @__PURE__ */ new Date()) {
|
|
7873
|
+
if (flow.lastTriggerScanAt) return flow.lastTriggerScanAt;
|
|
7874
|
+
await collections.flows.updateOne(
|
|
7875
|
+
{ _id: flow._id, lastTriggerScanAt: null },
|
|
7876
|
+
{ $set: { lastTriggerScanAt: now, updatedAt: now } }
|
|
7877
|
+
);
|
|
7878
|
+
return now;
|
|
7879
|
+
}
|
|
7880
|
+
async function armFlow(mailer, slug, opts) {
|
|
7881
|
+
const c = mailer.collections;
|
|
7882
|
+
const flow = await c.flows.findOne({ slug });
|
|
7883
|
+
if (!flow) throw new FlowOperationError("not_found", `no flow with slug "${slug}"`, 404);
|
|
7884
|
+
if (!Array.isArray(flow.steps) || flow.steps.length === 0) {
|
|
7885
|
+
throw new FlowOperationError(
|
|
7886
|
+
"no_live_steps",
|
|
7887
|
+
`flow "${slug}" (v${flow.version}) has no published steps \u2014 publish it first; an empty flow completes every run instantly`,
|
|
7888
|
+
409
|
|
7889
|
+
);
|
|
7890
|
+
}
|
|
7891
|
+
const eventName = flow.trigger?.eventName ?? null;
|
|
7892
|
+
const now = /* @__PURE__ */ new Date();
|
|
7893
|
+
const watermark = opts.since ?? now;
|
|
7894
|
+
if (flow.enabled) {
|
|
7895
|
+
return {
|
|
7896
|
+
slug,
|
|
7897
|
+
version: flow.version,
|
|
7898
|
+
armed: false,
|
|
7899
|
+
alreadyEnabled: true,
|
|
7900
|
+
watermark: flow.lastTriggerScanAt ?? null,
|
|
7901
|
+
eventName,
|
|
7902
|
+
skippedEvents: 0,
|
|
7903
|
+
pendingEvents: 0
|
|
7904
|
+
};
|
|
7905
|
+
}
|
|
7906
|
+
const previous = flow.lastTriggerScanAt ?? flow.createdAt;
|
|
7907
|
+
const overlapFrom = new Date(watermark.getTime() - SCAN_OVERLAP_MS);
|
|
7908
|
+
const [skippedEvents, pendingEvents] = eventName ? await Promise.all([
|
|
7909
|
+
c.events.countDocuments({ name: eventName, createdAt: { $gt: previous, $lte: overlapFrom } }),
|
|
7910
|
+
c.events.countDocuments({ name: eventName, createdAt: { $gt: overlapFrom } })
|
|
7911
|
+
]) : [0, 0];
|
|
7912
|
+
const res = await c.flows.updateOne(
|
|
7913
|
+
{ _id: flow._id, enabled: false },
|
|
7914
|
+
{ $set: { enabled: true, lastTriggerScanAt: watermark, updatedAt: now } }
|
|
7915
|
+
);
|
|
7916
|
+
if (res.modifiedCount === 0) {
|
|
7917
|
+
const again = await c.flows.findOne({ _id: flow._id });
|
|
7918
|
+
return {
|
|
7919
|
+
slug,
|
|
7920
|
+
version: flow.version,
|
|
7921
|
+
armed: false,
|
|
7922
|
+
alreadyEnabled: !!again?.enabled,
|
|
7923
|
+
watermark: again?.lastTriggerScanAt ?? null,
|
|
7924
|
+
eventName,
|
|
7925
|
+
skippedEvents: 0,
|
|
7926
|
+
pendingEvents: 0
|
|
7927
|
+
};
|
|
7928
|
+
}
|
|
7929
|
+
await mailer.audit({
|
|
7930
|
+
actor: opts.actor,
|
|
7931
|
+
action: "flow.arm",
|
|
7932
|
+
resource: { collection: "mailer_flows", id: flow._id, slug },
|
|
7933
|
+
diffSummary: `Enabled v${flow.version} with lastTriggerScanAt=${watermark.toISOString()} (skipped ${skippedEvents} earlier ${eventName ?? "trigger"} event(s), ${pendingEvents} pending)`
|
|
7934
|
+
});
|
|
7935
|
+
return {
|
|
7936
|
+
slug,
|
|
7937
|
+
version: flow.version,
|
|
7938
|
+
armed: true,
|
|
7939
|
+
alreadyEnabled: false,
|
|
7940
|
+
watermark,
|
|
7941
|
+
eventName,
|
|
7942
|
+
skippedEvents,
|
|
7943
|
+
pendingEvents
|
|
7944
|
+
};
|
|
7945
|
+
}
|
|
7946
|
+
async function disarmFlow(mailer, slug, actor) {
|
|
7947
|
+
const c = mailer.collections;
|
|
7948
|
+
const flow = await c.flows.findOne({ slug });
|
|
7949
|
+
if (!flow) throw new FlowOperationError("not_found", `no flow with slug "${slug}"`, 404);
|
|
7950
|
+
if (!flow.enabled) return { slug, disarmed: false };
|
|
7951
|
+
await c.flows.updateOne({ _id: flow._id }, { $set: { enabled: false, updatedAt: /* @__PURE__ */ new Date() } });
|
|
7952
|
+
await mailer.audit({
|
|
7953
|
+
actor,
|
|
7954
|
+
action: "flow.pause",
|
|
7955
|
+
resource: { collection: "mailer_flows", id: flow._id, slug },
|
|
7956
|
+
diffSummary: "Disarmed (enabled: false); in-flight runs continue"
|
|
7957
|
+
});
|
|
7958
|
+
return { slug, disarmed: true };
|
|
7959
|
+
}
|
|
7960
|
+
function isCanaryGate(step) {
|
|
7961
|
+
const s = step;
|
|
7962
|
+
return !!s && s.type === "condition" && s.canaryGate === true;
|
|
7963
|
+
}
|
|
7964
|
+
function gateStep(tag) {
|
|
7965
|
+
return { type: "condition", test: { hasTag: tag }, ifFalse: "exit", canaryGate: true };
|
|
7966
|
+
}
|
|
7967
|
+
async function publishVersion(mailer, flow, steps, actor, summary) {
|
|
7968
|
+
const c = mailer.collections;
|
|
7969
|
+
const nextVersion = (flow.version ?? 0) + 1;
|
|
7970
|
+
const now = /* @__PURE__ */ new Date();
|
|
7971
|
+
await c.flowVersions.insertOne({
|
|
7972
|
+
flowId: flow._id,
|
|
7973
|
+
version: nextVersion,
|
|
7974
|
+
steps,
|
|
7975
|
+
trigger: flow.trigger,
|
|
7976
|
+
publishedAt: now,
|
|
7977
|
+
publishedBy: actor
|
|
7978
|
+
});
|
|
7979
|
+
await c.flows.updateOne(
|
|
7980
|
+
{ _id: flow._id },
|
|
7981
|
+
{ $set: { steps, version: nextVersion, draft: null, publishedAt: now, publishedBy: actor, updatedAt: now } }
|
|
7982
|
+
);
|
|
7983
|
+
await mailer.audit({
|
|
7984
|
+
actor,
|
|
7985
|
+
action: "flow.publish",
|
|
7986
|
+
resource: { collection: "mailer_flows", id: flow._id, slug: flow.slug },
|
|
7987
|
+
diffSummary: `Published v${nextVersion}: ${summary}`
|
|
7988
|
+
});
|
|
7989
|
+
return { version: nextVersion };
|
|
7990
|
+
}
|
|
7991
|
+
async function gateFlow(mailer, slug, opts) {
|
|
7992
|
+
const tag = String(opts.tag ?? "").trim();
|
|
7993
|
+
if (!tag) throw new FlowOperationError("tag_required", "a canary tag is required");
|
|
7994
|
+
const flow = await mailer.collections.flows.findOne({ slug });
|
|
7995
|
+
if (!flow) throw new FlowOperationError("not_found", `no flow with slug "${slug}"`, 404);
|
|
7996
|
+
const live = Array.isArray(flow.steps) ? flow.steps : [];
|
|
7997
|
+
if (live.length === 0) {
|
|
7998
|
+
throw new FlowOperationError("no_live_steps", `flow "${slug}" has no published steps to gate`, 409);
|
|
7999
|
+
}
|
|
8000
|
+
if (isCanaryGate(live[0])) {
|
|
8001
|
+
throw new FlowOperationError(
|
|
8002
|
+
"already_gated",
|
|
8003
|
+
`flow "${slug}" v${flow.version} is already gated on "${live[0].test.hasTag}" \u2014 ungate first`,
|
|
8004
|
+
409
|
|
8005
|
+
);
|
|
8006
|
+
}
|
|
8007
|
+
await mailer.collections.flowVersions.updateOne(
|
|
8008
|
+
{ flowId: flow._id, version: flow.version },
|
|
8009
|
+
{
|
|
8010
|
+
$setOnInsert: {
|
|
8011
|
+
flowId: flow._id,
|
|
8012
|
+
version: flow.version,
|
|
8013
|
+
steps: live,
|
|
8014
|
+
trigger: flow.trigger,
|
|
8015
|
+
publishedAt: flow.publishedAt ?? flow.updatedAt ?? /* @__PURE__ */ new Date(),
|
|
8016
|
+
publishedBy: flow.publishedBy ?? "unknown"
|
|
8017
|
+
}
|
|
8018
|
+
},
|
|
8019
|
+
{ upsert: true }
|
|
8020
|
+
);
|
|
8021
|
+
const { version } = await publishVersion(
|
|
8022
|
+
mailer,
|
|
8023
|
+
flow,
|
|
8024
|
+
[gateStep(tag), ...live],
|
|
8025
|
+
opts.actor,
|
|
8026
|
+
`canary gate on tag "${tag}"`
|
|
8027
|
+
);
|
|
8028
|
+
return { slug, version, tag, enabled: flow.enabled };
|
|
8029
|
+
}
|
|
8030
|
+
async function ungateFlow(mailer, slug, opts) {
|
|
8031
|
+
const c = mailer.collections;
|
|
8032
|
+
const flow = await c.flows.findOne({ slug });
|
|
8033
|
+
if (!flow) throw new FlowOperationError("not_found", `no flow with slug "${slug}"`, 404);
|
|
8034
|
+
const live = Array.isArray(flow.steps) ? flow.steps : [];
|
|
8035
|
+
if (!isCanaryGate(live[0])) {
|
|
8036
|
+
throw new FlowOperationError("not_gated", `flow "${slug}" v${flow.version} is not gated`, 409);
|
|
8037
|
+
}
|
|
8038
|
+
const versions = await c.flowVersions.find({ flowId: flow._id }).sort({ version: -1 }).toArray();
|
|
8039
|
+
const clean = versions.find((v) => Array.isArray(v.steps) && v.steps.length > 0 && !isCanaryGate(v.steps[0]));
|
|
8040
|
+
if (!clean) {
|
|
8041
|
+
throw new FlowOperationError(
|
|
8042
|
+
"no_ungated_version",
|
|
8043
|
+
`flow "${slug}" has no ungated version in mailer_flow_versions to restore`,
|
|
8044
|
+
409
|
|
8045
|
+
);
|
|
8046
|
+
}
|
|
8047
|
+
const { version } = await publishVersion(
|
|
8048
|
+
mailer,
|
|
8049
|
+
flow,
|
|
8050
|
+
clean.steps,
|
|
8051
|
+
opts.actor,
|
|
8052
|
+
`restored steps of v${clean.version} (canary gate removed)`
|
|
8053
|
+
);
|
|
8054
|
+
return { slug, version, restoredFrom: clean.version, enabled: flow.enabled };
|
|
8055
|
+
}
|
|
8056
|
+
var MAX_STEPS = 1e3;
|
|
8057
|
+
async function simulateFlow(flow, contact, ctx, opts = {}) {
|
|
8058
|
+
const enteredAt = opts.at ?? /* @__PURE__ */ new Date();
|
|
8059
|
+
const steps = opts.steps ?? flow.steps ?? [];
|
|
8060
|
+
const eventName = flow.trigger?.eventName ?? "simulated";
|
|
8061
|
+
const eventProperties = opts.eventProperties ?? {};
|
|
8062
|
+
const reasons = [];
|
|
8063
|
+
if (!flow.enabled) reasons.push("flow is disabled (enabled: false)");
|
|
8064
|
+
const sub = await ctx.collections.subscriptions.findOne({ externalId: contact.externalId });
|
|
8065
|
+
if (!sub) reasons.push("contact has no subscription row \u2014 the trigger scan requires one");
|
|
8066
|
+
else if (sub.status !== "subscribed") reasons.push(`subscription status is "${sub.status}", not "subscribed"`);
|
|
8067
|
+
if (flow.trigger?.once) {
|
|
8068
|
+
const existing = await ctx.collections.flowRuns.findOne(
|
|
8069
|
+
{ externalId: contact.externalId, flowId: flow._id },
|
|
8070
|
+
{ projection: { _id: 1, status: 1 } }
|
|
8071
|
+
);
|
|
8072
|
+
if (existing) reasons.push(`trigger.once is true and the contact already has a run (${existing.status})`);
|
|
8073
|
+
}
|
|
8074
|
+
if (steps.length === 0) reasons.push("flow has no live steps \u2014 a run would complete immediately");
|
|
8075
|
+
const run = {
|
|
8076
|
+
_id: new ObjectId(),
|
|
8077
|
+
externalId: contact.externalId,
|
|
8078
|
+
flowId: flow._id,
|
|
8079
|
+
flowSlug: flow.slug,
|
|
8080
|
+
flowVersion: flow.version,
|
|
8081
|
+
emailAtEntry: contact.email,
|
|
8082
|
+
triggerEvent: { name: eventName, properties: eventProperties, occurredAt: enteredAt },
|
|
8083
|
+
triggerDedupeKey: null,
|
|
8084
|
+
enteredAt,
|
|
8085
|
+
status: "active",
|
|
8086
|
+
currentStepIndex: 0,
|
|
8087
|
+
currentBranchPath: [],
|
|
8088
|
+
nextActionAt: enteredAt,
|
|
8089
|
+
attemptsForCurrentStep: 0,
|
|
8090
|
+
history: [],
|
|
8091
|
+
exitedAt: null,
|
|
8092
|
+
exitReason: null,
|
|
8093
|
+
createdAt: enteredAt,
|
|
8094
|
+
updatedAt: enteredAt
|
|
8095
|
+
};
|
|
8096
|
+
const path3 = [];
|
|
8097
|
+
const sends = [];
|
|
8098
|
+
let list = steps;
|
|
8099
|
+
let index = 0;
|
|
8100
|
+
let branchPath = [];
|
|
8101
|
+
let t = enteredAt;
|
|
8102
|
+
let terminal = null;
|
|
8103
|
+
const record = (type, outcome, detail) => {
|
|
8104
|
+
path3.push({ at: t, stepIndex: index, branchPath: [...branchPath], type, outcome, ...detail ? { detail } : {} });
|
|
8105
|
+
};
|
|
8106
|
+
const predicateCtx = () => ({
|
|
8107
|
+
contact,
|
|
8108
|
+
run: { ...run, currentStepIndex: index, currentBranchPath: branchPath, nextActionAt: t },
|
|
8109
|
+
collections: ctx.collections,
|
|
8110
|
+
now: t,
|
|
8111
|
+
botFilter: ctx.config.botFilter
|
|
8112
|
+
});
|
|
8113
|
+
for (let guard = 0; guard < MAX_STEPS && !terminal; guard += 1) {
|
|
8114
|
+
const step = list[index];
|
|
8115
|
+
if (!step) {
|
|
8116
|
+
terminal = { kind: "completed", reason: "sequence_complete", at: t };
|
|
8117
|
+
break;
|
|
8118
|
+
}
|
|
8119
|
+
switch (step.type) {
|
|
8120
|
+
case "wait": {
|
|
8121
|
+
const ms = unitToMs2(step.value, step.unit);
|
|
8122
|
+
record("wait", "waited", { value: step.value, unit: step.unit, until: new Date(t.getTime() + ms) });
|
|
8123
|
+
t = new Date(t.getTime() + ms);
|
|
8124
|
+
index += 1;
|
|
8125
|
+
break;
|
|
8126
|
+
}
|
|
8127
|
+
case "condition": {
|
|
8128
|
+
const result = await evaluatePredicate(step.test, predicateCtx());
|
|
8129
|
+
if (result) {
|
|
8130
|
+
record("condition", "passed", { test: step.test, result });
|
|
8131
|
+
index += 1;
|
|
8132
|
+
} else if (step.ifFalse === "continue") {
|
|
8133
|
+
record("condition", "skipped_next", { test: step.test, result });
|
|
8134
|
+
index += 2;
|
|
8135
|
+
} else {
|
|
8136
|
+
record("condition", "exited", { test: step.test, result });
|
|
8137
|
+
terminal = { kind: "exited", reason: "condition_false", at: t };
|
|
8138
|
+
}
|
|
8139
|
+
break;
|
|
8140
|
+
}
|
|
8141
|
+
case "branch": {
|
|
8142
|
+
const result = await evaluatePredicate(step.test, predicateCtx());
|
|
8143
|
+
record("branch", result ? "branch_true" : "branch_false", { test: step.test, result });
|
|
8144
|
+
branchPath = [...branchPath, index, result ? "true" : "false", 0];
|
|
8145
|
+
list = result ? step.ifTrueSteps : step.ifFalseSteps;
|
|
8146
|
+
index = 0;
|
|
8147
|
+
break;
|
|
8148
|
+
}
|
|
8149
|
+
case "send": {
|
|
8150
|
+
let at = t;
|
|
8151
|
+
if (step.delivery) {
|
|
8152
|
+
at = computeDeliveryTime(t, step.delivery, contact.timezone);
|
|
8153
|
+
}
|
|
8154
|
+
if (at.getTime() > t.getTime() + 3e4) {
|
|
8155
|
+
record("send", "send_deferred", { templateSlug: step.templateSlug, delivery: step.delivery, until: at });
|
|
8156
|
+
t = at;
|
|
8157
|
+
}
|
|
8158
|
+
record("send", "send", { templateSlug: step.templateSlug });
|
|
8159
|
+
sends.push({ templateSlug: step.templateSlug, at: t, stepIndex: index, branchPath: [...branchPath] });
|
|
8160
|
+
index += 1;
|
|
8161
|
+
break;
|
|
8162
|
+
}
|
|
8163
|
+
case "tag":
|
|
8164
|
+
record("tag", "tagged", { addTags: step.addTags ?? [], removeTags: step.removeTags ?? [] });
|
|
8165
|
+
index += 1;
|
|
8166
|
+
break;
|
|
8167
|
+
case "fire_event":
|
|
8168
|
+
record("fire_event", "event_fired", { eventName: step.eventName });
|
|
8169
|
+
index += 1;
|
|
8170
|
+
break;
|
|
8171
|
+
case "webhook":
|
|
8172
|
+
record("webhook", "webhook", { url: step.url, method: step.method ?? "POST", note: "not called in simulation" });
|
|
8173
|
+
index += 1;
|
|
8174
|
+
break;
|
|
8175
|
+
case "exit":
|
|
8176
|
+
record("exit", "exited", { reason: step.reason ?? "exit_step" });
|
|
8177
|
+
terminal = { kind: "exited", reason: step.reason ?? "exit_step", at: t };
|
|
8178
|
+
break;
|
|
8179
|
+
}
|
|
8180
|
+
}
|
|
8181
|
+
if (!terminal) terminal = { kind: "truncated", reason: `stopped after ${MAX_STEPS} steps`, at: t };
|
|
8182
|
+
return {
|
|
8183
|
+
flow: { slug: flow.slug, version: flow.version, enabled: flow.enabled },
|
|
8184
|
+
contact: { externalId: contact.externalId, email: contact.email },
|
|
8185
|
+
enteredAt,
|
|
8186
|
+
wouldEnter: { ok: reasons.length === 0, reasons },
|
|
8187
|
+
path: path3,
|
|
8188
|
+
sends,
|
|
8189
|
+
terminal,
|
|
8190
|
+
durationMs: terminal.at.getTime() - enteredAt.getTime()
|
|
8191
|
+
};
|
|
8192
|
+
}
|
|
8193
|
+
function unitToMs2(value, unit) {
|
|
8194
|
+
const m = 6e4;
|
|
8195
|
+
switch (unit) {
|
|
8196
|
+
case "minutes":
|
|
8197
|
+
return value * m;
|
|
8198
|
+
case "hours":
|
|
8199
|
+
return value * 60 * m;
|
|
8200
|
+
case "days":
|
|
8201
|
+
return value * 24 * 60 * m;
|
|
8202
|
+
case "weeks":
|
|
8203
|
+
return value * 7 * 24 * 60 * m;
|
|
8204
|
+
}
|
|
8205
|
+
}
|
|
8206
|
+
|
|
8207
|
+
// src/server/api/agent.ts
|
|
8208
|
+
var VERSION = "0.16.0" ;
|
|
8209
|
+
var MIN_AGENT_TOKEN_LENGTH = 24;
|
|
8210
|
+
function createAgentRouter(mailer, opts) {
|
|
8211
|
+
if (!opts || !Array.isArray(opts.tokens) || opts.tokens.length === 0) {
|
|
8212
|
+
throw new Error("createAgentRouter: at least one bearer token is required \u2014 the agent API is never open");
|
|
8213
|
+
}
|
|
8214
|
+
for (const t of opts.tokens) {
|
|
8215
|
+
if (typeof t?.token !== "string" || t.token.length < MIN_AGENT_TOKEN_LENGTH) {
|
|
8216
|
+
throw new Error(
|
|
8217
|
+
`createAgentRouter: every token must be at least ${MIN_AGENT_TOKEN_LENGTH} characters (got ${t?.token?.length ?? 0})`
|
|
8218
|
+
);
|
|
8219
|
+
}
|
|
8220
|
+
if (typeof t.actor !== "string" || !t.actor.trim()) {
|
|
8221
|
+
throw new Error('createAgentRouter: every token needs an actor label, e.g. "agent:claude"');
|
|
8222
|
+
}
|
|
8223
|
+
}
|
|
8224
|
+
const logger = opts.logger ?? consoleRouteLogger;
|
|
8225
|
+
const isTestContact = testContactMatcher(opts.testContacts);
|
|
8226
|
+
const c = mailer.collections;
|
|
8227
|
+
const varsSchema = mailer.config.varsAdapter ? varsJsonSchema(mailer.config.varsAdapter) : null;
|
|
8228
|
+
const router = Router();
|
|
8229
|
+
router.use(express.json({ limit: "1mb" }));
|
|
8230
|
+
router.use(bearerAuth(opts.tokens));
|
|
8231
|
+
router.use("/api", createAdminApiRouter(mailer, { mailTesterClient: opts.mailTesterClient }));
|
|
8232
|
+
const actorOf = (req) => String(req.actor);
|
|
8233
|
+
function guardTestContact(res, contact) {
|
|
8234
|
+
if (!isTestContact) {
|
|
8235
|
+
res.status(403).json({
|
|
8236
|
+
error: "test_contacts_not_configured",
|
|
8237
|
+
message: "this route only acts on test contacts, and the router was constructed without a testContacts pattern"
|
|
8238
|
+
});
|
|
8239
|
+
return false;
|
|
8240
|
+
}
|
|
8241
|
+
if (!isTestContact(contact.email)) {
|
|
8242
|
+
res.status(403).json({
|
|
8243
|
+
error: "not_a_test_contact",
|
|
8244
|
+
message: `${contact.email} does not match the testContacts pattern`,
|
|
8245
|
+
externalId: contact.externalId
|
|
8246
|
+
});
|
|
8247
|
+
return false;
|
|
8248
|
+
}
|
|
8249
|
+
return true;
|
|
8250
|
+
}
|
|
8251
|
+
async function loadContact(res, externalId) {
|
|
8252
|
+
const contact = await mailer.adapter.getById(externalId);
|
|
8253
|
+
if (!contact) res.status(404).json({ error: "contact_not_found", externalId });
|
|
8254
|
+
return contact;
|
|
8255
|
+
}
|
|
8256
|
+
async function loadTemplate(res, slug) {
|
|
8257
|
+
const tpl = await c.templates.findOne({ slug });
|
|
8258
|
+
if (!tpl) res.status(404).json({ error: "template_not_found", slug });
|
|
8259
|
+
return tpl;
|
|
8260
|
+
}
|
|
8261
|
+
router.get("/", (req, res) => {
|
|
8262
|
+
res.json({
|
|
8263
|
+
service: "mailery-agent",
|
|
8264
|
+
version: VERSION,
|
|
8265
|
+
actor: actorOf(req),
|
|
8266
|
+
testContactsConfigured: !!isTestContact,
|
|
8267
|
+
docs: "https://jeffjassky.github.io/mailery/reference/agent-api",
|
|
8268
|
+
endpoints: ENDPOINTS
|
|
8269
|
+
});
|
|
8270
|
+
});
|
|
8271
|
+
router.post(
|
|
8272
|
+
"/templates/:slug/verify",
|
|
8273
|
+
wrap2(async (req, res) => {
|
|
8274
|
+
const tpl = await loadTemplate(res, String(req.params.slug));
|
|
8275
|
+
if (!tpl) return;
|
|
8276
|
+
const contact = await contactForRender(req, res);
|
|
8277
|
+
if (!contact) return;
|
|
8278
|
+
const report = await verifyTemplate(mailer, tpl, contact, {
|
|
8279
|
+
eventProperties: objectOrUndefined(req.body?.eventProperties),
|
|
8280
|
+
vars: objectOrUndefined(req.body?.vars),
|
|
8281
|
+
includeRendered: req.body?.includeRendered === true,
|
|
8282
|
+
varsSchema
|
|
8283
|
+
});
|
|
8284
|
+
res.status(200).json(report);
|
|
8285
|
+
})
|
|
8286
|
+
);
|
|
8287
|
+
router.post(
|
|
8288
|
+
"/templates/verify-all",
|
|
8289
|
+
wrap2(async (req, res) => {
|
|
8290
|
+
const slugs = Array.isArray(req.body?.slugs) ? req.body.slugs.map(String) : null;
|
|
8291
|
+
const contactIds = Array.isArray(req.body?.contactIds) ? req.body.contactIds.map(String) : [];
|
|
8292
|
+
if (contactIds.length === 0) {
|
|
8293
|
+
return res.status(400).json({ error: "validation_failed", message: "contactIds (non-empty array) is required" });
|
|
8294
|
+
}
|
|
8295
|
+
const templates = await c.templates.find(slugs ? { slug: { $in: slugs } } : {}).sort({ slug: 1 }).toArray();
|
|
8296
|
+
const contacts = [];
|
|
8297
|
+
for (const id of contactIds) {
|
|
8298
|
+
const found = await mailer.adapter.getById(id);
|
|
8299
|
+
if (!found) return res.status(404).json({ error: "contact_not_found", externalId: id });
|
|
8300
|
+
contacts.push(found);
|
|
8301
|
+
}
|
|
8302
|
+
const results = [];
|
|
8303
|
+
for (const tpl of templates) {
|
|
8304
|
+
for (const contact of contacts) {
|
|
8305
|
+
const report = await verifyTemplate(mailer, tpl, contact, {
|
|
8306
|
+
eventProperties: objectOrUndefined(req.body?.eventProperties),
|
|
8307
|
+
includeRendered: false,
|
|
8308
|
+
varsSchema
|
|
8309
|
+
});
|
|
8310
|
+
results.push({
|
|
8311
|
+
slug: tpl.slug,
|
|
8312
|
+
contactId: contact.externalId,
|
|
8313
|
+
ok: report.ok,
|
|
8314
|
+
failed: report.checks.filter((k) => k.status === "fail").map((k) => k.id),
|
|
8315
|
+
warned: report.checks.filter((k) => k.status === "warn").map((k) => k.id)
|
|
8316
|
+
});
|
|
8317
|
+
}
|
|
8318
|
+
}
|
|
8319
|
+
const failing = results.filter((r) => !r.ok);
|
|
8320
|
+
res.json({
|
|
8321
|
+
ok: failing.length === 0,
|
|
8322
|
+
templates: templates.length,
|
|
8323
|
+
contacts: contacts.length,
|
|
8324
|
+
verified: results.length,
|
|
8325
|
+
failing: failing.length,
|
|
8326
|
+
results
|
|
8327
|
+
});
|
|
8328
|
+
})
|
|
8329
|
+
);
|
|
8330
|
+
router.post(
|
|
8331
|
+
"/templates/:slug/render",
|
|
8332
|
+
wrap2(async (req, res) => {
|
|
8333
|
+
const tpl = await loadTemplate(res, String(req.params.slug));
|
|
8334
|
+
if (!tpl) return;
|
|
8335
|
+
const contact = await contactForRender(req, res);
|
|
8336
|
+
if (!contact) return;
|
|
8337
|
+
const out = await renderForContact(mailer, tpl, contact, {
|
|
8338
|
+
reason: "preview",
|
|
8339
|
+
eventProperties: objectOrUndefined(req.body?.eventProperties),
|
|
8340
|
+
vars: objectOrUndefined(req.body?.vars)
|
|
8341
|
+
});
|
|
8342
|
+
res.json({
|
|
8343
|
+
template: { slug: tpl.slug, kind: tpl.kind },
|
|
8344
|
+
contact: { externalId: contact.externalId, email: contact.email },
|
|
8345
|
+
subject: out.rendered.subject,
|
|
8346
|
+
preheader: out.rendered.preheader,
|
|
8347
|
+
fromName: out.rendered.fromName,
|
|
8348
|
+
fromEmail: out.rendered.fromEmail,
|
|
8349
|
+
replyTo: out.rendered.replyTo,
|
|
8350
|
+
html: out.rendered.html,
|
|
8351
|
+
plainText: out.rendered.plainText,
|
|
8352
|
+
resolvedVars: out.resolved,
|
|
8353
|
+
unsubscribeUrl: out.unsubscribeUrl
|
|
8354
|
+
});
|
|
8355
|
+
})
|
|
8356
|
+
);
|
|
8357
|
+
router.post(
|
|
8358
|
+
"/templates/:slug/send",
|
|
8359
|
+
wrap2(async (req, res) => {
|
|
8360
|
+
const tpl = await loadTemplate(res, String(req.params.slug));
|
|
8361
|
+
if (!tpl) return;
|
|
8362
|
+
const contactId = typeof req.body?.contactId === "string" ? req.body.contactId : "";
|
|
8363
|
+
if (!contactId) return res.status(400).json({ error: "validation_failed", message: "contactId is required" });
|
|
8364
|
+
const contact = await loadContact(res, contactId);
|
|
8365
|
+
if (!contact) return;
|
|
8366
|
+
if (!guardTestContact(res, contact)) return;
|
|
8367
|
+
if (!tpl.body?.html && !tpl.body?.mjml) {
|
|
8368
|
+
return res.status(409).json({ error: "not_published", message: "template has no published body" });
|
|
8369
|
+
}
|
|
8370
|
+
const dedupeKey = typeof req.body?.dedupeKey === "string" && req.body.dedupeKey ? String(req.body.dedupeKey) : `agent:${crypto2.randomUUID()}`;
|
|
8371
|
+
const { sendId } = await mailer.sendOneOff({
|
|
8372
|
+
templateSlug: tpl.slug,
|
|
8373
|
+
externalId: contact.externalId,
|
|
8374
|
+
dedupeKey,
|
|
8375
|
+
vars: objectOrUndefined(req.body?.vars)
|
|
8376
|
+
});
|
|
8377
|
+
const dispatchNow = req.body?.dispatch !== "queue";
|
|
8378
|
+
if (dispatchNow) {
|
|
8379
|
+
await dispatchSend(new ObjectId(sendId), mailer.getRunnerContext());
|
|
8380
|
+
}
|
|
8381
|
+
const send = await c.sends.findOne({ _id: new ObjectId(sendId) });
|
|
8382
|
+
await mailer.audit({
|
|
8383
|
+
actor: actorOf(req),
|
|
8384
|
+
action: "agent.send",
|
|
8385
|
+
resource: { collection: "mailer_sends", id: new ObjectId(sendId), slug: tpl.slug },
|
|
8386
|
+
diffSummary: `to=${contact.email} dispatch=${dispatchNow ? "now" : "queue"} dedupeKey=${dedupeKey}`
|
|
8387
|
+
});
|
|
8388
|
+
res.status(201).json({ sendId, dedupeKey, dispatched: dispatchNow, send: send ? sendSummary(send) : null });
|
|
8389
|
+
})
|
|
8390
|
+
);
|
|
8391
|
+
router.get(
|
|
8392
|
+
"/sends/:id/wait",
|
|
8393
|
+
wrap2(async (req, res) => {
|
|
8394
|
+
const id = String(req.params.id);
|
|
8395
|
+
if (!ObjectId.isValid(id)) return res.status(400).json({ error: "bad_id" });
|
|
8396
|
+
const target = String(req.query.status ?? "delivered");
|
|
8397
|
+
if (!WAIT_TARGETS.has(target)) {
|
|
8398
|
+
return res.status(400).json({ error: "validation_failed", message: `status must be one of ${[...WAIT_TARGETS].join(", ")}` });
|
|
8399
|
+
}
|
|
8400
|
+
const timeoutMs = Math.max(0, Math.min(Number(req.query.timeoutMs ?? 3e4) || 0, 55e3));
|
|
8401
|
+
const started = Date.now();
|
|
8402
|
+
let send = null;
|
|
8403
|
+
let reached = false;
|
|
8404
|
+
for (; ; ) {
|
|
8405
|
+
send = await c.sends.findOne({ _id: new ObjectId(id) });
|
|
8406
|
+
if (!send) return res.status(404).json({ error: "not_found" });
|
|
8407
|
+
reached = waitTargetReached(send, target);
|
|
8408
|
+
if (reached || Date.now() - started >= timeoutMs) break;
|
|
8409
|
+
await sleep2(1e3);
|
|
8410
|
+
}
|
|
8411
|
+
const webhookEvents = send.providerMessageId ? await c.webhookEvents.find({ providerMessageId: send.providerMessageId }).sort({ receivedAt: 1 }).limit(100).toArray() : [];
|
|
8412
|
+
res.json({ reached, target, waitedMs: Date.now() - started, send: sendSummary(send), webhookEvents });
|
|
8413
|
+
})
|
|
8414
|
+
);
|
|
8415
|
+
router.post(
|
|
8416
|
+
"/sends/:id/dispatch",
|
|
8417
|
+
wrap2(async (req, res) => {
|
|
8418
|
+
const id = String(req.params.id);
|
|
8419
|
+
if (!ObjectId.isValid(id)) return res.status(400).json({ error: "bad_id" });
|
|
8420
|
+
const send = await c.sends.findOne({ _id: new ObjectId(id) });
|
|
8421
|
+
if (!send) return res.status(404).json({ error: "not_found" });
|
|
8422
|
+
const contact = await loadContact(res, send.externalId);
|
|
8423
|
+
if (!contact) return;
|
|
8424
|
+
if (!guardTestContact(res, contact)) return;
|
|
8425
|
+
await dispatchSend(send._id, mailer.getRunnerContext());
|
|
8426
|
+
const after = await c.sends.findOne({ _id: send._id });
|
|
8427
|
+
res.json({ send: after ? sendSummary(after) : null });
|
|
8428
|
+
})
|
|
8429
|
+
);
|
|
8430
|
+
router.post(
|
|
8431
|
+
"/flows/:slug/simulate",
|
|
8432
|
+
wrap2(async (req, res) => {
|
|
8433
|
+
const flow = await c.flows.findOne({ slug: String(req.params.slug) });
|
|
8434
|
+
if (!flow) return res.status(404).json({ error: "flow_not_found", slug: String(req.params.slug) });
|
|
8435
|
+
const contactId = typeof req.body?.contactId === "string" ? req.body.contactId : "";
|
|
8436
|
+
if (!contactId) return res.status(400).json({ error: "validation_failed", message: "contactId is required" });
|
|
8437
|
+
const contact = await loadContact(res, contactId);
|
|
8438
|
+
if (!contact) return;
|
|
8439
|
+
let at;
|
|
8440
|
+
if (req.body?.at) {
|
|
8441
|
+
at = new Date(String(req.body.at));
|
|
8442
|
+
if (Number.isNaN(at.getTime())) return res.status(400).json({ error: "validation_failed", message: "at must be an ISO date" });
|
|
8443
|
+
}
|
|
8444
|
+
let steps = void 0;
|
|
8445
|
+
if (req.body?.version !== void 0) {
|
|
8446
|
+
const v = Number(req.body.version);
|
|
8447
|
+
if (v !== flow.version) {
|
|
8448
|
+
const snap = await c.flowVersions.findOne({ flowId: flow._id, version: v });
|
|
8449
|
+
if (!snap) return res.status(404).json({ error: "version_not_found", version: v });
|
|
8450
|
+
steps = snap.steps;
|
|
8451
|
+
}
|
|
8452
|
+
}
|
|
8453
|
+
const result = await simulateFlow(flow, contact, mailer.getRunnerContext(), {
|
|
8454
|
+
at,
|
|
8455
|
+
eventProperties: objectOrUndefined(req.body?.eventProperties),
|
|
8456
|
+
steps
|
|
8457
|
+
});
|
|
8458
|
+
res.json(result);
|
|
8459
|
+
})
|
|
8460
|
+
);
|
|
8461
|
+
router.post(
|
|
8462
|
+
"/flows/:slug/arm",
|
|
8463
|
+
wrap2(async (req, res) => {
|
|
8464
|
+
if (req.body?.confirm !== true) {
|
|
8465
|
+
return res.status(400).json({
|
|
8466
|
+
error: "confirm_required",
|
|
8467
|
+
message: 'arming enables a flow for every future matching event; pass {"confirm": true}'
|
|
8468
|
+
});
|
|
8469
|
+
}
|
|
8470
|
+
let since;
|
|
8471
|
+
if (req.body?.since) {
|
|
8472
|
+
since = new Date(String(req.body.since));
|
|
8473
|
+
if (Number.isNaN(since.getTime())) return res.status(400).json({ error: "validation_failed", message: "since must be an ISO date" });
|
|
8474
|
+
}
|
|
8475
|
+
const result = await armFlow(mailer, String(req.params.slug), { actor: actorOf(req), since });
|
|
8476
|
+
res.json(result);
|
|
8477
|
+
})
|
|
8478
|
+
);
|
|
8479
|
+
router.post(
|
|
8480
|
+
"/flows/:slug/disarm",
|
|
8481
|
+
wrap2(async (req, res) => {
|
|
8482
|
+
res.json(await disarmFlow(mailer, String(req.params.slug), actorOf(req)));
|
|
8483
|
+
})
|
|
8484
|
+
);
|
|
8485
|
+
router.post(
|
|
8486
|
+
"/flows/:slug/gate",
|
|
8487
|
+
wrap2(async (req, res) => {
|
|
8488
|
+
const tag = typeof req.body?.tag === "string" ? req.body.tag : "";
|
|
8489
|
+
res.json(await gateFlow(mailer, String(req.params.slug), { tag, actor: actorOf(req) }));
|
|
8490
|
+
})
|
|
8491
|
+
);
|
|
8492
|
+
router.post(
|
|
8493
|
+
"/flows/:slug/ungate",
|
|
8494
|
+
wrap2(async (req, res) => {
|
|
8495
|
+
res.json(await ungateFlow(mailer, String(req.params.slug), { actor: actorOf(req) }));
|
|
8496
|
+
})
|
|
8497
|
+
);
|
|
8498
|
+
router.get(
|
|
8499
|
+
"/runs",
|
|
8500
|
+
wrap2(async (req, res) => {
|
|
8501
|
+
const filter = {};
|
|
8502
|
+
if (typeof req.query.externalId === "string") filter.externalId = req.query.externalId;
|
|
8503
|
+
if (typeof req.query.flowSlug === "string") filter.flowSlug = req.query.flowSlug;
|
|
8504
|
+
if (typeof req.query.status === "string") filter.status = req.query.status;
|
|
8505
|
+
const limit = Math.min(Math.max(Number(req.query.limit ?? 50) || 50, 1), 200);
|
|
8506
|
+
const runs = await c.flowRuns.find(filter).sort({ enteredAt: -1 }).limit(limit).toArray();
|
|
8507
|
+
res.json(runs.map(runSummary));
|
|
8508
|
+
})
|
|
8509
|
+
);
|
|
8510
|
+
router.get(
|
|
8511
|
+
"/runs/:id",
|
|
8512
|
+
wrap2(async (req, res) => {
|
|
8513
|
+
const id = String(req.params.id);
|
|
8514
|
+
if (!ObjectId.isValid(id)) return res.status(400).json({ error: "bad_id" });
|
|
8515
|
+
const run = await c.flowRuns.findOne({ _id: new ObjectId(id) });
|
|
8516
|
+
if (!run) return res.status(404).json({ error: "not_found" });
|
|
8517
|
+
const sends = await c.sends.find({ flowRunId: run._id }).sort({ queuedAt: 1 }).toArray();
|
|
8518
|
+
res.json({ run, sends: sends.map(sendSummary) });
|
|
8519
|
+
})
|
|
8520
|
+
);
|
|
8521
|
+
router.post(
|
|
8522
|
+
"/runs/:id/advance",
|
|
8523
|
+
wrap2(async (req, res) => {
|
|
8524
|
+
const id = String(req.params.id);
|
|
8525
|
+
if (!ObjectId.isValid(id)) return res.status(400).json({ error: "bad_id" });
|
|
8526
|
+
const run = await c.flowRuns.findOne({ _id: new ObjectId(id) });
|
|
8527
|
+
if (!run) return res.status(404).json({ error: "not_found" });
|
|
8528
|
+
const contact = await loadContact(res, run.externalId);
|
|
8529
|
+
if (!contact) return;
|
|
8530
|
+
if (!guardTestContact(res, contact)) return;
|
|
8531
|
+
if (run.status !== "active") {
|
|
8532
|
+
return res.status(409).json({ error: "run_not_active", status: run.status, exitReason: run.exitReason });
|
|
8533
|
+
}
|
|
8534
|
+
const steps = Math.min(Math.max(Number(req.body?.steps ?? 1) || 1, 1), 50);
|
|
8535
|
+
const dispatch = req.body?.dispatch !== false;
|
|
8536
|
+
const ctx = mailer.getRunnerContext();
|
|
8537
|
+
const startedAt = /* @__PURE__ */ new Date();
|
|
8538
|
+
const historyBefore = run.history.length;
|
|
8539
|
+
const actor = actorOf(req);
|
|
8540
|
+
for (let i = 0; i < steps; i += 1) {
|
|
8541
|
+
const advanced = await advanceOnce(run._id, ctx, actor, c);
|
|
8542
|
+
if (!advanced) break;
|
|
8543
|
+
}
|
|
8544
|
+
const after = await c.flowRuns.findOne({ _id: run._id });
|
|
8545
|
+
const newSends = await c.sends.find({ flowRunId: run._id, queuedAt: { $gte: startedAt } }).toArray();
|
|
8546
|
+
if (dispatch) {
|
|
8547
|
+
for (const s of newSends) {
|
|
8548
|
+
if (s.status === "queued") await dispatchSend(s._id, ctx);
|
|
8549
|
+
}
|
|
8550
|
+
}
|
|
8551
|
+
const sends = await c.sends.find({ flowRunId: run._id, queuedAt: { $gte: startedAt } }).toArray();
|
|
8552
|
+
await mailer.audit({
|
|
8553
|
+
actor,
|
|
8554
|
+
action: "agent.run.advance",
|
|
8555
|
+
resource: { collection: "mailer_flow_runs", id: run._id, slug: run.flowSlug },
|
|
8556
|
+
diffSummary: `advanced ${steps} step(s) for ${contact.email}; ${sends.length} send(s) created`
|
|
8557
|
+
});
|
|
8558
|
+
res.json({
|
|
8559
|
+
run: after ? runSummary(after) : null,
|
|
8560
|
+
historyAdded: after ? after.history.slice(historyBefore) : [],
|
|
8561
|
+
sends: sends.map(sendSummary)
|
|
8562
|
+
});
|
|
8563
|
+
})
|
|
8564
|
+
);
|
|
8565
|
+
router.post(
|
|
8566
|
+
"/runs/:id/cancel",
|
|
8567
|
+
wrap2(async (req, res) => {
|
|
8568
|
+
const id = String(req.params.id);
|
|
8569
|
+
if (!ObjectId.isValid(id)) return res.status(400).json({ error: "bad_id" });
|
|
8570
|
+
const run = await c.flowRuns.findOne({ _id: new ObjectId(id) });
|
|
8571
|
+
if (!run) return res.status(404).json({ error: "not_found" });
|
|
8572
|
+
if (run.status !== "active") return res.status(409).json({ error: "run_not_active", status: run.status });
|
|
8573
|
+
const actor = actorOf(req);
|
|
8574
|
+
await exitFlowRun(run, `aborted_by_host:${actor}`, mailer.getRunnerContext());
|
|
8575
|
+
const cancelled = await c.sends.updateMany(
|
|
8576
|
+
{ flowRunId: run._id, status: "queued" },
|
|
8577
|
+
{ $set: { status: "cancelled", errorMessage: `cancelled: aborted_by_host:${actor}`, updatedAt: /* @__PURE__ */ new Date() } }
|
|
8578
|
+
);
|
|
8579
|
+
await mailer.audit({
|
|
8580
|
+
actor,
|
|
8581
|
+
action: "agent.run.cancel",
|
|
8582
|
+
resource: { collection: "mailer_flow_runs", id: run._id, slug: run.flowSlug },
|
|
8583
|
+
diffSummary: `cancelled run for ${run.externalId}; ${cancelled.modifiedCount} queued send(s) cancelled`
|
|
8584
|
+
});
|
|
8585
|
+
const after = await c.flowRuns.findOne({ _id: run._id });
|
|
8586
|
+
res.json({ run: after ? runSummary(after) : null, cancelledSends: cancelled.modifiedCount });
|
|
8587
|
+
})
|
|
8588
|
+
);
|
|
8589
|
+
router.post(
|
|
8590
|
+
"/events",
|
|
8591
|
+
wrap2(async (req, res) => {
|
|
8592
|
+
const name = typeof req.body?.name === "string" ? req.body.name : "";
|
|
8593
|
+
const externalId = typeof req.body?.externalId === "string" ? req.body.externalId : "";
|
|
8594
|
+
if (!name || !externalId) {
|
|
8595
|
+
return res.status(400).json({ error: "validation_failed", message: "name and externalId are required" });
|
|
8596
|
+
}
|
|
8597
|
+
const contact = await loadContact(res, externalId);
|
|
8598
|
+
if (!contact) return;
|
|
8599
|
+
if (!guardTestContact(res, contact)) return;
|
|
8600
|
+
const dedupeKey = typeof req.body?.dedupeKey === "string" && req.body.dedupeKey ? req.body.dedupeKey : void 0;
|
|
8601
|
+
try {
|
|
8602
|
+
await mailer.fire(name, externalId, objectOrUndefined(req.body?.properties) ?? {}, dedupeKey);
|
|
8603
|
+
} catch (err) {
|
|
8604
|
+
return res.status(400).json({ error: "fire_failed", message: String(err?.message ?? err) });
|
|
8605
|
+
}
|
|
8606
|
+
const latest = await c.events.findOne({ externalId, name }, { sort: { createdAt: -1 } });
|
|
8607
|
+
await mailer.audit({
|
|
8608
|
+
actor: actorOf(req),
|
|
8609
|
+
action: "agent.event.fire",
|
|
8610
|
+
resource: { collection: "mailer_events", id: latest?._id },
|
|
8611
|
+
diffSummary: `${name} for ${contact.email}${dedupeKey ? ` key=${dedupeKey}` : ""}`
|
|
8612
|
+
});
|
|
8613
|
+
res.status(201).json({ ok: true, event: latest });
|
|
8614
|
+
})
|
|
8615
|
+
);
|
|
8616
|
+
router.get(
|
|
8617
|
+
"/contacts/by-email/:email",
|
|
8618
|
+
wrap2(async (req, res) => {
|
|
8619
|
+
const contact = await mailer.adapter.getByEmail(String(req.params.email).toLowerCase());
|
|
8620
|
+
if (!contact) return res.status(404).json({ error: "contact_not_found", email: req.params.email });
|
|
8621
|
+
res.json(await contactDetail(contact));
|
|
8622
|
+
})
|
|
8623
|
+
);
|
|
8624
|
+
router.get(
|
|
8625
|
+
"/contacts/:externalId",
|
|
8626
|
+
wrap2(async (req, res) => {
|
|
8627
|
+
const contact = await loadContact(res, String(req.params.externalId));
|
|
8628
|
+
if (!contact) return;
|
|
8629
|
+
res.json(await contactDetail(contact));
|
|
8630
|
+
})
|
|
8631
|
+
);
|
|
8632
|
+
router.get(
|
|
8633
|
+
"/contacts/:externalId/unsubscribe-url",
|
|
8634
|
+
wrap2(async (req, res) => {
|
|
8635
|
+
const contact = await loadContact(res, String(req.params.externalId));
|
|
8636
|
+
if (!contact) return;
|
|
8637
|
+
if (!guardTestContact(res, contact)) return;
|
|
8638
|
+
res.json({ contact: { externalId: contact.externalId, email: contact.email }, unsubscribeUrl: unsubscribeUrlFor(mailer, contact.email) });
|
|
8639
|
+
})
|
|
8640
|
+
);
|
|
8641
|
+
router.post(
|
|
8642
|
+
"/contacts/:externalId/subscribe",
|
|
8643
|
+
wrap2(async (req, res) => {
|
|
8644
|
+
const contact = await loadContact(res, String(req.params.externalId));
|
|
8645
|
+
if (!contact) return;
|
|
8646
|
+
if (!guardTestContact(res, contact)) return;
|
|
8647
|
+
await mailer.upsertSubscription({ externalId: contact.externalId, source: "agent" });
|
|
8648
|
+
const sub = await c.subscriptions.findOne({ externalId: contact.externalId });
|
|
8649
|
+
await mailer.audit({
|
|
8650
|
+
actor: actorOf(req),
|
|
8651
|
+
action: "agent.contact.subscribe",
|
|
8652
|
+
resource: { collection: "mailer_subscriptions", id: sub?._id },
|
|
8653
|
+
diffSummary: contact.email
|
|
8654
|
+
});
|
|
8655
|
+
res.json({ subscription: sub });
|
|
8656
|
+
})
|
|
8657
|
+
);
|
|
8658
|
+
router.post(
|
|
8659
|
+
"/contacts/:externalId/unsubscribe",
|
|
8660
|
+
wrap2(async (req, res) => {
|
|
8661
|
+
const contact = await loadContact(res, String(req.params.externalId));
|
|
8662
|
+
if (!contact) return;
|
|
8663
|
+
if (!guardTestContact(res, contact)) return;
|
|
8664
|
+
await mailer.unsubscribe(contact.email, { scope: "marketing", reason: "user_request", source: "agent" });
|
|
8665
|
+
const sub = await c.subscriptions.findOne({ externalId: contact.externalId });
|
|
8666
|
+
await mailer.audit({
|
|
8667
|
+
actor: actorOf(req),
|
|
8668
|
+
action: "agent.contact.unsubscribe",
|
|
8669
|
+
resource: { collection: "mailer_subscriptions", id: sub?._id },
|
|
8670
|
+
diffSummary: contact.email
|
|
8671
|
+
});
|
|
8672
|
+
res.json({ subscription: sub });
|
|
8673
|
+
})
|
|
8674
|
+
);
|
|
8675
|
+
router.post(
|
|
8676
|
+
"/contacts/:externalId/reset",
|
|
8677
|
+
wrap2(async (req, res) => {
|
|
8678
|
+
const contact = await loadContact(res, String(req.params.externalId));
|
|
8679
|
+
if (!contact) return;
|
|
8680
|
+
if (!guardTestContact(res, contact)) return;
|
|
8681
|
+
const b = req.body ?? {};
|
|
8682
|
+
const eventFilter = { externalId: contact.externalId };
|
|
8683
|
+
if (Array.isArray(b.events)) eventFilter.name = { $in: b.events.map(String) };
|
|
8684
|
+
const doRuns = b.runs !== false;
|
|
8685
|
+
const doSends = b.sends !== false;
|
|
8686
|
+
const doEvents = b.events !== false;
|
|
8687
|
+
const doSuppressions = b.suppressions !== false;
|
|
8688
|
+
const doSubscribe = b.subscribe !== false;
|
|
8689
|
+
const removed = { runs: 0, sends: 0, events: 0, suppressions: 0 };
|
|
8690
|
+
if (doRuns) removed.runs = (await c.flowRuns.deleteMany({ externalId: contact.externalId })).deletedCount;
|
|
8691
|
+
if (doSends) removed.sends = (await c.sends.deleteMany({ externalId: contact.externalId })).deletedCount;
|
|
8692
|
+
if (doEvents) removed.events = (await c.events.deleteMany(eventFilter)).deletedCount;
|
|
8693
|
+
if (doSuppressions) removed.suppressions = (await c.suppressions.deleteMany({ email: contact.email })).deletedCount;
|
|
8694
|
+
if (doSubscribe) await mailer.upsertSubscription({ externalId: contact.externalId, source: "agent-reset" });
|
|
8695
|
+
const subscription = await c.subscriptions.findOne({ externalId: contact.externalId });
|
|
8696
|
+
await mailer.audit({
|
|
8697
|
+
actor: actorOf(req),
|
|
8698
|
+
action: "agent.contact.reset",
|
|
8699
|
+
resource: { collection: "mailer_subscriptions", id: subscription?._id },
|
|
8700
|
+
diffSummary: `${contact.email}: removed ${removed.runs} run(s), ${removed.sends} send(s), ${removed.events} event(s), ${removed.suppressions} suppression(s)${doSubscribe ? "; resubscribed" : ""}`
|
|
8701
|
+
});
|
|
8702
|
+
res.json({ contact: { externalId: contact.externalId, email: contact.email }, removed, subscription });
|
|
8703
|
+
})
|
|
8704
|
+
);
|
|
8705
|
+
router.post(
|
|
8706
|
+
"/tick",
|
|
8707
|
+
wrap2(async (_req, res) => {
|
|
8708
|
+
const started = Date.now();
|
|
8709
|
+
await runTick(mailer.getRunnerContext());
|
|
8710
|
+
res.json({ ok: true, ms: Date.now() - started });
|
|
8711
|
+
})
|
|
8712
|
+
);
|
|
8713
|
+
router.get(
|
|
8714
|
+
"/webhooks/status",
|
|
8715
|
+
wrap2(async (_req, res) => {
|
|
8716
|
+
const dayAgo = new Date(Date.now() - 24 * 60 * 60 * 1e3);
|
|
8717
|
+
const weekAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1e3);
|
|
8718
|
+
const [last, byType24h, total7d, unprocessed] = await Promise.all([
|
|
8719
|
+
c.webhookEvents.findOne({}, { sort: { receivedAt: -1 }, projection: { receivedAt: 1, provider: 1, normalizedType: 1 } }),
|
|
8720
|
+
c.webhookEvents.aggregate([{ $match: { receivedAt: { $gte: dayAgo } } }, { $group: { _id: "$normalizedType", n: { $sum: 1 } } }]).toArray(),
|
|
8721
|
+
c.webhookEvents.countDocuments({ receivedAt: { $gte: weekAgo } }),
|
|
8722
|
+
c.webhookEvents.countDocuments({ processed: false })
|
|
8723
|
+
]);
|
|
8724
|
+
res.json({
|
|
8725
|
+
providers: Object.keys(mailer.providers),
|
|
8726
|
+
lastReceivedAt: last?.receivedAt ?? null,
|
|
8727
|
+
lastProvider: last?.provider ?? null,
|
|
8728
|
+
last24h: Object.fromEntries(byType24h.map((r) => [r._id, r.n])),
|
|
8729
|
+
last7d: total7d,
|
|
8730
|
+
unprocessed,
|
|
8731
|
+
ingestPath: `${mailer.config.publicUrl}/m/webhooks/<provider>`
|
|
8732
|
+
});
|
|
8733
|
+
})
|
|
8734
|
+
);
|
|
8735
|
+
router.get(
|
|
8736
|
+
"/status",
|
|
8737
|
+
wrap2(async (_req, res) => {
|
|
8738
|
+
const dayAgo = new Date(Date.now() - 24 * 60 * 60 * 1e3);
|
|
8739
|
+
const [flows, templates, subscribed, suppressions, activeRuns, sends24h, webhooks24h, lastWebhook, healthDocs, setup] = await Promise.all([
|
|
8740
|
+
c.flows.find({}, { projection: { slug: 1, enabled: 1, version: 1, lastTriggerScanAt: 1, steps: 1, trigger: 1 } }).sort({ slug: 1 }).toArray(),
|
|
8741
|
+
c.templates.find({}, { projection: { slug: 1, kind: 1, publishedAt: 1, "body.html": 1, fromEmail: 1 } }).sort({ slug: 1 }).toArray(),
|
|
8742
|
+
c.subscriptions.countDocuments({ status: "subscribed" }),
|
|
8743
|
+
c.suppressions.estimatedDocumentCount(),
|
|
8744
|
+
c.flowRuns.countDocuments({ status: "active" }),
|
|
8745
|
+
c.sends.aggregate([{ $match: { queuedAt: { $gte: dayAgo } } }, { $group: { _id: "$status", n: { $sum: 1 } } }]).toArray(),
|
|
8746
|
+
c.webhookEvents.countDocuments({ receivedAt: { $gte: dayAgo } }),
|
|
8747
|
+
c.webhookEvents.findOne({}, { sort: { receivedAt: -1 }, projection: { receivedAt: 1 } }),
|
|
8748
|
+
c.health.find({}).limit(500).toArray(),
|
|
8749
|
+
runSetupChecks(mailer)
|
|
8750
|
+
]);
|
|
8751
|
+
const activeByFlow = await c.flowRuns.aggregate([{ $match: { status: "active" } }, { $group: { _id: "$flowSlug", n: { $sum: 1 } } }]).toArray();
|
|
8752
|
+
const activeMap = new Map(activeByFlow.map((r) => [r._id, r.n]));
|
|
8753
|
+
res.json({
|
|
8754
|
+
version: VERSION,
|
|
8755
|
+
now: /* @__PURE__ */ new Date(),
|
|
8756
|
+
testContactsConfigured: !!isTestContact,
|
|
8757
|
+
setup,
|
|
8758
|
+
health: { status: healthDocs.length ? effectiveOverallStatus(healthDocs) : null, aggregate: healthDocs.find((d) => d._id === HEALTH_AGG_ID) ?? null },
|
|
8759
|
+
flows: flows.map((f) => ({
|
|
8760
|
+
slug: f.slug,
|
|
8761
|
+
enabled: f.enabled,
|
|
8762
|
+
version: f.version,
|
|
8763
|
+
lastTriggerScanAt: f.lastTriggerScanAt ?? null,
|
|
8764
|
+
trigger: f.trigger,
|
|
8765
|
+
liveSteps: Array.isArray(f.steps) ? f.steps.length : 0,
|
|
8766
|
+
gated: Array.isArray(f.steps) && isCanaryGate(f.steps[0]) ? f.steps[0].test.hasTag : null,
|
|
8767
|
+
activeRuns: activeMap.get(f.slug) ?? 0
|
|
8768
|
+
})),
|
|
8769
|
+
templates: templates.map((t) => ({
|
|
8770
|
+
slug: t.slug,
|
|
8771
|
+
kind: t.kind,
|
|
8772
|
+
fromEmail: t.fromEmail,
|
|
8773
|
+
published: !!(t.body && t.body.html),
|
|
8774
|
+
publishedAt: t.publishedAt ?? null
|
|
8775
|
+
})),
|
|
8776
|
+
counts: {
|
|
8777
|
+
subscribed,
|
|
8778
|
+
suppressions,
|
|
8779
|
+
activeRuns,
|
|
8780
|
+
sendsLast24h: Object.fromEntries(sends24h.map((r) => [r._id, r.n])),
|
|
8781
|
+
webhookEventsLast24h: webhooks24h,
|
|
8782
|
+
lastWebhookAt: lastWebhook?.receivedAt ?? null
|
|
8783
|
+
}
|
|
8784
|
+
});
|
|
8785
|
+
})
|
|
8786
|
+
);
|
|
8787
|
+
router.use((req, res) => {
|
|
8788
|
+
res.status(404).json({ error: "not_found", message: `no agent route ${req.method} ${req.path}; GET / lists them` });
|
|
8789
|
+
});
|
|
8790
|
+
router.use((err, req, res, _next) => {
|
|
8791
|
+
if (err instanceof FlowOperationError) {
|
|
8792
|
+
return res.status(err.status).json({ error: err.code, message: err.message });
|
|
8793
|
+
}
|
|
8794
|
+
if (err?.name === "ZodError") {
|
|
8795
|
+
return res.status(400).json({ error: "validation_failed", issues: err.issues });
|
|
8796
|
+
}
|
|
8797
|
+
logger.error?.({ err: String(err?.message ?? err), path: req.path, method: req.method }, "mailery agent: request failed");
|
|
8798
|
+
if (res.headersSent) return;
|
|
8799
|
+
res.status(500).json({ error: "internal", message: String(err?.message ?? err) });
|
|
8800
|
+
});
|
|
8801
|
+
return router;
|
|
8802
|
+
async function contactForRender(req, res) {
|
|
8803
|
+
const contactId = typeof req.body?.contactId === "string" ? req.body.contactId : "";
|
|
8804
|
+
if (contactId) return loadContact(res, contactId);
|
|
8805
|
+
const sample = req.body?.sampleContact;
|
|
8806
|
+
if (sample && typeof sample === "object" && typeof sample.email === "string") {
|
|
8807
|
+
return {
|
|
8808
|
+
externalId: String(sample.externalId ?? "sample-contact"),
|
|
8809
|
+
email: sample.email,
|
|
8810
|
+
tags: Array.isArray(sample.tags) ? sample.tags.map(String) : [],
|
|
8811
|
+
fields: sample.fields && typeof sample.fields === "object" ? sample.fields : {},
|
|
8812
|
+
timezone: typeof sample.timezone === "string" ? sample.timezone : void 0
|
|
8813
|
+
};
|
|
8814
|
+
}
|
|
8815
|
+
res.status(400).json({ error: "validation_failed", message: "contactId (or a sampleContact with an email) is required" });
|
|
8816
|
+
return null;
|
|
8817
|
+
}
|
|
8818
|
+
async function contactDetail(contact) {
|
|
8819
|
+
const [subscription, recentEvents, recentSends, runs, suppressions] = await Promise.all([
|
|
8820
|
+
c.subscriptions.findOne({ externalId: contact.externalId }),
|
|
8821
|
+
c.events.find({ externalId: contact.externalId }).sort({ occurredAt: -1 }).limit(50).toArray(),
|
|
8822
|
+
c.sends.find({ externalId: contact.externalId }).sort({ queuedAt: -1 }).limit(50).toArray(),
|
|
8823
|
+
c.flowRuns.find({ externalId: contact.externalId }).sort({ enteredAt: -1 }).limit(50).toArray(),
|
|
8824
|
+
c.suppressions.find({ email: contact.email }).toArray()
|
|
8825
|
+
]);
|
|
8826
|
+
return {
|
|
8827
|
+
contact,
|
|
8828
|
+
isTestContact: isTestContact ? isTestContact(contact.email) : null,
|
|
8829
|
+
subscription,
|
|
8830
|
+
suppressions,
|
|
8831
|
+
recentEvents,
|
|
8832
|
+
recentSends: recentSends.map(sendSummary),
|
|
8833
|
+
runs: runs.map(runSummary)
|
|
8834
|
+
};
|
|
8835
|
+
}
|
|
8836
|
+
}
|
|
8837
|
+
var PLACEHOLDER_RE = /\{\{[^{}]*\}\}|\{\{\{[^{}]*\}\}\}/g;
|
|
8838
|
+
var HREF_RE = /href\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
|
|
8839
|
+
var GMAIL_CLIP_BYTES = 102 * 1024;
|
|
8840
|
+
async function verifyTemplate(mailer, tpl, contact, opts = {}) {
|
|
8841
|
+
const checks = [];
|
|
8842
|
+
const push = (id, status, detail) => checks.push(detail === void 0 ? { id, status } : { id, status, detail });
|
|
8843
|
+
const base = {
|
|
8844
|
+
template: { slug: tpl.slug, kind: tpl.kind, name: tpl.name },
|
|
8845
|
+
contact: { externalId: contact.externalId, email: contact.email }
|
|
8846
|
+
};
|
|
8847
|
+
const finish = (rendered2, links2) => ({
|
|
8848
|
+
ok: checks.every((k) => k.status !== "fail"),
|
|
8849
|
+
...base,
|
|
8850
|
+
checks,
|
|
8851
|
+
links: { total: links2.length, sample: links2.slice(0, 50) },
|
|
8852
|
+
rendered: rendered2 ? opts.includeRendered ? {
|
|
8853
|
+
subject: rendered2.subject,
|
|
8854
|
+
preheader: rendered2.preheader,
|
|
8855
|
+
html: rendered2.html,
|
|
8856
|
+
plainText: rendered2.plainText,
|
|
8857
|
+
fromEmail: rendered2.fromEmail,
|
|
8858
|
+
fromName: rendered2.fromName,
|
|
8859
|
+
replyTo: rendered2.replyTo
|
|
8860
|
+
} : {
|
|
8861
|
+
subject: rendered2.subject,
|
|
8862
|
+
preheader: rendered2.preheader,
|
|
8863
|
+
htmlBytes: Buffer.byteLength(rendered2.html, "utf8"),
|
|
8864
|
+
textLength: rendered2.plainText.trim().length,
|
|
8865
|
+
fromEmail: rendered2.fromEmail
|
|
8866
|
+
} : null
|
|
8867
|
+
});
|
|
8868
|
+
if (!tpl.body?.html && !tpl.body?.mjml) {
|
|
8869
|
+
push("published", "fail", "template has no published body (body.html and body.mjml are empty)");
|
|
8870
|
+
return finish(null, []);
|
|
8871
|
+
}
|
|
8872
|
+
push("published", "pass", { publishedAt: tpl.publishedAt ?? null });
|
|
8873
|
+
let out;
|
|
8874
|
+
try {
|
|
8875
|
+
out = await renderForContact(mailer, tpl, contact, {
|
|
8876
|
+
reason: "test",
|
|
8877
|
+
eventProperties: opts.eventProperties,
|
|
8878
|
+
vars: opts.vars
|
|
8879
|
+
});
|
|
8880
|
+
push("vars_resolved", "pass", { keys: Object.keys(out.resolved) });
|
|
8881
|
+
push("render", "pass");
|
|
8882
|
+
} catch (err) {
|
|
8883
|
+
const message = String(err?.message ?? err);
|
|
8884
|
+
push(message.startsWith("varsAdapter") ? "vars_resolved" : "render", "fail", message);
|
|
8885
|
+
return finish(null, []);
|
|
8886
|
+
}
|
|
8887
|
+
const { rendered, unsubscribeUrl } = out;
|
|
8888
|
+
const leftovers = /* @__PURE__ */ new Set();
|
|
8889
|
+
for (const part of [rendered.subject, rendered.preheader, rendered.html, rendered.plainText]) {
|
|
8890
|
+
for (const m of part.matchAll(PLACEHOLDER_RE)) leftovers.add(m[0]);
|
|
8891
|
+
}
|
|
8892
|
+
push("unresolved_placeholders", leftovers.size ? "fail" : "pass", leftovers.size ? { placeholders: [...leftovers] } : void 0);
|
|
8893
|
+
const referenced = referencedPaths(
|
|
8894
|
+
[tpl.subject, tpl.preheader, tpl.body.html, tpl.body.plainText, tpl.body.mjml ?? ""].join("\n"),
|
|
8895
|
+
Object.keys(mailer.config.handlebarsHelpers ?? {})
|
|
8896
|
+
);
|
|
8897
|
+
const missing = [];
|
|
8898
|
+
const empty = [];
|
|
8899
|
+
for (const path3 of referenced) {
|
|
8900
|
+
const value = lookupPath(out.context, path3);
|
|
8901
|
+
if (value === void 0) {
|
|
8902
|
+
const root = path3.split(".")[0];
|
|
8903
|
+
if (RESERVED_VAR_KEYS.includes(root)) empty.push(path3);
|
|
8904
|
+
else missing.push(path3);
|
|
8905
|
+
} else if (value === null || value === "") {
|
|
8906
|
+
empty.push(path3);
|
|
8907
|
+
}
|
|
8908
|
+
}
|
|
8909
|
+
push("unknown_variables", missing.length ? "fail" : "pass", { referenced: referenced.length, missing });
|
|
8910
|
+
push("empty_variables", empty.length ? "warn" : "pass", { empty });
|
|
8911
|
+
const links = extractLinks(rendered.html);
|
|
8912
|
+
const invalid = links.filter((l) => !/^(https?:\/\/|mailto:|tel:)/i.test(l));
|
|
8913
|
+
push("links_absolute", invalid.length ? "fail" : "pass", { total: links.length, invalid });
|
|
8914
|
+
if (tpl.kind === "marketing") {
|
|
8915
|
+
push("unsubscribe_link", rendered.html.includes(unsubscribeUrl) ? "pass" : "fail", {
|
|
8916
|
+
hint: "a marketing template must reference {{unsubscribeUrl}} in its body"
|
|
8917
|
+
});
|
|
8918
|
+
if (mailer.config.senderAddress) {
|
|
8919
|
+
push("sender_address", rendered.html.includes(mailer.config.senderAddress) ? "pass" : "fail", {
|
|
8920
|
+
hint: "CAN-SPAM: reference {{senderAddress}} in the footer"
|
|
8921
|
+
});
|
|
8922
|
+
}
|
|
8923
|
+
}
|
|
8924
|
+
const text = rendered.plainText.trim();
|
|
8925
|
+
push("plain_text", text.length === 0 ? "fail" : text.length < 40 ? "warn" : "pass", { length: text.length });
|
|
8926
|
+
const subject = rendered.subject.trim();
|
|
8927
|
+
push("subject", subject.length === 0 ? "fail" : subject.length > 78 ? "warn" : "pass", { length: subject.length });
|
|
8928
|
+
if (mailer.config.senderDomains && Object.keys(mailer.config.senderDomains).length > 0) {
|
|
8929
|
+
const v = validateSenderDomain(rendered.fromEmail, tpl.kind, mailer.config.senderDomains);
|
|
8930
|
+
push("from_domain", v.ok ? "pass" : "fail", v.ok ? { fromEmail: rendered.fromEmail } : { fromEmail: rendered.fromEmail, code: v.code, reason: v.reason });
|
|
8931
|
+
}
|
|
8932
|
+
const bytes = Buffer.byteLength(rendered.html, "utf8");
|
|
8933
|
+
push("html_size", bytes > GMAIL_CLIP_BYTES ? "warn" : "pass", { bytes, clipAt: GMAIL_CLIP_BYTES });
|
|
8934
|
+
const lint = lintTemplate(
|
|
8935
|
+
{
|
|
8936
|
+
subject: tpl.subject,
|
|
8937
|
+
preheader: tpl.preheader,
|
|
8938
|
+
mjml: tpl.body.mjml ?? "",
|
|
8939
|
+
editorJson: tpl.body.editorJson ?? void 0,
|
|
8940
|
+
html: tpl.body.html,
|
|
8941
|
+
plainText: tpl.body.plainText,
|
|
8942
|
+
kind: tpl.kind,
|
|
8943
|
+
fromEmail: tpl.fromEmail
|
|
8944
|
+
},
|
|
8945
|
+
{ senderDomains: mailer.config.senderDomains, varsJsonSchema: opts.varsSchema ?? null }
|
|
8946
|
+
);
|
|
8947
|
+
push("lint", lint.errors.length ? "fail" : lint.warnings.length ? "warn" : "pass", {
|
|
8948
|
+
errors: lint.errors.map((i) => ({ rule: i.rule, message: i.message })),
|
|
8949
|
+
warnings: lint.warnings.map((i) => i.rule)
|
|
8950
|
+
});
|
|
8951
|
+
return finish(rendered, links);
|
|
8952
|
+
}
|
|
8953
|
+
async function renderForContact(mailer, tpl, contact, opts) {
|
|
8954
|
+
let resolved;
|
|
8955
|
+
try {
|
|
8956
|
+
resolved = await resolveVars(mailer.config.varsAdapter, contact, {
|
|
8957
|
+
reason: opts.reason,
|
|
8958
|
+
templateSlug: tpl.slug,
|
|
8959
|
+
eventProperties: opts.eventProperties
|
|
8960
|
+
});
|
|
8961
|
+
} catch (err) {
|
|
8962
|
+
throw new Error(`varsAdapter.resolve threw: ${String(err?.message ?? err)}`);
|
|
8963
|
+
}
|
|
8964
|
+
const unsubscribeUrl = unsubscribeUrlFor(mailer, contact.email);
|
|
8965
|
+
const context = {
|
|
8966
|
+
...resolved,
|
|
8967
|
+
contact,
|
|
8968
|
+
vars: opts.vars ?? {},
|
|
8969
|
+
event: opts.eventProperties ?? {},
|
|
8970
|
+
unsubscribeUrl,
|
|
8971
|
+
senderAddress: mailer.config.senderAddress
|
|
8972
|
+
};
|
|
8973
|
+
const rendered = await renderTemplate(tpl, context, { helpers: mailer.config.handlebarsHelpers });
|
|
8974
|
+
return { rendered, resolved, unsubscribeUrl, context };
|
|
8975
|
+
}
|
|
8976
|
+
function unsubscribeUrlFor(mailer, email) {
|
|
8977
|
+
const expiresAt = new Date(Date.now() + mailer.config.unsubscribeTokenLifetimeDays * 24 * 60 * 60 * 1e3);
|
|
8978
|
+
const token = signUnsubscribeToken({ email, scope: "marketing", expiresAt }, mailer.config.unsubscribeSecret);
|
|
8979
|
+
return `${mailer.config.publicUrl}/m/unsub/${token}`;
|
|
8980
|
+
}
|
|
8981
|
+
function extractLinks(html) {
|
|
8982
|
+
const out = [];
|
|
8983
|
+
for (const m of html.matchAll(HREF_RE)) {
|
|
8984
|
+
const href = (m[1] ?? m[2] ?? "").trim();
|
|
8985
|
+
if (!href || href.startsWith("#")) continue;
|
|
8986
|
+
out.push(href);
|
|
8987
|
+
}
|
|
8988
|
+
return out;
|
|
8989
|
+
}
|
|
8990
|
+
var BUILTIN_HELPERS = /* @__PURE__ */ new Set([
|
|
8991
|
+
"eq",
|
|
8992
|
+
"ne",
|
|
8993
|
+
"gt",
|
|
8994
|
+
"lt",
|
|
8995
|
+
"gte",
|
|
8996
|
+
"lte",
|
|
8997
|
+
"and",
|
|
8998
|
+
"or",
|
|
8999
|
+
"not",
|
|
9000
|
+
"formatDate",
|
|
9001
|
+
"formatNumber",
|
|
9002
|
+
"formatCurrency",
|
|
9003
|
+
"pluralize",
|
|
9004
|
+
"if",
|
|
9005
|
+
"unless",
|
|
9006
|
+
"each",
|
|
9007
|
+
"with",
|
|
9008
|
+
"else",
|
|
9009
|
+
"lookup",
|
|
9010
|
+
"log",
|
|
9011
|
+
"this",
|
|
9012
|
+
"true",
|
|
9013
|
+
"false",
|
|
9014
|
+
"null",
|
|
9015
|
+
"undefined"
|
|
9016
|
+
]);
|
|
9017
|
+
var MUSTACHE_RE = /\{\{\{?([^{}]*)\}\}\}?/g;
|
|
9018
|
+
var BLOCK_SCOPE_RE = /\{\{#(each|with)\b[\s\S]*?\{\{\/\1\}\}/g;
|
|
9019
|
+
var HTML_COMMENT_RE = /<!--[\s\S]*?-->/g;
|
|
9020
|
+
var PATH_RE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/;
|
|
9021
|
+
function referencedPaths(source, helperNames = []) {
|
|
9022
|
+
const helpers = /* @__PURE__ */ new Set([...BUILTIN_HELPERS, ...helperNames]);
|
|
9023
|
+
const out = /* @__PURE__ */ new Set();
|
|
9024
|
+
const scanned = source.replace(HTML_COMMENT_RE, "").replace(BLOCK_SCOPE_RE, "");
|
|
9025
|
+
for (const m of scanned.matchAll(MUSTACHE_RE)) {
|
|
9026
|
+
let expr = (m[1] ?? "").trim();
|
|
9027
|
+
if (!expr || expr.startsWith("!")) continue;
|
|
9028
|
+
expr = expr.replace(/^[#/^]\s*/, "").replace(/^else\b\s*/, "");
|
|
9029
|
+
for (let tok of expr.split(/[\s()]+/)) {
|
|
9030
|
+
if (!tok) continue;
|
|
9031
|
+
const eq = tok.indexOf("=");
|
|
9032
|
+
if (eq > 0) tok = tok.slice(eq + 1);
|
|
9033
|
+
if (/^['"]/.test(tok) || /^-?\d/.test(tok)) continue;
|
|
9034
|
+
if (tok.startsWith("@") || tok.startsWith("../") || tok.startsWith("this.")) continue;
|
|
9035
|
+
if (helpers.has(tok) || !PATH_RE.test(tok)) continue;
|
|
9036
|
+
out.add(tok);
|
|
9037
|
+
}
|
|
9038
|
+
}
|
|
9039
|
+
return [...out];
|
|
9040
|
+
}
|
|
9041
|
+
function lookupPath(ctx, path3) {
|
|
9042
|
+
let cur = ctx;
|
|
9043
|
+
for (const part of path3.split(".")) {
|
|
9044
|
+
if (cur === null || typeof cur !== "object") return void 0;
|
|
9045
|
+
cur = cur[part];
|
|
9046
|
+
}
|
|
9047
|
+
return cur;
|
|
9048
|
+
}
|
|
9049
|
+
function testContactMatcher(spec) {
|
|
9050
|
+
if (!spec) return null;
|
|
9051
|
+
if (spec instanceof RegExp) return (email) => spec.test(email);
|
|
9052
|
+
if (typeof spec === "function") return (email) => !!spec(email);
|
|
9053
|
+
return null;
|
|
9054
|
+
}
|
|
9055
|
+
function bearerAuth(tokens) {
|
|
9056
|
+
const hashed = tokens.map((t) => ({ hash: crypto2.createHash("sha256").update(t.token).digest(), actor: t.actor }));
|
|
9057
|
+
return (req, res, next) => {
|
|
9058
|
+
const header = String(req.headers.authorization ?? "");
|
|
9059
|
+
const m = /^Bearer\s+(\S+)\s*$/i.exec(header);
|
|
9060
|
+
if (!m) {
|
|
9061
|
+
return res.status(401).json({ error: "unauthorized", message: "send Authorization: Bearer <token>" });
|
|
9062
|
+
}
|
|
9063
|
+
const presented = crypto2.createHash("sha256").update(m[1] ?? "").digest();
|
|
9064
|
+
const match = hashed.find((h) => crypto2.timingSafeEqual(h.hash, presented));
|
|
9065
|
+
if (!match) return res.status(401).json({ error: "unauthorized", message: "unknown token" });
|
|
9066
|
+
req.actor = match.actor;
|
|
9067
|
+
next();
|
|
9068
|
+
};
|
|
9069
|
+
}
|
|
9070
|
+
async function advanceOnce(runId, ctx, actor, c) {
|
|
9071
|
+
for (let hop = 0; hop < 10; hop += 1) {
|
|
9072
|
+
const run = await c.flowRuns.findOne({ _id: runId });
|
|
9073
|
+
if (!run || run.status !== "active") return false;
|
|
9074
|
+
if (run.nextActionAt && run.nextActionAt.getTime() > Date.now()) {
|
|
9075
|
+
await c.flowRuns.updateOne(
|
|
9076
|
+
{ _id: runId, status: "active" },
|
|
9077
|
+
{
|
|
9078
|
+
$set: { nextActionAt: /* @__PURE__ */ new Date(), updatedAt: /* @__PURE__ */ new Date() },
|
|
9079
|
+
$push: {
|
|
9080
|
+
history: {
|
|
9081
|
+
stepIndex: Math.max(0, run.currentStepIndex - 1),
|
|
9082
|
+
action: "wait_completed",
|
|
9083
|
+
at: /* @__PURE__ */ new Date(),
|
|
9084
|
+
details: { forcedBy: actor, scheduledFor: run.nextActionAt }
|
|
9085
|
+
}
|
|
9086
|
+
}
|
|
9087
|
+
}
|
|
9088
|
+
);
|
|
9089
|
+
}
|
|
9090
|
+
const before = (await c.flowRuns.findOne({ _id: runId }))?.history.length ?? 0;
|
|
9091
|
+
await processOneRunStep(runId, ctx);
|
|
9092
|
+
const after = await c.flowRuns.findOne({ _id: runId });
|
|
9093
|
+
if (!after) return false;
|
|
9094
|
+
const last = after.history[after.history.length - 1];
|
|
9095
|
+
const progressed = after.history.length > before;
|
|
9096
|
+
if (progressed && last?.action === "wait_started" && after.status === "active") continue;
|
|
9097
|
+
return after.status === "active" && progressed;
|
|
9098
|
+
}
|
|
9099
|
+
return false;
|
|
9100
|
+
}
|
|
9101
|
+
var WAIT_TARGETS = /* @__PURE__ */ new Set(["sent", "delivered", "opened", "clicked", "terminal"]);
|
|
9102
|
+
function waitTargetReached(send, target) {
|
|
9103
|
+
switch (target) {
|
|
9104
|
+
case "sent":
|
|
9105
|
+
return send.status === "sent" || send.status === "delivered" || !!send.sentAt;
|
|
9106
|
+
case "delivered":
|
|
9107
|
+
return send.status === "delivered" || !!send.deliveredAt;
|
|
9108
|
+
case "opened":
|
|
9109
|
+
return !!send.openedAt;
|
|
9110
|
+
case "clicked":
|
|
9111
|
+
return !!send.firstClickAt;
|
|
9112
|
+
case "terminal":
|
|
9113
|
+
return ["delivered", "bounced", "failed", "suppressed", "cancelled", "complained"].includes(send.status);
|
|
9114
|
+
default:
|
|
9115
|
+
return false;
|
|
9116
|
+
}
|
|
9117
|
+
}
|
|
9118
|
+
function sendSummary(s) {
|
|
9119
|
+
return {
|
|
9120
|
+
id: String(s._id),
|
|
9121
|
+
templateSlug: s.templateSlug,
|
|
9122
|
+
externalId: s.externalId,
|
|
9123
|
+
email: s.emailAtSend,
|
|
9124
|
+
kind: s.kind,
|
|
9125
|
+
status: s.status,
|
|
9126
|
+
provider: s.provider,
|
|
9127
|
+
providerMessageId: s.providerMessageId,
|
|
9128
|
+
subject: s.subject,
|
|
9129
|
+
errorMessage: s.errorMessage,
|
|
9130
|
+
flowRunId: s.flowRunId ? String(s.flowRunId) : null,
|
|
9131
|
+
queuedAt: s.queuedAt,
|
|
9132
|
+
sentAt: s.sentAt,
|
|
9133
|
+
deliveredAt: s.deliveredAt,
|
|
9134
|
+
openedAt: s.openedAt,
|
|
9135
|
+
firstClickAt: s.firstClickAt,
|
|
9136
|
+
bounceType: s.bounceType
|
|
9137
|
+
};
|
|
9138
|
+
}
|
|
9139
|
+
function runSummary(r) {
|
|
9140
|
+
return {
|
|
9141
|
+
id: String(r._id),
|
|
9142
|
+
flowSlug: r.flowSlug,
|
|
9143
|
+
flowVersion: r.flowVersion,
|
|
9144
|
+
externalId: r.externalId,
|
|
9145
|
+
email: r.emailAtEntry,
|
|
9146
|
+
status: r.status,
|
|
9147
|
+
currentStepIndex: r.currentStepIndex,
|
|
9148
|
+
currentBranchPath: r.currentBranchPath,
|
|
9149
|
+
nextActionAt: r.nextActionAt,
|
|
9150
|
+
enteredAt: r.enteredAt,
|
|
9151
|
+
exitedAt: r.exitedAt,
|
|
9152
|
+
exitReason: r.exitReason,
|
|
9153
|
+
triggerEvent: r.triggerEvent ?? null,
|
|
9154
|
+
history: r.history
|
|
9155
|
+
};
|
|
9156
|
+
}
|
|
9157
|
+
function objectOrUndefined(v) {
|
|
9158
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : void 0;
|
|
9159
|
+
}
|
|
9160
|
+
function sleep2(ms) {
|
|
9161
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
9162
|
+
}
|
|
9163
|
+
function wrap2(fn) {
|
|
9164
|
+
return (req, res, next) => {
|
|
9165
|
+
Promise.resolve(fn(req, res)).catch(next);
|
|
9166
|
+
};
|
|
9167
|
+
}
|
|
9168
|
+
var ENDPOINTS = [
|
|
9169
|
+
{ method: "GET", path: "/", summary: "This listing, the package version and the actor behind the token." },
|
|
9170
|
+
{ method: "*", path: "/api/*", summary: "The full admin JSON API (flows, templates, contacts, sends, health, setup-status, \u2026) with this token as the actor." },
|
|
9171
|
+
{ method: "POST", path: "/templates/:slug/verify", summary: "Render the published template as a contact ({contactId} or {sampleContact}) and run named checks: placeholders, links, unsubscribe, sender address, plain text, subject, from domain, size, lint. {includeRendered: true} returns the HTML." },
|
|
9172
|
+
{ method: "POST", path: "/templates/verify-all", summary: "Verify every template (or {slugs}) for each of {contactIds}; a matrix of pass/fail." },
|
|
9173
|
+
{ method: "POST", path: "/templates/:slug/render", summary: "Render for a contact and return subject, preheader, HTML, plain text, resolved vars and the signed unsubscribe URL." },
|
|
9174
|
+
{ method: "POST", path: "/templates/:slug/send", summary: 'A real send through the pipeline to a test contact ({contactId}); dispatched inline unless {dispatch: "queue"}. Returns the sendId.', testContactsOnly: true },
|
|
9175
|
+
{ method: "GET", path: "/sends/:id/wait?status=delivered&timeoutMs=30000", summary: "Long-poll a send until it reaches sent | delivered | opened | clicked | terminal, with its webhook events." },
|
|
9176
|
+
{ method: "POST", path: "/sends/:id/dispatch", summary: "Dispatch a queued send now (test contacts only).", testContactsOnly: true },
|
|
9177
|
+
{ method: "POST", path: "/flows/:slug/simulate", summary: "Dry-run the flow for {contactId} from {at} with {eventProperties}: the path taken, every gate verdict, projected send times, where it ends. Writes nothing." },
|
|
9178
|
+
{ method: "POST", path: "/flows/:slug/arm", summary: "Enable the flow for FUTURE events: stamps the trigger watermark ({since} or now) in the same write. Requires {confirm: true}." },
|
|
9179
|
+
{ method: "POST", path: "/flows/:slug/disarm", summary: "Disable the flow (pause). In-flight runs continue." },
|
|
9180
|
+
{ method: "POST", path: "/flows/:slug/gate", summary: "Publish a canary version whose first step exits anyone without {tag}." },
|
|
9181
|
+
{ method: "POST", path: "/flows/:slug/ungate", summary: "Restore the newest ungated version." },
|
|
9182
|
+
{ method: "GET", path: "/runs?externalId=&flowSlug=&status=&limit=", summary: "List flow runs." },
|
|
9183
|
+
{ method: "GET", path: "/runs/:id", summary: "One run with its history and sends." },
|
|
9184
|
+
{ method: "POST", path: "/runs/:id/advance", summary: "Walk a test contact's run forward now, skipping the wait in front of each of {steps} transitions; sends are dispatched inline.", testContactsOnly: true },
|
|
9185
|
+
{ method: "POST", path: "/runs/:id/cancel", summary: "Exit an active run and cancel its queued sends." },
|
|
9186
|
+
{ method: "POST", path: "/events", summary: "Fire {name} for a test contact {externalId} with {properties} and optional {dedupeKey}.", testContactsOnly: true },
|
|
9187
|
+
{ method: "GET", path: "/contacts/:externalId", summary: "Contact with subscription, suppressions, recent events, sends and runs." },
|
|
9188
|
+
{ method: "GET", path: "/contacts/by-email/:email", summary: "Same, looked up by email." },
|
|
9189
|
+
{ method: "GET", path: "/contacts/:externalId/unsubscribe-url", summary: "A signed one-click unsubscribe URL for a test contact, to exercise POST /m/unsub/:token.", testContactsOnly: true },
|
|
9190
|
+
{ method: "POST", path: "/contacts/:externalId/subscribe", summary: "Subscribe a test contact.", testContactsOnly: true },
|
|
9191
|
+
{ method: "POST", path: "/contacts/:externalId/unsubscribe", summary: "Unsubscribe a test contact (marketing scope).", testContactsOnly: true },
|
|
9192
|
+
{ method: "POST", path: "/contacts/:externalId/reset", summary: "Delete a test contact's runs, sends, events ({events: [names]} to narrow) and suppressions, then resubscribe. Each part can be turned off with false.", testContactsOnly: true },
|
|
9193
|
+
{ method: "POST", path: "/tick", summary: "Run the runner tick now (trigger scan, sweeps, outbox, webhook backlog)." },
|
|
9194
|
+
{ method: "GET", path: "/webhooks/status", summary: "Provider webhook ingest: last event received, counts by type (24h), unprocessed backlog." },
|
|
9195
|
+
{ method: "GET", path: "/status", summary: "One document with setup checks, health, every flow (enabled, version, watermark, gate, active runs), every template, and 24h counts." }
|
|
9196
|
+
];
|
|
7851
9197
|
var ALLOWED_EXTENSIONS = [".zip", ".gz", ".xml"];
|
|
7852
9198
|
var DEFAULT_PATH = "/inbound/dmarc";
|
|
7853
9199
|
var DEFAULT_MAX_FILE_BYTES = 10 * 1024 * 1024;
|
|
@@ -8559,8 +9905,8 @@ var DEDUPE_POLICIES = [
|
|
|
8559
9905
|
];
|
|
8560
9906
|
|
|
8561
9907
|
// src/server/index.ts
|
|
8562
|
-
var
|
|
9908
|
+
var VERSION2 = "0.16.0" ;
|
|
8563
9909
|
|
|
8564
|
-
export { DEDUPE_POLICIES, DEFAULT_BOT_UA_RE, FLOW_STEP_KINDS, Mailer, MongoContactAdapter, NullProvider, PREDICATE_KINDS, RESERVED_VAR_KEYS, SEGMENT_FILTER_KINDS, SendGridProvider, TRACKING_SIG_LENGTH, VERSION, applyTracking, applyWebhookEvent, compileMailyTemplate, compileTemplate, computeDeliveryTime, createAdminRouter, createPublicRouter, defaultFlowStep, defaultPredicate, defaultSegmentFilter, defineVars, derivePlaintext, dispatchSend, drainPendingUnsubscribes, ensureIndexes, getCollections, predicateKind, processNewlyFiredEventTriggers, processOneRunStep, renderTemplate, runTick, sendgridInboundParser, sha256Hex, signTrackingToken, signUnsubscribeToken, sweepStrandedFlowRuns, validateSenderDomain, varsJsonSchema, verifyTrackingToken, verifyUnsubscribeToken };
|
|
9910
|
+
export { DEDUPE_POLICIES, DEFAULT_BOT_UA_RE, FLOW_STEP_KINDS, FlowOperationError, MIN_AGENT_TOKEN_LENGTH, Mailer, MongoContactAdapter, NullProvider, PREDICATE_KINDS, RESERVED_VAR_KEYS, SEGMENT_FILTER_KINDS, SendGridProvider, TRACKING_SIG_LENGTH, VERSION2 as VERSION, applyTracking, applyWebhookEvent, armFlow, compileMailyTemplate, compileTemplate, computeDeliveryTime, createAdminApiRouter, createAdminRouter, createAgentRouter, createPublicRouter, defaultFlowStep, defaultPredicate, defaultSegmentFilter, defineVars, derivePlaintext, disarmFlow, dispatchSend, drainPendingUnsubscribes, ensureIndexes, gateFlow, getCollections, isCanaryGate, predicateKind, processNewlyFiredEventTriggers, processOneRunStep, referencedPaths, renderForContact, renderTemplate, runTick, sendgridInboundParser, sha256Hex, signTrackingToken, signUnsubscribeToken, simulateFlow, stampWatermarkIfNull, sweepStrandedFlowRuns, ungateFlow, validateSenderDomain, varsJsonSchema, verifyTemplate, verifyTrackingToken, verifyUnsubscribeToken };
|
|
8565
9911
|
//# sourceMappingURL=index.js.map
|
|
8566
9912
|
//# sourceMappingURL=index.js.map
|