outbound-sdk 0.7.0 → 0.8.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 (121) hide show
  1. package/dist/alerts/index.js +3 -3
  2. package/dist/audit/index.js +1 -1
  3. package/dist/benchmarks/index.js +3 -3
  4. package/dist/budget/index.d.ts +7 -0
  5. package/dist/budget/index.js +3 -3
  6. package/dist/cache/index.js +2 -2
  7. package/dist/cards/index.js +17 -5
  8. package/dist/chunks/{chunk-ZJCVLBAE.js → chunk-4GK56PRO.js} +667 -363
  9. package/dist/chunks/{chunk-MW4C6LTN.js → chunk-7TASUWPC.js} +2 -2
  10. package/dist/chunks/{chunk-M2VXGLLZ.js → chunk-CPACP4YD.js} +1 -1
  11. package/dist/chunks/{chunk-4AVYRVN5.js → chunk-FTK4JS65.js} +31 -10
  12. package/dist/chunks/{chunk-YW6FFVSZ.js → chunk-HXB2IOJJ.js} +1 -1
  13. package/dist/chunks/{chunk-Y7KECJAV.js → chunk-IKKCMWBK.js} +1 -1
  14. package/dist/chunks/{chunk-FHKSLCVW.js → chunk-KVAG5GM2.js} +19 -0
  15. package/dist/chunks/{chunk-7I3EPR23.js → chunk-MPE6VLLY.js} +3 -3
  16. package/dist/chunks/{chunk-UFQ4WMLU.js → chunk-NFWWA7MI.js} +1 -1
  17. package/dist/chunks/{chunk-GL7BABF2.js → chunk-OMCDMELK.js} +1 -1
  18. package/dist/chunks/{chunk-JRL3QRBS.js → chunk-OVTYA3IB.js} +88 -28
  19. package/dist/chunks/{chunk-HIAK2GCI.js → chunk-RMAHQ2OZ.js} +5 -1
  20. package/dist/chunks/{chunk-65YAGEWZ.js → chunk-RQLOPMMR.js} +153 -39
  21. package/dist/chunks/{chunk-OK3GAZMT.js → chunk-SYUMA3CP.js} +12 -0
  22. package/dist/chunks/{chunk-LVZGIKNF.js → chunk-U5AK6OJM.js} +1 -1
  23. package/dist/chunks/{chunk-KTYTE2BU.js → chunk-UAHYPASH.js} +20 -11
  24. package/dist/chunks/{chunk-BNDHEDHD.js → chunk-UOJG4VYF.js} +3 -3
  25. package/dist/chunks/{chunk-LD6F46UT.js → chunk-UWD65SK7.js} +2 -2
  26. package/dist/chunks/{chunk-I7DXXGNZ.js → chunk-UZLFZZ2U.js} +5 -5
  27. package/dist/chunks/{chunk-DNPNTD5W.js → chunk-VVDBCQLK.js} +1 -1
  28. package/dist/chunks/{chunk-IVH3NMQZ.js → chunk-WROJO6XB.js} +1 -1
  29. package/dist/chunks/chunk-XMCNRU4H.js +7279 -0
  30. package/dist/chunks/{chunk-QFC4ZHD3.js → chunk-XYHM4KHC.js} +1 -1
  31. package/dist/chunks/{chunk-NAWZ73QS.js → chunk-YFJ3OQZS.js} +8 -1
  32. package/dist/chunks/tools-II7GXAOM.js +23 -0
  33. package/dist/cli/args.d.ts +48 -0
  34. package/dist/cli/bin.js +14 -14
  35. package/dist/cli/commands.d.ts +0 -7
  36. package/dist/cli/config.d.ts +31 -2
  37. package/dist/cli/envelope.d.ts +2 -0
  38. package/dist/cli/index.d.ts +6 -0
  39. package/dist/cli/index.js +19 -15
  40. package/dist/cli/listing.d.ts +5 -2
  41. package/dist/cli/mcp.d.ts +9 -0
  42. package/dist/cli/offered.d.ts +10 -0
  43. package/dist/cli/options.d.ts +6 -0
  44. package/dist/cli/progress.d.ts +27 -0
  45. package/dist/cli/serve.d.ts +17 -0
  46. package/dist/cli/update.d.ts +25 -2
  47. package/dist/clients/index.js +3 -3
  48. package/dist/combine/index.js +154 -35
  49. package/dist/combine/newest.d.ts +18 -0
  50. package/dist/combine/route.d.ts +19 -5
  51. package/dist/emailbison/index.js +22 -14
  52. package/dist/emailbison/map-sequence.d.ts +2 -1
  53. package/dist/exporter/index.js +1 -1
  54. package/dist/failover/index.js +3 -3
  55. package/dist/fixtures/index.js +4 -4
  56. package/dist/heyreach/capabilities.d.ts +4 -0
  57. package/dist/heyreach/conversations.d.ts +23 -0
  58. package/dist/heyreach/inbox.d.ts +0 -1
  59. package/dist/heyreach/index.js +251 -92
  60. package/dist/identity/index.js +2 -2
  61. package/dist/index.js +7 -7
  62. package/dist/insights/capped.d.ts +6 -6
  63. package/dist/insights/copy/index.d.ts +2 -0
  64. package/dist/insights/copy/reply-timing.d.ts +4 -0
  65. package/dist/insights/cost.d.ts +11 -1
  66. package/dist/insights/define.d.ts +25 -16
  67. package/dist/insights/inbox.d.ts +12 -0
  68. package/dist/insights/index.js +42 -6578
  69. package/dist/insights/inputs.generated.d.ts +60 -24
  70. package/dist/insights/ops/anomalies.d.ts +9 -0
  71. package/dist/insights/ops/index.d.ts +2 -0
  72. package/dist/insights/ops/period-comparison.d.ts +7 -8
  73. package/dist/insights/ops/pipeline-forecast.d.ts +10 -0
  74. package/dist/insights/ops/shared.d.ts +6 -1
  75. package/dist/insights/people/auto-replies.d.ts +11 -7
  76. package/dist/insights/people/dropped-replies.d.ts +13 -4
  77. package/dist/insights/people/hot-leads-read.d.ts +31 -0
  78. package/dist/insights/people/hot-leads.d.ts +15 -3
  79. package/dist/insights/people/index.d.ts +10 -2
  80. package/dist/insights/people/read.d.ts +1 -1
  81. package/dist/insights/registry.d.ts +14 -2
  82. package/dist/insights/run-cap.d.ts +10 -0
  83. package/dist/insights/senders/read.d.ts +0 -3
  84. package/dist/insights/tools.d.ts +12 -0
  85. package/dist/insights/tracked-reads.d.ts +53 -0
  86. package/dist/instantly/capabilities.d.ts +13 -1
  87. package/dist/instantly/index.js +122 -46
  88. package/dist/instantly/map-account.d.ts +2 -1
  89. package/dist/instantly/map-lead.d.ts +1 -0
  90. package/dist/instantly/map.d.ts +4 -3
  91. package/dist/internal/adapter.d.ts +17 -0
  92. package/dist/internal/capabilities.d.ts +13 -0
  93. package/dist/internal/engine/budget.d.ts +9 -1
  94. package/dist/internal/engine/engine.d.ts +2 -1
  95. package/dist/internal/engine/request.d.ts +2 -0
  96. package/dist/internal/errors.d.ts +5 -0
  97. package/dist/internal/hooks.d.ts +11 -0
  98. package/dist/internal/notes.d.ts +16 -0
  99. package/dist/internal/outbound/api.d.ts +14 -0
  100. package/dist/internal/outbound/core.d.ts +4 -1
  101. package/dist/internal/outbound/operation-shared.d.ts +2 -0
  102. package/dist/internal/sha256.d.ts +2 -0
  103. package/dist/internal/url.d.ts +1 -0
  104. package/dist/loader/index.js +3 -3
  105. package/dist/memory/index.js +6 -6
  106. package/dist/redact/index.d.ts +1 -1
  107. package/dist/redact/index.js +107 -19
  108. package/dist/redact/plugin.d.ts +26 -3
  109. package/dist/smartlead/index.js +22 -13
  110. package/dist/smartlead/map.d.ts +3 -2
  111. package/dist/sync/index.js +2 -2
  112. package/dist/tools/ai-sdk.js +5 -5
  113. package/dist/tools/by-name.d.ts +9 -1
  114. package/dist/tools/campaign-tools.d.ts +3 -1
  115. package/dist/tools/claude-agent.js +5 -5
  116. package/dist/tools/index.js +6 -6
  117. package/dist/tools/registry.d.ts +6 -0
  118. package/dist/tools/shared.d.ts +5 -1
  119. package/dist/tracing/index.js +1 -1
  120. package/dist/webhooks/index.js +11 -11
  121. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  EVENT_TYPES,
