outbound-sdk 0.8.0 → 0.10.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.
@@ -29,6 +29,7 @@ var NO_CAPABILITIES = {
29
29
  "leads.byCampaign": false,
30
30
  "leads.byDomain": false,
31
31
  "leads.byInterest": false,
32
+ "leads.byStatus": false,
32
33
  "leads.engagement": false,
33
34
  "leads.get": false,
34
35
  "leads.list": false,
@@ -3813,10 +3813,13 @@ var describe2 = ({ complete, daysLeft, inSequence, remaining }, forecast) => {
3813
3813
  const range = low === high ? "" : ` (between ${low} and ${high})`;
3814
3814
  return `${leads}; expect about ${expected} ${noun(Number(expected), "reply", "replies")}${range}. This is an estimate.`;
3815
3815
  };
3816
+ var ownerOf = (context, campaign) => context.outbound.provider === "combined" ? context.outbound.workspace(`${campaign.provider}:${campaign.workspaceId}`) : context.outbound;
3816
3817
  var runwayOf = async (context, campaign, options) => {
3818
+ const owner = ownerOf(context, campaign);
3819
+ const status = options.activeOnly === true && owner.capabilities["leads.byStatus"] ? "active" : void 0;
3817
3820
  const { capped: capped2, items: leads } = await readCapped(
3818
3821
  context,
3819
- (max) => context.outbound.campaign(campaign.ref).leads.listAll({ max }),
3822
+ (max) => owner.campaign(campaign.ref).leads.listAll({ max, status }),
3820
3823
  {
3821
3824
  input: options.leadsInput,
3822
3825
  max: options.maxLeads,
@@ -3901,7 +3904,9 @@ var input13 = z16.object({
3901
3904
  days: z16.number().int().min(1).max(90).default(7).describe("The length of the period, in complete days ending yesterday"),
3902
3905
  limit: z16.number().int().min(1).max(20).default(3).describe("How many best and worst campaigns to show"),
3903
3906
  max_bounce_rate: z16.number().min(0).max(1).default(0.03).describe("A campaign bounce rate over this is a bounce problem"),
3904
- max_leads_per_campaign: z16.number().int().min(1).max(5e4).default(500).describe("The most leads to read per active campaign, for leads left"),
3907
+ max_leads_per_campaign: z16.number().int().min(1).max(5e4).default(5e3).describe(
3908
+ "The most leads to read per active campaign, for leads left. Where the tool lists active leads alone (leads.byStatus), only those are read."
3909
+ ),
3905
3910
  min_baseline_points: z16.number().int().min(2).default(5).describe("The fewest baseline days with data a day needs to be tested"),
3906
3911
  min_sent: z16.number().int().min(0).default(50).describe("Campaigns under this many sends in the period are not judged"),
3907
3912
  runway_days: z16.number().min(0).default(7).describe(
@@ -3963,6 +3968,7 @@ var readRunways = async (context, campaigns, options) => {
3963
3968
  async (campaign) => ({
3964
3969
  campaign,
3965
3970
  forecast: await runwayOf(context, campaign, {
3971
+ activeOnly: true,
3966
3972
  days: options.days,
3967
3973
  leadsInput: "max_leads_per_campaign",
3968
3974
  leadsWhat: "leads of a campaign",
@@ -4040,7 +4046,7 @@ var actionsOf = (report) => {
4040
4046
  ];
4041
4047
  };
4042
4048
  var clientReport = defineInsight({
4043
- description: "One report for one client or workspace over the last `days` complete days: totals and the change from the period before, the best and worst campaigns by the low end of the interval of the reply rate, campaigns with a bounce problem, unusual days, active campaigns running out of leads, and a short list of action items in plain language, each naming the campaign and the number behind it. Reply rates divide by messages sent (`replyRateBasis`), since a period's replies also answer leads contacted before it, and by leads contacted for both periods only when a period does not report messages sent. Use it for a weekly client update. A section the adapter cannot serve is null and named in `leftOut`, and a null count is one the vendor does not report. Costs two stats requests per campaign, one for the workspace, and for each active campaign one more plus its pages of leads. On Instantly a stats read is 2 requests, since it also reads the campaign's tracking settings, so each active campaign costs about 7.",
4049
+ description: "One report for one client or workspace over the last `days` complete days: totals and the change from the period before, the best and worst campaigns by the low end of the interval of the reply rate, campaigns with a bounce problem, unusual days, active campaigns running out of leads, and a short list of action items in plain language, each naming the campaign and the number behind it. Reply rates divide by messages sent (`replyRateBasis`), since a period's replies also answer leads contacted before it, and by leads contacted for both periods only when a period does not report messages sent. Use it for a weekly client update. A section the adapter cannot serve is null and named in `leftOut`, and a null count is one the vendor does not report. Costs two stats requests per campaign, one for the workspace, and for each active campaign one more plus its pages of leads, its active leads only where the tool lists them alone (leads.byStatus). On Instantly a stats read is 2 requests, since it also reads the campaign's tracking settings, so each active campaign costs about 7.",
4044
4050
  inputSchema: input13,
4045
4051
  key: "clientReport",
4046
4052
  cost: (values, price) => {
@@ -4435,9 +4441,135 @@ var accountSummary = defineInsight({
4435
4441
 
4436
4442
  // src/insights/people/dropped-replies.ts
4437
4443
  import { z as z19 } from "zod";
4444
+
4445
+ // src/insights/people/dropped-replies-check.ts
4438
4446
  var HOUR = 36e5;
4439
- var DAY = 24 * HOUR;
4440
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;
4441
4573
  var DEFAULT_DAYS = 14;
4442
4574
  var WINDOW_REPLIES = 2e3;
4443
4575
  var input16 = z19.object({
@@ -4486,46 +4618,6 @@ var conversationsOf = (replies2, readers) => {
4486
4618
  }
4487
4619
  return [...groups.values()];
4488
4620
  };
4489
- var unanswered = (replies2, messages) => {
4490
- const lastSent = Math.max(
4491
- Number.NEGATIVE_INFINITY,
4492
- ...messages.flatMap(
4493
- (message) => message.direction === "out" && message.sentAt !== null ? [Date.parse(message.sentAt)] : []
4494
- )
4495
- );
4496
- return replies2.filter(
4497
- (reply) => reply.sentAt !== null && Date.parse(reply.sentAt) > lastSent
4498
- ).toSorted(
4499
- (left, right) => (left.sentAt ?? "").localeCompare(right.sentAt ?? "")
4500
- );
4501
- };
4502
- var toDropped = (open, by, now) => {
4503
- const [first] = open;
4504
- if (first === void 0 || first.sentAt === null) {
4505
- return [];
4506
- }
4507
- const hoursWaiting = round((now - Date.parse(first.sentAt)) / HOUR) ?? 0;
4508
- return [
4509
- {
4510
- campaign: first.campaignRef,
4511
- campaignName: null,
4512
- category: first.category,
4513
- channel: first.channel,
4514
- checkedBy: by,
4515
- finding: `${/^[aeiou]/u.test(first.category) ? "An" : "A"} ${first.category} reply has waited ${waited(hoursWaiting)} with nothing sent after it.`,
4516
- hoursWaiting,
4517
- email: null,
4518
- lead: first.leadRef,
4519
- linkedinUrl: null,
4520
- name: null,
4521
- provider: first.provider,
4522
- receivedAt: first.sentAt,
4523
- reply: first.ref,
4524
- subject: first.subject,
4525
- unansweredReplies: open.length
4526
- }
4527
- ];
4528
- };
4529
4621
  var refsOf = (refs) => [
4530
4622
  ...new Set(refs.flatMap((ref) => ref === null ? [] : [ref]))
4531
4623
  ];
@@ -4590,65 +4682,8 @@ var readReplies = (context, since, given) => {
4590
4682
  given === null ? "the most one window reads; pass a later since" : "max_replies"
4591
4683
  );
4592
4684
  };
4593
- var sentByHand = async (context, since, max) => {
4594
- const { capabilities, messages } = context.outbound;
4595
- if (!capabilities["messages.byHand"] || capabilities["messages.since"] !== "server") {
4596
- return null;
4597
- }
4598
- const walk = messages.listAll({ byHand: true, max, since });
4599
- const found = await walk.toArray();
4600
- if (walk.meta !== void 0) {
4601
- context.one({ meta: walk.meta });
4602
- }
4603
- if (walk.truncated) {
4604
- context.note(
4605
- `The messages sent by hand stopped at ${max}, so each conversation they did not settle was read in full.`
4606
- );
4607
- }
4608
- return { messages: found, whole: !walk.truncated };
4609
- };
4610
- var answersIn = (conversation, sent) => sent.filter(
4611
- (message) => conversation.by === "thread" ? message.threadId === conversation.id : message.leadRef === conversation.id
4612
- );
4613
- var check = async (context, checkable, sent, olderThanHours) => {
4614
- const checked = { answered: 0, dropped: [], tooRecent: 0 };
4615
- const openIn = (conversation, messages) => toDropped(
4616
- unanswered(conversation.replies, messages),
4617
- conversation.by,
4618
- context.now
4619
- );
4620
- const settle = (found, whole) => {
4621
- if (found.length === 0) {
4622
- checked.answered += 1;
4623
- } else if (found.every((each) => each.hoursWaiting < olderThanHours)) {
4624
- checked.tooRecent += 1;
4625
- } else if (whole) {
4626
- checked.dropped.push(...found);
4627
- } else {
4628
- return false;
4629
- }
4630
- return true;
4631
- };
4632
- const toRead = sent === null ? checkable : checkable.filter((conversation) => {
4633
- const found = openIn(
4634
- conversation,
4635
- answersIn(conversation, sent.messages)
4636
- );
4637
- return !((found.length === 0 || sent.whole) && settle(found, false));
4638
- });
4639
- const threads = await mapConcurrent(toRead, async (conversation) => ({
4640
- conversation,
4641
- messages: context.page(
4642
- await (conversation.by === "thread" ? context.outbound.thread(conversation.id).messages() : context.outbound.lead(conversation.id).timeline())
4643
- )
4644
- }));
4645
- for (const { conversation, messages } of threads) {
4646
- settle(openIn(conversation, messages), true);
4647
- }
4648
- return checked;
4649
- };
4650
4685
  var droppedReplies = defineInsight({
4651
- 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.",
4652
4687
  inputSchema: input16,
4653
4688
  key: "droppedReplies",
4654
4689
  cost: (values, price) => {
@@ -4695,7 +4730,7 @@ var droppedReplies = defineInsight({
4695
4730
  since,
4696
4731
  values.max_replies ?? WINDOW_REPLIES
4697
4732
  );
4698
- const { answered, dropped, tooRecent } = await check(
4733
+ const { answered, dropped, tooRecent, unread } = await check(
4699
4734
  context,
4700
4735
  checkable,
4701
4736
  sent,
@@ -4718,7 +4753,7 @@ var droppedReplies = defineInsight({
4718
4753
  skippedAuto: wanted.length - kept.length,
4719
4754
  skippedByCategory: replies2.length - wanted.length,
4720
4755
  tooRecent,
4721
- unchecked
4756
+ unchecked: unchecked + unread
4722
4757
  }
4723
4758
  };
4724
4759
  return answer;
@@ -5390,10 +5425,14 @@ var input18 = z21.object({
5390
5425
  max_leads_per_campaign: z21.number().int().min(1).max(2e4).default(500).describe("The most leads to read from each campaign"),
5391
5426
  statuses: statusesField
5392
5427
  });
5393
- 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) => {
5394
5433
  const byKey = /* @__PURE__ */ new Map();
5395
5434
  for (const entry of entries) {
5396
- const keys = keysOfLead(entry.lead);
5435
+ const keys = keysOf(entry.lead);
5397
5436
  const found = new Set(keys.flatMap((key) => byKey.get(key) ?? []));
5398
5437
  const group = { entries: [entry], keys: new Set(keys) };
5399
5438
  for (const other of found) {
@@ -5464,17 +5503,15 @@ var leadCollisions = defineInsight({
5464
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.",
5465
5504
  inputSchema: input18,
5466
5505
  key: "leadCollisions",
5467
- // Under mask an address is a token keyed for the plugin. Whether people
5468
- // tools match by it is OUT-107's decision, so it stays refused until then.
5469
- // A hashed one tells people apart.
5470
- maskedOut: ({ fields, strategy }) => fields.includes("email") && strategy === "mask" ? "email addresses, which it matches people by" : null,
5471
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),
5472
5507
  scales: "max_campaigns",
5473
5508
  name: "lead_collisions",
5474
5509
  needs: ["leads.byCampaign"],
5475
5510
  next: "Use person_summary with one of the identifiers or lead refs to see what that person was sent and whether they replied.",
5476
5511
  run: async (context, values) => {
5477
- 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")) {
5478
5515
  context.partial(
5479
5516
  "The redact plugin masks LinkedIn profiles, so people were matched by email address only."
5480
5517
  );
@@ -5494,7 +5531,7 @@ var leadCollisions = defineInsight({
5494
5531
  return leads.map((lead) => ({ campaign, lead }));
5495
5532
  });
5496
5533
  const entries = perCampaign.flat();
5497
- const overlaps = groupPeople(entries).flatMap(toCollision);
5534
+ const overlaps = groupPeople(entries, keysOf).flatMap(toCollision);
5498
5535
  const pastOverlaps = overlaps.filter((each) => each.stillActive < 2).length;
5499
5536
  const collisions = overlaps.filter((each) => values.include_past || each.stillActive >= 2).toSorted(worstFirst);
5500
5537
  const acrossTools = collisions.filter(
@@ -5509,7 +5546,7 @@ var leadCollisions = defineInsight({
5509
5546
  concurrent: collisions.filter((each) => each.stillActive >= 2).length,
5510
5547
  leadsRead: entries.length,
5511
5548
  leadsWithoutIdentifier: entries.filter(
5512
- (entry) => keysOfLead(entry.lead).length === 0
5549
+ (entry) => keysOf(entry.lead).length === 0
5513
5550
  ).length,
5514
5551
  pastOverlaps,
5515
5552
  withinTool: collisions.length - acrossTools
@@ -5857,7 +5894,11 @@ var input21 = z24.object({
5857
5894
  statuses: statusesField
5858
5895
  });
5859
5896
  var slugOfEntry = (value) => profileSlug(value) ?? value.trim().replaceAll(/^\/+|\/+$/gu, "").toLowerCase();
5860
- 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) => {
5861
5902
  const blocked = {
5862
5903
  domain: /* @__PURE__ */ new Map(),
5863
5904
  email: /* @__PURE__ */ new Map(),
@@ -5875,13 +5916,16 @@ var indexEntries = (entries) => {
5875
5916
  entry
5876
5917
  );
5877
5918
  } else if (entry.kind === "linkedin") {
5878
- blocked.linkedin.set(slugOfEntry(entry.value), entry);
5919
+ blocked.linkedin.set(
5920
+ tokens ? entry.value : slugOfEntry(entry.value),
5921
+ entry
5922
+ );
5879
5923
  }
5880
5924
  }
5881
5925
  return blocked;
5882
5926
  };
5883
- var matchLead = (lead, blocked) => {
5884
- const slug = profileSlug(lead.linkedinUrl);
5927
+ var matchLead = (lead, blocked, tokens) => {
5928
+ const slug = tokens ? lead.linkedinUrl : profileSlug(lead.linkedinUrl);
5885
5929
  const candidates = [
5886
5930
  ["email", blocked.email.get(lead.email ?? "")],
5887
5931
  ["linkedin", blocked.linkedin.get(slug ?? "")],
@@ -5908,7 +5952,7 @@ var toViolation = (lead, campaign, { entry, matchedBy }) => ({
5908
5952
  var maskNote = (outbound) => {
5909
5953
  const fields = maskingOf(outbound)?.fields ?? [];
5910
5954
  const email = fields.includes("email");
5911
- const linkedin = fields.includes("linkedin");
5955
+ const linkedin = fields.includes("linkedin") && !profileTokens(outbound);
5912
5956
  const masked = [
5913
5957
  ...email ? ["email addresses"] : [],
5914
5958
  ...linkedin ? ["LinkedIn profiles"] : []
@@ -5924,10 +5968,6 @@ var suppressionCheck = defineInsight({
5924
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.",
5925
5969
  inputSchema: input21,
5926
5970
  key: "suppressionCheck",
5927
- // Under mask an address is a token keyed for the plugin. Whether people
5928
- // tools match by it is OUT-107's decision, so it stays refused until then.
5929
- // A hashed one still matches the same address on the list.
5930
- maskedOut: ({ fields, strategy }) => fields.includes("email") && strategy === "mask" ? "email addresses, which it matches leads to the block list by" : null,
5931
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),
5932
5972
  scales: "max_campaigns",
5933
5973
  name: "suppression_check",
@@ -5942,7 +5982,8 @@ var suppressionCheck = defineInsight({
5942
5982
  "max_block_entries"
5943
5983
  );
5944
5984
  const entries = listed2.items;
5945
- const blocked = indexEntries(entries);
5985
+ const tokens = profileTokens(context.outbound);
5986
+ const blocked = indexEntries(entries, tokens);
5946
5987
  const unmatched = maskNote(context.outbound);
5947
5988
  if (unmatched !== null) {
5948
5989
  context.partial(unmatched);
@@ -5968,7 +6009,7 @@ var suppressionCheck = defineInsight({
5968
6009
  }));
5969
6010
  for (const { campaign, items: leads } of read) {
5970
6011
  const matched = leads.flatMap((lead) => {
5971
- const hit = matchLead(lead, blocked);
6012
+ const hit = matchLead(lead, blocked, tokens);
5972
6013
  return hit === null ? [] : [toViolation(lead, campaign, hit)];
5973
6014
  });
5974
6015
  const found = matched.filter((each) => sendable.has(each.leadStatus));
@@ -15,7 +15,7 @@ import {
15
15
  } from "./chunk-4PA526S7.js";
16
16
  import {
17
17
  createOutbound
18
- } from "./chunk-RQLOPMMR.js";
18
+ } from "./chunk-MEEJIIIA.js";
19
19
  import {
20
20
  plural
21
21
  } from "./chunk-PTZO4QXR.js";
@@ -25,7 +25,7 @@ import {
25
25
  } from "./chunk-QGRZDTX4.js";
26
26
  import {
27
27
  fromEnv
28
- } from "./chunk-7TASUWPC.js";
28
+ } from "./chunk-5XLR6XVV.js";
29
29
  import {
30
30
  OutboundError
31
31
  } from "./chunk-XYHM4KHC.js";
@@ -756,7 +756,7 @@ var COMMAND_TABLE = {
756
756
  const offered = await offeredTools(outbound, input.flags);
757
757
  const tool = offered.find((candidate) => candidate.name === name);
758
758
  if (tool === void 0) {
759
- const { insightLeftOutReason } = await import("./tools-II7GXAOM.js");
759
+ const { insightLeftOutReason } = await import("./tools-AVJ3XJ5A.js");
760
760
  const why = leftOutReason(outbound, name) ?? insightLeftOutReason(outbound, name);
761
761
  if (why !== void 0) {
762
762
  throw new OutboundError("Unsupported", why, {
@@ -18,7 +18,7 @@ import {
18
18
  senderHealthSchema,
19
19
  tagSchema,
20
20
  webhookSubscriptionSchema
21
- } from "./chunk-RMAHQ2OZ.js";
21
+ } from "./chunk-A7DLJUA6.js";
22
22
  import {
23
23
  plural
24
24
  } from "./chunk-PTZO4QXR.js";
@@ -1361,6 +1361,28 @@ var checkInterest = (core, interest) => {
1361
1361
  );
1362
1362
  }
1363
1363
  };
1364
+ var checkStatus = (core, filters) => {
1365
+ if (filters.status === void 0) {
1366
+ return;
1367
+ }
1368
+ requireCapability(
1369
+ core.gate,
1370
+ "leads.byStatus",
1371
+ "Listing only the active leads"
1372
+ );
1373
+ if (filters.status !== "active") {
1374
+ throw new OutboundError(
1375
+ "Invalid",
1376
+ `status takes "active", not "${String(filters.status)}"`
1377
+ );
1378
+ }
1379
+ if (filters.interest !== void 0) {
1380
+ throw new OutboundError(
1381
+ "Invalid",
1382
+ "Leads can be listed by interest or by status, not both at once"
1383
+ );
1384
+ }
1385
+ };
1364
1386
  var leadList = (core) => ({
1365
1387
  action: "leads.list",
1366
1388
  takes: {
@@ -1372,6 +1394,7 @@ var leadList = (core) => ({
1372
1394
  linkedinUrl: true,
1373
1395
  listId: true,
1374
1396
  since: true,
1397
+ status: true,
1375
1398
  until: true
1376
1399
  },
1377
1400
  // A lookup returns one record per campaign the person is in. On a vendor
@@ -1395,6 +1418,7 @@ var leadList = (core) => ({
1395
1418
  }
1396
1419
  const emails = manyAddresses(core, filters.emails);
1397
1420
  checkInterest(core, filters.interest);
1421
+ checkStatus(core, filters);
1398
1422
  const domain = filters.domain?.trim().toLowerCase();
1399
1423
  if (domain !== void 0) {
1400
1424
  requireCapability(
@@ -1431,6 +1455,7 @@ var leadList = (core) => ({
1431
1455
  interest: filters.interest,
1432
1456
  linkedinUrl: filters.linkedinUrl?.trim(),
1433
1457
  listId: filters.listId,
1458
+ status: filters.status,
1434
1459
  ...normalizeRange(filters)
1435
1460
  };
1436
1461
  },
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  run
3
- } from "./chunk-4GK56PRO.js";
3
+ } from "./chunk-KQCIF5IT.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-XMCNRU4H.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,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import "../chunks/chunk-IKKCMWBK.js";
3
- import "../chunks/chunk-4GK56PRO.js";
2
+ import "../chunks/chunk-NAYVG7SI.js";
3
+ import "../chunks/chunk-KQCIF5IT.js";
4
4
  import "../chunks/chunk-OMCDMELK.js";
5
5
  import "../chunks/chunk-OVTYA3IB.js";
6
6
  import "../chunks/chunk-FTK4JS65.js";
7
7
  import "../chunks/chunk-4PA526S7.js";
8
8
  import "../chunks/chunk-HZCTYL22.js";
9
- import "../chunks/chunk-RQLOPMMR.js";
9
+ import "../chunks/chunk-MEEJIIIA.js";
10
10
  import "../chunks/chunk-4O2HRTTI.js";
11
11
  import "../chunks/chunk-HPNGSG5E.js";
12
- import "../chunks/chunk-RMAHQ2OZ.js";
12
+ import "../chunks/chunk-A7DLJUA6.js";
13
13
  import "../chunks/chunk-PTZO4QXR.js";
14
14
  import "../chunks/chunk-POBAY3TI.js";
15
15
  import "../chunks/chunk-CPACP4YD.js";
@@ -17,7 +17,7 @@ import "../chunks/chunk-QGRZDTX4.js";
17
17
  import "../chunks/chunk-HXB2IOJJ.js";
18
18
  import "../chunks/chunk-YFJ3OQZS.js";
19
19
  import "../chunks/chunk-KVAG5GM2.js";
20
- import "../chunks/chunk-7TASUWPC.js";
20
+ import "../chunks/chunk-5XLR6XVV.js";
21
21
  import "../chunks/chunk-NFWWA7MI.js";
22
22
  import "../chunks/chunk-XYHM4KHC.js";
23
23
  import "../chunks/chunk-45TXPJW7.js";
package/dist/cli/index.js CHANGED
@@ -6,16 +6,16 @@ import {
6
6
  run,
7
7
  serveStdio,
8
8
  throttleMonitor
9
- } from "../chunks/chunk-4GK56PRO.js";
9
+ } from "../chunks/chunk-KQCIF5IT.js";
10
10
  import "../chunks/chunk-OMCDMELK.js";
11
11
  import "../chunks/chunk-OVTYA3IB.js";
12
12
  import "../chunks/chunk-FTK4JS65.js";
13
13
  import "../chunks/chunk-4PA526S7.js";
14
14
  import "../chunks/chunk-HZCTYL22.js";
15
- import "../chunks/chunk-RQLOPMMR.js";
15
+ import "../chunks/chunk-MEEJIIIA.js";
16
16
  import "../chunks/chunk-4O2HRTTI.js";
17
17
  import "../chunks/chunk-HPNGSG5E.js";
18
- import "../chunks/chunk-RMAHQ2OZ.js";
18
+ import "../chunks/chunk-A7DLJUA6.js";
19
19
  import "../chunks/chunk-PTZO4QXR.js";
20
20
  import "../chunks/chunk-POBAY3TI.js";
21
21
  import "../chunks/chunk-CPACP4YD.js";
@@ -23,7 +23,7 @@ import "../chunks/chunk-QGRZDTX4.js";
23
23
  import "../chunks/chunk-HXB2IOJJ.js";
24
24
  import "../chunks/chunk-YFJ3OQZS.js";
25
25
  import "../chunks/chunk-KVAG5GM2.js";
26
- import "../chunks/chunk-7TASUWPC.js";
26
+ import "../chunks/chunk-5XLR6XVV.js";
27
27
  import "../chunks/chunk-NFWWA7MI.js";
28
28
  import "../chunks/chunk-XYHM4KHC.js";
29
29
  import "../chunks/chunk-45TXPJW7.js";
@@ -3,7 +3,7 @@ import {
3
3
  mergeFields,
4
4
  resolveCapabilities,
5
5
  resolveFields
6
- } from "../chunks/chunk-RMAHQ2OZ.js";
6
+ } from "../chunks/chunk-A7DLJUA6.js";
7
7
  import {
8
8
  recordBase
9
9
  } from "../chunks/chunk-U5AK6OJM.js";
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  Outbound,
4
4
  createOutbound,
5
5
  fullJitterBackoff
6
- } from "./chunks/chunk-RQLOPMMR.js";
6
+ } from "./chunks/chunk-MEEJIIIA.js";
7
7
  import {
8
8
  MemoryRateLimitStore
9
9
  } from "./chunks/chunk-4O2HRTTI.js";
@@ -22,7 +22,7 @@ import {
22
22
  senderHealthSchema,
23
23
  tagSchema,
24
24
  webhookSubscriptionSchema
25
- } from "./chunks/chunk-RMAHQ2OZ.js";
25
+ } from "./chunks/chunk-A7DLJUA6.js";
26
26
  import "./chunks/chunk-PTZO4QXR.js";
27
27
  import {
28
28
  defineNative
@@ -18,7 +18,7 @@ import {
18
18
  total,
19
19
  wilson,
20
20
  zScore
21
- } from "../chunks/chunk-XMCNRU4H.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";
@@ -993,9 +993,9 @@ export interface InsightInputs {
993
993
  */
994
994
  readonly max_bounce_rate?: number | undefined;
995
995
  /**
996
- * The most leads to read per active campaign, for leads left
996
+ * The most leads to read per active campaign, for leads left. Where the tool lists active leads alone (leads.byStatus), only those are read.
997
997
  *
998
- * A whole number from 1 to 50,000. Defaults to `500`.
998
+ * A whole number from 1 to 50,000. Defaults to `5000`.
999
999
  */
1000
1000
  readonly max_leads_per_campaign?: number | undefined;
1001
1001
  /**
@@ -51,6 +51,12 @@ export interface ForecastOptions {
51
51
  readonly leadsInput: string;
52
52
  /** What `maxLeads` counts, for that note: `leads`, or `leads of a campaign`. */
53
53
  readonly leadsWhat: string;
54
+ /**
55
+ * Read only the active leads where the campaign's tool can list them
56
+ * (`leads.byStatus`), since only they decide the runway. `byStatus` then
57
+ * counts the active leads alone.
58
+ */
59
+ readonly activeOnly?: boolean | undefined;
54
60
  }
55
61
  /** Reads one campaign's leads, totals and recent pace, and projects what is left. */
56
62
  /** How long a campaign's leads last: its leads by status and the recent pace of new leads started. */
@@ -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";
@@ -463,6 +463,9 @@ var capabilities = {
463
463
  // The `filter` field of POST /leads/list, one positive interest status
464
464
  // (FILTER_LEAD_INTERESTED and the rest) after another.
465
465
  "leads.byInterest": true,
466
+ // The `filter` FILTER_VAL_ACTIVE of POST /leads/list; the adapter keeps
467
+ // only the leads it maps to active, so the answer is exact either way.
468
+ "leads.byStatus": true,
466
469
  "leads.engagement": true,
467
470
  "leads.get": true,
468
471
  "leads.list": true,
@@ -1428,6 +1431,9 @@ var leadListBody = (query) => {
1428
1431
  if (query.domain !== void 0) {
1429
1432
  body.search = query.domain;
1430
1433
  }
1434
+ if (query.status === "active") {
1435
+ body.filter = "FILTER_VAL_ACTIVE";
1436
+ }
1431
1437
  if (query.interest === "positive") {
1432
1438
  const { after: after2, at } = interestAt(query.next);
1433
1439
  body.filter = POSITIVE_FILTERS[at] ?? null;
@@ -1464,7 +1470,7 @@ var listLeads = async (client, query, ctx) => {
1464
1470
  var chosen = (query, leads) => {
1465
1471
  const wanted = new Set(query.emails);
1466
1472
  return leads.filter(
1467
- (lead) => (query.email === void 0 || lead.email === query.email) && (query.emails === void 0 || lead.email !== null && wanted.has(lead.email)) && (query.domain === void 0 || lead.email?.split("@").at(-1) === query.domain) && (query.interest === void 0 || lead.interestCategory === "positive")
1473
+ (lead) => (query.email === void 0 || lead.email === query.email) && (query.emails === void 0 || lead.email !== null && wanted.has(lead.email)) && (query.domain === void 0 || lead.email?.split("@").at(-1) === query.domain) && (query.interest === void 0 || lead.interestCategory === "positive") && (query.status === void 0 || lead.status === query.status)
1468
1474
  );
1469
1475
  };
1470
1476
  var nextOf = (query, envelope) => {
@@ -74,6 +74,8 @@ export interface LeadQuery extends PageQuery, TimeRange {
74
74
  readonly emails?: readonly string[] | undefined;
75
75
  /** `positive`: only the leads the vendor labels positive, whose `interestCategory` is `positive`. */
76
76
  readonly interest?: "positive" | undefined;
77
+ /** `active`: only the leads whose `status` is `active`. Never set together with `interest`. */
78
+ readonly status?: "active" | undefined;
77
79
  }
78
80
  export interface MessageQuery extends PageQuery, TimeRange {
79
81
  readonly campaignId?: string | undefined;
@@ -37,6 +37,8 @@ export interface Capabilities {
37
37
  "leads.lookupMany": boolean;
38
38
  /** List only the leads the vendor labels positive, without walking every lead. */
39
39
  "leads.byInterest": boolean;
40
+ /** List only the active leads, those still in the sequence, without walking every lead. */
41
+ "leads.byStatus": boolean;
40
42
  /** Leads carry open, click and reply counts. */
41
43
  "leads.engagement": boolean;
42
44
  /** List the saved lead lists. */
@@ -108,6 +108,8 @@ export interface LeadFilters extends TimeRange {
108
108
  readonly emails?: readonly string[] | undefined;
109
109
  /** `positive`: only the leads the vendor labels positive (`interestCategory` `positive`). Needs `leads.byInterest`. */
110
110
  readonly interest?: "positive" | undefined;
111
+ /** `active`: only the leads still in the sequence (`status` `active`). Needs `leads.byStatus`. Not together with `interest`. */
112
+ readonly status?: "active" | undefined;
111
113
  }
112
114
  export interface WebhookFilters {
113
115
  readonly campaignId?: string | undefined;
@@ -3,7 +3,7 @@ import {
3
3
  configuredProviders,
4
4
  fromEnv,
5
5
  loadableProviders
6
- } from "../chunks/chunk-7TASUWPC.js";
6
+ } from "../chunks/chunk-5XLR6XVV.js";
7
7
  import "../chunks/chunk-NFWWA7MI.js";
8
8
  import "../chunks/chunk-XYHM4KHC.js";
9
9
  import "../chunks/chunk-45TXPJW7.js";
@@ -424,6 +424,7 @@ var FULL_CAPABILITIES = {
424
424
  "campaigns.status": "server",
425
425
  "leads.byCampaign": true,
426
426
  "leads.byDomain": true,
427
+ "leads.byStatus": true,
427
428
  "leads.engagement": true,
428
429
  "leads.get": true,
429
430
  "leads.list": true,
@@ -468,6 +469,9 @@ var selectMessages = (store, query, key) => (store.data.messages ?? []).filter(
468
469
  var selectLeads = (store, query) => (store.data.leads ?? []).filter(
469
470
  (lead) => (query.campaignId === void 0 || lead.campaignId === query.campaignId) && (query.listId === void 0 || (lead.listIds ?? []).includes(query.listId)) && (query.email === void 0 || lead.email?.trim().toLowerCase() === query.email) && (query.domain === void 0 || lead.email?.trim().toLowerCase().split("@").at(-1) === query.domain) && (query.linkedinUrl === void 0 || profileSlug(lead.linkedinUrl) !== null && profileSlug(lead.linkedinUrl) === profileSlug(query.linkedinUrl)) && (!filtersByTime(store, "leads.since") || within(lead.createdAt, query))
470
471
  );
472
+ var selectedLeads = (store, query) => selectLeads(store, query).map((seed) => toLead(store.identity, seed)).filter(
473
+ (lead) => query.status === void 0 || lead.status === query.status
474
+ );
471
475
  var getters = (store) => {
472
476
  const { data, identity } = store;
473
477
  return {
@@ -503,16 +507,7 @@ var listers = (store) => {
503
507
  pageSize
504
508
  )
505
509
  ),
506
- listLeads: (query) => {
507
- const seeds = selectLeads(store, query);
508
- return Promise.resolve(
509
- paginate(
510
- seeds.map((seed) => toLead(identity, seed)),
511
- query,
512
- pageSize
513
- )
514
- );
515
- },
510
+ listLeads: (query) => Promise.resolve(paginate(selectedLeads(store, query), query, pageSize)),
516
511
  listMessages: (query) => Promise.resolve(
517
512
  paginate(
518
513
  selectMessages(store, query, "messages.since").map(
@@ -232,12 +232,25 @@ var remasked = (known, error) => new OutboundError(error.code, known.remask(erro
232
232
  status: error.status,
233
233
  timedOut: error.timedOut
234
234
  });
235
+ var unmaskedQuery = (known, query) => {
236
+ if (JSON.stringify(query).match(TOKEN) === null) {
237
+ return void 0;
238
+ }
239
+ const fields = query;
240
+ return Object.fromEntries(
241
+ Object.entries(fields).map(([key, value]) => [
242
+ key,
243
+ maskEach(value, (text) => known.unmask(text))
244
+ ])
245
+ );
246
+ };
235
247
  var unmasked = (known, operation) => {
236
- if (!("id" in operation)) {
237
- return operation;
248
+ if ("id" in operation) {
249
+ const id = known.unmask(operation.id);
250
+ return id === operation.id ? operation : { ...operation, id };
238
251
  }
239
- const id = known.unmask(operation.id);
240
- return id === operation.id ? operation : { ...operation, id };
252
+ const query = unmaskedQuery(known, operation.query);
253
+ return query === void 0 ? operation : { ...operation, query };
241
254
  };
242
255
  var redact = (options = {}) => {
243
256
  const fields = new Set(options.fields ?? ALL_FIELDS);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "outbound-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "One small, typed, read-only API over outbound sending tools.",
5
5
  "keywords": [
6
6
  "cold-email",