outbound-sdk 0.1.0 → 0.2.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.
Files changed (145) hide show
  1. package/README.md +0 -2
  2. package/dist/alerts/index.js +5 -1
  3. package/dist/audit/index.js +2 -2
  4. package/dist/benchmarks/index.js +5 -3
  5. package/dist/budget/index.js +31 -10
  6. package/dist/cache/index.js +2 -2
  7. package/dist/cards/index.js +1 -1
  8. package/dist/chunks/{chunk-WAM6N4OF.js → chunk-4PSO6JEK.js} +107 -19
  9. package/dist/chunks/chunk-6CVZOUHB.js +152 -0
  10. package/dist/chunks/{chunk-OCV66TS2.js → chunk-AFU5E5QB.js} +17 -8
  11. package/dist/chunks/{chunk-R6AM4GJR.js → chunk-DJ2IUQEU.js} +24 -18
  12. package/dist/chunks/{chunk-LOXBLQ3I.js → chunk-E7JHLNLG.js} +9 -2
  13. package/dist/chunks/{chunk-LNCOGBMI.js → chunk-FHKSLCVW.js} +13 -3
  14. package/dist/chunks/chunk-FKH5N47I.js +40 -0
  15. package/dist/chunks/chunk-HZCTYL22.js +29 -0
  16. package/dist/chunks/{chunk-CMQ5ZHLZ.js → chunk-IPUYZD4O.js} +1 -1
  17. package/dist/chunks/{chunk-VURTOVGI.js → chunk-IVH3NMQZ.js} +1 -1
  18. package/dist/chunks/{chunk-ZGHQYZEH.js → chunk-LVYG7XZJ.js} +1 -1
  19. package/dist/chunks/chunk-NAKXLBA6.js +30 -0
  20. package/dist/chunks/{chunk-7BCYLIDG.js → chunk-PMSSUWD7.js} +186 -33
  21. package/dist/chunks/{chunk-Q465X22Y.js → chunk-PURHK3JU.js} +93 -209
  22. package/dist/chunks/{chunk-F7MKFVIG.js → chunk-R3Y56YVF.js} +2 -2
  23. package/dist/chunks/chunk-RCZ7ZZFU.js +92 -0
  24. package/dist/chunks/chunk-SBIZDCRY.js +106 -0
  25. package/dist/chunks/{chunk-IBC52BX3.js → chunk-U2D34ARZ.js} +20 -3
  26. package/dist/chunks/chunk-UAT3JSJZ.js +331 -0
  27. package/dist/chunks/{chunk-QZNNCXXD.js → chunk-VQSCHOBV.js} +20 -1
  28. package/dist/chunks/{chunk-B7V6EOAC.js → chunk-XNFESPZH.js} +160 -126
  29. package/dist/chunks/{chunk-WW746NJF.js → chunk-YOTW5ESM.js} +25 -1
  30. package/dist/cli/bin.js +14 -13
  31. package/dist/cli/commands.d.ts +3 -0
  32. package/dist/cli/config.d.ts +22 -0
  33. package/dist/cli/index.d.ts +5 -1
  34. package/dist/cli/index.js +20 -15
  35. package/dist/cli/stdio.d.ts +9 -0
  36. package/dist/clients/index.js +13 -3
  37. package/dist/combine/account.d.ts +1 -1
  38. package/dist/combine/index.js +90 -15
  39. package/dist/combine/route.d.ts +7 -0
  40. package/dist/exporter/index.js +2 -2
  41. package/dist/failover/index.js +4 -4
  42. package/dist/fixtures/index.js +40 -21
  43. package/dist/heyreach/account.d.ts +1 -1
  44. package/dist/heyreach/adapter.d.ts +1 -1
  45. package/dist/heyreach/capabilities.d.ts +2 -0
  46. package/dist/heyreach/client.d.ts +3 -5
  47. package/dist/heyreach/index.d.ts +7 -0
  48. package/dist/heyreach/index.js +428 -205
  49. package/dist/heyreach/leads.d.ts +4 -0
  50. package/dist/heyreach/map-account.d.ts +7 -1
  51. package/dist/heyreach/map-stats.d.ts +8 -5
  52. package/dist/heyreach/map.d.ts +3 -1
  53. package/dist/heyreach/webhooks.d.ts +1 -0
  54. package/dist/identity/index.js +22 -11
  55. package/dist/index.d.ts +1 -4
  56. package/dist/index.js +29 -17
  57. package/dist/insights/copy/index.d.ts +2 -2
  58. package/dist/insights/copy/variant-test.d.ts +2 -2
  59. package/dist/insights/index.js +248 -184
  60. package/dist/insights/ops/anomalies.d.ts +3 -3
  61. package/dist/insights/ops/index.d.ts +2 -2
  62. package/dist/insights/ops/shared.d.ts +7 -1
  63. package/dist/insights/registry.d.ts +4 -4
  64. package/dist/instantly/adapter-account.d.ts +1 -1
  65. package/dist/instantly/capabilities.d.ts +2 -0
  66. package/dist/instantly/client.d.ts +4 -9
  67. package/dist/instantly/index.d.ts +7 -0
  68. package/dist/instantly/index.js +410 -155
  69. package/dist/instantly/map-account.d.ts +20 -5
  70. package/dist/instantly/map-stats.d.ts +9 -6
  71. package/dist/instantly/map.d.ts +0 -2
  72. package/dist/instantly/native-agents-sales.d.ts +41 -41
  73. package/dist/instantly/native-agents.d.ts +44 -44
  74. package/dist/instantly/native-campaigns.d.ts +21 -21
  75. package/dist/instantly/native-leads.d.ts +12 -12
  76. package/dist/instantly/native-params.d.ts +2 -19
  77. package/dist/instantly/native-search.d.ts +10 -10
  78. package/dist/instantly/native-senders.d.ts +56 -56
  79. package/dist/instantly/native-supersearch.d.ts +33 -33
  80. package/dist/instantly/native-workspace.d.ts +45 -45
  81. package/dist/instantly/native.d.ts +262 -262
  82. package/dist/instantly/webhooks.d.ts +1 -0
  83. package/dist/internal/adapter.d.ts +24 -2
  84. package/dist/internal/capabilities.d.ts +18 -0
  85. package/dist/internal/client.d.ts +15 -0
  86. package/dist/internal/concurrency.d.ts +8 -0
  87. package/dist/internal/engine/request.d.ts +7 -0
  88. package/dist/internal/entities-account.d.ts +73 -3
  89. package/dist/internal/entities.d.ts +116 -12
  90. package/dist/internal/errors.d.ts +6 -1
  91. package/dist/internal/fields.d.ts +462 -0
  92. package/dist/internal/json.d.ts +9 -0
  93. package/dist/internal/lead-fields.d.ts +21 -0
  94. package/dist/internal/lead-status.d.ts +13 -0
  95. package/dist/internal/metrics.d.ts +14 -2
  96. package/dist/internal/native.d.ts +15 -0
  97. package/dist/internal/outbound/api.d.ts +29 -4
  98. package/dist/internal/outbound/operations-account.d.ts +12 -0
  99. package/dist/internal/outbound/outbound.d.ts +6 -3
  100. package/dist/internal/outbound/specs-account.d.ts +5 -1
  101. package/dist/internal/page.d.ts +14 -0
  102. package/dist/internal/record.d.ts +17 -0
  103. package/dist/internal/records.d.ts +7 -0
  104. package/dist/internal/sequence.d.ts +14 -0
  105. package/dist/internal/sha256.d.ts +2 -0
  106. package/dist/loader/index.d.ts +14 -2
  107. package/dist/loader/index.js +8 -4
  108. package/dist/memory/account-reads.d.ts +1 -1
  109. package/dist/memory/account.d.ts +15 -1
  110. package/dist/memory/data.d.ts +17 -2
  111. package/dist/memory/index.js +110 -35
  112. package/dist/redact/index.js +11 -6
  113. package/dist/redact/plugin.d.ts +1 -1
  114. package/dist/smartlead/account.d.ts +1 -1
  115. package/dist/smartlead/adapter.d.ts +1 -1
  116. package/dist/smartlead/capabilities.d.ts +2 -0
  117. package/dist/smartlead/client.d.ts +6 -11
  118. package/dist/smartlead/hmac.d.ts +0 -2
  119. package/dist/smartlead/index.d.ts +7 -0
  120. package/dist/smartlead/index.js +731 -572
  121. package/dist/smartlead/leads.d.ts +4 -1
  122. package/dist/smartlead/map-account.d.ts +17 -5
  123. package/dist/smartlead/map-stats.d.ts +9 -10
  124. package/dist/smartlead/map.d.ts +15 -5
  125. package/dist/smartlead/native-analytics.d.ts +87 -87
  126. package/dist/smartlead/native-campaigns.d.ts +64 -64
  127. package/dist/smartlead/native-inbox.d.ts +51 -51
  128. package/dist/smartlead/native-params.d.ts +2 -23
  129. package/dist/smartlead/native-services.d.ts +34 -34
  130. package/dist/smartlead/native.d.ts +236 -236
  131. package/dist/smartlead/shared.d.ts +6 -5
  132. package/dist/smartlead/webhooks.d.ts +1 -0
  133. package/dist/sync/index.js +3 -3
  134. package/dist/tools/ai-sdk.js +7 -5
  135. package/dist/tools/campaign-tools.d.ts +1 -1
  136. package/dist/tools/claude-agent.js +7 -5
  137. package/dist/tools/index.js +8 -6
  138. package/dist/tracing/index.js +2 -2
  139. package/dist/webhooks/index.js +10 -9
  140. package/package.json +1 -1
  141. package/dist/chunks/chunk-FZF6CLPX.js +0 -232
  142. package/dist/chunks/chunk-GPEJG34O.js +0 -53
  143. package/dist/chunks/chunk-HEC7XFFH.js +0 -65
  144. package/dist/chunks/chunk-QTB747K4.js +0 -100
  145. package/dist/chunks/chunk-TIJKJJDW.js +0 -6