3
3
  heyreachEvents
4
- } from "../chunks/chunk-LD6F46UT.js";
4
+ } from "../chunks/chunk-UWD65SK7.js";
5
5
  import {
6
6
  mapPage,
7
7
  withLeadFields,
@@ -13,7 +13,7 @@ import {
13
13
  listIn,
14
14
  toVariant,
15
15
  variantKey
16
- } from "../chunks/chunk-BNDHEDHD.js";
16
+ } from "../chunks/chunk-UOJG4VYF.js";
17
17
  import {
18
18
  normalizeBody
19
19
  } from "../chunks/chunk-FALWG5U3.js";
@@ -25,32 +25,32 @@ import {
25
25
  recordBase,
26
26
  refTo,
27
27
  refsTo
28
- } from "../chunks/chunk-LVZGIKNF.js";
28
+ } from "../chunks/chunk-U5AK6OJM.js";
29
29
  import "../chunks/chunk-POBAY3TI.js";
30
30
  import {
31
31
  emptyCounts,
32
32
  metricRow
33
- } from "../chunks/chunk-M2VXGLLZ.js";
33
+ } from "../chunks/chunk-CPACP4YD.js";
34
34
  import "../chunks/chunk-QGRZDTX4.js";
35
35
  import {
36
36
  assertWorkspaceId
37
- } from "../chunks/chunk-YW6FFVSZ.js";
37
+ } from "../chunks/chunk-HXB2IOJJ.js";
38
38
  import {
39
39
  profileSlug
40
- } from "../chunks/chunk-NAWZ73QS.js";
40
+ } from "../chunks/chunk-YFJ3OQZS.js";
41
41
  import {
42
42
  stableId
43
- } from "../chunks/chunk-FHKSLCVW.js";
43
+ } from "../chunks/chunk-KVAG5GM2.js";
44
44
  import {
45
45
  readEnv,
46
46
  requireCredential
47
- } from "../chunks/chunk-UFQ4WMLU.js";
47
+ } from "../chunks/chunk-NFWWA7MI.js";
48
48
  import {
49
49
  OutboundError,
50
50
  isHttpFailure,
51
51
  makeErrorMapper,
52
52
  requireObject
53
- } from "../chunks/chunk-QFC4ZHD3.js";
53
+ } from "../chunks/chunk-XYHM4KHC.js";
54
54
  import {
55
55
  count,
56
56
  emailAddress,
@@ -381,6 +381,9 @@ var capabilities = {
381
381
  "replies.category": "vendor",
382
382
  // GetConversationsV3 takes `seen`.
383
383
  "replies.unread": "server",
384
+ // GetConversationsV3 lists the sender's whole LinkedIn inbox, and a
385
+ // conversation names no campaign: only the `campaignIds` filter tells.
386
+ "replies.inbox": true,
384
387
  "replies.list": true,
385
388
  "replies.since": "server",
386
389
  // GET /campaign/GetById names the campaign's account ids; the account list
@@ -519,9 +522,22 @@ var costs = {
519
522
  // eight at most; a later page is two again.
520
523
  "leads.lookup": { pageSize: PAGE_SIZE, perPage: 2, perWalk: 6 },
521
524
  "lists.list": { pageSize: PAGE_SIZE, perPage: 1 },
522
- // One conversation by thread id is a single request.
523
- "messages.list": { pageSize: PAGE_SIZE, perPage: 1 },
524
- "replies.list": { pageSize: PAGE_SIZE, perPage: 1 },
525
+ // One conversation by thread id is a single request. Without a campaign
526
+ // the listing walks every campaign, a request each even when it has no
527
+ // conversation, after one per page of campaigns; a page of the inbox's own
528
+ // conversations costs one more, to set the campaigns' apart.
529
+ "messages.list": {
530
+ pageSize: PAGE_SIZE,
531
+ perPage: 1,
532
+ perPageAtMost: 2,
533
+ perWalk: 1
534
+ },
535
+ "replies.list": {
536
+ pageSize: PAGE_SIZE,
537
+ perPage: 1,
538
+ perPageAtMost: 2,
539
+ perWalk: 1
540
+ },
525
541
  "senders.get": { perPage: 1 },
526
542
  "senders.health": { perPage: 1 },
527
543
  // A campaign's senders cost one more request, once, to read the campaign.
@@ -561,12 +577,12 @@ var caveats = [
561
577
  "The step after a MESSAGE or INMAIL has no branch: a reply ends the sequence, so every later step already means the lead has not replied. A step's delayDays includes the wait of any CHECK_ node between it and its parent.",
562
578
  "Sequence variants come from payload.messages (or messageVersions), which the docs describe as A/B variants for MESSAGE nodes only; INMAIL and LIKE_POST payloads are not documented.",
563
579
  "Stats: replied is totalMessageReplies plus totalInmailReplies. contacted is uniqueLeadsContacted and positive is autoTaggedInterested; the live API returns both but the API reference lists neither, so they are null when absent. totalMessageStarted and totalInmailStarted are not defined in the docs and are not read.",
564
- "Daily stats are keyed by UTC midnight; the docs do not say which timezone buckets a day or whether endDate is inclusive. Stats need both from and to, or neither.",
580
+ "Daily stats are keyed by UTC midnight; the docs do not say which timezone buckets a day or whether endDate is inclusive. A day's contacted is null: HeyReach reports uniqueLeadsContacted as 0 on every day and counts it only over the whole range (the 2026-11-16 stress test saw 0 on each of three days and 35 for the three together), so read the range's total instead of adding days. Stats take from and to, from alone (read up to the end of today, UTC, with a note) or neither; to alone is refused.",
565
581
  "Messages and replies are read from conversations. Checked against one live workspace on 2026-11-14: sender is ME or CORRESPONDENT, and each of 257 conversations carried its whole thread (longest read: 40 messages). Whether a longer thread is cut short is not known.",
566
582
  "Conversations are listed with GetConversationsV3, which pages by cursor and bounds a conversation by the time of its newest message. A since filter is sent as that lower bound and the older messages inside each conversation are then dropped, so a page can hold fewer messages than its conversations do. An until filter cannot be sent, because a conversation that continued past it still holds earlier messages; it is applied after fetching. A page marker saved from before the move to V3 (a number) is not valid and starts from the first page.",
567
583
  "A message's id is built from the conversation, the time, the side and the text, so an edited message gets a new id. The live API now returns a messageId the API reference does not list; it stays in raw so that existing ids do not change.",
568
584
  "A message's threadId is the LinkedIn account id and the conversation id joined by a colon, because one conversation can only be read back with both. A thread read returns the whole conversation in one page and does not know its campaign, so campaignRef is null.",
569
- "A message's campaign is known only when the listing is filtered to one campaign; otherwise campaignRef is null. A page is a page of conversations, so it can hold more messages than the limit asked for.",
585
+ "GetConversationsV3 lists the sender's whole LinkedIn inbox: personal messages, recruiters and inbound pitches as well as campaign conversations. The reference says a conversation names its campaign in campaignId, but seen live on 2026-11-17 none does, filtered by campaign or not; only the campaignIds filter tells which campaign a conversation is in. So a listing without a campaign walks every campaign of the workspace (a lead's own campaigns, for a lead's timeline) one after the other, a request each even when it has no conversation, and a message's campaignRef is the campaign it was listed under. replies.list stops there unless asked for includeInbox (--include-inbox); messages.list then lists the conversations in no campaign, with a null campaignRef, each page with one more request to set apart the campaigns' conversations of the same times. A conversation of a campaign deleted since counts as the inbox's. Listed this way, a page is one campaign's conversations, not the newest across campaigns. A page is a page of conversations, so it can hold more messages than the limit asked for.",
570
586
  "A reply's category is its lead's: HeyReach's auto-tag is made from a lead's first campaign reply and stored on the lead, with no link to a message, so every reply of a conversation takes the lead's newest one (categorySource: lead). Interested is positive, Not Interested negative and Generic neutral, matched without case; any other name is unknown. Filtering replies by category is done after fetching, so a page can come back short. unread is the conversation's read flag, the same on each of its replies.",
571
587
  "The blacklist is two lists read one after the other, leads then companies. An entry's id is prefixed lead- or company- because the two are numbered separately. A blacklisted lead's value is its profile URL, else its email, else its name (kind other); a company's is its name, else its LinkedIn page. matchingStatus and resolutionStage stay in raw.",
572
588
  "A webhook subscription lists one event type. Filtering webhooks by campaign is done after fetching and keeps webhooks that cover every campaign. Custom headers are never requested, because they can hold a secret; a request for one webhook by id (native webhookById, or raw) is always sent with includeCustomHeaders=false. HeyReach gives a webhook no creation time.",
@@ -739,8 +755,168 @@ var campaignSenders = async (client, ctx, query) => {
739
755
  };
740
756
  };
741
757
 
742
- // src/heyreach/inbox.ts
758
+ // src/heyreach/conversations.ts
743
759
  var CONVERSATIONS_PATH = "/inbox/GetConversationsV3";
760
+ var CAMPAIGNS_PATH = "/campaign/GetAll";
761
+ var LEAD_CAMPAIGNS_PATH = "/campaign/GetCampaignsForLead";
762
+ var numeric = (id) => /^\d+$/u.test(id) ? Number(id) : null;
763
+ var readPage = async (client, ctx, query, bounds) => {
764
+ const filters = {};
765
+ if (bounds.campaignIds !== void 0) {
766
+ filters.campaignIds = [...bounds.campaignIds];
767
+ }
768
+ if ("unread" in query && query.unread !== void 0) {
769
+ filters.seen = !query.unread;
770
+ }
771
+ if ("leadId" in query && query.leadId !== void 0) {
772
+ filters.leadProfileUrl = query.leadId;
773
+ }
774
+ const request = {
775
+ filters,
776
+ limit: Math.min(bounds.limit ?? query.limit ?? PAGE_SIZE, PAGE_SIZE)
777
+ };
778
+ if (bounds.cursor !== void 0) {
779
+ request.cursor = bounds.cursor;
780
+ }
781
+ const from = bounds.from ?? query.since;
782
+ if (from !== void 0) {
783
+ request.from = from;
784
+ }
785
+ if (bounds.to !== void 0) {
786
+ request.to = bounds.to;
787
+ }
788
+ const body = await client.post(ctx, CONVERSATIONS_PATH, request);
789
+ const next = text(field(body, "nextCursor"));
790
+ return {
791
+ conversations: client.items(body, CONVERSATIONS_PATH),
792
+ next: field(body, "hasNextPage") === true && next !== null ? next : void 0
793
+ };
794
+ };
795
+ var campaignConversations = async (client, ctx, query) => {
796
+ const id = numeric(query.campaignId);
797
+ const page2 = await readPage(client, ctx, query, {
798
+ campaignIds: id === null ? void 0 : [id],
799
+ cursor: isString(query.next) && query.next !== "" ? query.next : void 0
800
+ });
801
+ return {
802
+ items: page2.conversations.map((conversation) => ({
803
+ campaignId: query.campaignId,
804
+ conversation
805
+ })),
806
+ next: page2.next
807
+ };
808
+ };
809
+ var unlessMissing = async (request) => {
810
+ try {
811
+ return await request;
812
+ } catch (error) {
813
+ if (OutboundError.is(error) && error.code === "NotFound") {
814
+ return;
815
+ }
816
+ throw error;
817
+ }
818
+ };
819
+ var campaignsToWalk = async (client, ctx, query) => {
820
+ const leadId = "leadId" in query ? query.leadId : void 0;
821
+ const path = leadId === void 0 ? CAMPAIGNS_PATH : LEAD_CAMPAIGNS_PATH;
822
+ const key = leadId === void 0 ? "id" : "campaignId";
823
+ const ids = [];
824
+ let offset = 0;
825
+ while (offset !== void 0) {
826
+ const body = { limit: PAGE_SIZE, offset };
827
+ if (leadId !== void 0) {
828
+ body.profileUrl = leadId;
829
+ }
830
+ const answer = await unlessMissing(client.post(ctx, path, body));
831
+ if (answer === void 0) {
832
+ return ids;
833
+ }
834
+ const envelope = listEnvelope(
835
+ answer,
836
+ offset,
837
+ client.identity.provider,
838
+ path
839
+ );
840
+ ids.push(
841
+ ...envelope.items.flatMap((item) => {
842
+ const id = text(item[key]);
843
+ return id !== null && numeric(id) !== null ? [id] : [];
844
+ })
845
+ );
846
+ offset = envelope.next;
847
+ }
848
+ return ids;
849
+ };
850
+ var inCampaigns = async (client, ctx, query, campaignIds, conversations) => {
851
+ const times = conversations.map((each) => timestamp(each.lastMessageAt));
852
+ const known = times.flatMap((time) => time ?? []).toSorted();
853
+ const bounded = known.length === times.length;
854
+ const ids = /* @__PURE__ */ new Set();
855
+ let cursor;
856
+ do {
857
+ const page2 = await readPage(client, ctx, query, {
858
+ campaignIds,
859
+ cursor,
860
+ from: bounded ? known[0] : void 0,
861
+ // The caller's page size is for the records it gets, not this check.
862
+ limit: PAGE_SIZE,
863
+ to: bounded ? known.at(-1) : void 0
864
+ });
865
+ for (const conversation of page2.conversations) {
866
+ const id = text(conversation.id);
867
+ if (id !== null) {
868
+ ids.add(id);
869
+ }
870
+ }
871
+ cursor = page2.next;
872
+ } while (cursor !== void 0);
873
+ return ids;
874
+ };
875
+ var walkOf = (next) => isJsonObject(next) && Array.isArray(next.campaigns) ? {
876
+ at: count(next.at) ?? 0,
877
+ campaigns: list(next.campaigns).flatMap((id) => text(id) ?? []),
878
+ cursor: text(next.cursor) ?? void 0
879
+ } : void 0;
880
+ var walkCursor = (walk2) => ({
881
+ at: walk2.at,
882
+ campaigns: [...walk2.campaigns],
883
+ cursor: walk2.cursor ?? null
884
+ });
885
+ var inboxPage = async (client, ctx, query, walk2) => {
886
+ const page2 = await readPage(client, ctx, query, { cursor: walk2.cursor });
887
+ const campaignIds = walk2.campaigns.flatMap((id) => numeric(id) ?? []);
888
+ const taken = campaignIds.length === 0 || page2.conversations.length === 0 ? /* @__PURE__ */ new Set() : await inCampaigns(client, ctx, query, campaignIds, page2.conversations);
889
+ return {
890
+ items: page2.conversations.filter((conversation) => {
891
+ const id = text(conversation.id);
892
+ return id === null || !taken.has(id);
893
+ }).map((conversation) => ({ campaignId: null, conversation })),
894
+ next: page2.next === void 0 ? void 0 : walkCursor({ ...walk2, cursor: page2.next })
895
+ };
896
+ };
897
+ var everyConversation = async (client, ctx, query, inbox) => {
898
+ const walk2 = walkOf(query.next) ?? {
899
+ at: 0,
900
+ campaigns: await campaignsToWalk(client, ctx, query),
901
+ cursor: void 0
902
+ };
903
+ const campaignId = walk2.campaigns[walk2.at];
904
+ if (campaignId === void 0) {
905
+ return inbox ? await inboxPage(client, ctx, query, walk2) : { items: [], next: void 0 };
906
+ }
907
+ const page2 = await campaignConversations(client, ctx, {
908
+ ...query,
909
+ campaignId,
910
+ next: walk2.cursor
911
+ });
912
+ const after = page2.next === void 0 ? { ...walk2, at: walk2.at + 1, cursor: void 0 } : { ...walk2, cursor: text(page2.next) ?? void 0 };
913
+ return {
914
+ items: page2.items,
915
+ next: after.at >= after.campaigns.length && !inbox ? void 0 : walkCursor(after)
916
+ };
917
+ };
918
+
919
+ // src/heyreach/inbox.ts
744
920
  var FROM_LEAD = "CORRESPONDENT";
745
921
  var messageFields = (scope, conversation, raw) => {
746
922
  const conversationId = text(conversation.id) ?? "";
@@ -785,36 +961,6 @@ var toReply = (scope, conversation, raw) => {
785
961
  unread: read === null ? null : !read
786
962
  };
787
963
  };
788
- var numeric = (id) => /^\d+$/u.test(id) ? Number(id) : null;
789
- var readConversations = async (client, ctx, query) => {
790
- const filters = {};
791
- const campaign = query.campaignId === void 0 ? null : numeric(query.campaignId);
792
- if (campaign !== null) {
793
- filters.campaignIds = [campaign];
794
- }
795
- if ("unread" in query && query.unread !== void 0) {
796
- filters.seen = !query.unread;
797
- }
798
- if ("leadId" in query && query.leadId !== void 0) {
799
- filters.leadProfileUrl = query.leadId;
800
- }
801
- const request = {
802
- filters,
803
- limit: Math.min(query.limit ?? PAGE_SIZE, PAGE_SIZE)
804
- };
805
- if (isString(query.next) && query.next !== "") {
806
- request.cursor = query.next;
807
- }
808
- if (query.since !== void 0) {
809
- request.from = query.since;
810
- }
811
- const body = await client.post(ctx, CONVERSATIONS_PATH, request);
812
- const next = text(field(body, "nextCursor"));
813
- return {
814
- conversations: client.items(body, CONVERSATIONS_PATH),
815
- next: field(body, "hasNextPage") === true && next !== null ? next : void 0
816
- };
817
- };
818
964
  var inRange = (sentAt, range) => {
819
965
  if (range.since === void 0 && range.until === void 0) {
820
966
  return true;
@@ -837,47 +983,53 @@ var readThread = async (client, ctx, threadId) => {
837
983
  const path = `/inbox/GetChatroom/${accountId}/${encodeURIComponent(conversationId)}`;
838
984
  return client.object(await client.get(ctx, path), path);
839
985
  };
986
+ var conversationsFor = (client, ctx, query, inbox) => {
987
+ const { campaignId } = query;
988
+ return campaignId === void 0 ? everyConversation(client, ctx, query, inbox) : campaignConversations(client, ctx, { ...query, campaignId });
989
+ };
990
+ var scopeOf = (client, listed, includeBody) => ({
991
+ campaignId: listed.campaignId,
992
+ identity: client.identity,
993
+ includeBody
994
+ });
840
995
  var inboxReaders = (client) => ({
841
996
  listMessages: async (query, ctx) => {
842
997
  if (query.threadId !== void 0) {
843
998
  const conversation = await readThread(client, ctx, query.threadId);
844
- const scope2 = {
845
- campaignId: void 0,
846
- identity: client.identity,
847
- includeBody: query.includeBody
848
- };
999
+ const scope = scopeOf(
1000
+ client,
1001
+ { campaignId: null, conversation },
1002
+ query.includeBody
1003
+ );
849
1004
  return {
850
- items: objects(conversation.messages).map((raw) => toMessage(scope2, conversation, raw)).filter((message) => inRange(message.sentAt, query))
1005
+ items: objects(conversation.messages).map((raw) => toMessage(scope, conversation, raw)).filter((message) => inRange(message.sentAt, query))
851
1006
  };
852
1007
  }
853
- const page2 = await readConversations(client, ctx, query);
854
- const scope = {
855
- campaignId: query.campaignId,
856
- identity: client.identity,
857
- includeBody: query.includeBody
858
- };
1008
+ const page2 = await conversationsFor(client, ctx, query, true);
859
1009
  return {
860
- items: page2.conversations.flatMap(
861
- (conversation) => objects(conversation.messages).map(
862
- (raw) => toMessage(scope, conversation, raw)
863
- )
864
- ).filter((message) => inRange(message.sentAt, query)),
1010
+ items: page2.items.flatMap((listed) => {
1011
+ const scope = scopeOf(client, listed, query.includeBody);
1012
+ return objects(listed.conversation.messages).map(
1013
+ (raw) => toMessage(scope, listed.conversation, raw)
1014
+ );
1015
+ }).filter((message) => inRange(message.sentAt, query)),
865
1016
  next: page2.next
866
1017
  };
867
1018
  },
868
1019
  listReplies: async (query, ctx) => {
869
- const page2 = await readConversations(client, ctx, query);
870
- const scope = {
871
- campaignId: query.campaignId,
872
- identity: client.identity,
873
- includeBody: query.includeBody
874
- };
1020
+ const page2 = await conversationsFor(
1021
+ client,
1022
+ ctx,
1023
+ query,
1024
+ query.includeInbox === true
1025
+ );
875
1026
  return {
876
- items: page2.conversations.flatMap(
877
- (conversation) => objects(conversation.messages).flatMap(
878
- (raw) => isFromLead(raw) ? [toReply(scope, conversation, raw)] : []
879
- )
880
- ).filter(
1027
+ items: page2.items.flatMap((listed) => {
1028
+ const scope = scopeOf(client, listed, query.includeBody);
1029
+ return objects(listed.conversation.messages).flatMap(
1030
+ (raw) => isFromLead(raw) ? [toReply(scope, listed.conversation, raw)] : []
1031
+ );
1032
+ }).filter(
881
1033
  (reply) => inRange(reply.sentAt, query) && // The auto-tag filter of the listing takes HeyReach's own tag
882
1034
  // names, which the reference does not list, so the category is
883
1035
  // matched here on the mapped value.
@@ -889,7 +1041,7 @@ var inboxReaders = (client) => ({
889
1041
  });
890
1042
 
891
1043
  // src/heyreach/lookup.ts
892
- var CAMPAIGNS_PATH = "/campaign/GetCampaignsForLead";
1044
+ var CAMPAIGNS_PATH2 = "/campaign/GetCampaignsForLead";
893
1045
  var MAX_CANDIDATES = 5;
894
1046
  var canonicalProfileUrl = (url) => {
895
1047
  const slug = profileSlug(url);
@@ -948,7 +1100,7 @@ var ask = async (client, ctx, query, offset) => {
948
1100
  if (profileUrl !== null) {
949
1101
  const key = query.linkedinUrl === void 0 ? { email: query.email ?? "" } : { profileUrl };
950
1102
  const [campaigns2, profile] = await Promise.all([
951
- found(client.post(ctx, CAMPAIGNS_PATH, { ...key, ...paging })),
1103
+ found(client.post(ctx, CAMPAIGNS_PATH2, { ...key, ...paging })),
952
1104
  readProfile(client, ctx, profileUrl)
953
1105
  ]);
954
1106
  return { campaigns: campaigns2, profile };
@@ -958,7 +1110,7 @@ var ask = async (client, ctx, query, offset) => {
958
1110
  return { campaigns: void 0, profile: void 0 };
959
1111
  }
960
1112
  const campaigns = await found(
961
- client.post(ctx, CAMPAIGNS_PATH, { email, ...paging })
1113
+ client.post(ctx, CAMPAIGNS_PATH2, { email, ...paging })
962
1114
  );
963
1115
  return {
964
1116
  campaigns,
@@ -991,7 +1143,7 @@ var lookupLeads = async (client, ctx, query) => {
991
1143
  if (profile === void 0 || !isPerson(profile, query)) {
992
1144
  return { items: [] };
993
1145
  }
994
- const envelope = campaigns === void 0 ? { items: [], next: void 0 } : listEnvelope(campaigns, offset, provider, CAMPAIGNS_PATH);
1146
+ const envelope = campaigns === void 0 ? { items: [], next: void 0 } : listEnvelope(campaigns, offset, provider, CAMPAIGNS_PATH2);
995
1147
  if (envelope.items.length === 0 && offset === 0) {
996
1148
  return {
997
1149
  items: query.campaignId === void 0 ? [toLookupLead(client.identity, profile, null, query.email)] : []
@@ -1057,12 +1209,12 @@ var campaignLeads = async (client, ctx, query, offset) => {
1057
1209
  next: envelope.next
1058
1210
  };
1059
1211
  };
1060
- var walkOf = (next) => isJsonObject(next) ? {
1212
+ var walkOf2 = (next) => isJsonObject(next) ? {
1061
1213
  campaignOffset: count(next.campaignOffset) ?? void 0,
1062
1214
  campaigns: list(next.campaigns).flatMap((id) => text(id) ?? []),
1063
1215
  offset: count(next.offset) ?? 0
1064
1216
  } : void 0;
1065
- var walkCursor = (walk2) => walk2.campaigns.length === 0 && walk2.campaignOffset === void 0 ? void 0 : {
1217
+ var walkCursor2 = (walk2) => walk2.campaigns.length === 0 && walk2.campaignOffset === void 0 ? void 0 : {
1066
1218
  campaignOffset: walk2.campaignOffset ?? null,
1067
1219
  campaigns: [...walk2.campaigns],
1068
1220
  offset: walk2.offset
@@ -1088,7 +1240,7 @@ var nextCampaigns = async (client, ctx, walk2) => {
1088
1240
  };
1089
1241
  };
1090
1242
  var allLeads = async (client, ctx, query) => {
1091
- const walk2 = await nextCampaigns(client, ctx, walkOf(query.next));
1243
+ const walk2 = await nextCampaigns(client, ctx, walkOf2(query.next));
1092
1244
  const [campaignId, ...rest] = walk2.campaigns;
1093
1245
  if (campaignId === void 0) {
1094
1246
  return { items: [] };
@@ -1101,7 +1253,7 @@ var allLeads = async (client, ctx, query) => {
1101
1253
  );
1102
1254
  return {
1103
1255
  items: page2.items,
1104
- next: walkCursor(
1256
+ next: walkCursor2(
1105
1257
  page2.next === void 0 ? { ...walk2, campaigns: rest, offset: 0 } : { ...walk2, offset: page2.next }
1106
1258
  )
1107
1259
  };
@@ -1257,10 +1409,11 @@ var counts = (stats) => ({
1257
1409
  });
1258
1410
  var row = (scope, stats, date) => (
1259
1411
  // Days are keyed by UTC midnight.
1260
- metricRow(scope, counts(stats), {
1261
- date,
1262
- timezone: date === null ? null : "UTC"
1263
- })
1412
+ metricRow(
1413
+ scope,
1414
+ date === null ? counts(stats) : { ...counts(stats), contacted: null },
1415
+ { date, timezone: date === null ? null : "UTC" }
1416
+ )
1264
1417
  );
1265
1418
  var totalRow = (scope, body) => row(scope, field(body, "overallStats"), null);
1266
1419
  var dailyRows = (scope, body) => {
@@ -1290,17 +1443,17 @@ var campaignRows = (identity, body, by) => {
1290
1443
  };
1291
1444
 
1292
1445
  // src/heyreach/adapter.ts
1293
- var statsBody = (client, query) => {
1446
+ var statsBody = (client, ctx, query) => {
1294
1447
  const { provider } = client.identity;
1295
1448
  if (query.scope === "step") {
1296
1449
  throw new OutboundError("Unsupported", "HeyReach has no step analytics", {
1297
1450
  provider
1298
1451
  });
1299
1452
  }
1300
- if (query.from === void 0 !== (query.to === void 0)) {
1453
+ if (query.from === void 0 && query.to !== void 0) {
1301
1454
  throw new OutboundError(
1302
1455
  "Invalid",
1303
- "HeyReach stats need both from and to, or neither",
1456
+ "HeyReach stats need a from date with to; give from alone to read up to today",
1304
1457
  { provider }
1305
1458
  );
1306
1459
  }
@@ -1309,9 +1462,15 @@ var statsBody = (client, query) => {
1309
1462
  accountIds: query.scope === "sender" ? [numericId(client, id ?? "", "account")] : [],
1310
1463
  campaignIds: query.scope === "campaign" && id !== void 0 ? [numericId(client, id, "campaign")] : []
1311
1464
  };
1312
- if (query.from !== void 0 && query.to !== void 0) {
1465
+ if (query.from !== void 0) {
1466
+ const to = query.to ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
1467
+ if (query.to === void 0) {
1468
+ ctx.note(
1469
+ `HeyReach stats take a whole range, so from ${query.from} was read up to today, ${to} (UTC).`
1470
+ );
1471
+ }
1313
1472
  body.startDate = `${query.from}T00:00:00.000Z`;
1314
- body.endDate = `${query.to}T23:59:59.999Z`;
1473
+ body.endDate = `${to}T23:59:59.999Z`;
1315
1474
  }
1316
1475
  return body;
1317
1476
  };
@@ -1322,7 +1481,7 @@ var readStats = async (client, ctx, query) => {
1322
1481
  await client.post(
1323
1482
  ctx,
1324
1483
  "/stats/GetOverallStatsByCampaign",
1325
- statsBody(client, query)
1484
+ statsBody(client, ctx, query)
1326
1485
  ),
1327
1486
  query.by
1328
1487
  );
@@ -1330,7 +1489,7 @@ var readStats = async (client, ctx, query) => {
1330
1489
  const body = await client.post(
1331
1490
  ctx,
1332
1491
  "/stats/GetOverallStats",
1333
- statsBody(client, query)
1492
+ statsBody(client, ctx, query)
1334
1493
  );
1335
1494
  const scope = {
1336
1495
  ...client.identity,
@@ -3,10 +3,10 @@ import {
3
3
  } from "../chunks/chunk-HZCTYL22.js";
4
4
  import {
5
5
  profileSlug
6
- } from "../chunks/chunk-NAWZ73QS.js";
6
+ } from "../chunks/chunk-YFJ3OQZS.js";
7
7
  import {
8
8
  OutboundError
9
- } from "../chunks/chunk-QFC4ZHD3.js";
9
+ } from "../chunks/chunk-XYHM4KHC.js";
10
10
  import "../chunks/chunk-45TXPJW7.js";
11
11
 
12
12
  // src/identity/keys.ts
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  Outbound,
4
4
  createOutbound,
5
5
  fullJitterBackoff
6
- } from "./chunks/chunk-65YAGEWZ.js";
6
+ } from "./chunks/chunk-RQLOPMMR.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-HIAK2GCI.js";
25
+ } from "./chunks/chunk-RMAHQ2OZ.js";
26
26
  import "./chunks/chunk-PTZO4QXR.js";
27
27
  import {
28
28
  defineNative
@@ -53,7 +53,7 @@ import {
53
53
  computeRates,
54
54
  emptyCounts,
55
55
  sumCounts
56
- } from "./chunks/chunk-M2VXGLLZ.js";
56
+ } from "./chunks/chunk-CPACP4YD.js";
57
57
  import {
58
58
  SCHEMA_VERSION,
59
59
  campaignStatusSchema,
@@ -62,21 +62,21 @@ import {
62
62
  import {
63
63
  makeRef,
64
64
  parseRef
65
- } from "./chunks/chunk-YW6FFVSZ.js";
65
+ } from "./chunks/chunk-HXB2IOJJ.js";
66
66
  import {
67
67
  profileSlug
68
- } from "./chunks/chunk-NAWZ73QS.js";
68
+ } from "./chunks/chunk-YFJ3OQZS.js";
69
69
  import {
70
70
  sha256Hex,
71
71
  stableId
72
- } from "./chunks/chunk-FHKSLCVW.js";
72
+ } from "./chunks/chunk-KVAG5GM2.js";
73
73
  import {
74
74
  OutboundError,
75
75
  REDACTED_EMAIL,
76
76
  REDACTED_KEY,
77
77
  makeErrorMapper,
78
78
  redactText
79
- } from "./chunks/chunk-QFC4ZHD3.js";
79
+ } from "./chunks/chunk-XYHM4KHC.js";
80
80
  import "./chunks/chunk-45TXPJW7.js";
81
81
  export {
82
82
  CAPABILITY_KEYS,
@@ -1,6 +1,7 @@
1
1
  import type { Campaign, CampaignStatus } from "../internal/entities.ts";
2
2
  import type { ListAll } from "../internal/outbound/api.ts";
3
- import type { Cap, InsightContext } from "./define.ts";
3
+ import type { InsightContext } from "./define.ts";
4
+ import type { Cap } from "./tracked-reads.ts";
4
5
  export interface Capped<Item> {
5
6
  readonly items: Item[];
6
7
  /** `true` when the cap stopped the read with more records left. */
@@ -19,11 +20,10 @@ export interface CampaignsRead {
19
20
  readonly moreCampaignsExist: boolean;
20
21
  }
21
22
  export declare const campaignsReadOf: (read: Capped<Campaign>) => CampaignsRead;
23
+ /** `active`, `active or paused`, `active, paused or completed`. */
24
+ export declare const either: (words: readonly string[]) => string;
22
25
  /**
23
- * The campaigns in the given states, up to `max` in all. Asks the vendor per
24
- * state when it can filter, and filters after reading when it cannot, so
25
- * there the cap counts every campaign read. A state read after the cap is
26
- * reached still asks for its first page, so campaigns left out are reported
27
- * instead of silently dropped.
26
+ * The campaigns in the given states, up to `max` in all. On a combined
27
+ * instance `max` is shared among its tools, so each gets its share.
28
28
  */
29
29
  export declare const readCampaignsIn: (context: InsightContext, statuses: readonly CampaignStatus[], max: number, input?: string) => Promise<Capped<Campaign>>;
@@ -63,12 +63,14 @@ export declare const COPY_INSIGHTS: readonly [import("../define.ts").InsightDefi
63
63
  }>, import("../define.ts").InsightDefinition<"replyTiming", {
64
64
  campaign: string | null;
65
65
  include_auto: boolean;
66
+ include_inbox: boolean;
66
67
  max_messages: number;
67
68
  since: string | null;
68
69
  timezone_offset_minutes: number;
69
70
  }, import("./reply-timing.ts").ReplyTiming, {
70
71
  campaign?: string | null | undefined;
71
72
  include_auto?: boolean | undefined;
73
+ include_inbox?: boolean | undefined;
72
74
  max_messages?: number | undefined;
73
75
  since?: string | null | undefined;
74
76
  timezone_offset_minutes?: number | undefined;
@@ -57,17 +57,21 @@ export interface ReplyTiming {
57
57
  readonly unpairedShare: number | null;
58
58
  /** Received messages flagged automatic and left out of every figure; 0 with `include_auto`. Always set by reply_timing; optional so a value built by hand stays valid. */
59
59
  readonly autoReplies?: number;
60
+ /** Messages in conversations that belong to no campaign, left out of every figure; 0 with `include_inbox`. `null` when the vendor's conversations are all campaign ones (no `replies.inbox`). Always set by reply_timing; optional so a value built by hand stays valid. */
61
+ readonly notInCampaign?: number | null;
60
62
  };
61
63
  }
62
64
  export declare const replyTiming: import("../define.ts").InsightDefinition<"replyTiming", {
63
65
  campaign: string | null;
64
66
  include_auto: boolean;
67
+ include_inbox: boolean;
65
68
  max_messages: number;
66
69
  since: string | null;
67
70
  timezone_offset_minutes: number;
68
71
  }, ReplyTiming, {
69
72
  campaign?: string | null | undefined;
70
73
  include_auto?: boolean | undefined;
74
+ include_inbox?: boolean | undefined;
71
75
  max_messages?: number | undefined;
72
76
  since?: string | null | undefined;
73
77
  timezone_offset_minutes?: number | undefined;