outbound-sdk 0.2.1 → 0.5.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 (175) hide show
  1. package/README.md +2 -2
  2. package/dist/alerts/check-evaluate.d.ts +53 -0
  3. package/dist/alerts/check-measure.d.ts +100 -0
  4. package/dist/alerts/check-schema.d.ts +184 -0
  5. package/dist/alerts/check-validate.d.ts +18 -0
  6. package/dist/alerts/index.d.ts +7 -0
  7. package/dist/alerts/index.js +684 -20
  8. package/dist/alerts/plugin.d.ts +20 -3
  9. package/dist/audit/index.js +2 -2
  10. package/dist/benchmarks/index.js +5 -5
  11. package/dist/budget/index.d.ts +5 -2
  12. package/dist/budget/index.js +12 -10
  13. package/dist/cards/content.d.ts +6 -1
  14. package/dist/cards/format.d.ts +17 -2
  15. package/dist/cards/index.d.ts +1 -1
  16. package/dist/cards/index.js +298 -132
  17. package/dist/cards/parts.d.ts +9 -2
  18. package/dist/cards/render.d.ts +20 -3
  19. package/dist/chunks/{chunk-U2D34ARZ.js → chunk-2D42TQFU.js} +3 -3
  20. package/dist/chunks/{chunk-6CVZOUHB.js → chunk-3S32R2MH.js} +53 -63
  21. package/dist/chunks/chunk-4PA526S7.js +17 -0
  22. package/dist/chunks/{chunk-RCZ7ZZFU.js → chunk-5J7GGV62.js} +12 -5
  23. package/dist/chunks/chunk-6TKFISG4.js +676 -0
  24. package/dist/chunks/{chunk-AFU5E5QB.js → chunk-BK5SLY32.js} +104 -84
  25. package/dist/chunks/{chunk-VQSCHOBV.js → chunk-BLCJHP5H.js} +11 -4
  26. package/dist/chunks/{chunk-SBIZDCRY.js → chunk-BN6WCAWX.js} +7 -7
  27. package/dist/chunks/{chunk-4PSO6JEK.js → chunk-BOWXGMN3.js} +6 -21
  28. package/dist/chunks/{chunk-PURHK3JU.js → chunk-EHSJGQ5K.js} +8 -8
  29. package/dist/chunks/{chunk-IPUYZD4O.js → chunk-GFDNRWR3.js} +1 -1
  30. package/dist/chunks/chunk-HPNGSG5E.js +51 -0
  31. package/dist/chunks/chunk-HWHI4LFY.js +102 -0
  32. package/dist/chunks/{chunk-E7JHLNLG.js → chunk-J7DDZ4C2.js} +15 -2
  33. package/dist/chunks/{chunk-DJ2IUQEU.js → chunk-JWGSB7PT.js} +6 -6
  34. package/dist/chunks/{chunk-R3Y56YVF.js → chunk-OLPMBRXM.js} +4 -3
  35. package/dist/chunks/{chunk-YOTW5ESM.js → chunk-PQSTQKRD.js} +2 -2
  36. package/dist/chunks/chunk-PTZO4QXR.js +15 -0
  37. package/dist/chunks/{chunk-LVYG7XZJ.js → chunk-QAKJ76HB.js} +1 -1
  38. package/dist/chunks/chunk-QGRZDTX4.js +26 -0
  39. package/dist/chunks/chunk-WGW3ROLY.js +18 -0
  40. package/dist/chunks/{chunk-XC6CZP73.js → chunk-WH6V3YNN.js} +32 -1
  41. package/dist/chunks/{chunk-P3IJBJUI.js → chunk-X4RDBD4J.js} +296 -62
  42. package/dist/chunks/chunk-XL6LJVHJ.js +71 -0
  43. package/dist/chunks/{chunk-XNFESPZH.js → chunk-YYCT3NGV.js} +200 -39
  44. package/dist/chunks/{chunk-UAT3JSJZ.js → chunk-ZOAG2C6V.js} +2 -2
  45. package/dist/cli/bin.js +19 -30
  46. package/dist/cli/commands.d.ts +11 -0
  47. package/dist/cli/index.d.ts +3 -0
  48. package/dist/cli/index.js +18 -13
  49. package/dist/cli/mcp.d.ts +5 -0
  50. package/dist/cli/update.d.ts +15 -0
  51. package/dist/clients/index.d.ts +1 -1
  52. package/dist/clients/index.js +35 -10
  53. package/dist/clients/plugin.d.ts +9 -2
  54. package/dist/combine/index.js +7 -6
  55. package/dist/emailbison/account.d.ts +7 -0
  56. package/dist/emailbison/adapter.d.ts +5 -0
  57. package/dist/emailbison/capabilities.d.ts +78 -0
  58. package/dist/emailbison/client.d.ts +29 -0
  59. package/dist/emailbison/index.d.ts +30 -0
  60. package/dist/emailbison/index.js +1017 -0
  61. package/dist/emailbison/mail.d.ts +5 -0
  62. package/dist/emailbison/map-mail.d.ts +13 -0
  63. package/dist/emailbison/map-sequence.d.ts +12 -0
  64. package/dist/emailbison/map-stats.d.ts +47 -0
  65. package/dist/emailbison/map.d.ts +24 -0
  66. package/dist/emailbison/native-params.d.ts +5 -0
  67. package/dist/emailbison/native-workspace.d.ts +167 -0
  68. package/dist/emailbison/native.d.ts +327 -0
  69. package/dist/emailbison/stats.d.ts +4 -0
  70. package/dist/emailbison/webhooks.d.ts +2 -0
  71. package/dist/exporter/index.d.ts +5 -2
  72. package/dist/exporter/index.js +2 -2
  73. package/dist/failover/index.js +3 -3
  74. package/dist/fixtures/index.js +10 -9
  75. package/dist/heyreach/capabilities.d.ts +3 -0
  76. package/dist/heyreach/client.d.ts +2 -0
  77. package/dist/heyreach/index.js +83 -51
  78. package/dist/heyreach/map.d.ts +5 -2
  79. package/dist/identity/index.js +33 -17
  80. package/dist/identity/plugin.d.ts +2 -0
  81. package/dist/index.d.ts +2 -2
  82. package/dist/index.js +29 -25
  83. package/dist/insights/campaign.d.ts +3 -0
  84. package/dist/insights/capped.d.ts +29 -0
  85. package/dist/insights/copy/copy-audit.d.ts +2 -0
  86. package/dist/insights/copy/copy-reuse.d.ts +27 -3
  87. package/dist/insights/copy/index.d.ts +8 -8
  88. package/dist/insights/copy/reply-timing.d.ts +8 -0
  89. package/dist/insights/copy/reuse-base.d.ts +32 -0
  90. package/dist/insights/copy/shared.d.ts +39 -15
  91. package/dist/insights/copy/step-funnel.d.ts +16 -5
  92. package/dist/insights/copy/variant-test.d.ts +19 -8
  93. package/dist/insights/cost.d.ts +91 -0
  94. package/dist/insights/define.d.ts +78 -3
  95. package/dist/insights/fields.d.ts +16 -0
  96. package/dist/insights/index.d.ts +6 -4
  97. package/dist/insights/index.js +1816 -748
  98. package/dist/insights/inputs.generated.d.ts +951 -0
  99. package/dist/insights/ops/campaign-diagnosis.d.ts +3 -1
  100. package/dist/insights/ops/campaign-ranking.d.ts +15 -7
  101. package/dist/insights/ops/channel-mix.d.ts +2 -1
  102. package/dist/insights/ops/client-report.d.ts +18 -5
  103. package/dist/insights/ops/index.d.ts +8 -4
  104. package/dist/insights/ops/period-comparison.d.ts +14 -3
  105. package/dist/insights/ops/pipeline-forecast.d.ts +14 -4
  106. package/dist/insights/ops/shared.d.ts +39 -24
  107. package/dist/insights/ops/tag-rollup.d.ts +2 -1
  108. package/dist/insights/people/account-summary.d.ts +13 -0
  109. package/dist/insights/people/dropped-replies.d.ts +8 -0
  110. package/dist/insights/people/find.d.ts +7 -1
  111. package/dist/insights/people/hot-leads.d.ts +16 -1
  112. package/dist/insights/people/person-summary.d.ts +6 -0
  113. package/dist/insights/people/read.d.ts +26 -10
  114. package/dist/insights/people/suppression-check.d.ts +11 -2
  115. package/dist/insights/plugin.d.ts +26 -5
  116. package/dist/insights/ref.d.ts +6 -0
  117. package/dist/insights/registry.d.ts +30 -18
  118. package/dist/insights/run-cap.d.ts +35 -0
  119. package/dist/insights/senders/bounce-watch.d.ts +25 -8
  120. package/dist/insights/senders/capacity-sends.d.ts +22 -0
  121. package/dist/insights/senders/domain-health.d.ts +10 -4
  122. package/dist/insights/senders/index.d.ts +14 -6
  123. package/dist/insights/senders/read.d.ts +15 -14
  124. package/dist/insights/senders/sender-capacity.d.ts +5 -13
  125. package/dist/insights/senders/sender-load.d.ts +2 -0
  126. package/dist/insights/stats.d.ts +8 -0
  127. package/dist/insights/tools.d.ts +13 -2
  128. package/dist/instantly/capabilities.d.ts +13 -0
  129. package/dist/instantly/client.d.ts +2 -0
  130. package/dist/instantly/index.js +77 -49
  131. package/dist/instantly/map.d.ts +6 -2
  132. package/dist/internal/adapter.d.ts +12 -0
  133. package/dist/internal/engine/request.d.ts +5 -0
  134. package/dist/internal/entities.d.ts +3 -20
  135. package/dist/internal/errors.d.ts +44 -0
  136. package/dist/internal/fields.d.ts +1 -1
  137. package/dist/internal/json.d.ts +9 -2
  138. package/dist/internal/lists.d.ts +24 -0
  139. package/dist/internal/numbers.d.ts +8 -0
  140. package/dist/internal/outbound/collections.d.ts +4 -0
  141. package/dist/internal/outbound/create.d.ts +24 -3
  142. package/dist/internal/outbound/outbound.d.ts +18 -2
  143. package/dist/internal/outbound/validate.d.ts +4 -0
  144. package/dist/internal/outbound/walker.d.ts +3 -2
  145. package/dist/internal/plural.d.ts +12 -0
  146. package/dist/internal/renamed.d.ts +28 -0
  147. package/dist/internal/request-cap.d.ts +35 -0
  148. package/dist/internal/vocabulary.d.ts +20 -0
  149. package/dist/loader/index.js +5 -5
  150. package/dist/memory/adapter.d.ts +7 -0
  151. package/dist/memory/demo-stats.d.ts +3 -0
  152. package/dist/memory/demo.d.ts +14 -3
  153. package/dist/memory/index.d.ts +1 -0
  154. package/dist/memory/index.js +209 -104
  155. package/dist/providers/index.d.ts +92 -0
  156. package/dist/providers/index.js +3 -1
  157. package/dist/reconcile/index.js +5 -4
  158. package/dist/redact/index.js +13 -7
  159. package/dist/redact/plugin.d.ts +7 -0
  160. package/dist/smartlead/capabilities.d.ts +5 -0
  161. package/dist/smartlead/index.js +119 -66
  162. package/dist/smartlead/shared.d.ts +13 -0
  163. package/dist/sync/index.js +2 -2
  164. package/dist/tools/ai-sdk.js +10 -6
  165. package/dist/tools/campaign-tools.d.ts +1 -1
  166. package/dist/tools/claude-agent.js +10 -6
  167. package/dist/tools/index.d.ts +2 -2
  168. package/dist/tools/index.js +16 -9
  169. package/dist/tools/input-problem.d.ts +8 -0
  170. package/dist/tools/registry.d.ts +26 -2
  171. package/dist/tools/shared.d.ts +27 -1
  172. package/dist/tracing/index.js +2 -2
  173. package/dist/webhooks/index.js +22 -12
  174. package/package.json +8 -2
  175. package/dist/chunks/chunk-FKH5N47I.js +0 -40
