outbound-sdk 0.6.0 → 0.7.1

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 (119) hide show
  1. package/dist/alerts/check-schema.d.ts +1 -1
  2. package/dist/alerts/index.js +6 -6
  3. package/dist/audit/index.js +2 -2
  4. package/dist/benchmarks/index.js +4 -4
  5. package/dist/budget/index.js +2 -2
  6. package/dist/cards/index.js +54 -44
  7. package/dist/chunks/{chunk-BLCJHP5H.js → chunk-45TXPJW7.js} +1 -0
  8. package/dist/chunks/chunk-4AVYRVN5.js +239 -0
  9. package/dist/chunks/{chunk-YYCT3NGV.js → chunk-65YAGEWZ.js} +24 -7
  10. package/dist/chunks/{chunk-3JOC5DGD.js → chunk-6NSCPTOY.js} +488 -127
  11. package/dist/chunks/{chunk-W22SDX6S.js → chunk-7I3EPR23.js} +3 -3
  12. package/dist/chunks/{chunk-MGR6HREO.js → chunk-BNDHEDHD.js} +2 -2
  13. package/dist/chunks/chunk-DNPNTD5W.js +81 -0
  14. package/dist/chunks/{chunk-53DCVFUB.js → chunk-FALWG5U3.js} +1 -0
  15. package/dist/chunks/{chunk-OLPMBRXM.js → chunk-GL7BABF2.js} +2 -2
  16. package/dist/chunks/{chunk-ZOAG2C6V.js → chunk-HIAK2GCI.js} +9 -2
  17. package/dist/chunks/{chunk-SXGCKCAR.js → chunk-I7DXXGNZ.js} +40 -9
  18. package/dist/chunks/{chunk-BK5SLY32.js → chunk-JRL3QRBS.js} +264 -76
  19. package/dist/chunks/{chunk-PHNQ3WC2.js → chunk-KTYTE2BU.js} +4 -3
  20. package/dist/chunks/{chunk-JWGSB7PT.js → chunk-LD6F46UT.js} +2 -2
  21. package/dist/chunks/{chunk-2D42TQFU.js → chunk-LVZGIKNF.js} +2 -2
  22. package/dist/chunks/{chunk-PQSTQKRD.js → chunk-M2VXGLLZ.js} +35 -2
  23. package/dist/chunks/{chunk-UWUPUMM2.js → chunk-MW4C6LTN.js} +2 -2
  24. package/dist/chunks/chunk-OK3GAZMT.js +51 -0
  25. package/dist/chunks/{chunk-BOWXGMN3.js → chunk-POBAY3TI.js} +80 -4
  26. package/dist/chunks/{chunk-J7DDZ4C2.js → chunk-QFC4ZHD3.js} +1 -1
  27. package/dist/chunks/{chunk-TFICTGM2.js → chunk-T5MJMW3R.js} +1 -1
  28. package/dist/chunks/{chunk-GFDNRWR3.js → chunk-UFQ4WMLU.js} +1 -1
  29. package/dist/chunks/{chunk-QAKJ76HB.js → chunk-YW6FFVSZ.js} +1 -1
  30. package/dist/cli/bin.js +14 -14
  31. package/dist/cli/by-name.d.ts +28 -0
  32. package/dist/cli/commands.d.ts +2 -1
  33. package/dist/cli/config.d.ts +3 -2
  34. package/dist/cli/envelope.d.ts +50 -0
  35. package/dist/cli/index.d.ts +5 -0
  36. package/dist/cli/index.js +13 -13
  37. package/dist/cli/listing.d.ts +13 -0
  38. package/dist/cli/native.d.ts +4 -0
  39. package/dist/cli/options.d.ts +88 -0
  40. package/dist/cli/output.d.ts +13 -1
  41. package/dist/cli/suggest.d.ts +10 -0
  42. package/dist/cli/update.d.ts +25 -2
  43. package/dist/clients/index.js +6 -6
  44. package/dist/combine/index.js +7 -7
  45. package/dist/emailbison/capabilities.d.ts +1 -0
  46. package/dist/emailbison/index.js +38 -14
  47. package/dist/emailbison/map-stats.d.ts +10 -0
  48. package/dist/exporter/index.js +2 -2
  49. package/dist/failover/index.js +2 -2
  50. package/dist/fixtures/index.js +4 -4
  51. package/dist/heyreach/capabilities.d.ts +3 -0
  52. package/dist/heyreach/index.js +34 -12
  53. package/dist/heyreach/map-account.d.ts +2 -2
  54. package/dist/identity/index.js +2 -2
  55. package/dist/index.js +9 -7
  56. package/dist/insights/copy/audit-samples.d.ts +24 -0
  57. package/dist/insights/copy/audit-variant.d.ts +34 -0
  58. package/dist/insights/copy/copy-audit.d.ts +26 -12
  59. package/dist/insights/copy/copy-preview.d.ts +16 -3
  60. package/dist/insights/copy/index.d.ts +6 -0
  61. package/dist/insights/copy/reply-timing.d.ts +4 -0
  62. package/dist/insights/copy/shared.d.ts +4 -1
  63. package/dist/insights/copy/step-funnel.d.ts +20 -6
  64. package/dist/insights/copy/variant-test.d.ts +2 -3
  65. package/dist/insights/index.js +1138 -589
  66. package/dist/insights/inputs.generated.d.ts +47 -11
  67. package/dist/insights/ops/campaign-diagnosis.d.ts +2 -0
  68. package/dist/insights/ops/diagnosis-checks.d.ts +20 -1
  69. package/dist/insights/ops/index.d.ts +2 -0
  70. package/dist/insights/ops/pipeline-forecast.d.ts +17 -6
  71. package/dist/insights/people/account-summary.d.ts +14 -1
  72. package/dist/insights/people/auto-replies.d.ts +14 -0
  73. package/dist/insights/people/dropped-replies.d.ts +1 -1
  74. package/dist/insights/people/hot-leads.d.ts +5 -1
  75. package/dist/insights/people/index.d.ts +4 -0
  76. package/dist/insights/people/lead-collisions.d.ts +11 -2
  77. package/dist/insights/people/person-summary.d.ts +19 -3
  78. package/dist/insights/people/personalization-gaps.d.ts +14 -8
  79. package/dist/insights/people/suppression-check.d.ts +9 -0
  80. package/dist/insights/registry.d.ts +12 -0
  81. package/dist/insights/step.d.ts +15 -0
  82. package/dist/insights/variables.d.ts +2 -0
  83. package/dist/instantly/capabilities.d.ts +4 -0
  84. package/dist/instantly/index.js +263 -53
  85. package/dist/instantly/map-stats.d.ts +4 -0
  86. package/dist/instantly/stats-tracking.d.ts +19 -0
  87. package/dist/instantly/thread.d.ts +9 -0
  88. package/dist/internal/adapter.d.ts +5 -0
  89. package/dist/internal/auto-reply.d.ts +20 -0
  90. package/dist/internal/capabilities.d.ts +2 -0
  91. package/dist/internal/entities-account.d.ts +1 -0
  92. package/dist/internal/entities.d.ts +79 -2
  93. package/dist/internal/fields.d.ts +37 -1
  94. package/dist/internal/metrics.d.ts +23 -1
  95. package/dist/internal/outbound/api.d.ts +2 -0
  96. package/dist/internal/records.d.ts +2 -2
  97. package/dist/internal/reply-people.d.ts +37 -0
  98. package/dist/internal/runway.d.ts +42 -0
  99. package/dist/internal/sender-screen.d.ts +9 -0
  100. package/dist/internal/tracking.d.ts +33 -0
  101. package/dist/loader/index.js +4 -4
  102. package/dist/memory/data.d.ts +2 -1
  103. package/dist/memory/index.js +23 -12
  104. package/dist/redact/index.js +3 -3
  105. package/dist/smartlead/capabilities.d.ts +4 -0
  106. package/dist/smartlead/index.js +152 -38
  107. package/dist/smartlead/map-account.d.ts +3 -0
  108. package/dist/smartlead/stats-tracking.d.ts +22 -0
  109. package/dist/sync/index.js +2 -2
  110. package/dist/tools/ai-sdk.js +8 -7
  111. package/dist/tools/by-name.d.ts +18 -0
  112. package/dist/tools/campaign-tools.d.ts +6 -2
  113. package/dist/tools/claude-agent.js +8 -7
  114. package/dist/tools/index.js +9 -8
  115. package/dist/tools/shared.d.ts +7 -0
  116. package/dist/tracing/index.js +2 -2
  117. package/dist/webhooks/index.js +12 -11
  118. package/package.json +1 -1
  119. package/dist/chunks/chunk-HWHI4LFY.js +0 -102
