outbound-sdk 0.9.0 → 0.11.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.
@@ -26,6 +26,9 @@ import {
26
26
  import {
27
27
  fromEnv
28
28
  } from "./chunk-5XLR6XVV.js";
29
+ import {
30
+ readEnv
31
+ } from "./chunk-NFWWA7MI.js";
29
32
  import {
30
33
  OutboundError
31
34
  } from "./chunk-XYHM4KHC.js";
@@ -144,6 +147,7 @@ var wantsRedact = (flags, fromConfig, mcp) => {
144
147
  }
145
148
  return !fromConfig && (flags.redact === true || mcp);
146
149
  };
150
+ var REDACT_KEY_ENV = "OUTBOUND_REDACT_KEY";
147
151
  var capSetting = (mcp) => mcp ? "--max-requests on outbound mcp" : "--max-requests";
148
152
  var insightCaps = (flags, mcp) => ({
149
153
  capSetting: capSetting(mcp),
@@ -161,9 +165,14 @@ var setupFor = async (flags, mcp, note) => {
161
165
  const configured = loaded.plugins;
162
166
  const fromConfig = configured.some((plugin) => plugin.name === "redact");
163
167
  const plugins = [];
168
+ const key = readEnv(REDACT_KEY_ENV);
164
169
  if (wantsRedact(flags, fromConfig, mcp)) {
165
170
  const { redact } = await import("../redact/index.js");
166
- plugins.push(redact());
171
+ plugins.push(redact({ key }));
172
+ } else if (fromConfig && key !== void 0) {
173
+ note(
174
+ `${REDACT_KEY_ENV} is set, but the config file's redact() takes its own options, so it is not used. Pass it there as redact({ key: process.env.${REDACT_KEY_ENV} }).`
175
+ );
167
176
  }
168
177
  plugins.push(...configured);
169
178
  if (flags.cache !== void 0) {
@@ -756,7 +765,7 @@ var COMMAND_TABLE = {
756
765
  const offered = await offeredTools(outbound, input.flags);
757
766
  const tool = offered.find((candidate) => candidate.name === name);
758
767
  if (tool === void 0) {
759
- const { insightLeftOutReason } = await import("./tools-ATY622UC.js");
768
+ const { insightLeftOutReason } = await import("./tools-AVJ3XJ5A.js");
760
769
  const why = leftOutReason(outbound, name) ?? insightLeftOutReason(outbound, name);
761
770
  if (why !== void 0) {
762
771
  throw new OutboundError("Unsupported", why, {
@@ -1021,7 +1030,8 @@ var GLOBAL_HELP = [
1021
1030
  " --cache <seconds> reuse an answer for this long, within this process (for mcp; use a config-file store to persist)",
1022
1031
  " --max-requests <n> the most vendor requests one command, or one MCP tool call, may make",
1023
1032
  "",
1024
- "Each adapter reads its own key from the environment, for example INSTANTLY_API_KEY."
1033
+ "Each adapter reads its own key from the environment, for example INSTANTLY_API_KEY.",
1034
+ "OUTBOUND_REDACT_KEY, a secret of at least 32 characters, gives redact the same tokens in every run."
1025
1035
  ];
1026
1036
  var helpText = () => [
1027
1037
  "outbound: read-only access to outbound sending tools",
@@ -4441,9 +4441,135 @@ var accountSummary = defineInsight({
4441
4441
 
4442
4442
  // src/insights/people/dropped-replies.ts
4443
4443
  import { z as z19 } from "zod";
4444
+
4445
+ // src/insights/people/dropped-replies-check.ts
4444
4446
  var HOUR = 36e5;
4445
- var DAY = 24 * HOUR;
4446
4447
  var waited = (hours) => hours >= 48 ? plural(Math.floor(hours / 24), "day") : plural(Math.floor(hours), "hour");
4448
+ var unanswered = (replies2, messages) => {
4449
+ const lastSent = Math.max(
4450
+ Number.NEGATIVE_INFINITY,
4451
+ ...messages.flatMap(
4452
+ (message) => message.direction === "out" && message.sentAt !== null ? [Date.parse(message.sentAt)] : []
4453
+ )
4454
+ );
4455
+ return replies2.filter(
4456
+ (reply) => reply.sentAt !== null && Date.parse(reply.sentAt) > lastSent
4457
+ ).toSorted(
4458
+ (left, right) => (left.sentAt ?? "").localeCompare(right.sentAt ?? "")
4459
+ );
4460
+ };
4461
+ var toDropped = (open, by, now) => {
4462
+ const [first] = open;
4463
+ if (first === void 0 || first.sentAt === null) {
4464
+ return [];
4465
+ }
4466
+ const hoursWaiting = round((now - Date.parse(first.sentAt)) / HOUR) ?? 0;
4467
+ return [
4468
+ {
4469
+ campaign: first.campaignRef,
4470
+ campaignName: null,
4471
+ category: first.category,
4472
+ channel: first.channel,
4473
+ checkedBy: by,
4474
+ finding: `${/^[aeiou]/u.test(first.category) ? "An" : "A"} ${first.category} reply has waited ${waited(hoursWaiting)} with nothing sent after it.`,
4475
+ hoursWaiting,
4476
+ email: null,
4477
+ lead: first.leadRef,
4478
+ linkedinUrl: null,
4479
+ name: null,
4480
+ provider: first.provider,
4481
+ receivedAt: first.sentAt,
4482
+ reply: first.ref,
4483
+ subject: first.subject,
4484
+ unansweredReplies: open.length
4485
+ }
4486
+ ];
4487
+ };
4488
+ var sentByHand = async (context, since, max) => {
4489
+ const { capabilities, messages } = context.outbound;
4490
+ if (!capabilities["messages.byHand"] || capabilities["messages.since"] !== "server") {
4491
+ return null;
4492
+ }
4493
+ const walk = messages.listAll({ byHand: true, max, since });
4494
+ const found = await walk.toArray();
4495
+ if (walk.meta !== void 0) {
4496
+ context.one({ meta: walk.meta });
4497
+ }
4498
+ if (walk.truncated) {
4499
+ context.note(
4500
+ `The messages sent by hand stopped at ${max}, so each conversation they did not settle was read in full.`
4501
+ );
4502
+ }
4503
+ return { messages: found, whole: !walk.truncated };
4504
+ };
4505
+ var answersIn = (conversation, sent) => sent.filter(
4506
+ (message) => conversation.by === "thread" ? message.threadId === conversation.id : message.leadRef === conversation.id
4507
+ );
4508
+ var check = async (context, checkable, sent, olderThanHours) => {
4509
+ const checked = {
4510
+ answered: 0,
4511
+ dropped: [],
4512
+ tooRecent: 0,
4513
+ unread: 0
4514
+ };
4515
+ const openIn = (conversation, messages) => toDropped(
4516
+ unanswered(conversation.replies, messages),
4517
+ conversation.by,
4518
+ context.now
4519
+ );
4520
+ const settle = (found, whole) => {
4521
+ if (found.length === 0) {
4522
+ checked.answered += 1;
4523
+ } else if (found.every((each) => each.hoursWaiting < olderThanHours)) {
4524
+ checked.tooRecent += 1;
4525
+ } else if (whole) {
4526
+ checked.dropped.push(...found);
4527
+ } else {
4528
+ return false;
4529
+ }
4530
+ return true;
4531
+ };
4532
+ const toRead = sent === null ? checkable : checkable.filter((conversation) => {
4533
+ const found = openIn(
4534
+ conversation,
4535
+ answersIn(conversation, sent.messages)
4536
+ );
4537
+ return !((found.length === 0 || sent.whole) && settle(found, false));
4538
+ });
4539
+ const threads = await mapConcurrent(toRead, async (conversation) => {
4540
+ try {
4541
+ const read = await (conversation.by === "thread" ? context.outbound.thread(conversation.id).messages() : context.outbound.lead(conversation.id).timeline());
4542
+ return { conversation, failed: null, messages: context.page(read) };
4543
+ } catch (error) {
4544
+ if (isCapStop(error)) {
4545
+ throw error;
4546
+ }
4547
+ return {
4548
+ conversation,
4549
+ failed: OutboundError.is(error) ? error.code : "an unexpected error",
4550
+ messages: []
4551
+ };
4552
+ }
4553
+ });
4554
+ const reasons = /* @__PURE__ */ new Set();
4555
+ for (const { conversation, failed, messages } of threads) {
4556
+ if (failed === null) {
4557
+ settle(openIn(conversation, messages), true);
4558
+ } else {
4559
+ checked.unread += 1;
4560
+ reasons.add(failed);
4561
+ }
4562
+ }
4563
+ if (checked.unread > 0) {
4564
+ context.note(
4565
+ `${plural(checked.unread, "conversation")} could not be read, so ${noun(checked.unread, "it is", "they are")} counted in totals.unchecked, not as dropped (${[...reasons].join("; ")}).`
4566
+ );
4567
+ }
4568
+ return checked;
4569
+ };
4570
+
4571
+ // src/insights/people/dropped-replies.ts
4572
+ var DAY = 24 * HOUR;
4447
4573
  var DEFAULT_DAYS = 14;
4448
4574
  var WINDOW_REPLIES = 2e3;
4449
4575
  var input16 = z19.object({
@@ -4492,46 +4618,6 @@ var conversationsOf = (replies2, readers) => {
4492
4618
  }
4493
4619
  return [...groups.values()];
4494
4620
  };
4495
- var unanswered = (replies2, messages) => {
4496
- const lastSent = Math.max(
4497
- Number.NEGATIVE_INFINITY,
4498
- ...messages.flatMap(
4499
- (message) => message.direction === "out" && message.sentAt !== null ? [Date.parse(message.sentAt)] : []
4500
- )
4501
- );
4502
- return replies2.filter(
4503
- (reply) => reply.sentAt !== null && Date.parse(reply.sentAt) > lastSent
4504
- ).toSorted(
4505
- (left, right) => (left.sentAt ?? "").localeCompare(right.sentAt ?? "")
4506
- );
4507
- };
4508
- var toDropped = (open, by, now) => {
4509
- const [first] = open;
4510
- if (first === void 0 || first.sentAt === null) {
4511
- return [];
4512
- }
4513
- const hoursWaiting = round((now - Date.parse(first.sentAt)) / HOUR) ?? 0;
4514
- return [
4515
- {
4516
- campaign: first.campaignRef,
4517
- campaignName: null,
4518
- category: first.category,
4519
- channel: first.channel,
4520
- checkedBy: by,
4521
- finding: `${/^[aeiou]/u.test(first.category) ? "An" : "A"} ${first.category} reply has waited ${waited(hoursWaiting)} with nothing sent after it.`,
4522
- hoursWaiting,
4523
- email: null,
4524
- lead: first.leadRef,
4525
- linkedinUrl: null,
4526
- name: null,
4527
- provider: first.provider,
4528
- receivedAt: first.sentAt,
4529
- reply: first.ref,
4530
- subject: first.subject,
4531
- unansweredReplies: open.length
4532
- }
4533
- ];
4534
- };
4535
4621
  var refsOf = (refs) => [
4536
4622
  ...new Set(refs.flatMap((ref) => ref === null ? [] : [ref]))
4537
4623
  ];
@@ -4596,65 +4682,8 @@ var readReplies = (context, since, given) => {
4596
4682
  given === null ? "the most one window reads; pass a later since" : "max_replies"
4597
4683
  );
4598
4684
  };
4599
- var sentByHand = async (context, since, max) => {
4600
- const { capabilities, messages } = context.outbound;
4601
- if (!capabilities["messages.byHand"] || capabilities["messages.since"] !== "server") {
4602
- return null;
4603
- }
4604
- const walk = messages.listAll({ byHand: true, max, since });
4605
- const found = await walk.toArray();
4606
- if (walk.meta !== void 0) {
4607
- context.one({ meta: walk.meta });
4608
- }
4609
- if (walk.truncated) {
4610
- context.note(
4611
- `The messages sent by hand stopped at ${max}, so each conversation they did not settle was read in full.`
4612
- );
4613
- }
4614
- return { messages: found, whole: !walk.truncated };
4615
- };
4616
- var answersIn = (conversation, sent) => sent.filter(
4617
- (message) => conversation.by === "thread" ? message.threadId === conversation.id : message.leadRef === conversation.id
4618
- );
4619
- var check = async (context, checkable, sent, olderThanHours) => {
4620
- const checked = { answered: 0, dropped: [], tooRecent: 0 };
4621
- const openIn = (conversation, messages) => toDropped(
4622
- unanswered(conversation.replies, messages),
4623
- conversation.by,
4624
- context.now
4625
- );
4626
- const settle = (found, whole) => {
4627
- if (found.length === 0) {
4628
- checked.answered += 1;
4629
- } else if (found.every((each) => each.hoursWaiting < olderThanHours)) {
4630
- checked.tooRecent += 1;
4631
- } else if (whole) {
4632
- checked.dropped.push(...found);
4633
- } else {
4634
- return false;
4635
- }
4636
- return true;
4637
- };
4638
- const toRead = sent === null ? checkable : checkable.filter((conversation) => {
4639
- const found = openIn(
4640
- conversation,
4641
- answersIn(conversation, sent.messages)
4642
- );
4643
- return !((found.length === 0 || sent.whole) && settle(found, false));
4644
- });
4645
- const threads = await mapConcurrent(toRead, async (conversation) => ({
4646
- conversation,
4647
- messages: context.page(
4648
- await (conversation.by === "thread" ? context.outbound.thread(conversation.id).messages() : context.outbound.lead(conversation.id).timeline())
4649
- )
4650
- }));
4651
- for (const { conversation, messages } of threads) {
4652
- settle(openIn(conversation, messages), true);
4653
- }
4654
- return checked;
4655
- };
4656
4685
  var droppedReplies = defineInsight({
4657
- description: "Replies from prospects that nobody answered. Reads every reply since a date (14 days before now by default, up to 2,000 or max_replies), keeps the categories that need an answer, and reports a conversation as dropped when nothing was sent after the reply and it has waited longer than older_than_hours. Where the tool lists the messages sent by hand (messages.byHand), one listing of those in the window settles every answered conversation; a conversation is read in full, by its thread or the lead's timeline, only when it may be dropped, or when that listing stopped at its max and did not answer it. Replies in conversations that belong to no campaign, such as a LinkedIn account's own messages on HeyReach, are set aside and counted in totals.notInCampaign unless include_inbox is true. Returns the dropped replies longest waiting first with hours waiting, category, the campaign and its name, and the lead with their name, email and LinkedIn profile. A reply that could not be checked is counted in totals.unchecked, never reported as dropped. Costs one request per page of replies and of messages sent by hand, one per conversation read in full, and one per lead and per campaign among the dropped replies to name them. totals.moreRepliesExist is true when the read stopped with replies left unread.",
4686
+ description: "Replies from prospects that nobody answered. Reads every reply since a date (14 days before now by default, up to 2,000 or max_replies), keeps the categories that need an answer, and reports a conversation as dropped when nothing was sent after the reply and it has waited longer than older_than_hours. Where the tool lists the messages sent by hand (messages.byHand), one listing of those in the window settles every answered conversation; a conversation is read in full, by its thread or the lead's timeline, only when it may be dropped, or when that listing stopped at its max and did not answer it. Replies in conversations that belong to no campaign, such as a LinkedIn account's own messages on HeyReach, are set aside and counted in totals.notInCampaign unless include_inbox is true. Returns the dropped replies longest waiting first with hours waiting, category, the campaign and its name, and the lead with their name, email and LinkedIn profile. A reply that could not be checked, including one whose conversation could not be read, is counted in totals.unchecked with a note, never reported as dropped. Costs one request per page of replies and of messages sent by hand, one per conversation read in full, and one per lead and per campaign among the dropped replies to name them. totals.moreRepliesExist is true when the read stopped with replies left unread.",
4658
4687
  inputSchema: input16,
4659
4688
  key: "droppedReplies",
4660
4689
  cost: (values, price) => {
@@ -4701,7 +4730,7 @@ var droppedReplies = defineInsight({
4701
4730
  since,
4702
4731
  values.max_replies ?? WINDOW_REPLIES
4703
4732
  );
4704
- const { answered, dropped, tooRecent } = await check(
4733
+ const { answered, dropped, tooRecent, unread } = await check(
4705
4734
  context,
4706
4735
  checkable,
4707
4736
  sent,
@@ -4724,7 +4753,7 @@ var droppedReplies = defineInsight({
4724
4753
  skippedAuto: wanted.length - kept.length,
4725
4754
  skippedByCategory: replies2.length - wanted.length,
4726
4755
  tooRecent,
4727
- unchecked
4756
+ unchecked: unchecked + unread
4728
4757
  }
4729
4758
  };
4730
4759
  return answer;
@@ -5396,10 +5425,14 @@ var input18 = z21.object({
5396
5425
  max_leads_per_campaign: z21.number().int().min(1).max(2e4).default(500).describe("The most leads to read from each campaign"),
5397
5426
  statuses: statusesField
5398
5427
  });
5399
- var groupPeople = (entries) => {
5428
+ var keysFor = (masking) => masking?.strategy === "mask" && masking.fields.includes("linkedin") ? (lead) => [
5429
+ ...lead.email === null ? [] : [`email:${lead.email}`],
5430
+ ...lead.linkedinUrl === null ? [] : [`linkedin:${lead.linkedinUrl}`]
5431
+ ] : keysOfLead;
5432
+ var groupPeople = (entries, keysOf) => {
5400
5433
  const byKey = /* @__PURE__ */ new Map();
5401
5434
  for (const entry of entries) {
5402
- const keys = keysOfLead(entry.lead);
5435
+ const keys = keysOf(entry.lead);
5403
5436
  const found = new Set(keys.flatMap((key) => byKey.get(key) ?? []));
5404
5437
  const group = { entries: [entry], keys: new Set(keys) };
5405
5438
  for (const other of found) {
@@ -5470,17 +5503,15 @@ var leadCollisions = defineInsight({
5470
5503
  description: "People who are in two or more campaigns at once, so they get overlapping outreach. Reads the campaigns in the given statuses (active by default) and their leads, matches people by exact email address or LinkedIn profile, and returns each person with their campaigns, channel and tool, most active campaigns first. By default a person counts only when their own status is active in two or more of the campaigns; include_past also reports people who finished, replied to or left one campaign and are in another, counted in totals.pastOverlaps either way. A collision across tools (for example email in one and LinkedIn in another) is marked across_tools; one inside a tool is within_tool. Costs one request per page of campaigns plus one per page of each campaign's leads; the caps make the answer incomplete rather than slow.",
5471
5504
  inputSchema: input18,
5472
5505
  key: "leadCollisions",
5473
- // Under mask an address is a token keyed for the plugin. Whether people
5474
- // tools match by it is OUT-107's decision, so it stays refused until then.
5475
- // A hashed one tells people apart.
5476
- maskedOut: ({ fields, strategy }) => fields.includes("email") && strategy === "mask" ? "email addresses, which it matches people by" : null,
5477
5506
  cost: (values, price) => price.campaignsIn(new Set(values.statuses).size, values.max_campaigns) + price.campaigns(values.max_campaigns) * price.list("leads.list", values.max_leads_per_campaign),
5478
5507
  scales: "max_campaigns",
5479
5508
  name: "lead_collisions",
5480
5509
  needs: ["leads.byCampaign"],
5481
5510
  next: "Use person_summary with one of the identifiers or lead refs to see what that person was sent and whether they replied.",
5482
5511
  run: async (context, values) => {
5483
- if (maskingOf(context.outbound)?.fields.includes("linkedin") === true) {
5512
+ const masking = maskingOf(context.outbound);
5513
+ const keysOf = keysFor(masking);
5514
+ if (masking?.strategy === "hash" && masking.fields.includes("linkedin")) {
5484
5515
  context.partial(
5485
5516
  "The redact plugin masks LinkedIn profiles, so people were matched by email address only."
5486
5517
  );
@@ -5500,7 +5531,7 @@ var leadCollisions = defineInsight({
5500
5531
  return leads.map((lead) => ({ campaign, lead }));
5501
5532
  });
5502
5533
  const entries = perCampaign.flat();
5503
- const overlaps = groupPeople(entries).flatMap(toCollision);
5534
+ const overlaps = groupPeople(entries, keysOf).flatMap(toCollision);
5504
5535
  const pastOverlaps = overlaps.filter((each) => each.stillActive < 2).length;
5505
5536
  const collisions = overlaps.filter((each) => values.include_past || each.stillActive >= 2).toSorted(worstFirst);
5506
5537
  const acrossTools = collisions.filter(
@@ -5515,7 +5546,7 @@ var leadCollisions = defineInsight({
5515
5546
  concurrent: collisions.filter((each) => each.stillActive >= 2).length,
5516
5547
  leadsRead: entries.length,
5517
5548
  leadsWithoutIdentifier: entries.filter(
5518
- (entry) => keysOfLead(entry.lead).length === 0
5549
+ (entry) => keysOf(entry.lead).length === 0
5519
5550
  ).length,
5520
5551
  pastOverlaps,
5521
5552
  withinTool: collisions.length - acrossTools
@@ -5863,7 +5894,11 @@ var input21 = z24.object({
5863
5894
  statuses: statusesField
5864
5895
  });
5865
5896
  var slugOfEntry = (value) => profileSlug(value) ?? value.trim().replaceAll(/^\/+|\/+$/gu, "").toLowerCase();
5866
- var indexEntries = (entries) => {
5897
+ var profileTokens = (outbound) => {
5898
+ const masking = maskingOf(outbound);
5899
+ return masking?.strategy === "mask" && masking.fields.includes("linkedin");
5900
+ };
5901
+ var indexEntries = (entries, tokens) => {
5867
5902
  const blocked = {
5868
5903
  domain: /* @__PURE__ */ new Map(),
5869
5904
  email: /* @__PURE__ */ new Map(),
@@ -5881,13 +5916,16 @@ var indexEntries = (entries) => {
5881
5916
  entry
5882
5917
  );
5883
5918
  } else if (entry.kind === "linkedin") {
5884
- blocked.linkedin.set(slugOfEntry(entry.value), entry);
5919
+ blocked.linkedin.set(
5920
+ tokens ? entry.value : slugOfEntry(entry.value),
5921
+ entry
5922
+ );
5885
5923
  }
5886
5924
  }
5887
5925
  return blocked;
5888
5926
  };
5889
- var matchLead = (lead, blocked) => {
5890
- const slug = profileSlug(lead.linkedinUrl);
5927
+ var matchLead = (lead, blocked, tokens) => {
5928
+ const slug = tokens ? lead.linkedinUrl : profileSlug(lead.linkedinUrl);
5891
5929
  const candidates = [
5892
5930
  ["email", blocked.email.get(lead.email ?? "")],
5893
5931
  ["linkedin", blocked.linkedin.get(slug ?? "")],
@@ -5914,7 +5952,7 @@ var toViolation = (lead, campaign, { entry, matchedBy }) => ({
5914
5952
  var maskNote = (outbound) => {
5915
5953
  const fields = maskingOf(outbound)?.fields ?? [];
5916
5954
  const email = fields.includes("email");
5917
- const linkedin = fields.includes("linkedin");
5955
+ const linkedin = fields.includes("linkedin") && !profileTokens(outbound);
5918
5956
  const masked = [
5919
5957
  ...email ? ["email addresses"] : [],
5920
5958
  ...linkedin ? ["LinkedIn profiles"] : []
@@ -5930,10 +5968,6 @@ var suppressionCheck = defineInsight({
5930
5968
  description: "Leads sitting in campaigns although they are on the block list. Reads the block list, then the leads of each campaign in the given statuses (active by default), and matches a lead by exact email address, by email domain against domain entries, and by LinkedIn profile against profile entries. A match is a violation only when the lead's own status is in lead_statuses (active, paused or unknown by default, the leads still being sent to); a lead that already unsubscribed, bounced, replied or completed is counted in totals.alreadyStopped instead. Returns each violation with the lead, the campaign, the entry and how it matched, counts per campaign, and how many block entries were read; totals.moreBlockEntriesExist is true when max_block_entries left entries unread, which were not checked. On several tools an entry on one tool's list is also matched against the other tools' leads and marked sameTool false. Costs one request per page of block entries plus one per page of each campaign's leads.",
5931
5969
  inputSchema: input21,
5932
5970
  key: "suppressionCheck",
5933
- // Under mask an address is a token keyed for the plugin. Whether people
5934
- // tools match by it is OUT-107's decision, so it stays refused until then.
5935
- // A hashed one still matches the same address on the list.
5936
- maskedOut: ({ fields, strategy }) => fields.includes("email") && strategy === "mask" ? "email addresses, which it matches leads to the block list by" : null,
5937
5971
  cost: (values, price) => price.list("blocklist.list", values.max_block_entries) + price.campaignsIn(new Set(values.statuses).size, values.max_campaigns) + price.campaigns(values.max_campaigns) * price.list("leads.list", values.max_leads_per_campaign),
5938
5972
  scales: "max_campaigns",
5939
5973
  name: "suppression_check",
@@ -5948,7 +5982,8 @@ var suppressionCheck = defineInsight({
5948
5982
  "max_block_entries"
5949
5983
  );
5950
5984
  const entries = listed2.items;
5951
- const blocked = indexEntries(entries);
5985
+ const tokens = profileTokens(context.outbound);
5986
+ const blocked = indexEntries(entries, tokens);
5952
5987
  const unmatched = maskNote(context.outbound);
5953
5988
  if (unmatched !== null) {
5954
5989
  context.partial(unmatched);
@@ -5974,7 +6009,7 @@ var suppressionCheck = defineInsight({
5974
6009
  }));
5975
6010
  for (const { campaign, items: leads } of read) {
5976
6011
  const matched = leads.flatMap((lead) => {
5977
- const hit = matchLead(lead, blocked);
6012
+ const hit = matchLead(lead, blocked, tokens);
5978
6013
  return hit === null ? [] : [toViolation(lead, campaign, hit)];
5979
6014
  });
5980
6015
  const found = matched.filter((each) => sendable.has(each.leadStatus));
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  run
3
- } from "./chunk-4BH5LRCS.js";
3
+ } from "./chunk-CVLGFVDC.js";
4
4
 
5
5
  // src/cli/bin.ts
6
6
  import process from "node:process";
@@ -2,7 +2,7 @@ import {
2
2
  INSIGHT_TOOL_CEILING,
3
3
  insightLeftOutReason,
4
4
  insightTools
5
- } from "./chunk-REDFBY74.js";
5
+ } from "./chunk-KMQHXFIZ.js";
6
6
  import "./chunk-FTK4JS65.js";
7
7
  import "./chunk-4PA526S7.js";
8
8
  import "./chunk-HZCTYL22.js";
package/dist/cli/bin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import "../chunks/chunk-QTWJ5FO7.js";
3
- import "../chunks/chunk-4BH5LRCS.js";
2
+ import "../chunks/chunk-V7JKTNRO.js";
3
+ import "../chunks/chunk-CVLGFVDC.js";
4
4
  import "../chunks/chunk-OMCDMELK.js";
5
5
  import "../chunks/chunk-OVTYA3IB.js";
6
6
  import "../chunks/chunk-FTK4JS65.js";
@@ -21,6 +21,8 @@ export interface PluginFlags {
21
21
  readonly "max-requests"?: string | undefined;
22
22
  readonly cache?: string | undefined;
23
23
  }
24
+ /** The secret that keys redact's tokens across runs, when set. Never printed. */
25
+ export declare const REDACT_KEY_ENV = "OUTBOUND_REDACT_KEY";
24
26
  /** What a cap message tells a CLI user to raise. */
25
27
  export declare const capSetting: (mcp: boolean) => string;
26
28
  /**
package/dist/cli/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  run,
7
7
  serveStdio,
8
8
  throttleMonitor
9
- } from "../chunks/chunk-4BH5LRCS.js";
9
+ } from "../chunks/chunk-CVLGFVDC.js";
10
10
  import "../chunks/chunk-OMCDMELK.js";
11
11
  import "../chunks/chunk-OVTYA3IB.js";
12
12
  import "../chunks/chunk-FTK4JS65.js";
@@ -18,7 +18,7 @@ import {
18
18
  total,
19
19
  wilson,
20
20
  zScore
21
- } from "../chunks/chunk-REDFBY74.js";
21
+ } from "../chunks/chunk-KMQHXFIZ.js";
22
22
  import "../chunks/chunk-FTK4JS65.js";
23
23
  import "../chunks/chunk-4PA526S7.js";
24
24
  import "../chunks/chunk-HZCTYL22.js";
@@ -0,0 +1,62 @@
1
+ import type { Message, Reply } from "../../internal/entities.ts";
2
+ import type { InsightContext } from "../define.ts";
3
+ export declare const HOUR = 3600000;
4
+ export interface DroppedReply {
5
+ /** The oldest reply in the conversation that got no answer. */
6
+ readonly reply: string;
7
+ readonly lead: string | null;
8
+ /** The person's first and last name. `null` when the lead could not be read or has neither. */
9
+ readonly name: string | null;
10
+ readonly email: string | null;
11
+ readonly linkedinUrl: string | null;
12
+ readonly campaign: string | null;
13
+ /** The campaign's name. `null` when the reply names no campaign or it could not be read. */
14
+ readonly campaignName: string | null;
15
+ readonly channel: "email" | "linkedin";
16
+ readonly provider: string;
17
+ readonly category: string;
18
+ readonly subject: string | null;
19
+ readonly receivedAt: string;
20
+ readonly hoursWaiting: number;
21
+ /** Replies in the conversation since the last message sent to the person. */
22
+ readonly unansweredReplies: number;
23
+ /** Whether the conversation was read by its thread or by the lead's timeline. */
24
+ readonly checkedBy: "thread" | "timeline";
25
+ readonly finding: string;
26
+ }
27
+ export interface Conversation {
28
+ readonly by: "thread" | "timeline" | null;
29
+ readonly id: string;
30
+ readonly replies: Reply[];
31
+ }
32
+ interface SentByHand {
33
+ readonly messages: readonly Message[];
34
+ /** `false` when the listing stopped at its max with more left. */
35
+ readonly whole: boolean;
36
+ }
37
+ /**
38
+ * The messages sent by hand since `since`, up to `max`, where the tool can
39
+ * list them by date on its side: one request per page. `null` where it
40
+ * cannot. Only an answer is read from them, so stopping at `max` leaves the
41
+ * rest to be read by thread and loses nothing.
42
+ */
43
+ export declare const sentByHand: (context: InsightContext, since: string, max: number) => Promise<SentByHand | null>;
44
+ export interface Checkable extends Conversation {
45
+ readonly by: "thread" | "timeline";
46
+ }
47
+ interface Checked {
48
+ answered: number;
49
+ readonly dropped: DroppedReply[];
50
+ tooRecent: number;
51
+ /** Conversations whose read failed. */
52
+ unread: number;
53
+ }
54
+ /**
55
+ * Settles each conversation as answered, too recent or dropped. An answer
56
+ * sent by hand after the replies settles one without reading it, and so does
57
+ * an open reply too recent to count, unless the listing stopped at its max
58
+ * and its answer may lie past the stop. The rest are read in full, since a
59
+ * campaign send after the reply counts as an answer too.
60
+ */
61
+ export declare const check: (context: InsightContext, checkable: readonly Checkable[], sent: SentByHand | null, olderThanHours: number) => Promise<Checked>;
62
+ export {};
@@ -1,26 +1,4 @@
1
- export interface DroppedReply {
2
- /** The oldest reply in the conversation that got no answer. */
3
- readonly reply: string;
4
- readonly lead: string | null;
5
- /** The person's first and last name. `null` when the lead could not be read or has neither. */
6
- readonly name: string | null;
7
- readonly email: string | null;
8
- readonly linkedinUrl: string | null;
9
- readonly campaign: string | null;
10
- /** The campaign's name. `null` when the reply names no campaign or it could not be read. */
11
- readonly campaignName: string | null;
12
- readonly channel: "email" | "linkedin";
13
- readonly provider: string;
14
- readonly category: string;
15
- readonly subject: string | null;
16
- readonly receivedAt: string;
17
- readonly hoursWaiting: number;
18
- /** Replies in the conversation since the last message sent to the person. */
19
- readonly unansweredReplies: number;
20
- /** Whether the conversation was read by its thread or by the lead's timeline. */
21
- readonly checkedBy: "thread" | "timeline";
22
- readonly finding: string;
23
- }
1
+ import type { DroppedReply } from "./dropped-replies-check.ts";
24
2
  export interface DroppedReplies {
25
3
  /** Longest waiting first. */
26
4
  readonly dropped: readonly DroppedReply[];
@@ -43,7 +21,7 @@ export interface DroppedReplies {
43
21
  readonly dropped: number;
44
22
  /** Unanswered, as far as was read, but waiting less than `older_than_hours`. */
45
23
  readonly tooRecent: number;
46
- /** Could not be checked: no thread or lead to read, or no time on the reply. Not counted as dropped. */
24
+ /** Could not be checked: no thread or lead to read, a read that failed, or no time on the reply. Not counted as dropped. */
47
25
  readonly unchecked: number;
48
26
  /** `true` when `max_replies`, or the 2,000 replies one window reads, stopped the read with more replies left, so dropped ones may be missing. */
49
27
  readonly moreRepliesExist: boolean;
@@ -92,7 +92,8 @@ export declare const PEOPLE_INSIGHTS: readonly [import("../define.ts").InsightDe
92
92
  max_leads?: number | undefined;
93
93
  }>];
94
94
  export type { AccountPerson, AccountRecord, AccountSummary, } from "./account-summary.ts";
95
- export type { DroppedReplies, DroppedReply } from "./dropped-replies.ts";
95
+ export type { DroppedReply } from "./dropped-replies-check.ts";
96
+ export type { DroppedReplies } from "./dropped-replies.ts";
96
97
  export type { HotLead, HotLeadParts, HotLeads } from "./hot-leads.ts";
97
98
  export type { CollisionCampaign, LeadCollision, LeadCollisions, } from "./lead-collisions.ts";
98
99
  export type { PersonCampaign, PersonSummary } from "./person-summary.ts";
@@ -1,2 +1,2 @@
1
- export { ALL_FIELDS, KNOWN_TOKENS, MASK, redact } from "./plugin.ts";
1
+ export { ALL_FIELDS, KNOWN_TOKENS, MASK, MIN_KEY_LENGTH, redact, } from "./plugin.ts";
2
2
  export type { RedactExtension, RedactField, RedactOptions } from "./plugin.ts";
@@ -18,28 +18,30 @@ import {
18
18
  isString
19
19
  } from "../chunks/chunk-45TXPJW7.js";
20
20
 
21
- // src/redact/plugin.ts
22
- var ALL_FIELDS = [
23
- "body",
24
- "company",
25
- "custom",
26
- "email",
27
- "linkedin",
28
- "name",
29
- "phone",
30
- "subject"
31
- ];
32
- var MASK = "[redacted]";
33
- var replacer = (strategy) => (value) => {
34
- if (value === null) {
35
- return null;
36
- }
37
- return strategy === "mask" ? MASK : `redacted:${stableId(value).slice(0, 16)}`;
38
- };
39
- var keyedToken = () => {
40
- const key = crypto.getRandomValues(new Uint8Array(32));
21
+ // src/redact/tokens.ts
22
+ var MIN_KEY_LENGTH = 32;
23
+ var keyedToken = (secret) => {
24
+ const key = secret === void 0 ? crypto.getRandomValues(new Uint8Array(32)) : new TextEncoder().encode(secret);
41
25
  return (value) => `redacted:${hmacSha256Hex(key, value).slice(0, 16)}`;
42
26
  };
27
+ var checkedKey = (key, strategy) => {
28
+ if (key === void 0) {
29
+ return void 0;
30
+ }
31
+ if (strategy !== "mask") {
32
+ throw new OutboundError(
33
+ "Invalid",
34
+ 'redact takes a key only with strategy "mask": "hash" writes the same token without one'
35
+ );
36
+ }
37
+ if (key.length < MIN_KEY_LENGTH) {
38
+ throw new OutboundError(
39
+ "Invalid",
40
+ `The redact key must be at least ${MIN_KEY_LENGTH} characters. It is a secret: make one with \`openssl rand -hex 32\``
41
+ );
42
+ }
43
+ return key;
44
+ };
43
45
  var KNOWN_TOKENS = 1e4;
44
46
  var TOKEN = /redacted:[0-9a-f]{16}/gu;
45
47
  var knownTokens = () => {
@@ -67,8 +69,27 @@ var knownTokens = () => {
67
69
  unmask: (text) => text.replaceAll(TOKEN, (token) => values.get(token)?.value ?? token)
68
70
  };
69
71
  };
72
+
73
+ // src/redact/plugin.ts
74
+ var ALL_FIELDS = [
75
+ "body",
76
+ "company",
77
+ "custom",
78
+ "email",
79
+ "linkedin",
80
+ "name",
81
+ "phone",
82
+ "subject"
83
+ ];
84
+ var MASK = "[redacted]";
85
+ var replacer = (strategy) => (value) => {
86
+ if (value === null) {
87
+ return null;
88
+ }
89
+ return strategy === "mask" ? MASK : `redacted:${stableId(value).slice(0, 16)}`;
90
+ };
70
91
  var maskIdentifier = (masks, field, value) => masks.has(field) ? masks.identifier(field, value) : value;
71
- var masksFor = (fields, strategy) => {
92
+ var masksFor = (fields, strategy, secret) => {
72
93
  const replace = replacer(strategy);
73
94
  const has = (field) => fields.has(field);
74
95
  const known = knownTokens();
@@ -81,7 +102,7 @@ var masksFor = (fields, strategy) => {
81
102
  token: (kind, value, original = value) => known.remember(replace(value) ?? MASK, kind, original)
82
103
  };
83
104
  }
84
- const keyed = keyedToken();
105
+ const keyed = keyedToken(secret);
85
106
  const token = (kind, value, original = value) => known.remember(keyed(value), kind, original);
86
107
  return {
87
108
  has,
@@ -232,17 +253,30 @@ var remasked = (known, error) => new OutboundError(error.code, known.remask(erro
232
253
  status: error.status,
233
254
  timedOut: error.timedOut
234
255
  });
256
+ var unmaskedQuery = (known, query) => {
257
+ if (JSON.stringify(query).match(TOKEN) === null) {
258
+ return void 0;
259
+ }
260
+ const fields = query;
261
+ return Object.fromEntries(
262
+ Object.entries(fields).map(([key, value]) => [
263
+ key,
264
+ maskEach(value, (text) => known.unmask(text))
265
+ ])
266
+ );
267
+ };
235
268
  var unmasked = (known, operation) => {
236
- if (!("id" in operation)) {
237
- return operation;
269
+ if ("id" in operation) {
270
+ const id = known.unmask(operation.id);
271
+ return id === operation.id ? operation : { ...operation, id };
238
272
  }
239
- const id = known.unmask(operation.id);
240
- return id === operation.id ? operation : { ...operation, id };
273
+ const query = unmaskedQuery(known, operation.query);
274
+ return query === void 0 ? operation : { ...operation, query };
241
275
  };
242
276
  var redact = (options = {}) => {
243
277
  const fields = new Set(options.fields ?? ALL_FIELDS);
244
278
  const strategy = options.strategy ?? "mask";
245
- const masks = masksFor(fields, strategy);
279
+ const masks = masksFor(fields, strategy, checkedKey(options.key, strategy));
246
280
  return {
247
281
  // Asking for bodies while they are being removed is a contradiction, so
248
282
  // the capability is turned off and the request is refused up front.
@@ -287,5 +321,6 @@ export {
287
321
  ALL_FIELDS,
288
322
  KNOWN_TOKENS,
289
323
  MASK,
324
+ MIN_KEY_LENGTH,
290
325
  redact
291
326
  };
@@ -1,6 +1,8 @@
1
1
  import type { Lead } from "../internal/entities.ts";
2
2
  import type { ListAll } from "../internal/outbound/api.ts";
3
3
  import type { OutboundPlugin } from "../internal/outbound/plugins.ts";
4
+ import type { Identifier } from "./tokens.ts";
5
+ export { KNOWN_TOKENS, MIN_KEY_LENGTH } from "./tokens.ts";
4
6
  export type RedactField = "body" | "company" | "custom" | "email" | "linkedin" | "name" | "phone" | "subject";
5
7
  export interface RedactOptions {
6
8
  /** What to mask. Defaults to everything. */
@@ -12,6 +14,16 @@ export interface RedactOptions {
12
14
  * so the same person gets the same token from one run to the next.
13
15
  */
14
16
  readonly strategy?: "hash" | "mask" | undefined;
17
+ /**
18
+ * A secret, at least `MIN_KEY_LENGTH` (32) characters, that keys the
19
+ * tokens `mask` writes for addresses and profiles. With it the same person
20
+ * gets the same token in every instance and process given the same key, so
21
+ * redacted data can be joined across runs. Without it each plugin makes a
22
+ * random key of its own. Anyone holding the key can test a guessed address
23
+ * against a token, and a new key gives every person a new token. Only for
24
+ * `mask`; `hash` needs no key.
25
+ */
26
+ readonly key?: string | undefined;
15
27
  }
16
28
  export declare const ALL_FIELDS: readonly RedactField[];
17
29
  export declare const MASK = "[redacted]";
@@ -44,9 +56,5 @@ export interface RedactExtension {
44
56
  readonly leadsByToken: (tokens: readonly string[], campaign: string | null) => ListAll<Lead>;
45
57
  };
46
58
  }
47
- type Identifier = "email" | "linkedin";
48
- /** The most tokens one redact remembers the value of; the oldest go first. */
49
- export declare const KNOWN_TOKENS = 10000;
50
59
  /** Masks emails, names, companies, LinkedIn URLs, custom fields and message text. */
51
60
  export declare const redact: (options?: RedactOptions) => OutboundPlugin<RedactExtension>;
52
- export {};
@@ -0,0 +1,21 @@
1
+ /** The shortest `key` `redact` accepts. */
2
+ export declare const MIN_KEY_LENGTH = 32;
3
+ export declare const keyedToken: (secret: string | undefined) => ((value: string) => string);
4
+ export declare const checkedKey: (key: string | undefined, strategy: "hash" | "mask") => string | undefined;
5
+ export type Identifier = "email" | "linkedin";
6
+ /** The most tokens one redact remembers the value of; the oldest go first. */
7
+ export declare const KNOWN_TOKENS = 10000;
8
+ export declare const TOKEN: RegExp;
9
+ /**
10
+ * The values behind the tokens this redact wrote for addresses and profiles,
11
+ * held in memory for its lifetime and never written out.
12
+ */
13
+ export interface Known {
14
+ readonly remember: (token: string, kind: Identifier, value: string) => string;
15
+ readonly kindOf: (token: string) => Identifier | null;
16
+ /** Puts each known token's value back, for a call on its way to the vendor. */
17
+ readonly unmask: (text: string) => string;
18
+ /** Puts the tokens back where a value from `unmask` appears. */
19
+ readonly remask: (text: string) => string;
20
+ }
21
+ export declare const knownTokens: () => Known;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "outbound-sdk",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "One small, typed, read-only API over outbound sending tools.",
5
5
  "keywords": [
6
6
  "cold-email",