@@ -4,12 +4,12 @@ import {
4
4
  import "../chunks/chunk-FHKSLCVW.js";
5
5
  import {
6
6
  OutboundError
7
- } from "../chunks/chunk-E7JHLNLG.js";
8
- import "../chunks/chunk-VQSCHOBV.js";
7
+ } from "../chunks/chunk-J7DDZ4C2.js";
8
+ import "../chunks/chunk-BLCJHP5H.js";
9
9
 
10
10
  // src/failover/index.ts
11
11
  var WEEK_SECONDS = 7 * 24 * 60 * 60;
12
- var vendorIsDown = (cause) => OutboundError.is(cause) && !cause.aborted && (cause.code === "Provider" || cause.code === "RateLimited" && cause.status !== void 0);
12
+ var vendorIsDown = (cause) => OutboundError.is(cause) && !cause.aborted && (cause.code === "Provider" || cause.code === "RateLimited" && cause.limit === "vendor");
13
13
  var fetchedAtOf = (fetchedAt, now) => fetchedAt === void 0 ? now : Date.parse(fetchedAt);
14
14
  var failover = (options) => {
15
15
  const now = options.now ?? (() => Date.now());
@@ -1,25 +1,26 @@
1
+ import {
2
+ evidenceSchema
3
+ } from "../chunks/chunk-BOWXGMN3.js";
4
+ import "../chunks/chunk-QGRZDTX4.js";
5
+ import {
6
+ makeRef,
7
+ parseRef
8
+ } from "../chunks/chunk-QAKJ76HB.js";
1
9
  import {
2
10
  profileSlug
3
11
  } from "../chunks/chunk-NAWZ73QS.js";
4
12
  import {
5
13
  stableId
6
14
  } from "../chunks/chunk-FHKSLCVW.js";
7
- import {
8
- evidenceSchema
9
- } from "../chunks/chunk-4PSO6JEK.js";
10
- import {
11
- makeRef,
12
- parseRef
13
- } from "../chunks/chunk-LVYG7XZJ.js";
14
15
  import {
15
16
  OutboundError
16
- } from "../chunks/chunk-E7JHLNLG.js";
17
+ } from "../chunks/chunk-J7DDZ4C2.js";
17
18
  import {
18
19
  field,
19
20
  objects,
20
21
  parseJson,
21
22
  toJson
22
- } from "../chunks/chunk-VQSCHOBV.js";
23
+ } from "../chunks/chunk-BLCJHP5H.js";
23
24
 