@@ -1,20 +1,24 @@
1
+ import {
2
+ mapConcurrent
3
+ } from "../chunks/chunk-HZCTYL22.js";
1
4
  import {
2
5
  sumCounts
3
- } from "../chunks/chunk-WW746NJF.js";
6
+ } from "../chunks/chunk-YOTW5ESM.js";
4
7
  import {
5
8
  profileSlug
6
9
  } from "../chunks/chunk-NAWZ73QS.js";
7
10
  import {
8
11
  campaignStatusSchema,
9
12
  replyCategorySchema
10
- } from "../chunks/chunk-WAM6N4OF.js";
13
+ } from "../chunks/chunk-4PSO6JEK.js";
14
+ import "../chunks/chunk-LVYG7XZJ.js";
11
15
  import {
12
16
  OutboundError
13
- } from "../chunks/chunk-LOXBLQ3I.js";
17
+ } from "../chunks/chunk-E7JHLNLG.js";
14
18
  import {
15
19
  toJson,
16
20
  unknownKey
17
- } from "../chunks/chunk-QZNNCXXD.js";
21
+ } from "../chunks/chunk-VQSCHOBV.js";
18
22
 
19
23
  // src/insights/plugin.ts
20
24
  import { z as z31 } from "zod";
@@ -718,14 +722,19 @@ var spreadOf = (uses, minSent) => {
718
722
  };
719
723
  };