@@ -30,6 +30,9 @@ export declare const costs: {
30
30
  perPage: number;
31
31
  perWalk: number;
32
32
  };
33
+ "campaigns.progress": {
34
+ perPage: number;
35
+ };
33
36
  "campaigns.settings": {
34
37
  perPage: number;
35
38
  };
@@ -80,6 +83,7 @@ export declare const costs: {
80
83
  };
81
84
  stats: {
82
85
  perPage: number;
86
+ perPageAtMost: number;
83
87
  };
84
88
  "tags.list": {
85
89
  pageSize: number;
@@ -1,7 +1,16 @@
1
1
  import {
2
2
  EVENT_TYPES,
3
3
  instantlyEvents
4
- } from "../chunks/chunk-W22SDX6S.js";
4
+ } from "../chunks/chunk-7I3EPR23.js";
5
+ import {
6
+ applyTracking,
7
+ ownTracking,
8
+ unlessFailed
9
+ } from "../chunks/chunk-DNPNTD5W.js";
10
+ import {
11
+ answeredAtOnce,
12
+ detectAutoReply
13
+ } from "../chunks/chunk-OK3GAZMT.js";
5
14
  import {
6
15
  flatMapPage,
7
16
  mapPage,
@@ -14,10 +23,10 @@ import {
14
23
  listIn,
15
24
  toVariant,
16
25
  variantKey
17
- } from "../chunks/chunk-MGR6HREO.js";
26
+ } from "../chunks/chunk-BNDHEDHD.js";
18
27
  import {
19
28
  normalizeBody
20
- } from "../chunks/chunk-53DCVFUB.js";
29
+ } from "../chunks/chunk-FALWG5U3.js";
21
30
  import {
22
31
  defineNative,
23
32
  inBody,
@@ -31,28 +40,28 @@ import {
31
40
  recordBase,
32
41
  refTo,
33
42
  refsTo
34
- } from "../chunks/chunk-2D42TQFU.js";
35
- import "../chunks/chunk-BOWXGMN3.js";
43
+ } from "../chunks/chunk-LVZGIKNF.js";
44
+ import "../chunks/chunk-POBAY3TI.js";
36
45
  import {
37
46
  emptyCounts,
38
47
  metricRow,
39
48
  sumCounts
40
- } from "../chunks/chunk-PQSTQKRD.js";
49
+ } from "../chunks/chunk-M2VXGLLZ.js";
41
50
  import "../chunks/chunk-QGRZDTX4.js";