24
25
  // src/fixtures/index.ts
25
26
  import { mkdir, readFile, writeFile } from "node:fs/promises";
@@ -29,10 +29,12 @@ export declare const costs: {
29
29
  "leads.list": {
30
30
  pageSize: number;
31
31
  perPage: number;
32
+ perWalk: number;
32
33
  };
33
34
  "leads.lookup": {
34
35
  pageSize: number;
35
36
  perPage: number;
37
+ perWalk: number;
36
38
  };
37
39
  "lists.list": {
38
40
  pageSize: number;
@@ -55,6 +57,7 @@ export declare const costs: {
55
57
  "senders.list": {
56
58
  pageSize: number;
57
59
  perPage: number;
60
+ perWalk: number;
58
61
  };
59
62
  "sequence.get": {
60
63
  perPage: number;
@@ -12,6 +12,8 @@ export interface HeyReachClient extends VendorClient {
12
12
  readonly raw: RawDescriptor;
13
13
  /** Narrows a response to one object, or throws a `Provider` error. */
14
14
  readonly object: (body: Json, path: string) => JsonObject;
15
+ /** The `items` array every HeyReach list answers with, or a `Provider` error. */
16
+ readonly items: (body: Json | undefined, path: string) => JsonObject[];
15
17
  }
16
18
  export declare const isSecret: (path: string) => boolean;
17
19
  export declare const isRead: (method: HttpMethod, path: string) => boolean;
@@ -1,26 +1,38 @@
1
1
  import {
2
2
  EVENT_TYPES,
3
3
  heyreachEvents
4
- } from "../chunks/chunk-DJ2IUQEU.js";
4
+ } from "../chunks/chunk-JWGSB7PT.js";
5
5
  import {
6
- createVendorClient,
7
6
  mapPage,
8
- normalizeBody,
9
7
  withLeadFields,
10
8
  withMappedFields
11
- } from "../chunks/chunk-6CVZOUHB.js";
9
+ } from "../chunks/chunk-XL6LJVHJ.js";
12
10
  import {
11
+ createVendorClient,
13
12
  leadStanding,
13
+ listIn,
14
+ normalizeBody,
14
15
  toVariant,
15
16
  variantKey
16
- } from "../chunks/chunk-FKH5N47I.js";
17
+ } from "../chunks/chunk-3S32R2MH.js";
17
18
  import {
18
19
  defineNative
19
20
  } from "../chunks/chunk-NAKXLBA6.js";
21
+ import {
22
+ eventTypesOf,
23
+ recordBase,
24
+ refTo,
25
+ refsTo
26
+ } from "../chunks/chunk-2D42TQFU.js";
27
+ import "../chunks/chunk-BOWXGMN3.js";
20
28
  import {
21
29
  emptyCounts,
22
30
  metricRow
23
- } from "../chunks/chunk-YOTW5ESM.js";
31
+ } from "../chunks/chunk-PQSTQKRD.js";
32
+ import "../chunks/chunk-QGRZDTX4.js";
33
+ import {
34
+ assertWorkspaceId
35
+ } from "../chunks/chunk-QAKJ76HB.js";
24
36
  import {
25
37
  profileSlug
26
38
  } from "../chunks/chunk-NAWZ73QS.js";