720
724
  var readPlacements = async (context, campaigns) => {
721
- const placements = [];
722
- for (const campaign of campaigns) {
725
+ const perCampaign = await mapConcurrent(campaigns, async (campaign) => {
723
726
  const handle = context.outbound.campaign(campaign.ref);
724
- const sequence2 = context.one(await handle.sequence());
725
- const rows = context.rows(await handle.stats({ scope: "step" }));
726
- placements.push(...placementsOf(campaign, sequence2, splitStats(rows)));
727
- }
728
- return placements;
727
+ const [sequence2, stats] = await Promise.all([
728
+ handle.sequence(),
729
+ handle.stats({ scope: "step" })
730
+ ]);
731
+ return placementsOf(
732
+ campaign,
733
+ context.one(sequence2),
734
+ splitStats(context.rows(stats))
735
+ );
736
+ });
737
+ return perCampaign.flat();
729
738
  };
730
739
  var copyReuse = defineInsight({
731
740
  description: "How the same piece of copy performs in different campaigns. Reads each campaign's sequence and step stats, matches variants by the hash of their subject and body, and returns every piece of copy used in two or more campaigns with its totals, its reply rate per campaign and the spread between its best and worst campaign, plus the copy with the highest pooled reply rate. Use it to tell a copy problem from an audience problem. Costs 2 requests per campaign plus the campaign listing. A null count means the vendor does not report it for that variant; it is never 0.",
@@ -1367,21 +1376,42 @@ var readTotals = async (context, campaign, range) => sumCounts(
1367
1376
  await context.outbound.campaign(campaign).stats({ from: range.from ?? void 0, to: range.to ?? void 0 })
1368
1377
  )
1369
1378
  );
1379
+ var readAllTotals = async (context, range) => {
1380
+ if (context.outbound.capabilities["stats.allCampaigns"] !== "full") {
1381
+ return void 0;
1382
+ }
1383
+ const rows = context.rows(
1384
+ await context.outbound.stats({
1385
+ from: range.from ?? void 0,
1386
+ scope: "campaign",
1387
+ to: range.to ?? void 0
1388
+ })
1389
+ );
1390
+ const byCampaign = /* @__PURE__ */ new Map();
1391
+ for (const row of rows) {
1392
+ byCampaign.set(row.scopeRef, [
1393
+ ...byCampaign.get(row.scopeRef) ?? [],
1394
+ row
1395
+ ]);
1396
+ }
1397
+ return new Map(
1398
+ [...byCampaign].map(([ref, counts]) => [ref, sumCounts(counts)])
1399
+ );
1400
+ };
1370
1401
  var readCampaignTotals = async (context, input27) => {
1371
1402
  const campaigns = await readCampaigns(
1372
1403
  context,
1373
1404
  input27.statuses,
1374
1405
  input27.max_campaigns
1375
1406
  );
1376
- const entries = [];
1377
- for (const campaign of campaigns) {
1378
- entries.push({
1407
+ const reported = campaigns.length > 1 ? await readAllTotals(context, input27) : void 0;
1408
+ return await mapConcurrent(
1409
+ campaigns,
1410
+ async (campaign) => ({
1379
1411
  campaign,
1380
- // oxlint-disable-next-line no-await-in-loop -- one campaign at a time keeps the rate budget predictable.
1381
- counts: await readTotals(context, campaign.ref, input27)
1382
- });
1383
- }
1384
- return entries;
1412
+ counts: reported?.get(campaign.ref) ?? await readTotals(context, campaign.ref, input27)
1413
+ })
1414
+ );
1385
1415
  };
1386
1416
  var readDaily = async (context, campaign, range) => {
1387
1417
  const options = { by: "day", from: range.from, to: range.to };
@@ -1919,7 +1949,7 @@ var rankCampaigns = (entries, metric, minSent) => {
1919
1949
  };
1920
1950
  };
1921
1951
  var campaignRanking = defineInsight({
1922
- description: "Which campaigns are best, ranked fairly: by the low end of the 95% Wilson interval of the reply rate (or positive reply rate; for bounce rate, by the high end, lowest first), so 2 replies from 10 sends cannot outrank 150 from 1,000. Use it to pick winners and losers across a workspace. Returns each campaign with its count, rate, interval and rank, the campaigns left out for too few sends, those whose count the vendor does not report (a null rate is unknown, not zero), and the gap between the top and the median. Costs one listing per status plus one stats request per campaign.",
1952
+ description: "Which campaigns are best, ranked fairly: by the low end of the 95% Wilson interval of the reply rate (or positive reply rate; for bounce rate, by the high end, lowest first), so 2 replies from 10 sends cannot outrank 150 from 1,000. Use it to pick winners and losers across a workspace. Returns each campaign with its count, rate, interval and rank, the campaigns left out for too few sends, those whose count the vendor does not report (a null rate is unknown, not zero), and the gap between the top and the median. Costs one listing per status plus one stats request per campaign (one for all of them on a vendor that reports every campaign in one call with every count).",
1923
1953
  inputSchema: input8,
1924
1954
  key: "campaignRanking",
1925
1955
  name: "campaign_ranking",
@@ -2023,7 +2053,7 @@ var compare = (groups, alpha) => {
2023
2053
  };
2024
2054
  };
2025
2055
  var channelMix = defineInsight({
2026
- description: "Email against LinkedIn: campaign totals added up per channel, with campaigns, leads contacted, messages sent, replies, positive replies, the reply rate with its 95% interval and, for LinkedIn, the connection acceptance rate; whether the difference in reply rate is more than chance (a two-proportion test); and the same numbers per tool. Use it to decide where to put volume. With one channel present it returns that channel and says there is nothing to compare. A null count is one the vendor does not report; a rate counts only the campaigns that report both its count and what it divides by, and a note names a group whose rate leaves campaigns out. Costs one listing per status plus one stats request per campaign.",
2056
+ description: "Email against LinkedIn: campaign totals added up per channel, with campaigns, leads contacted, messages sent, replies, positive replies, the reply rate with its 95% interval and, for LinkedIn, the connection acceptance rate; whether the difference in reply rate is more than chance (a two-proportion test); and the same numbers per tool. Use it to decide where to put volume. With one channel present it returns that channel and says there is nothing to compare. A null count is one the vendor does not report; a rate counts only the campaigns that report both its count and what it divides by, and a note names a group whose rate leaves campaigns out. Costs one listing per status plus one stats request per campaign (one for all of them on a vendor that reports every campaign in one call with every count).",
2027
2057
  inputSchema: input9,
2028
2058
  key: "channelMix",
2029
2059
  name: "channel_mix",
@@ -2140,21 +2170,21 @@ var compareAcross = (current, previous, alpha) => {
2140
2170
  var readPeriods = async (context, options) => {
2141
2171
  const current = lastDays(context.now, options.days);
2142
2172
  const previous = lastDays(context.now, options.days, 1);
2143
- const campaigns = [];
2144
2173
  const found = await readCampaigns(
2145
2174
  context,
2146
2175
  options.statuses,
2147
2176
  options.max_campaigns
2148
2177
  );
2149
- for (const campaign of found) {
2150
- campaigns.push({
2151
- campaign,
2152
- // oxlint-disable-next-line no-await-in-loop -- one campaign at a time keeps the rate budget predictable.
2153
- current: await readTotals(context, campaign.ref, current),
2154
- // oxlint-disable-next-line no-await-in-loop -- one campaign at a time keeps the rate budget predictable.
2155
- previous: await readTotals(context, campaign.ref, previous)
2156
- });
2157
- }
2178
+ const campaigns = await mapConcurrent(
2179
+ found,
2180
+ async (campaign) => {
2181
+ const [now, before] = await Promise.all([
2182
+ readTotals(context, campaign.ref, current),
2183
+ readTotals(context, campaign.ref, previous)
2184
+ ]);
2185
+ return { campaign, current: now, previous: before };
2186
+ }
2187
+ );
2158
2188
  return { campaigns, current, previous };
2159
2189
  };
2160
2190
  var totalOf = (campaigns, alpha) => compareAcross(
@@ -2383,23 +2413,26 @@ var readRunways = async (context, campaigns, options) => {
2383
2413
  if (!capabilities["leads.byCampaign"] || capabilities["stats.byDay"] === false) {
2384
2414
  return null;
2385
2415
  }
2386
- const runways = [];
2387
- for (const { campaign } of campaigns) {
2388
- if (campaign.status === "active") {
2389
- const forecast = await forecastCampaign(context, campaign, {
2390
- days: options.days,
2391
- maxLeads: options.max_leads_per_campaign
2392
- });
2393
- if (forecast.leadsComplete && forecast.daysLeft !== null && forecast.daysLeft <= options.runway_days) {
2394
- runways.push({
2395
- ...labelOf(campaign),
2396
- dailyContactRate: forecast.dailyContactRate,
2397
- daysLeft: forecast.daysLeft,
2398
- remaining: forecast.remaining
2399
- });
2416
+ const active = campaigns.flatMap(
2417
+ ({ campaign }) => campaign.status === "active" ? [campaign] : []
2418
+ );
2419
+ const forecasts = await mapConcurrent(active, async (campaign) => ({
2420
+ campaign,
2421
+ forecast: await forecastCampaign(context, campaign, {
2422
+ days: options.days,
2423
+ maxLeads: options.max_leads_per_campaign
2424
+ })
2425
+ }));
2426
+ const runways = forecasts.flatMap(
2427
+ ({ campaign, forecast }) => forecast.leadsComplete && forecast.daysLeft !== null && forecast.daysLeft <= options.runway_days ? [
2428
+ {
2429
+ ...labelOf(campaign),
2430
+ dailyContactRate: forecast.dailyContactRate,
2431
+ daysLeft: forecast.daysLeft,
2432
+ remaining: forecast.remaining
2400
2433
  }
2401
- }
2402
- }
2434
+ ] : []
2435
+ );
2403
2436
  return runways.toSorted((left, right) => left.daysLeft - right.daysLeft);
2404
2437
  };
2405
2438
  var actionsOf = (report) => {
@@ -2520,7 +2553,7 @@ var groupOf2 = (tag, entries) => {
2520
2553
  };
2521
2554
  var named = (group) => group.tag ?? "";
2522
2555
  var tagRollup = defineInsight({
2523
- description: "Results by campaign tag (for example one tag per client, offer or audience): for each tag the campaigns, messages sent, leads contacted, replies, positive replies and bounces, with reply, positive reply and bounce rates and their 95% intervals, sorted by the low end of the reply rate interval. A campaign with two tags counts in both; campaigns with none are grouped under a null tag. Tags under min_sent sends are listed apart. A null count is one the vendor does not report; a rate counts only the campaigns that report both its count and what it divides by, and a note names a tag whose rate leaves campaigns out. Costs one listing per status plus one stats request per campaign.",
2556
+ description: "Results by campaign tag (for example one tag per client, offer or audience): for each tag the campaigns, messages sent, leads contacted, replies, positive replies and bounces, with reply, positive reply and bounce rates and their 95% intervals, sorted by the low end of the reply rate interval. A campaign with two tags counts in both; campaigns with none are grouped under a null tag. Tags under min_sent sends are listed apart. A null count is one the vendor does not report; a rate counts only the campaigns that report both its count and what it divides by, and a note names a tag whose rate leaves campaigns out. Costs one listing per status plus one stats request per campaign (one for all of them on a vendor that reports every campaign in one call with every count).",
2524
2557
  inputSchema: input13,
2525
2558
  key: "tagRollup",
2526
2559
  name: "tag_rollup",
@@ -2633,7 +2666,7 @@ var positiveLabelsField = z16.array(z16.string().min(1)).default(DEFAULT_POSITIV
2633
2666
  var isPositive = (label, labels) => label === null ? null : labels.some(
2634
2667
  (each) => each.trim().toLowerCase() === label.trim().toLowerCase()
2635
2668
  );
2636
- var hasReplied = (lead) => lead.status === "replied" || (lead.engagement?.replies ?? 0) > 0 || (lead.engagement?.lastRepliedAt ?? null) !== null;
2669
+ var hasReplied = (lead) => lead.replied === true || (lead.engagement?.replies ?? 0) > 0 || (lead.engagement?.lastRepliedAt ?? null) !== null;
2637
2670
  var COUNTS = "no per-lead open, click or reply counts";
2638
2671
  var noteEngagement = (context, leads, effect) => {
2639
2672
  const { outbound } = context;
@@ -2961,29 +2994,29 @@ var droppedReplies = defineInsight({
2961
2994
  const conversations = conversationsOf(kept, readers);
2962
2995
  const dropped = [];
2963
2996
  let answered = 0;
2964
- let unchecked = 0;
2965
2997
  let tooRecent = 0;
2966
- for (const conversation of conversations) {
2967
- const timed = conversation.replies.some((each) => each.sentAt !== null);
2968
- if (conversation.by === null || !timed) {
2969
- unchecked += 1;
2970
- } else {
2971
- const messages = context.page(
2972
- // oxlint-disable-next-line no-await-in-loop -- one conversation at a time keeps the rate budget predictable.
2973
- await (conversation.by === "thread" ? context.outbound.thread(conversation.id).messages() : context.outbound.lead(conversation.id).timeline())
2974
- );
2975
- const found = toDropped(
2976
- unanswered(conversation.replies, messages),
2977
- conversation.by,
2978
- context.now
2979
- );
2980
- const old = found.filter(
2981
- (each) => each.hoursWaiting >= values.older_than_hours
2982
- );
2983
- dropped.push(...old);
2984
- answered += found.length === 0 ? 1 : 0;
2985
- tooRecent += found.length - old.length;
2986
- }
2998
+ const checkable = conversations.flatMap(
2999
+ (conversation) => conversation.by !== null && conversation.replies.some((each) => each.sentAt !== null) ? [{ ...conversation, by: conversation.by }] : []
3000
+ );
3001
+ const unchecked = conversations.length - checkable.length;
3002
+ const threads = await mapConcurrent(checkable, async (conversation) => ({
3003
+ conversation,
3004
+ messages: context.page(
3005
+ await (conversation.by === "thread" ? context.outbound.thread(conversation.id).messages() : context.outbound.lead(conversation.id).timeline())
3006
+ )
3007
+ }));
3008
+ for (const { conversation, messages } of threads) {
3009
+ const found = toDropped(
3010
+ unanswered(conversation.replies, messages),
3011
+ conversation.by,
3012
+ context.now
3013
+ );
3014
+ const old = found.filter(
3015
+ (each) => each.hoursWaiting >= values.older_than_hours
3016
+ );
3017
+ dropped.push(...old);
3018
+ answered += found.length === 0 ? 1 : 0;
3019
+ tooRecent += found.length - old.length;
2987
3020
  }
2988
3021
  const answer = {
2989
3022
  dropped: dropped.toSorted(
@@ -3035,7 +3068,7 @@ var capped = (count, points, cap) => count === null ? null : Math.min(count, cap
3035
3068
  var partsOf = (lead, values, now) => {
3036
3069
  const engagement = lead.engagement ?? null;
3037
3070
  const positive = isPositive(lead.interest, values.positive_labels);
3038
- const replies2 = engagement?.replies ?? (lead.status === "replied" ? 1 : null);
3071
+ const replies2 = engagement?.replies ?? (lead.replied === true ? 1 : null);
3039
3072
  const repliedAt = engagement?.lastRepliedAt ?? null;
3040
3073
  const age = repliedAt === null ? null : Math.max(0, now - Date.parse(repliedAt)) / DAY2 / values.recency_days;
3041
3074
  return {
@@ -3125,7 +3158,7 @@ var hotLeads = defineInsight({
3125
3158
  "scores rest on the interest label and the lead's status"
3126
3159
  );
3127
3160
  const open = leads.filter(
3128
- (lead) => lead.status !== "unsubscribed" && lead.status !== "bounced"
3161
+ (lead) => lead.unsubscribed !== true && lead.bounced !== true
3129
3162
  );
3130
3163
  const scored = open.flatMap((lead) => toHotLead(lead, values, context.now));
3131
3164
  const hot = scored.filter((lead) => lead.score > 0).toSorted(hottestFirst);
@@ -3165,6 +3198,10 @@ var keysOfLead = (lead) => {
3165
3198
  var filterFor = (key) => key.startsWith("email:") ? { email: key.slice("email:".length) } : {
3166
3199
  linkedinUrl: `https://www.linkedin.com/in/${key.slice("linkedin:".length)}`
3167
3200
  };
3201
+ var isRedacted = (outbound) => "redacted" in outbound;
3202
+ var maskedIdentifiers = (outbound) => isRedacted(outbound) ? outbound.redacted.fields.filter(
3203
+ (field) => field === "email" || field === "linkedin"
3204
+ ) : [];
3168
3205
  var findPerson = async (context, identifier, maxRecords) => {
3169
3206
  const first = personKey(identifier);
3170
3207
  if (first === null) {
@@ -3174,21 +3211,37 @@ var findPerson = async (context, identifier, maxRecords) => {
3174
3211
  { provider: context.outbound.provider }
3175
3212
  );
3176
3213
  }
3214
+ const masked = maskedIdentifiers(context.outbound);
3215
+ if (masked.length > 0) {
3216
+ throw new OutboundError(
3217
+ "Unsupported",
3218
+ `A person cannot be looked up while the redact plugin masks ${masked.join(" and ")}: the records could not be matched to the identifier`,
3219
+ { provider: context.outbound.provider }
3220
+ );
3221
+ }
3177
3222
  const keys = /* @__PURE__ */ new Set([first]);
3178
3223
  const asked = /* @__PURE__ */ new Set();
3179
3224
  const records = /* @__PURE__ */ new Map();
3180
- for (let next = [...keys].find((key) => !asked.has(key)); next !== void 0; next = [...keys].find((key) => !asked.has(key))) {
3181
- asked.add(next);
3182
- const leads = await context.all(
3183
- context.outbound.leads.listAll({ ...filterFor(next), max: maxRecords }),
3184
- `${maxRecords} records of the person`
3225
+ for (let round2 = [...keys].filter((key) => !asked.has(key)); round2.length > 0; round2 = [...keys].filter((key) => !asked.has(key))) {
3226
+ for (const key of round2) {
3227
+ asked.add(key);
3228
+ }
3229
+ const answers = await mapConcurrent(
3230
+ round2,
3231
+ (key) => context.all(
3232
+ context.outbound.leads.listAll({ ...filterFor(key), max: maxRecords }),
3233
+ `${maxRecords} records of the person`
3234
+ )
3185
3235
  );
3186
- for (const lead of leads) {
3187
- const leadKeys = keysOfLead(lead);
3188
- if (leadKeys.includes(next)) {
3189
- records.set(`${lead.ref} ${lead.campaignRef ?? ""}`, lead);
3190
- for (const key of leadKeys) {
3191
- keys.add(key);
3236
+ for (const [index, leads] of answers.entries()) {
3237
+ const asking = round2[index];
3238
+ for (const lead of leads) {
3239
+ const leadKeys = keysOfLead(lead);
3240
+ if (asking !== void 0 && leadKeys.includes(asking)) {
3241
+ records.set(`${lead.ref} ${lead.campaignRef ?? ""}`, lead);
3242
+ for (const key of leadKeys) {
3243
+ keys.add(key);
3244
+ }
3192
3245
  }
3193
3246
  }
3194
3247
  }
@@ -3271,15 +3324,15 @@ var leadCollisions = defineInsight({
3271
3324
  values.statuses,
3272
3325
  values.max_campaigns
3273
3326
  );
3274
- const entries = [];
3275
- for (const campaign of campaigns) {
3327
+ const perCampaign = await mapConcurrent(campaigns, async (campaign) => {
3276
3328
  const leads = await leadsOf(
3277
3329
  context,
3278
3330
  campaign.ref,
3279
3331
  values.max_leads_per_campaign
3280
3332
  );
3281
- entries.push(...leads.map((lead) => ({ campaign, lead })));
3282
- }
3333
+ return leads.map((lead) => ({ campaign, lead }));
3334
+ });
3335
+ const entries = perCampaign.flat();
3283
3336
  const collisions = groupPeople(entries).flatMap(toCollision).toSorted(worstFirst);
3284
3337
  const acrossTools = collisions.filter(
3285
3338
  (each) => each.scope === "across_tools"
@@ -3346,17 +3399,22 @@ var activityOf = (lead, messages) => {
3346
3399
  };
3347
3400
  };
3348
3401
  var timelineOf = async (context, timelines, lead) => {
3349
- const known2 = timelines.get(lead.ref);
3350
- const all = known2 ?? context.page(await context.outbound.lead(lead.ref).timeline());
3351
- timelines.set(lead.ref, all);
3352
- return all.filter(
3402
+ let all = timelines.get(lead.ref);
3403
+ if (all === void 0) {
3404
+ all = context.outbound.lead(lead.ref).timeline().then((page) => context.page(page));
3405
+ timelines.set(lead.ref, all);
3406
+ }
3407
+ const messages = await all;
3408
+ return messages.filter(
3353
3409
  (message) => message.campaignRef === null || lead.campaignRef === null || message.campaignRef === lead.campaignRef
3354
3410
  );
3355
3411
  };
3356
3412
  var summarize2 = async (context, timelines, lead) => {
3357
3413
  const { outbound } = context;
3358
- const messages = await timelineOf(context, timelines, lead);
3359
- const campaign = lead.campaignRef === null ? null : context.one(await outbound.campaigns.get(lead.campaignRef));
3414
+ const [messages, campaign] = await Promise.all([
3415
+ timelineOf(context, timelines, lead),
3416
+ lead.campaignRef === null ? null : outbound.campaigns.get(lead.campaignRef).then(context.one)
3417
+ ]);
3360
3418
  const { threadIsShort, ...activity } = activityOf(lead, messages);
3361
3419
  if (threadIsShort) {
3362
3420
  context.note(
@@ -3373,7 +3431,7 @@ var summarize2 = async (context, timelines, lead) => {
3373
3431
  lead: lead.ref,
3374
3432
  leadStatus: lead.status,
3375
3433
  provider: lead.provider,
3376
- replied: activity.replies > 0 || lead.status === "replied",
3434
+ replied: activity.replies > 0 || lead.replied === true,
3377
3435
  repliedSteps: repliedSteps(lead, messages)
3378
3436
  };
3379
3437
  };
@@ -3400,11 +3458,11 @@ var personSummary = defineInsight({
3400
3458
  next: "Use account_summary with their email domain to see everyone at the same company.",
3401
3459
  run: async (context, { max_campaigns: maxCampaigns, person }) => {
3402
3460
  const found = await findPerson(context, person, maxCampaigns);
3403
- const campaigns = [];
3404
3461
  const timelines = /* @__PURE__ */ new Map();
3405
- for (const lead of found.records) {
3406
- campaigns.push(await summarize2(context, timelines, lead));
3407
- }
3462
+ const campaigns = await mapConcurrent(
3463
+ found.records,
3464
+ (lead) => summarize2(context, timelines, lead)
3465
+ );
3408
3466
  const contacted = campaigns.filter((entry) => entry.messagesSent > 0);
3409
3467
  const replied = campaigns.filter((entry) => entry.replied);
3410
3468
  const summary = {
@@ -3663,12 +3721,15 @@ var suppressionCheck = defineInsight({
3663
3721
  );
3664
3722
  const violations = [];
3665
3723
  const byCampaign = [];
3666
- for (const campaign of campaigns) {
3667
- const leads = await leadsOf(
3724
+ const read = await mapConcurrent(campaigns, async (campaign) => ({
3725
+ campaign,
3726
+ leads: await leadsOf(
3668
3727
  context,
3669
3728
  campaign.ref,
3670
3729
  values.max_leads_per_campaign
3671
- );
3730
+ )
3731
+ }));
3732
+ for (const { campaign, leads } of read) {
3672
3733
  const found = leads.flatMap((lead) => {
3673
3734
  const hit = matchLead(lead, blocked);
3674
3735
  return hit === null ? [] : [toViolation(lead, campaign, hit)];
@@ -3809,30 +3870,31 @@ var whyUnknown = (row) => {
3809
3870
  };
3810
3871
  var senderReader = (context, range) => {
3811
3872
  const seen = /* @__PURE__ */ new Map();
3812
- return async (ref) => {
3813
- if (!seen.has(ref)) {
3814
- const [row] = context.rows(
3815
- await context.outbound.sender(ref).stats(range)
3816
- );
3817
- seen.set(ref, known(row));
3873
+ return (ref) => {
3874
+ let counts = seen.get(ref);
3875
+ if (counts === void 0) {
3876
+ counts = context.outbound.sender(ref).stats(range).then((stats) => known(context.rows(stats)[0]));
3877
+ seen.set(ref, counts);
3818
3878
  }
3819
- return seen.get(ref) ?? null;
3879
+ return counts;
3820
3880
  };
3821
3881
  };
3822
3882
  var sendersOver = async (context, campaign, options) => {
3823
3883
  const senders2 = await readCampaignSenders(context, campaign, options.max);
3824
- const over = [];
3825
- for (const sender of senders2) {
3826
- const counts = await options.read(sender.ref);
3827
- if (counts !== null && isOver(counts, options.threshold)) {
3828
- over.push({
3884
+ const read = await mapConcurrent(senders2, async (sender) => ({
3885
+ counts: await options.read(sender.ref),
3886
+ sender
3887
+ }));
3888
+ const over = read.flatMap(
3889
+ ({ counts, sender }) => counts !== null && isOver(counts, options.threshold) ? [
3890
+ {
3829
3891
  ...counts,
3830
3892
  address: sender.address,
3831
3893
  name: sender.name,
3832
3894
  sender: sender.ref
3833
- });
3834
- }
3835
- }
3895
+ }
3896
+ ] : []
3897
+ );
3836
3898
  return over.toSorted((left, right) => (right.rate ?? 0) - (left.rate ?? 0));
3837
3899
  };
3838
3900
  var canCheckSenders = (context, wanted) => {
@@ -3867,15 +3929,15 @@ var bounceWatch = defineInsight({
3867
3929
  );
3868
3930
  const withSenders = campaigns.length > 0 && canCheckSenders(context, options.include_senders);
3869
3931
  const read = senderReader(context, range);
3870
- const over = [];
3932
+ const overBy = [];
3871
3933
  const tooFewSends = [];
3872
3934
  const unknown = [];
3873
3935
  const counted = [];
3874
- for (const campaign of campaigns) {
3875
- const [row] = context.rows(
3876
- // oxlint-disable-next-line no-await-in-loop -- one campaign at a time keeps the rate budget predictable.
3877
- await outbound.campaign(campaign.ref).stats(range)
3878
- );
3936
+ const rows = await mapConcurrent(campaigns, async (campaign) => ({
3937
+ campaign,
3938
+ row: context.rows(await outbound.campaign(campaign.ref).stats(range))[0]
3939
+ }));
3940
+ for (const { campaign, row } of rows) {
3879
3941
  const counts = known(row);
3880
3942
  const entry = {
3881
3943
  campaign: campaign.ref,
@@ -3895,22 +3957,29 @@ var bounceWatch = defineInsight({
3895
3957
  } else {
3896
3958
  counted.push(counts);
3897
3959
  if (isOver(counts, threshold)) {
3898
- over.push({
3899
- ...entry,
3900
- ...counts,
3901
- finding: `${counts.bounced} of ${counts.sent} sends bounced (${counts.rate}), over the ${threshold} threshold.`,
3902
- senders: withSenders ? (
3903
- // oxlint-disable-next-line no-await-in-loop -- one campaign at a time keeps the rate budget predictable.
3904
- await sendersOver(context, campaign, {
3905
- max: options.max_senders_per_campaign,
3906
- read,
3907
- threshold
3908
- })
3909
- ) : null
3960
+ overBy.push({
3961
+ campaign,
3962
+ entry: {
3963
+ ...entry,
3964
+ ...counts,
3965
+ finding: `${counts.bounced} of ${counts.sent} sends bounced (${counts.rate}), over the ${threshold} threshold.`,
3966
+ senders: null
3967
+ }
3910
3968
  });
3911
3969
  }
3912
3970
  }
3913
3971
  }
3972
+ const over = await mapConcurrent(
3973
+ overBy,
3974
+ async ({ campaign, entry }) => withSenders ? {
3975
+ ...entry,
3976
+ senders: await sendersOver(context, campaign, {
3977
+ max: options.max_senders_per_campaign,
3978
+ read,
3979
+ threshold
3980
+ })
3981
+ } : entry
3982
+ );
3914
3983
  const bounced = total(counted.map((each) => each.bounced));
3915
3984
  const sent = total(counted.map((each) => each.sent));
3916
3985
  const byRate2 = (left, right) => (right.rate ?? -1) - (left.rate ?? -1);
@@ -4049,8 +4118,11 @@ var domainHealth = defineInsight({
4049
4118
  const byDomain = /* @__PURE__ */ new Map();
4050
4119
  const linkedinSeats = [];
4051
4120
  const mailboxesWithoutDomain = [];
4052
- for (const sender of senders2) {
4053
- const health = context.one(await outbound.sender(sender.ref).health());
4121
+ const checks = await mapConcurrent(senders2, async (sender) => ({
4122
+ health: context.one(await outbound.sender(sender.ref).health()),
4123
+ sender
4124
+ }));
4125
+ for (const { health, sender } of checks) {
4054
4126
  const domain = health.domain ?? domainOf2(sender.address);
4055
4127
  if (sender.kind === "linkedin") {
4056
4128
  linkedinSeats.push({
@@ -4149,15 +4221,13 @@ var dailyRows = async (context, campaigns, range) => {
4149
4221
  );
4150
4222
  return null;
4151
4223
  }
4152
- const rows = [];
4153
- for (const campaign of campaigns) {
4154
- rows.push(
4155
- ...context.rows(
4156
- // oxlint-disable-next-line no-await-in-loop -- one campaign at a time keeps the rate budget predictable.
4157
- await outbound.campaign(campaign.ref).stats({ ...range, by: "day" })
4158
- )
4159
- );
4160
- }
4224
+ const perCampaign = await mapConcurrent(
4225
+ campaigns,
4226
+ async (campaign) => context.rows(
4227
+ await outbound.campaign(campaign.ref).stats({ ...range, by: "day" })
4228
+ )
4229
+ );
4230
+ const rows = perCampaign.flat();
4161
4231
  context.note(
4162
4232
  "Average daily sends cover the active campaigns read, not the whole workspace."
4163
4233
  );
@@ -4254,10 +4324,10 @@ var senderCapacity = defineInsight({
4254
4324
  "senders"
4255
4325
  );
4256
4326
  const campaigns = await readCampaigns2(context, ["active"], maxCampaigns);
4257
- const reads = [];
4258
- for (const campaign of campaigns) {
4259
- reads.push(await readOne(context, campaign, maxSenders));
4260
- }
4327
+ const reads = await mapConcurrent(
4328
+ campaigns,
4329
+ (campaign) => readOne(context, campaign, maxSenders)
4330
+ );
4261
4331
  const hasSettings = capabilities["campaigns.settings"];
4262
4332
  const canCompare = hasSettings && capabilities["senders.byCampaign"];
4263
4333
  if (!hasSettings) {
@@ -4350,12 +4420,11 @@ var senderLoad = defineInsight({
4350
4420
  const known2 = new Map(senders2.map((sender) => [sender.ref, sender]));
4351
4421
  const attached = /* @__PURE__ */ new Map();
4352
4422
  const risks = [];
4353
- for (const campaign of campaigns) {
4354
- const own = await readCampaignSenders(
4355
- context,
4356
- campaign,
4357
- options.max_senders
4358
- );
4423
+ const read = await mapConcurrent(campaigns, async (campaign) => ({
4424
+ campaign,
4425
+ own: await readCampaignSenders(context, campaign, options.max_senders)
4426
+ }));
4427
+ for (const { campaign, own } of read) {
4359
4428
  const risk = riskOf(campaign, own);
4360
4429
  if (risk !== null) {
4361
4430
  risks.push(risk);
@@ -4588,30 +4657,26 @@ var settingsAudit = defineInsight({
4588
4657
  "The daily limit was not compared with the sender count: the adapter cannot list a campaign's senders."
4589
4658
  );
4590
4659
  }
4591
- const audited = [];
4592
- for (const campaign of campaigns) {
4593
- const settings = context.one(
4594
- // oxlint-disable-next-line no-await-in-loop -- one campaign at a time keeps the rate budget predictable.
4595
- await outbound.campaign(campaign.ref).settings()
4596
- );
4597
- const senders2 = countSenders ? (
4598
- // oxlint-disable-next-line no-await-in-loop -- one campaign at a time keeps the rate budget predictable.
4599
- await readCampaignSenders(
4600
- context,
4601
- campaign,
4602
- options.max_senders_per_campaign
4603
- )
4604
- ) : null;
4605
- audited.push(
4606
- audit({
4660
+ const audited = await mapConcurrent(
4661
+ campaigns,
4662
+ async (campaign) => {
4663
+ const [settings, senders2] = await Promise.all([
4664
+ outbound.campaign(campaign.ref).settings(),
4665
+ countSenders ? readCampaignSenders(
4666
+ context,
4667
+ campaign,
4668
+ options.max_senders_per_campaign
4669
+ ) : null
4670
+ ]);
4671
+ return audit({
4607
4672
  bars,
4608
4673
  campaign,
4609
4674
  senders: senders2?.length ?? null,
4610
- settings,
4675
+ settings: context.one(settings),
4611
4676
  today: dayFrom(context.now, 0)
4612
- })
4613
- );
4614
- }
4677
+ });
4678
+ }
4679
+ );
4615
4680
  const flagged = audited.filter((campaign) => campaign.findings.length > 0).toSorted(worstFirst3);
4616
4681
  const sum = (severity) => flagged.reduce((all, campaign) => all + countOf2(campaign, severity), 0);
4617
4682
  const answer = {
@@ -4729,14 +4794,13 @@ var warmupReadiness = defineInsight({
4729
4794
  "DNS records and warmup spam were not checked: the adapter cannot read a sender's health."
4730
4795
  );
4731
4796
  }
4732
- const judged = [];
4733
- for (const sender of senders2) {
4734
- const health = healthChecked && sender.kind === "mailbox" ? (
4735
- // oxlint-disable-next-line no-await-in-loop -- one sender at a time keeps the rate budget predictable.
4736
- context.one(await outbound.sender(sender.ref).health())
4737
- ) : null;
4738
- judged.push(judge2(sender, health, bars));
4739
- }
4797
+ const judged = await mapConcurrent(
4798
+ senders2,
4799
+ async (sender) => {
4800
+ const health = healthChecked && sender.kind === "mailbox" ? context.one(await outbound.sender(sender.ref).health()) : null;
4801
+ return judge2(sender, health, bars);
4802
+ }
4803
+ );
4740
4804
  const notReady = judged.filter((sender) => sender.reasons.length > 0).toSorted((left, right) => right.reasons.length - left.reasons.length);
4741
4805
  const answer = {
4742
4806
  byReason: countReasons(notReady),