42
51
  import {
43
52
  assertWorkspaceId
44
- } from "../chunks/chunk-QAKJ76HB.js";
53
+ } from "../chunks/chunk-YW6FFVSZ.js";
45
54
  import "../chunks/chunk-NAWZ73QS.js";
46
55
  import "../chunks/chunk-FHKSLCVW.js";
47
56
  import {
48
57
  readEnv,
49
58
  requireCredential
50
- } from "../chunks/chunk-GFDNRWR3.js";
59
+ } from "../chunks/chunk-UFQ4WMLU.js";
51
60
  import {
52
61
  OutboundError,
53
62
  makeErrorMapper,
54
63
  requireObject
55
- } from "../chunks/chunk-J7DDZ4C2.js";
64
+ } from "../chunks/chunk-QFC4ZHD3.js";
56
65
  import {
57
66
  count,
58
67
  emailAddress,
@@ -67,7 +76,7 @@ import {
67
76
  text,
68
77
  timestamp,
69
78
  withoutKeys
70
- } from "../chunks/chunk-BLCJHP5H.js";
79
+ } from "../chunks/chunk-45TXPJW7.js";
71
80
 
72
81
  // src/instantly/map-account.ts
73
82
  var CLOCK = /^\d{2}:\d{2}$/u;
@@ -116,6 +125,7 @@ var toCampaignProgress = (identity, campaignId, raw) => ({
116
125
  inProgress: null,
117
126
  leads: count(raw.leads_count),
118
127
  notStarted: null,
128
+ skipped: null,
119
129
  stopped: null
120
130
  });