@@ -30,23 +42,13 @@ import {
30
42
  import {
31
43
  readEnv,
32
44
  requireCredential
33
- } from "../chunks/chunk-IPUYZD4O.js";
34
- import {
35
- eventTypesOf,
36
- recordBase,
37
- refTo,
38
- refsTo
39
- } from "../chunks/chunk-U2D34ARZ.js";
40
- import "../chunks/chunk-4PSO6JEK.js";
41
- import {
42
- assertWorkspaceId
43
- } from "../chunks/chunk-LVYG7XZJ.js";
45
+ } from "../chunks/chunk-GFDNRWR3.js";
44
46
  import {
45
47
  OutboundError,
46
48
  isHttpFailure,
47
49
  makeErrorMapper,
48
50
  requireObject
49
- } from "../chunks/chunk-E7JHLNLG.js";
51
+ } from "../chunks/chunk-J7DDZ4C2.js";
50
52
  import {
51
53
  count,
52
54
  emailAddress,
@@ -60,7 +62,7 @@ import {
60
62
  objects,
61
63
  text,
62
64
  timestamp
63
- } from "../chunks/chunk-VQSCHOBV.js";
65
+ } from "../chunks/chunk-BLCJHP5H.js";
64
66
 
65
67
  // src/heyreach/map-account.ts
66
68
  var toCampaignProgress = (identity, campaignId, raw) => {
@@ -307,8 +309,10 @@ var toLookupLead = (identity, profile, campaign, email) => {
307
309
  email: email ?? lead.email
308
310
  };
309
311
  };