121
131
  var ACCOUNT_ISSUE = /* @__PURE__ */ new Map([
@@ -421,6 +431,9 @@ var capabilities = {
421
431
  // Instantly does not sign webhooks. Use a secret header or URL path.
422
432
  "events.verify": "secret",
423
433
  "leads.byCampaign": true,
434
+ // The `search` field of POST /leads/list, which matches whole words of the
435
+ // lead's email; the adapter keeps only addresses at exactly that domain.
436
+ "leads.byDomain": true,
424
437
  "leads.engagement": true,
425
438
  "leads.get": true,
426
439
  "leads.list": true,
@@ -478,6 +491,7 @@ var fields = {
478
491
  failed: false,
479
492
  inProgress: false,
480
493
  notStarted: false,
494
+ skipped: false,
481
495
  stopped: false
482
496
  },
483
497
  lead: {
@@ -486,6 +500,9 @@ var fields = {
486
500
  location: false,
487
501
  tags: false
488
502
  },
503
+ // No email carried is_auto_reply live: a fixed rule decides, and in a
504
+ // timeline the step comes from the send a reply answers.
505
+ message: { isAuto: "derived", isAutoSource: "derived" },
489
506
  metricRow: {
490
507
  connectionsAccepted: false,
491
508
  connectionsSent: false,
@@ -496,6 +513,7 @@ var fields = {
496
513
  },
497
514
  // A test has a creation time and a next run, and no start or end date.
498
515
  placementTest: { endsAt: false, startsAt: false },
516
+ reply: { isAuto: "derived", isAutoSource: "derived", leftCompany: "derived" },
499
517
  sender: { linkedinUrl: false },
500
518
  senderHealth: { blacklisted: false, checkedAt: false }
501
519
  };
@@ -518,6 +536,8 @@ var costs = {
518
536
  "campaigns.get": { perPage: 3 },
519
537
  // The campaigns, their tag assignments, then the tags' names.
520
538
  "campaigns.list": { pageSize: PAGE_SIZE, perPage: 3, perWalk: 1 },
539
+ // The per-campaign report, asked for one campaign.
540
+ "campaigns.progress": { perPage: 1 },
521
541
  "campaigns.settings": { perPage: 1 },
522
542
  // A custom interest label costs one more read of the label list, made only
523
543
  // when the lead or a page of leads holds one.
@@ -543,7 +563,10 @@ var costs = {
543
563
  "senders.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
544
564
  "sequence.get": { perPage: 1 },
545
565
  "sequence.subsequences": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
546
- stats: { perPage: 1 },
566
+ // The counts, then the tracking settings: the campaign, or for a workspace
567
+ // or mailbox the per-campaign report and the campaign listing. The bound
568
+ // is for up to 100 campaigns; each further 100 adds a listing page.
569
+ stats: { perPage: 2, perPageAtMost: 3 },
547
570
  "tags.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
548
571
  "webhooks.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
549
572
  "workspaces.list": { perPage: 1 }
@@ -554,7 +577,7 @@ var caveats = [
554
577
  "A lead's progress is its status when that is 1 (active), 2 (paused) or 3 (completed). Status -1 is bounced and -2 unsubscribed: they say what came back, so progress is then unknown. replied is email_reply_count above 0, and a lead that replied has the status replied whatever its progress.",
555
578
  "A placement test's kind reads type 1 as a one-time test and 2 as an automated one: the reference names the two kinds in that order and gives the numbers no names. A test's results stay native, because Instantly reports them as one row per test email.",
556
579
  "Instantly sends next_starting_after on a last page too (seen live), and the page after it is empty. A listing therefore ends one request late; the small lookups for tags and labels stop at the first page that is not full.",
557
- "A reply's category is read from the email's i_status using the lead interest status values (seen live: 0, 1, -1 and -2). A received email carries the lead's address but no lead id, so a reply's leadRef is null; a sent message has one. Instantly does not mark an email as automatic, so isAuto is null.",
580
+ `A reply's category is read from the email's i_status using the lead interest status values (seen live: 0, 1, -1 and -2). An email names its lead by address (lead_id was absent live), so a message's or reply's leadRef holds the lead's lowercased address, from lead or, on a received email, from_address_email. leads.get and leads.timeline take that ref; leads.get then returns the first record with the address, one of several when the person is in several campaigns. No live email carried the documented is_auto_reply and the email list cannot filter by it, so when it is missing isAuto is decided by a fixed rule (isAutoSource rule): a machine sender address (noreply, auto-responder, mailer-daemon), an automatic subject (OOO, Out of Office, Automatic reply, "is no longer at"), a canned autoresponder phrase in the body, or, in a timeline or thread, a reply within a minute of the send it answers. An Out of Office i_status counts as the vendor saying so. leftCompany is true when the reply says the person left or the contact changed. In a timeline or thread a received email takes its stepIndex from the send it answers, since its own step lags on the last step.`,
558
581
  "An email's step and a lead's last step are ids of the form sequence_step_variant, each counted from 0 (seen live, not documented); any other form gives a null step. Step analytics count steps from 0 too, and can hold a row with no step for counts Instantly could not tie to one.",
559
582
  "Whether reply_count includes automatic replies is not documented; replied uses the unique reply count and repliedAuto the unique automatic count.",
560
583
  "Open counts are returned even when a campaign has open tracking turned off, because the analytics response does not say whether tracking was on.",
@@ -568,6 +591,7 @@ var caveats = [
568
591
  "connected is true for an Active account and false for a Connection Error; every other account status is null.",
569
592
  "A lead's engagement.stepIndex is the last step sent, read from its status summary; lastOpenedAt is null when open tracking is off. A lead has no tags in Instantly, and the lead object was seen without a job title.",
570
593
  "A lead is found by email with the contacts filter of POST /leads/list, documented only as the emails a lead needs to have. Whether it compares whole addresses and ignores case is not documented and was not run live, so the adapter keeps only the records whose address equals the one asked for, and a page can hold fewer records than Instantly returned. One record comes back per campaign or list the address is in. A lead has no LinkedIn profile: a lookup by profile returns nothing and sends no request.",
594
+ "Leads at one domain are found with the search field of POST /leads/list, documented (read 2026-11-16) as matched against the lead's email and profile fields on whole words and the start of a value. Whether an address's domain counts as a whole word was not run live. The search also matches names, companies and titles, so the adapter keeps only the records whose address is at exactly that domain, and a page can hold fewer records than Instantly returned.",
571
595
  "A lead's interest is the documented label for lt_interest_status. A custom label costs one more read (lead-labels, first 100 labels), made only when a page holds a status that is not a built-in one; the same read gives a reply with a custom status its category.",
572
596
  "A listed lead list's size is null: the list object has no count. lists.get reads GET /lead-lists/{id}/verification-stats as well and takes total_leads from it, so one list by id costs two requests. kind is always leads.",
573
597
  "Native reads return what Instantly sends, unmapped. dfyAccounts never asks for passwords. Instantly refuses per-mailbox daily analytics (413) on a large workspace unless a mailbox is named, which the per-sender stats always do.",
@@ -621,10 +645,16 @@ var category = (value, labels) => {
621
645
  return INTEREST.get(code)?.[1] ?? SENTIMENT.get(text(labels.get(code)?.interest_status_label) ?? "");
622
646
  };
623
647
  var LEAD_PROGRESS = /* @__PURE__ */ new Map([
648
+ [-3, "skipped"],
624
649
  [1, "active"],
625
650
  [2, "paused"],
626
651
  [3, "completed"]
627
652
  ]);
653
+ var RECIPIENT_PROVIDER = new Map([
654
+ [1, "google"],
655
+ [2, "microsoft"],
656
+ ...[3, 8, 9, 10, 12, 13, 999].map((code) => [code, "other"])
657
+ ]);
628
658
  var BOUNCED = -1;
629
659
  var UNSUBSCRIBED = -2;
630
660
  var standing = (raw) => {
@@ -685,6 +715,7 @@ var toLead = (identity, raw, labels = NO_LABELS) => ({
685
715
  linkedinUrl: null,
686
716
  location: null,
687
717
  phone: text(raw.phone),
718
+ recipientMailProvider: RECIPIENT_PROVIDER.get(count(raw.esp_code) ?? Number.NaN) ?? null,
688
719
  // Instantly tags mailboxes and campaigns, never leads.
689
720
  tags: [],
690
721
  title: text(raw.job_title),
@@ -692,6 +723,7 @@ var toLead = (identity, raw, labels = NO_LABELS) => ({
692
723
  });
693
724
  var SCHEDULED = 4;
694
725
  var RECEIVED = 2;
726
+ var leadOf = (raw) => emailAddress(raw.lead) ?? (count(raw.ue_type) === RECEIVED ? emailAddress(raw.from_address_email) : null) ?? text(raw.lead_id);
695
727
  var messageFields = (identity, raw, includeBody) => {
696
728
  const body = field(raw.body, "html") ?? field(raw.body, "text");
697
729
  return {
@@ -699,7 +731,7 @@ var messageFields = (identity, raw, includeBody) => {
699
731
  ...normalizeBody(text(body), includeBody),
700
732
  campaignRef: refTo(identity, text(raw.campaign_id)),
701
733
  channel: "email",
702
- leadRef: refTo(identity, text(raw.lead_id)),
734
+ leadRef: refTo(identity, leadOf(raw)),
703
735
  senderRef: refTo(identity, emailAddress(raw.eaccount)),
704
736
  sentAt: timestamp(raw.timestamp_email) ?? timestamp(raw.timestamp_created),
705
737
  subject: text(raw.subject),
@@ -709,11 +741,36 @@ var messageFields = (identity, raw, includeBody) => {
709
741
  };
710
742
  var isScheduled = (raw) => count(raw.ue_type) === SCHEDULED;
711
743
  var isTruncated = (raw) => text(raw.body_fallback_reason) !== null;
712
- var toMessage = (identity, raw, includeBody) => ({
713
- ...messageFields(identity, raw, includeBody),
714
- direction: count(raw.ue_type) === RECEIVED ? "in" : "out"
715
- });
716
744
  var oneOrZero = (value) => flag(value) ?? (count(value) === null ? null : count(value) === 1);
745
+ var rawBody = (raw) => text(field(raw.body, "text")) ?? text(field(raw.body, "html")) ?? text(raw.content_preview);
746
+ var autoOf = (raw, mapped) => {
747
+ const verdict = detectAutoReply({
748
+ body: rawBody(raw),
749
+ from: text(raw.from_address_email),
750
+ subject: text(raw.subject)
751
+ });
752
+ const vendor = oneOrZero(raw.is_auto_reply) ?? (mapped === "ooo" ? true : null);
753
+ return {
754
+ isAuto: vendor ?? verdict.isAuto,
755
+ isAutoSource: vendor === null ? "rule" : "vendor",
756
+ leftCompany: verdict.leftCompany
757
+ };
758
+ };
759
+ var toMessage = (identity, raw, includeBody) => {
760
+ if (count(raw.ue_type) !== RECEIVED) {
761
+ return { ...messageFields(identity, raw, includeBody), direction: "out" };
762
+ }
763
+ const { isAuto, isAutoSource } = autoOf(
764
+ raw,
765
+ category(raw.i_status, NO_LABELS)
766
+ );
767
+ return {
768
+ ...messageFields(identity, raw, includeBody),
769
+ direction: "in",
770
+ isAuto,
771
+ isAutoSource
772
+ };
773
+ };
717
774
  var toReply = (identity, raw, includeBody, labels = NO_LABELS) => {
718
775
  const mapped = category(raw.i_status, labels);
719
776
  return {
@@ -721,7 +778,7 @@ var toReply = (identity, raw, includeBody, labels = NO_LABELS) => {
721
778
  category: mapped ?? "unknown",
722
779
  categorySource: mapped === void 0 ? null : "vendor",
723
780
  direction: "in",
724
- isAuto: oneOrZero(raw.is_auto_reply),
781
+ ...autoOf(raw, mapped),
725
782
  unread: oneOrZero(raw.is_unread)
726
783
  };
727
784
  };
@@ -855,6 +912,41 @@ var accountReaders = (client) => {
855
912
  };
856
913
  };
857
914
 
915
+ // src/instantly/thread.ts
916
+ var timeOf = (message) => message.sentAt === null ? Number.NaN : Date.parse(message.sentAt);
917
+ var answering = (message, answered) => {
918
+ const next = { ...message };
919
+ if (answered.stepIndex !== null) {
920
+ next.stepIndex = answered.stepIndex;
921
+ next.variantKey = answered.variantKey;
922
+ }
923
+ if (message.isAutoSource !== "vendor" && answeredAtOnce(answered.sentAt, message.sentAt)) {
924
+ next.isAuto = true;
925
+ next.isAutoSource = "rule";
926
+ }
927
+ return next;
928
+ };
929
+ var withAnsweredSteps = (messages) => {
930
+ const order = messages.flatMap(
931
+ (message, index) => Number.isNaN(timeOf(message)) ? [] : [{ index, message }]
932
+ ).toSorted(
933
+ (left, right) => timeOf(left.message) - timeOf(right.message) || left.index - right.index
934
+ );
935
+ const lastSent = /* @__PURE__ */ new Map();
936
+ const result = [...messages];
937
+ for (const { index, message } of order) {
938
+ const thread = message.threadId;
939
+ if (thread !== null && message.direction === "out") {
940
+ lastSent.set(thread, message);
941
+ }
942
+ const answered = thread === null || message.direction === "out" ? void 0 : lastSent.get(thread);
943
+ if (answered !== void 0) {
944
+ result[index] = answering(message, answered);
945
+ }
946
+ }
947
+ return result;
948
+ };
949
+
858
950
  // src/instantly/adapter-mail.ts
859
951
  var emailCursor = (next) => ({
860
952
  after: text(field(next, "after")) ?? void 0,
@@ -864,6 +956,10 @@ var leadAddress = async (client, ctx, leadId, cursor) => {
864
956
  if (leadId === void 0 || cursor.lead !== void 0) {
865
957
  return cursor.lead;
866
958
  }
959
+ const given = emailAddress(leadId);
960
+ if (given !== null) {
961
+ return given;
962
+ }
867
963
  const lead = await client.getObject(
868
964
  ctx,
869
965
  `/leads/${encodeURIComponent(leadId)}`
@@ -916,10 +1012,11 @@ var listEmails = async (client, ctx, query, received) => {
916
1012
  var mailReaders = (client) => ({
917
1013
  listMessages: async (query, ctx) => {
918
1014
  const page = await listEmails(client, ctx, query, false);
919
- return mapPage(
1015
+ const mapped = mapPage(
920
1016
  page,
921
1017
  (item) => toMessage(client.identity, item, query.includeBody)
922
1018
  );
1019
+ return { ...mapped, items: withAnsweredSteps(mapped.items) };
923
1020
  },
924
1021
  listReplies: async (query, ctx) => {
925
1022
  const page = await listEmails(client, ctx, query, true);
@@ -946,12 +1043,17 @@ var overviewRow = (scope, raw) => metricRow(scope, {
946
1043
  bounced: count(raw.bounced_count),
947
1044
  clicked: count(raw.link_click_count_unique),
948
1045
  clickedTotal: count(raw.link_click_count),
949
- contacted: count(raw.contacted_count),
1046
+ completed: count(raw.completed_count),
1047
+ contacted: count(raw.new_leads_contacted_count),
950
1048
  opened: count(raw.open_count_unique),
951
1049
  openedTotal: count(raw.open_count),
1050
+ opportunities: count(raw.total_opportunities),
1051
+ opportunityValue: count(raw.total_opportunity_value),
952
1052
  positive: count(raw.total_interested),
953
1053
  replied: count(raw.reply_count_unique),
954
1054
  repliedAuto: count(raw.reply_count_automatic_unique),
1055
+ repliedAutoTotal: count(raw.reply_count_automatic),
1056
+ repliedTotal: count(raw.reply_count),
955
1057
  sent: count(raw.emails_sent_count),
956
1058
  unsubscribed: count(raw.unsubscribed_count)
957
1059
  });
@@ -960,36 +1062,96 @@ var campaignRow = (scope, raw) => metricRow(scope, {
960
1062
  bounced: count(raw.bounced_count),
961
1063
  clicked: count(raw.link_click_count_unique),
962
1064
  clickedTotal: count(raw.link_click_count),
963
- contacted: count(raw.contacted_count),
1065
+ completed: count(raw.completed_count),
1066
+ contacted: count(raw.new_leads_contacted_count),
1067
+ leads: count(raw.leads_count),
964
1068
  opened: count(raw.open_count_unique),
1069
+ opportunities: count(raw.total_opportunities),
1070
+ opportunityValue: count(raw.total_opportunity_value),
965
1071
  replied: count(raw.reply_count_unique),
966
1072
  repliedAuto: count(raw.reply_count_automatic_unique),
1073
+ repliedAutoTotal: count(raw.reply_count_automatic),
1074
+ repliedTotal: count(raw.reply_count),
967
1075
  sent: count(raw.emails_sent_count),
968
1076
  unsubscribed: count(raw.unsubscribed_count)
969
1077
  });
970
- var dailyCounts = (raw) => ({
1078
+ var reportCounts = (raw, contacted) => ({
971
1079
  ...emptyCounts(),
972
1080
  bounced: count(raw.bounced),
973
1081
  clicked: count(raw.unique_clicks),
974
1082
  clickedTotal: count(raw.clicks),
975
- contacted: count(raw.contacted),
1083
+ contacted,
976
1084
  opened: count(raw.unique_opened),
977
1085
  openedTotal: count(raw.opened),
978
1086
  replied: count(raw.unique_replies),
979
1087
  repliedAuto: count(raw.unique_replies_automatic),
1088
+ repliedAutoTotal: count(raw.replies_automatic),
1089
+ repliedTotal: count(raw.replies),
980
1090
  sent: count(raw.sent)
981
1091
  });
1092
+ var dailyCounts = (raw) => reportCounts(raw, count(raw.new_leads_contacted));
982
1093
  var dailyRow = (scope, raw) => metricRow(scope, dailyCounts(raw), { date: text(raw.date) });
983
1094
  var summedRow = (scope, days2) => metricRow(scope, sumCounts(days2.map(dailyCounts)), { evidence: "derived" });
984
1095
  var stepRow = (scope, raw) => {
985
1096
  const step = count(raw.step);
986
1097
  const variant = count(raw.variant);
987
- return metricRow(scope, dailyCounts(raw), {
1098
+ return metricRow(scope, reportCounts(raw, count(raw.contacted)), {
988
1099
  stepIndex: step !== null && Number.isInteger(step) ? step : null,
989
1100
  variantKey: variant === null ? null : variantKey(variant)
990
1101
  });
991
1102
  };
992
1103
 
1104
+ // src/instantly/stats-tracking.ts
1105
+ var LISTING_PAGES = 10;
1106
+ var UNKNOWN = { clicks: null, opens: null };
1107
+ var trackingFlags = (raw) => ({
1108
+ clicks: flag(raw.link_tracking),
1109
+ opens: flag(raw.open_tracking)
1110
+ });
1111
+ var campaignFlags = async (client, ctx, campaignId) => await unlessFailed(
1112
+ async () => trackingFlags(
1113
+ await client.getObject(
1114
+ ctx,
1115
+ `/campaigns/${encodeURIComponent(campaignId)}`
1116
+ )
1117
+ )
1118
+ );
1119
+ var everyCampaignFlags = async (client, ctx) => await unlessFailed(async () => {
1120
+ const campaigns = await readLookup(client, ctx, {
1121
+ filters: {},
1122
+ pages: LISTING_PAGES,
1123
+ path: "/campaigns"
1124
+ });
1125
+ return new Map(
1126
+ campaigns.flatMap((campaign) => {
1127
+ const id = text(campaign.id);
1128
+ return id === null ? [] : [[id, trackingFlags(campaign)]];
1129
+ })
1130
+ );
1131
+ });
1132
+ var plus = (left, right) => left === null && right === null ? null : (left ?? 0) + (right ?? 0);
1133
+ var reportTracking = (raw, flags) => ({
1134
+ clicked: plus(
1135
+ count(raw.link_click_count_unique),
1136
+ count(raw.link_click_count)
1137
+ ),
1138
+ flags: flags ?? UNKNOWN,
1139
+ opened: plus(count(raw.open_count_unique), count(raw.open_count)),
1140
+ sent: count(raw.emails_sent_count)
1141
+ });
1142
+ var workspaceTracking = async (client, ctx, range2) => {
1143
+ const report = await unlessFailed(
1144
+ async () => await client.getRows(ctx, "/campaigns/analytics", { query: range2 })
1145
+ );
1146
+ if (report === null) {
1147
+ return null;
1148
+ }
1149
+ const flags = await everyCampaignFlags(client, ctx);
1150
+ return flags === null ? null : report.map(
1151
+ (raw) => reportTracking(raw, flags.get(text(raw.campaign_id) ?? ""))
1152
+ );
1153
+ };
1154
+
993
1155
  // src/instantly/stats.ts
994
1156
  var range = (query) => ({
995
1157
  end_date: query.to,
@@ -999,8 +1161,20 @@ var senderStats = async (client, ctx, scope, query) => {
999
1161
  const days2 = await client.getRows(ctx, "/accounts/analytics/daily", {
1000
1162
  query: { ...range(query), emails: scope.scopeId }
1001
1163
  });
1002
- return query.by === "day" ? days2.map((day) => dailyRow(scope, day)) : [summedRow(scope, days2)];
1164
+ const rows = query.by === "day" ? days2.map((day) => dailyRow(scope, day)) : [summedRow(scope, days2)];
1165
+ return applyTracking(
1166
+ rows,
1167
+ await workspaceTracking(client, ctx, range(query))
1168
+ );
1169
+ };
1170
+ var ownRows = async (client, ctx, campaignId, rows) => {
1171
+ const flags = await campaignFlags(client, ctx, campaignId);
1172
+ return applyTracking(
1173
+ rows,
1174
+ flags === null ? null : [ownTracking(flags, rows)]
1175
+ );
1003
1176
  };
1177
+ var judged = async (client, ctx, query, rows) => query.scopeId === void 0 ? applyTracking(rows, await workspaceTracking(client, ctx, range(query))) : await ownRows(client, ctx, query.scopeId, rows);
1004
1178
  var readStats = async (client, ctx, query) => {
1005
1179
  const { identity } = client;
1006
1180
  const scope = {
@@ -1022,9 +1196,17 @@ var readStats = async (client, ctx, query) => {
1022
1196
  const campaigns = await client.getRows(ctx, "/campaigns/analytics", {
1023
1197
  query: range(query)
1024
1198
  });
1199
+ const flags = await everyCampaignFlags(client, ctx);
1025
1200
  return campaigns.flatMap((campaign) => {
1026
1201
  const scopeId = text(campaign.campaign_id);
1027
- return scopeId === null ? [] : [campaignRow({ ...scope, scopeId }, campaign)];
1202
+ if (scopeId === null) {
1203
+ return [];
1204
+ }
1205
+ const row = campaignRow({ ...scope, scopeId }, campaign);
1206
+ return applyTracking(
1207
+ [row],
1208
+ flags === null ? null : [{ ...reportTracking(campaign, flags.get(scopeId)), sent: null }]
1209
+ );
1028
1210
  });
1029
1211
  }
1030
1212
  if (query.scope === "step") {
@@ -1040,13 +1222,23 @@ var readStats = async (client, ctx, query) => {
1040
1222
  const steps = await client.getRows(ctx, "/campaigns/analytics/steps", {
1041
1223
  query: { ...range(query), campaign_id: query.scopeId }
1042
1224
  });
1043
- return steps.map((step) => stepRow(scope, step));
1225
+ return await judged(
1226
+ client,
1227
+ ctx,
1228
+ query,
1229
+ steps.map((step) => stepRow(scope, step))
1230
+ );
1044
1231
  }
1045
1232
  if (query.by === "day") {
1046
1233
  const days2 = await client.getRows(ctx, "/campaigns/analytics/daily", {
1047
1234
  query: { ...range(query), campaign_id: query.scopeId }
1048
1235
  });
1049
- return days2.map((day) => dailyRow(scope, day));
1236
+ return await judged(
1237
+ client,
1238
+ ctx,
1239
+ query,
1240
+ days2.map((day) => dailyRow(scope, day))
1241
+ );
1050
1242
  }
1051
1243
  const overview = await client.getObject(
1052
1244
  ctx,
@@ -1055,7 +1247,7 @@ var readStats = async (client, ctx, query) => {
1055
1247
  query: { ...range(query), id: query.scopeId }
1056
1248
  }
1057
1249
  );
1058
- return [overviewRow(scope, overview)];
1250
+ return await judged(client, ctx, query, [overviewRow(scope, overview)]);
1059
1251
  };
1060
1252
 
1061
1253
  // src/instantly/adapter.ts
@@ -1177,13 +1369,54 @@ var leadListBody = (query) => {
1177
1369
  if (query.email !== void 0) {
1178
1370
  body.contacts = [query.email];
1179
1371
  }
1372
+ if (query.domain !== void 0) {
1373
+ body.search = query.domain;
1374
+ }
1180
1375
  if (isString(query.next)) {
1181
1376
  body.starting_after = query.next;
1182
1377
  }
1183
1378
  return body;
1184
1379
  };
1380
+ var listLeads = async (client, query, ctx) => {
1381
+ if (query.linkedinUrl !== void 0) {
1382
+ return { items: [] };
1383
+ }
1384
+ const envelope = listEnvelope(
1385
+ await client.post(ctx, "/leads/list", leadListBody(query)),
1386
+ client.identity.provider,
1387
+ "/leads/list"
1388
+ );
1389
+ const labels = await readLabels(
1390
+ client,
1391
+ ctx,
1392
+ envelope.items.map((item) => item.lt_interest_status)
1393
+ );
1394
+ const leads = envelope.items.map(
1395
+ (item) => toLead(client.identity, item, labels)
1396
+ );
1397
+ return {
1398
+ // `contacts` is documented as the emails a lead needs to have, but not
1399
+ // how it compares them, and `search` matches more than the address, so
1400
+ // both matches are made exact here.
1401
+ items: leads.filter(
1402
+ (lead) => (query.email === void 0 || lead.email === query.email) && (query.domain === void 0 || lead.email?.split("@").at(-1) === query.domain)
1403
+ ),
1404
+ next: envelope.next
1405
+ };
1406
+ };
1185
1407
  var leadReaders = (client) => ({
1186
1408
  getLead: async (id, ctx) => {
1409
+ const address = emailAddress(id);
1410
+ if (address !== null) {
1411
+ const page = await listLeads(client, { email: address }, ctx);
1412
+ const [lead2] = page.items;
1413
+ if (lead2 === void 0) {
1414
+ throw new OutboundError("NotFound", "No lead has that address", {
1415
+ provider: client.identity.provider
1416
+ });
1417
+ }
1418
+ return lead2;
1419
+ }
1187
1420
  const lead = await client.getObject(
1188
1421
  ctx,
1189
1422
  `/leads/${encodeURIComponent(id)}`
@@ -1194,30 +1427,7 @@ var leadReaders = (client) => ({
1194
1427
  await readLabels(client, ctx, [lead.lt_interest_status])
1195
1428
  );
1196
1429
  },
1197
- listLeads: async (query, ctx) => {
1198
- if (query.linkedinUrl !== void 0) {
1199
- return { items: [] };
1200
- }
1201
- const envelope = listEnvelope(
1202
- await client.post(ctx, "/leads/list", leadListBody(query)),
1203
- client.identity.provider,
1204
- "/leads/list"
1205
- );
1206
- const labels = await readLabels(
1207
- client,
1208
- ctx,
1209
- envelope.items.map((item) => item.lt_interest_status)
1210
- );
1211
- const leads = envelope.items.map(
1212
- (item) => toLead(client.identity, item, labels)
1213
- );
1214
- return {
1215
- // `contacts` is documented as the emails a lead needs to have, but not
1216
- // how it compares them, so the match is made exact here.
1217
- items: query.email === void 0 ? leads : leads.filter((lead) => lead.email === query.email),
1218
- next: envelope.next
1219
- };
1220
- }
1430
+ listLeads: async (query, ctx) => await listLeads(client, query, ctx)
1221
1431
  });
1222
1432
  var readers = (client) => {
1223
1433
  const { identity } = client;
@@ -21,5 +21,9 @@ export declare const summedRow: (scope: RowScope, days: readonly JsonObject[]) =
21
21
  * `GET /campaigns/analytics/steps`. Step and variant are both counted from 0
22
22
  * (seen live: a seven-step campaign reports steps "0" to "6"). A row whose
23
23
  * step is null or `\N` holds counts Instantly could not tie to a step.
24
+ *
25
+ * The reference lists no contacted count for a step. Where a row has
26
+ * `contacted`, it is the leads that step reached, so it is read as it is:
27
+ * a step's leads, not leads whose sequence started.
24
28
  */
25
29
  export declare const stepRow: (scope: RowScope, raw: JsonObject) => MetricRow;
@@ -0,0 +1,19 @@
1
+ import type { AdapterContext } from "../internal/adapter.ts";
2
+ import type { JsonObject } from "../internal/json.ts";
3
+ import type { CampaignTracking, TrackingFlags } from "../internal/tracking.ts";
4
+ import type { InstantlyClient } from "./client.ts";
5
+ export declare const trackingFlags: (raw: JsonObject) => TrackingFlags;
6
+ /** One campaign's settings, or `null` when they could not be read. */
7
+ export declare const campaignFlags: (client: InstantlyClient, ctx: AdapterContext, campaignId: string) => Promise<TrackingFlags | null>;
8
+ /** Every campaign's settings by id, or `null` when the listing failed. */
9
+ export declare const everyCampaignFlags: (client: InstantlyClient, ctx: AdapterContext) => Promise<Map<string, TrackingFlags> | null>;
10
+ /** One campaign's row of `GET /campaigns/analytics` with its settings. */
11
+ export declare const reportTracking: (raw: JsonObject, flags: TrackingFlags | undefined) => CampaignTracking;
12
+ /**
13
+ * Every campaign behind a workspace or sender total over the range, or
14
+ * `null` when either read failed.
15
+ */
16
+ export declare const workspaceTracking: (client: InstantlyClient, ctx: AdapterContext, range: {
17
+ readonly start_date: string | undefined;
18
+ readonly end_date: string | undefined;
19
+ }) => Promise<CampaignTracking[] | null>;
@@ -0,0 +1,9 @@
1
+ import type { Message } from "../internal/entities.ts";
2
+ /**
3
+ * Sets each received email's step from the sent email it answers: the last
4
+ * one sent before it in its thread. A received email's own `step` lags on a
5
+ * sequence's last step (seen live 2026-11-15: a reply to step 3 carried step
6
+ * 2). A reply under a minute after that send is automatic unless Instantly
7
+ * said otherwise. A reply with no earlier send in its thread is left as it is.
8
+ */
9
+ export declare const withAnsweredSteps: (messages: readonly Message[]) => Message[];
@@ -59,6 +59,11 @@ export interface LeadQuery extends PageQuery, TimeRange {
59
59
  readonly email?: string | undefined;
60
60
  /** Only the lead records with exactly this LinkedIn profile URL. */
61
61
  readonly linkedinUrl?: string | undefined;
62
+ /**
63
+ * Only the lead records whose address is at exactly this domain, lowercased.
64
+ * A subdomain is another domain.
65
+ */
66
+ readonly domain?: string | undefined;
62
67
  }
63
68
  export interface MessageQuery extends PageQuery, TimeRange {
64
69
  readonly campaignId?: string | undefined;