310
- var listEnvelope = (body, offset) => {
311
- const items = objects(isJsonObject(body) ? body.items : void 0);
312
+ var listEnvelope = (body, offset, provider, path) => {
313
+ const items = objects(
314
+ listIn(body, { key: "items", path, provider, vendor: "HeyReach" })
315
+ );
312
316
  const total = count(field(body, "totalCount"));
313
317
  const end = offset + items.length;
314
318
  return {
@@ -484,12 +488,12 @@ var costs = {
484
488
  "leads.get": { perPage: 2 },
485
489
  // A campaign's leads. A saved list's leads come up to 1000 a page. Without
486
490
  // a campaign or a list, each new page of campaigns costs one more request.
487
- "leads.list": { pageSize: PAGE_SIZE, perPage: 1 },
491
+ "leads.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
488
492
  // One person by profile URL: the campaigns and the profile, two requests.
489
493
  // By email it is three (campaigns, the lists the address is in, a name
490
494
  // search in one list) and one more per profile read to find the address,
491
495
  // eight at most; a later page is two again.
492
- "leads.lookup": { pageSize: PAGE_SIZE, perPage: 2 },
496
+ "leads.lookup": { pageSize: PAGE_SIZE, perPage: 2, perWalk: 6 },
493
497
  "lists.list": { pageSize: PAGE_SIZE, perPage: 1 },
494
498
  // One conversation by thread id is a single request.
495
499
  "messages.list": { pageSize: PAGE_SIZE, perPage: 1 },
@@ -497,7 +501,7 @@ var costs = {
497
501
  "senders.get": { perPage: 1 },
498
502
  "senders.health": { perPage: 1 },
499
503
  // A campaign's senders cost one more request, once, to read the campaign.
500
- "senders.list": { pageSize: PAGE_SIZE, perPage: 1 },
504
+ "senders.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
501
505
  "sequence.get": { perPage: 1 },
502
506
  stats: { perPage: 1 },
503
507
  "webhooks.list": { pageSize: PAGE_SIZE, perPage: 1 }
@@ -571,13 +575,12 @@ var blocklistCursor = (next) => ({
571
575
  });
572
576
  var listBlocklist = (client) => async (query, ctx) => {
573
577
  const { companies, offset } = blocklistCursor(query.next);
578
+ const path = companies ? "/blacklist/GetCompanies" : "/blacklist/GetLeads";
574
579
  const envelope = listEnvelope(
575
- await client.post(
576
- ctx,
577
- companies ? "/blacklist/GetCompanies" : "/blacklist/GetLeads",
578
- { limit: pageSize(query.limit), offset }
579
- ),
580
- offset
580
+ await client.post(ctx, path, { limit: pageSize(query.limit), offset }),
581
+ offset,
582
+ client.identity.provider,
583
+ path
581
584
  );
582
585
  const toEntries = companies ? toBlockedCompany : toBlockedLead;
583
586
  const items = envelope.items.flatMap(
@@ -645,7 +648,9 @@ var accountReaders = (client) => ({
645
648
  limit: pageSize(query.limit),
646
649
  offset
647
650
  }),
648
- offset
651
+ offset,
652
+ client.identity.provider,
653
+ "/list/GetAll"
649
654
  );
650
655
  return mapPage(envelope, (item) => toLeadList(client.identity, item));
651
656
  },
@@ -658,7 +663,9 @@ var accountReaders = (client) => ({
658
663
  limit: pageSize(query.limit),
659
664
  offset
660
665
  }),
661
- offset
666
+ offset,
667
+ client.identity.provider,
668
+ "/webhooks/GetAllWebhooks"
662
669
  );
663
670
  const { campaignId } = query;
664
671
  return {
@@ -698,7 +705,9 @@ var campaignSenders = async (client, ctx, query) => {
698
705
  limit: pageSize(query.limit),
699
706
  offset
700
707
  }),
701
- offset
708
+ offset,
709
+ client.identity.provider,
710
+ "/li_account/GetAll"
702
711
  );
703
712
  return {
704
713
  items: envelope.items.filter((item) => isNumber(item.id) && accountIds.includes(item.id)).map((item) => toSender(client.identity, item)),
@@ -778,7 +787,7 @@ var readConversations = async (client, ctx, query) => {
778
787
  const body = await client.post(ctx, CONVERSATIONS_PATH, request);
779
788
  const next = text(field(body, "nextCursor"));
780
789
  return {
781
- conversations: objects(field(body, "items")),
790
+ conversations: client.items(body, CONVERSATIONS_PATH),
782
791
  next: field(body, "hasNextPage") === true && next !== null ? next : void 0
783
792
  };
784
793
  };
@@ -883,20 +892,18 @@ var profileByEmail = async (client, ctx, email, fullName2) => {
883
892
  const lists = await found(
884
893
  client.post(ctx, "/list/GetListsForLead", { email, limit: 1, offset: 0 })
885
894
  );
886
- const listId = field(objects(field(lists, "items"))[0], "listId");
895
+ const listId = lists === void 0 ? void 0 : field(client.items(lists, "/list/GetListsForLead")[0], "listId");
887
896
  if (!isNumber(listId)) {
888
897
  return void 0;
889
898
  }
890
- const rows = objects(
891
- field(
892
- await client.post(ctx, "/list/GetLeadsFromList", {
893
- keyword: fullName2,
894
- limit: MAX_CANDIDATES,
895
- listId,
896
- offset: 0
897
- }),
898
- "items"
899
- )
899
+ const rows = client.items(
900
+ await client.post(ctx, "/list/GetLeadsFromList", {
901
+ keyword: fullName2,
902
+ limit: MAX_CANDIDATES,
903
+ listId,
904
+ offset: 0
905
+ }),
906
+ "/list/GetLeadsFromList"
900
907
  );
901
908
  for (const row2 of rows) {
902
909
  const profileUrl = text(row2.profileUrl);
@@ -960,7 +967,7 @@ var lookupLeads = async (client, ctx, query) => {
960
967
  if (profile === void 0 || !isPerson(profile, query)) {
961
968
  return { items: [] };
962
969
  }
963
- const envelope = listEnvelope(campaigns ?? null, offset);
970
+ const envelope = campaigns === void 0 ? { items: [], next: void 0 } : listEnvelope(campaigns, offset, provider, CAMPAIGNS_PATH);
964
971
  if (envelope.items.length === 0 && offset === 0) {
965
972
  return {
966
973
  items: query.campaignId === void 0 ? [toLookupLead(client.identity, profile, null, query.email)] : []
@@ -1015,7 +1022,9 @@ var campaignLeads = async (client, ctx, query, offset) => {
1015
1022
  "/campaign/GetLeadsFromCampaign",
1016
1023
  campaignLeadsBody(client, query, offset)
1017
1024
  ),
1018
- offset
1025
+ offset,
1026
+ client.identity.provider,
1027
+ "/campaign/GetLeadsFromCampaign"
1019
1028
  );
1020
1029
  return {
1021
1030
  items: envelope.items.map(
@@ -1044,7 +1053,9 @@ var nextCampaigns = async (client, ctx, walk2) => {
1044
1053
  }
1045
1054
  const envelope = listEnvelope(
1046
1055
  await client.post(ctx, "/campaign/GetAll", { limit: PAGE_SIZE, offset }),
1047
- offset
1056
+ offset,
1057
+ client.identity.provider,
1058
+ "/campaign/GetAll"
1048
1059
  );
1049
1060
  return {
1050
1061
  campaignOffset: envelope.next,
@@ -1082,6 +1093,13 @@ var leadReaders = (client) => ({
1082
1093
  client.post(ctx, path, { profileUrl }),
1083
1094
  client.post(ctx, "/lead/GetTags", { profileUrl })
1084
1095
  ]);
1096
+ if (isString(tags)) {
1097
+ throw new OutboundError(
1098
+ "Provider",
1099
+ "HeyReach returned no JSON for /lead/GetTags",
1100
+ { provider: client.identity.provider }
1101
+ );
1102
+ }
1085
1103
  return toLead(
1086
1104
  client.identity,
1087
1105
  client.object(lead, path),
@@ -1101,7 +1119,9 @@ var leadReaders = (client) => ({
1101
1119
  "/list/GetLeadsFromList",
1102
1120
  listLeadsBody(client, { ...query, listId }, offset)
1103
1121
  ),
1104
- offset
1122
+ offset,
1123
+ client.identity.provider,
1124
+ "/list/GetLeadsFromList"
1105
1125
  );
1106
1126
  return mapPage(envelope, (item) => toLead(client.identity, item));
1107
1127
  }
@@ -1343,7 +1363,9 @@ var readers = (client) => {
1343
1363
  }
1344
1364
  const envelope = listEnvelope(
1345
1365
  await client.post(ctx, "/campaign/GetAll", body),
1346
- offset
1366
+ offset,
1367
+ identity.provider,
1368
+ "/campaign/GetAll"
1347
1369
  );
1348
1370
  return mapPage(envelope, (item) => toCampaign(identity, item));
1349
1371
  },
@@ -1358,7 +1380,9 @@ var readers = (client) => {
1358
1380
  limit: pageSize(query.limit),
1359
1381
  offset
1360
1382
  }),
1361
- offset
1383
+ offset,
1384
+ identity.provider,
1385
+ "/li_account/GetAll"
1362
1386
  );
1363
1387
  return mapPage(envelope, (item) => toSender(identity, item));
1364
1388
  },
@@ -1419,6 +1443,14 @@ var createClient = (options) => {
1419
1443
  return {
1420
1444
  ...createVendorClient(baseUrl, authorize),
1421
1445
  identity: options.identity,
1446
+ items: (body, path) => objects(
1447
+ listIn(body, {
1448
+ key: "items",
1449
+ path,
1450
+ provider: options.identity.provider,
1451
+ vendor: "HeyReach"
1452
+ })
1453
+ ),
1422
1454
  object: (body, path) => requireObject(
1423
1455
  body,
1424
1456
  options.identity.provider,
@@ -33,5 +33,8 @@ export interface ListEnvelope {
33
33
  /** The offset of the next page, when there is one. */
34
34
  readonly next: number | undefined;
35
35
  }
36
- /** `{ totalCount, items }`: there is no next marker, so it is computed. */
37
- export declare const listEnvelope: (body: Json, offset: number) => ListEnvelope;
36
+ /**
37
+ * `{ totalCount, items }`: there is no next marker, so it is computed.
38
+ * `items` is required; any other answer is a `Provider` error naming `path`.
39
+ */
40
+ export declare const listEnvelope: (body: Json, offset: number, provider: string, path: string) => ListEnvelope;
@@ -6,8 +6,8 @@ import {
6
6
  } from "../chunks/chunk-NAWZ73QS.js";
7
7
  import {
8
8
  OutboundError
9
- } from "../chunks/chunk-E7JHLNLG.js";
10
- import "../chunks/chunk-VQSCHOBV.js";
9
+ } from "../chunks/chunk-J7DDZ4C2.js";
10
+ import "../chunks/chunk-BLCJHP5H.js";
11
11
 
12
12
  // src/identity/keys.ts
13
13
  var emailKey = (email) => {
@@ -44,20 +44,29 @@ var withKeys = (record) => {
44
44
  };
45
45
  return tagged;
46
46
  };
47
- var scanLeads = async function* scanLeads2(outbound, options) {
47
+ var scanLeads = async function* scanLeads2(outbound, options, tally) {
48
48
  if (options.campaignIds === void 0 && outbound.capabilities["leads.list"]) {
49
- yield* outbound.leads.listAll();
49
+ const walk = outbound.leads.listAll();
50
+ yield* walk;
51
+ tally.requests += walk.meta?.requests ?? 0;
50
52
  return;
51
53
  }
52
- const campaigns = options.campaignIds === void 0 ? await outbound.campaigns.listAll().toArray() : [];
53
- const campaignIds = options.campaignIds ?? campaigns.map((campaign) => campaign.ref);
54
+ let { campaignIds } = options;
55
+ if (campaignIds === void 0) {
56
+ const listing = outbound.campaigns.listAll();
57
+ const campaigns = await listing.toArray();
58
+ campaignIds = campaigns.map((campaign) => campaign.ref);
59
+ tally.requests += listing.meta?.requests ?? 0;
60
+ }
54
61
  for (const campaignId of campaignIds) {
55
- yield* outbound.campaign(campaignId).leads.listAll();
62
+ const walk = outbound.campaign(campaignId).leads.listAll();
63
+ yield* walk;
64
+ tally.requests += walk.meta?.requests ?? 0;
56
65
  }
57
66
  };
58
- var collect = async (outbound, options, keys, found) => {
67
+ var collect = async (outbound, options, keys, found, tally) => {
59
68
  let grew = false;
60
- for await (const lead of scanLeads(outbound, options)) {
69
+ for await (const lead of scanLeads(outbound, options, tally)) {
61
70
  const leadKeys = keysOf(lead);
62
71
  if (!found.has(lead.ref) && leadKeys.some((key) => keys.has(key))) {
63
72
  found.set(lead.ref, lead);
@@ -72,16 +81,18 @@ var collect = async (outbound, options, keys, found) => {
72
81
  var filterFor = (key) => key.startsWith("email:") ? { email: key.slice("email:".length) } : {
73
82
  linkedinUrl: `https://www.linkedin.com/in/${key.slice("linkedin:".length)}`
74
83
  };
75
- var find = async (outbound, keys, found) => {
84
+ var find = async (outbound, keys, found, tally) => {
76
85
  const asked = /* @__PURE__ */ new Set();
77
86
  for (let round = [...keys].filter((key) => !asked.has(key)); round.length > 0; round = [...keys].filter((key) => !asked.has(key))) {
78
87
  for (const key of round) {
79
88
  asked.add(key);
80
89
  }
81
- const answers = await mapConcurrent(
82
- round,
83
- (key) => outbound.leads.listAll(filterFor(key)).toArray()
84
- );
90
+ const answers = await mapConcurrent(round, async (key) => {
91
+ const walk = outbound.leads.listAll(filterFor(key));
92
+ const leads = await walk.toArray();
93
+ tally.requests += walk.meta?.requests ?? 0;
94
+ return leads;
95
+ });
85
96
  for (const [index, leads] of answers.entries()) {
86
97
  const asking = round[index];
87
98
  for (const lead of leads) {
@@ -120,10 +131,11 @@ var lookup = async (outbound, identifier, options) => {
120
131
  assertIdentifiersReadable(outbound);
121
132
  const keys = /* @__PURE__ */ new Set([key]);
122
133
  const found = /* @__PURE__ */ new Map();
134
+ const tally = { requests: 0 };
123
135
  if (outbound.capabilities["leads.lookup"] && options.campaignIds === void 0) {
124
- await find(outbound, keys, found);
125
- } else if (await collect(outbound, options, keys, found)) {
126
- await collect(outbound, options, keys, found);
136
+ await find(outbound, keys, found, tally);
137
+ } else if (await collect(outbound, options, keys, found, tally)) {
138
+ await collect(outbound, options, keys, found, tally);
127
139
  }
128
140
  const records = [...found.values()];
129
141
  const wantsTimeline = (options.timeline ?? true) && outbound.capabilities["leads.timeline"];
@@ -137,6 +149,10 @@ var lookup = async (outbound, identifier, options) => {
137
149
  key,
138
150
  keys: [...keys].toSorted(),
139
151
  records,
152
+ requests: timelines.reduce(
153
+ (sum, page) => sum + page.meta.requests,
154
+ tally.requests
155
+ ),
140
156
  timeline: timelines.flatMap((page) => page.items).toSorted(bySentAt)
141
157
  };
142
158
  };
@@ -26,6 +26,8 @@ export interface Person {
26
26
  readonly records: readonly Lead[];
27
27
  /** Every message to and from the person across tools, oldest first. */
28
28
  readonly timeline: readonly Message[];
29
+ /** Vendor requests the lookup made. */
30
+ readonly requests: number;
29
31
  }
30
32
  export interface IdentityExtension {
31
33
  readonly person: (identifier: string, options?: PersonOptions) => Promise<Person>;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export { createOutbound } from "./internal/outbound/create.ts";
2
- export type { ExtensionsOf } from "./internal/outbound/create.ts";
2
+ export type { ExtensionsOf, OutboundWith } from "./internal/outbound/create.ts";
3
3
  export { Outbound } from "./internal/outbound/outbound.ts";
4
4
  export type { OutboundOptions } from "./internal/outbound/outbound.ts";
5
5
  export type { BulkOptions, BulkResult, CampaignFilters, CampaignHandle, Collection, Estimate, EstimateQuery, Include, LeadFilters, LeadHandle, ListAll, ListHandle, ListAllOptions, ListOptions, MessageFilters, NativeClient, NativeParams, NativeReads, NativeResult, OutboundApi, PageResult, RawClient, RawRequestOptions, ReadCollection, ReplyFilters, ResultMeta, SenderFilters, SenderHandle, StatsOptions, StatsResult, ThreadHandle, TopLevelStatsOptions, WebhookFilters, WithMeta, } from "./internal/outbound/api.ts";
6
6
  export type { Operation, OperationKind, OperationOutput, OutboundRecord, } from "./internal/outbound/operations.ts";
7
7
  export type { NextOperation, OperationInfo, OutboundPlugin, } from "./internal/outbound/plugins.ts";
8
8
  export { makeErrorMapper, OutboundError } from "./internal/errors.ts";
9
- export type { ErrorMapper, ErrorMapperOptions, HttpFailure, OutboundErrorCode, OutboundErrorOptions, } from "./internal/errors.ts";
9
+ export type { ErrorMapper, ErrorMapperOptions, HttpFailure, OutboundErrorCode, OutboundErrorOptions, PartialWalk, RequestLimit, } from "./internal/errors.ts";
10
10
  export * from "./internal/records.ts";
11
11
  export { defineNative } from "./internal/native.ts";
12
12
  export type { NativeCatalog, NativeParam, NativeParamsOf, NativeRead, NoNative, } from "./internal/native.ts";
package/dist/index.js CHANGED
@@ -3,26 +3,11 @@ import {
3
3
  Outbound,
4
4
  createOutbound,
5
5
  fullJitterBackoff
6
- } from "./chunks/chunk-XNFESPZH.js";
6
+ } from "./chunks/chunk-YYCT3NGV.js";
7
7
  import {
8
8
  MemoryRateLimitStore
9
9
  } from "./chunks/chunk-4O2HRTTI.js";
10
- import {
11
- defineNative
12
- } from "./chunks/chunk-NAKXLBA6.js";
13
- import {
14
- METRIC_DEFINITIONS,
15
- computeRates,
16
- emptyCounts,
17
- sumCounts
18
- } from "./chunks/chunk-YOTW5ESM.js";
19
- import {
20
- profileSlug
21
- } from "./chunks/chunk-NAWZ73QS.js";
22
- import {
23
- sha256Hex,
24
- stableId
25
- } from "./chunks/chunk-FHKSLCVW.js";
10
+ import "./chunks/chunk-HPNGSG5E.js";
26
11
  import {
27
12
  CAPABILITY_KEYS,
28
13
  NO_CAPABILITIES,
@@ -37,11 +22,13 @@ import {
37
22
  senderHealthSchema,
38
23
  tagSchema,
39
24
  webhookSubscriptionSchema
40
- } from "./chunks/chunk-UAT3JSJZ.js";
25
+ } from "./chunks/chunk-ZOAG2C6V.js";
26
+ import "./chunks/chunk-PTZO4QXR.js";
27
+ import {
28
+ defineNative
29
+ } from "./chunks/chunk-NAKXLBA6.js";
41
30
  import {
42
- SCHEMA_VERSION,
43
31
  campaignSchema,
44
- campaignStatusSchema,
45
32
  channelSchema,
46
33
  eventDataSchema,
47
34
  eventTypeSchema,
@@ -54,25 +41,42 @@ import {
54
41
  metricRowSchema,
55
42
  metricScopeSchema,
56
43
  outboundEventSchema,
57
- replyCategorySchema,
58
44
  replySchema,
59
45
  senderSchema,
60
46
  senderStatusSchema,
61
47
  sequenceSchema,
62
48
  workspaceSchema
63
- } from "./chunks/chunk-4PSO6JEK.js";
49
+ } from "./chunks/chunk-BOWXGMN3.js";
50
+ import {
51
+ METRIC_DEFINITIONS,
52
+ computeRates,
53
+ emptyCounts,
54
+ sumCounts
55
+ } from "./chunks/chunk-PQSTQKRD.js";
56
+ import {
57
+ SCHEMA_VERSION,
58
+ campaignStatusSchema,
59
+ replyCategorySchema
60
+ } from "./chunks/chunk-QGRZDTX4.js";
64
61
  import {
65
62
  makeRef,
66
63
  parseRef
67
- } from "./chunks/chunk-LVYG7XZJ.js";
64
+ } from "./chunks/chunk-QAKJ76HB.js";
65
+ import {
66
+ profileSlug
67
+ } from "./chunks/chunk-NAWZ73QS.js";
68
+ import {
69
+ sha256Hex,
70
+ stableId
71
+ } from "./chunks/chunk-FHKSLCVW.js";
68
72
  import {
69
73
  OutboundError,
70
74
  REDACTED_EMAIL,
71
75
  REDACTED_KEY,
72
76
  makeErrorMapper,
73
77
  redactText
74
- } from "./chunks/chunk-E7JHLNLG.js";
75
- import "./chunks/chunk-VQSCHOBV.js";
78
+ } from "./chunks/chunk-J7DDZ4C2.js";
79
+ import "./chunks/chunk-BLCJHP5H.js";
76
80
  export {
77
81
  CAPABILITY_KEYS,
78
82
  DEFAULT_SHARE,
@@ -0,0 +1,3 @@
1
+ import type { InsightContext } from "./define.ts";
2
+ /** Reads the campaign, which throws `NotFound` when it does not exist. One request. */
3
+ export declare const confirmCampaign: (context: InsightContext, campaign: string) => Promise<void>;
@@ -0,0 +1,29 @@
1
+ import type { Campaign, CampaignStatus } from "../internal/entities.ts";
2
+ import type { ListAll } from "../internal/outbound/api.ts";
3
+ import type { Cap, InsightContext } from "./define.ts";
4
+ export interface Capped<Item> {
5
+ readonly items: Item[];
6
+ /** `true` when the cap stopped the read with more records left. */
7
+ readonly capped: boolean;
8
+ }
9
+ /**
10
+ * Reads up to `room` records, which is the cap unless less is left under it,
11
+ * and says so in a note naming the cap's input when more exist.
12
+ */
13
+ export declare const readCapped: <Item>(context: InsightContext, open: (max: number) => ListAll<Item>, cap: Cap, room?: number) => Promise<Capped<Item>>;
14
+ /** How many campaigns an insight read, and whether its cap left some unread. */
15
+ export interface CampaignsRead {
16
+ /** Campaigns read, in the states asked for. */
17
+ readonly campaignsRead: number;
18
+ /** `true` when `max_campaigns` stopped the read with more campaigns left. */
19
+ readonly moreCampaignsExist: boolean;
20
+ }
21
+ export declare const campaignsReadOf: (read: Capped<Campaign>) => CampaignsRead;
22
+ /**
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.
28
+ */
29
+ export declare const readCampaignsIn: (context: InsightContext, statuses: readonly CampaignStatus[], max: number, input?: string) => Promise<Capped<Campaign>>;
@@ -17,6 +17,8 @@ export interface CheckCount {
17
17
  }
18
18
  export interface CopyAudit {
19
19
  readonly campaign: string;
20
+ /** The campaign's name, from the campaign record the audit reads. */
21
+ readonly campaignName: string;
20
22
  readonly channel: "email" | "linkedin";
21
23
  /** `true` when no check found anything in the copy that could be read. */
22
24
  readonly clean: boolean;