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
@@ -1,20 +1,21 @@
1
1
  import {
2
2
  EVENT_TYPES,
3
3
  instantlyEvents
4
- } from "../chunks/chunk-SBIZDCRY.js";
4
+ } from "../chunks/chunk-BN6WCAWX.js";
5
5
  import {
6
- createVendorClient,
7
6
  flatMapPage,
8
7
  mapPage,
9
- normalizeBody,
10
8
  withLeadFields,
11
9
  withMappedFields
12
- } from "../chunks/chunk-6CVZOUHB.js";
10
+ } from "../chunks/chunk-XL6LJVHJ.js";
13
11
  import {
12
+ createVendorClient,
14
13
  leadStanding,
14
+ listIn,
15
+ normalizeBody,
15
16
  toVariant,
16
17
  variantKey
17
- } from "../chunks/chunk-FKH5N47I.js";
18
+ } from "../chunks/chunk-3S32R2MH.js";
18
19
  import {
19
20
  defineNative,
20
21
  inBody,
@@ -23,32 +24,33 @@ import {
23
24
  inQuery,
24
25
  inQueryRequired
25
26
  } from "../chunks/chunk-NAKXLBA6.js";
27
+ import {
28
+ eventTypesOf,
29
+ recordBase,
30
+ refTo,
31
+ refsTo
32
+ } from "../chunks/chunk-2D42TQFU.js";
33
+ import "../chunks/chunk-BOWXGMN3.js";
26
34
  import {
27
35
  emptyCounts,
28
36
  metricRow,
29
37
  sumCounts
30
- } from "../chunks/chunk-YOTW5ESM.js";
38
+ } from "../chunks/chunk-PQSTQKRD.js";
39
+ import "../chunks/chunk-QGRZDTX4.js";
40
+ import {
41
+ assertWorkspaceId
42
+ } from "../chunks/chunk-QAKJ76HB.js";
31
43
  import "../chunks/chunk-NAWZ73QS.js";
32
44
  import "../chunks/chunk-FHKSLCVW.js";
33
45
  import {
34
46
  readEnv,
35
47
  requireCredential
36
- } from "../chunks/chunk-IPUYZD4O.js";
37
- import {
38
- eventTypesOf,
39
- recordBase,
40
- refTo,
41
- refsTo
42
- } from "../chunks/chunk-U2D34ARZ.js";
43
- import "../chunks/chunk-4PSO6JEK.js";
44
- import {
45
- assertWorkspaceId
46
- } from "../chunks/chunk-LVYG7XZJ.js";
48
+ } from "../chunks/chunk-GFDNRWR3.js";
47
49
  import {
48
50
  OutboundError,
49
51
  makeErrorMapper,
50
52
  requireObject
51
- } from "../chunks/chunk-E7JHLNLG.js";
53
+ } from "../chunks/chunk-J7DDZ4C2.js";
52
54
  import {
53
55
  count,
54
56
  emailAddress,
@@ -63,7 +65,7 @@ import {
63
65
  text,
64
66
  timestamp,
65
67
  withoutKeys
66
- } from "../chunks/chunk-VQSCHOBV.js";
68
+ } from "../chunks/chunk-BLCJHP5H.js";
67
69
 
68
70
  // src/instantly/map-account.ts
69
71
  var CLOCK = /^\d{2}:\d{2}$/u;
@@ -385,8 +387,10 @@ var toWorkspace = (identity, raw) => ({
385
387
  ...recordBase(identity, text(raw.id) ?? identity.workspaceId, raw),
386
388
  name: text(raw.name) ?? identity.workspaceId
387
389
  });
388
- var listEnvelope = (body) => ({
389
- items: objects(isJsonObject(body) ? body.items : body),
390
+ var listEnvelope = (body, provider, path) => ({
391
+ items: objects(
392
+ listIn(body, { key: "items", path, provider, vendor: "Instantly" })
393
+ ),
390
394
  next: text(field(body, "next_starting_after")) ?? void 0
391
395
  });
392
396
 
@@ -507,26 +511,39 @@ var limits = {
507
511
  ]
508
512
  };
509
513
  var costs = {
510
- "blocklist.list": { pageSize: PAGE_SIZE, perPage: 1 },
514
+ "blocklist.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
511
515
  // The campaign, its tag assignments, then the tags' names.
512
516
  "campaigns.get": { perPage: 3 },
513
517
  // The campaigns, their tag assignments, then the tags' names.
514
- "campaigns.list": { pageSize: PAGE_SIZE, perPage: 3 },
518
+ "campaigns.list": { pageSize: PAGE_SIZE, perPage: 3, perWalk: 1 },
515
519
  "campaigns.settings": { perPage: 1 },
516
- "leads.get": { perPage: 1 },
517
- "leads.list": { pageSize: PAGE_SIZE, perPage: 1 },
518
- "lists.list": { pageSize: PAGE_SIZE, perPage: 1 },
519
- "messages.list": { pageSize: PAGE_SIZE, perPage: 1 },
520
- "replies.list": { pageSize: PAGE_SIZE, perPage: 1 },
520
+ // A custom interest label costs one more read of the label list, made only
521
+ // when the lead or a page of leads holds one.
522
+ "leads.get": { perPage: 1, perWalk: 1 },
523
+ "leads.list": {
524
+ pageSize: PAGE_SIZE,
525
+ perPage: 1,
526
+ perPageAtMost: 2,
527
+ perWalk: 1
528
+ },
529
+ "lists.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
530
+ "messages.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
531
+ // The same label read, for a page of replies with a custom status.
532
+ "replies.list": {
533
+ pageSize: PAGE_SIZE,
534
+ perPage: 1,
535
+ perPageAtMost: 2,
536
+ perWalk: 1
537
+ },
521
538
  "senders.get": { perPage: 1 },
522
539
  // The account, its DNS test, then its warmup analytics.
523
540
  "senders.health": { perPage: 3 },
524
- "senders.list": { pageSize: PAGE_SIZE, perPage: 1 },
541
+ "senders.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
525
542
  "sequence.get": { perPage: 1 },
526
- "sequence.subsequences": { pageSize: PAGE_SIZE, perPage: 1 },
543
+ "sequence.subsequences": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
527
544
  stats: { perPage: 1 },
528
- "tags.list": { pageSize: PAGE_SIZE, perPage: 1 },
529
- "webhooks.list": { pageSize: PAGE_SIZE, perPage: 1 },
545
+ "tags.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
546
+ "webhooks.list": { pageSize: PAGE_SIZE, perPage: 1, perWalk: 1 },
530
547
  "workspaces.list": { perPage: 1 }
531
548
  };
532
549
  var caveats = [
@@ -717,7 +734,9 @@ var listPage = async (client, ctx, path, query, filters = {}) => listEnvelope(
717
734
  limit: pageSize(query.limit),
718
735
  starting_after: after(query.next)
719
736
  }
720
- })
737
+ }),
738
+ client.identity.provider,
739
+ path
721
740
  );
722
741
  var readLookup = async (client, ctx, lookup, next) => {
723
742
  const envelope = await listPage(
@@ -759,9 +778,9 @@ var accountReaders = (client) => {
759
778
  return {
760
779
  // The per-campaign report, asked for one campaign: an array of one row.
761
780
  getCampaignProgress: async (id, ctx) => {
762
- const rows = objects(
763
- await client.get(ctx, "/campaigns/analytics", { query: { id } })
764
- );
781
+ const rows = await client.getRows(ctx, "/campaigns/analytics", {
782
+ query: { id }
783
+ });
765
784
  const row = rows.find((each) => text(each.campaign_id) === id) ?? rows[0];
766
785
  if (row === void 0) {
767
786
  throw new OutboundError("NotFound", `Campaign ${id} was not found`, {
@@ -880,7 +899,9 @@ var listEmails = async (client, ctx, query, received) => {
880
899
  search: threadId === void 0 ? void 0 : `thread:${threadId}`,
881
900
  starting_after: cursor.after
882
901
  }
883
- })
902
+ }),
903
+ client.identity.provider,
904
+ "/emails"
884
905
  );
885
906
  const sent = envelope.items.filter((item) => !isScheduled(item));
886
907
  return {
@@ -973,11 +994,9 @@ var range = (query) => ({
973
994
  start_date: query.from
974
995
  });
975
996
  var senderStats = async (client, ctx, scope, query) => {
976
- const days2 = objects(
977
- await client.get(ctx, "/accounts/analytics/daily", {
978
- query: { ...range(query), emails: scope.scopeId }
979
- })
980
- );
997
+ const days2 = await client.getRows(ctx, "/accounts/analytics/daily", {
998
+ query: { ...range(query), emails: scope.scopeId }
999
+ });
981
1000
  return query.by === "day" ? days2.map((day) => dailyRow(scope, day)) : [summedRow(scope, days2)];
982
1001
  };
983
1002
  var readStats = async (client, ctx, query) => {
@@ -998,10 +1017,10 @@ var readStats = async (client, ctx, query) => {
998
1017
  { provider: identity.provider }
999
1018
  );
1000
1019
  }
1001
- const campaigns = await client.get(ctx, "/campaigns/analytics", {
1020
+ const campaigns = await client.getRows(ctx, "/campaigns/analytics", {
1002
1021
  query: range(query)
1003
1022
  });
1004
- return objects(campaigns).flatMap((campaign) => {
1023
+ return campaigns.flatMap((campaign) => {
1005
1024
  const scopeId = text(campaign.campaign_id);
1006
1025
  return scopeId === null ? [] : [campaignRow({ ...scope, scopeId }, campaign)];
1007
1026
  });
@@ -1016,16 +1035,16 @@ var readStats = async (client, ctx, query) => {
1016
1035
  }
1017
1036
  );
1018
1037
  }
1019
- const steps = await client.get(ctx, "/campaigns/analytics/steps", {
1038
+ const steps = await client.getRows(ctx, "/campaigns/analytics/steps", {
1020
1039
  query: { ...range(query), campaign_id: query.scopeId }
1021
1040
  });
1022
- return objects(steps).map((step) => stepRow(scope, step));
1041
+ return steps.map((step) => stepRow(scope, step));
1023
1042
  }
1024
1043
  if (query.by === "day") {
1025
- const days2 = await client.get(ctx, "/campaigns/analytics/daily", {
1044
+ const days2 = await client.getRows(ctx, "/campaigns/analytics/daily", {
1026
1045
  query: { ...range(query), campaign_id: query.scopeId }
1027
1046
  });
1028
- return objects(days2).map((day) => dailyRow(scope, day));
1047
+ return days2.map((day) => dailyRow(scope, day));
1029
1048
  }
1030
1049
  const overview = await client.getObject(
1031
1050
  ctx,
@@ -1178,7 +1197,9 @@ var leadReaders = (client) => ({
1178
1197
  return { items: [] };
1179
1198
  }
1180
1199
  const envelope = listEnvelope(
1181
- await client.post(ctx, "/leads/list", leadListBody(query))
1200
+ await client.post(ctx, "/leads/list", leadListBody(query)),
1201
+ client.identity.provider,
1202
+ "/leads/list"
1182
1203
  );
1183
1204
  const labels = await readLabels(
1184
1205
  client,
@@ -2575,6 +2596,13 @@ var createClient = (options) => {
2575
2596
  options.identity.provider,
2576
2597
  `Instantly returned no object for ${path}`
2577
2598
  ),
2599
+ getRows: async (ctx, path, request) => objects(
2600
+ listIn(await http.get(ctx, path, request), {
2601
+ path,
2602
+ provider: options.identity.provider,
2603
+ vendor: "Instantly"
2604
+ })
2605
+ ),
2578
2606
  identity: options.identity,
2579
2607
  raw: { authorize, baseUrl, isRead, isSecret },
2580
2608
  readTags: options.readTags
@@ -18,5 +18,9 @@ export interface ListEnvelope {
18
18
  readonly items: JsonObject[];
19
19
  readonly next: string | undefined;
20
20
  }
21
- /** `{ items, next_starting_after }`: the shape of every Instantly list. */
22
- export declare const listEnvelope: (body: Json) => ListEnvelope;
21
+ /**
22
+ * `{ items, next_starting_after }`: the shape of every Instantly list, with
23
+ * `items` required. Any other answer, a bare array included, is a `Provider`
24
+ * error naming `path`.
25
+ */
26
+ export declare const listEnvelope: (body: Json, provider: string, path: string) => ListEnvelope;
@@ -139,6 +139,18 @@ export interface OperationCost {
139
139
  readonly pageSize?: number | undefined;
140
140
  /** Extra requests per record, for example one per lead to fetch a body. */
141
141
  readonly perRecord?: number | undefined;
142
+ /**
143
+ * The most extra requests a listing makes once, whatever its length, for
144
+ * example a lookup of category names on its first page. Counted in the
145
+ * upper bound of an insight's cost, never in its lower bound.
146
+ */
147
+ readonly perWalk?: number | undefined;
148
+ /**
149
+ * The most requests one page can cost, when some pages cost more than
150
+ * `perPage`, for example a label lookup made only when a page holds a
151
+ * custom label. Counted in the upper bound of an insight's cost only.
152
+ */
153
+ readonly perPageAtMost?: number | undefined;
142
154
  }
143
155
  export interface Adapter<Native extends NativeCatalog = NoNative> {
144
156
  readonly name: string;
@@ -15,6 +15,11 @@ export interface CallState {
15
15
  readonly deadlineAt: number | undefined;
16
16
  /** Stop after this many vendor requests. A plugin may lower it. */
17
17
  maxRequests: number | undefined;
18
+ /**
19
+ * The setting to raise when `maxRequests` stops the call, named in the
20
+ * error. Defaults to "maxRequests". A plugin that lowers the cap sets it.
21
+ */
22
+ maxRequestsSetBy: string | undefined;
18
23
  /**
19
24
  * Runs as each vendor request is about to be sent, after any wait, with no
20
25
  * other request able to slip in between. A plugin that caps requests across
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
- /** Bumped only for a breaking change to the shapes below. */
3
- export declare const SCHEMA_VERSION: 1;
2
+ import { campaignStatusSchema, replyCategorySchema } from "./vocabulary.ts";
3
+ export { campaignStatusSchema, replyCategorySchema, SCHEMA_VERSION, } from "./vocabulary.ts";
4
4
  /** The fields every entity carries. */
5
5
  export declare const baseFields: {
6
6
  provider: z.ZodString;
@@ -17,14 +17,6 @@ export declare const channelSchema: z.ZodEnum<{
17
17
  linkedin: "linkedin";
18
18
  }>;
19
19
  export type Channel = z.infer<typeof channelSchema>;
20
- export declare const campaignStatusSchema: z.ZodEnum<{
21
- active: "active";
22
- archived: "archived";
23
- completed: "completed";
24
- draft: "draft";
25
- paused: "paused";
26
- unknown: "unknown";
27
- }>;
28
20
  export type CampaignStatus = z.infer<typeof campaignStatusSchema>;
29
21
  export declare const campaignSchema: z.ZodObject<{
30
22
  channel: z.ZodEnum<{
@@ -149,15 +141,6 @@ export declare const senderSchema: z.ZodObject<{
149
141
  workspaceId: z.ZodString;
150
142
  }, z.core.$strip>;
151
143
  export type Sender = z.infer<typeof senderSchema>;
152
- export declare const replyCategorySchema: z.ZodEnum<{
153
- unknown: "unknown";
154
- bounce: "bounce";
155
- negative: "negative";
156
- neutral: "neutral";
157
- ooo: "ooo";
158
- positive: "positive";
159
- unsubscribe: "unsubscribe";
160
- }>;
161
144
  export type ReplyCategory = z.infer<typeof replyCategorySchema>;
162
145
  export declare const leadStatusSchema: z.ZodEnum<{
163
146
  active: "active";
@@ -252,8 +235,8 @@ export declare const leadSchema: z.ZodObject<{
252
235
  export type Lead = z.infer<typeof leadSchema>;
253
236
  export declare const messageSchema: z.ZodObject<{
254
237
  direction: z.ZodEnum<{
255
- in: "in";
256
238
  out: "out";
239
+ in: "in";
257
240
  }>;
258
241
  bodyHtml: z.ZodNullable<z.ZodString>;
259
242
  bodyText: z.ZodNullable<z.ZodString>;
@@ -1,5 +1,31 @@
1
1
  import type { Json, JsonObject } from "./json.ts";
2
2
  export type OutboundErrorCode = "Invalid" | "NotFound" | "Provider" | "RateLimited" | "Unauthorized" | "Unsupported";
3
+ /**
4
+ * What stopped a `RateLimited` call.
5
+ *
6
+ * - `vendor`: the vendor answered 429 and the SDK's retries did not get past it.
7
+ * - `deadline`: the SDK's own rate budget was full, and waiting for room
8
+ * would pass the call's `deadline`. No request was sent.
9
+ * - `call`: the call reached its request cap (`maxRequests` on the call or on
10
+ * `createOutbound`, or `budget({ per: "call" })`).
11
+ * - `run`: a `budget({ per: "run" })` has nothing left.
12
+ *
13
+ * `vendor` and `deadline` can work later. `call` and `run` are caps you set,
14
+ * so the same call stops the same way until you raise or reset them.
15
+ */
16
+ export type RequestLimit = "call" | "deadline" | "run" | "vendor";
17
+ /**
18
+ * What a `listAll().toArray()` walk had fetched when it stopped. Resume with
19
+ * `listAll({ cursor })`: no record is skipped or repeated.
20
+ */
21
+ export interface PartialWalk {
22
+ /** The records fetched before the stop, in order. */
23
+ readonly items: readonly unknown[];
24
+ /** Where to resume. `undefined` when no page was finished: start over. */
25
+ readonly cursor: string | undefined;
26
+ /** Vendor requests the walk made, including the one that failed. */
27
+ readonly requests: number;
28
+ }
3
29
  export interface OutboundErrorOptions {
4
30
  /**
5
31
  * The original error or vendor response, for debugging. It is kept as a
@@ -14,6 +40,13 @@ export interface OutboundErrorOptions {
14
40
  readonly retryAfterMs?: number | undefined;
15
41
  readonly aborted?: boolean | undefined;
16
42
  readonly timedOut?: boolean | undefined;
43
+ /**
44
+ * What stopped a `RateLimited` call. Defaults to `vendor` when there is an
45
+ * HTTP status. A `call` or `run` cap makes the error permanent.
46
+ */
47
+ readonly limit?: RequestLimit | undefined;
48
+ /** What a `toArray()` walk had fetched when it stopped. */
49
+ readonly partial?: PartialWalk | undefined;
17
50
  /** Secrets to strip from the message. */
18
51
  readonly secrets?: readonly string[] | undefined;
19
52
  }
@@ -29,6 +62,17 @@ export declare class OutboundError extends Error {
29
62
  readonly retryAfterMs: number | undefined;
30
63
  readonly aborted: boolean;
31
64
  readonly timedOut: boolean;
65
+ /**
66
+ * What stopped a `RateLimited` call: the vendor, a deadline, or a request
67
+ * cap of your own. `undefined` on every other code.
68
+ */
69
+ readonly limit: RequestLimit | undefined;
70
+ /**
71
+ * Set when `listAll().toArray()` stopped part way: the records it had
72
+ * fetched and the cursor to resume from. A partial answer is never returned
73
+ * as if it were complete.
74
+ */
75
+ readonly partial: PartialWalk | undefined;
32
76
  /** `true` when retrying the same call cannot succeed. */
33
77
  readonly permanent: boolean;
34
78
  readonly [BRAND] = true;
@@ -162,8 +162,8 @@ export declare const RECORD_SCHEMAS: {
162
162
  }, z.core.$strip>;
163
163
  readonly message: z.ZodObject<{
164
164
  direction: z.ZodEnum<{
165
- in: "in";
166
165
  out: "out";
166
+ in: "in";
167
167
  }>;
168
168
  bodyHtml: z.ZodNullable<z.ZodString>;
169
169
  bodyText: z.ZodNullable<z.ZodString>;
@@ -36,9 +36,16 @@ export declare const compactObject: (entries: Readonly<Record<string, Json | und
36
36
  */
37
37
  export declare const toJson: <Value>(value: Value) => Json;
38
38
  /**
39
- * Says which key of `input` is not one of `known`, or `undefined` when every
40
- * key is. Used so an input that would be ignored is refused instead.
39
+ * `toJson`, or `undefined` for a value `JSON.stringify` cannot write (a
40
+ * BigInt, a cycle). For an input from a caller, such as a tool's.
41
41
  */
42
+ export declare const jsonInput: <Value>(value: Value) => Json | undefined;
43
+ /**
44
+ * Says which of the `given` keys is not one of `known`, or `undefined` when
45
+ * every one is. Used so an input that would be ignored is refused instead.
46
+ */
47
+ export declare const strayKey: (known: readonly string[], given: readonly string[], noun?: string) => string | undefined;
48
+ /** `strayKey` for a JSON input: which key of `input` is not one of `known`. */
42
49
  export declare const unknownKey: (known: readonly string[], input: Json | undefined) => string | undefined;
43
50
  /**
44
51
  * A copy of `value` without any key that matches `secret`, at any depth. A
@@ -0,0 +1,24 @@
1
+ import type { Json } from "./json.ts";
2
+ /**
3
+ * A vendor list that must be a JSON array. Anything else is a `Provider`
4
+ * error with `status: 200`, the answer it was found in.
5
+ */
6
+ export declare const requireList: (value: Json | undefined, provider: string, message: string) => Json[];
7
+ export interface ListPlace {
8
+ /** The vendor as a person names it: `Instantly`. */
9
+ readonly vendor: string;
10
+ /** The adapter's provider name, for the error. */
11
+ readonly provider: string;
12
+ /** The request, as the error names it: `/campaigns`. */
13
+ readonly path: string;
14
+ /** The field of the answer that holds the array. Omitted when the answer is the array. */
15
+ readonly key?: string | undefined;
16
+ }
17
+ /** The message for an answer that is not the documented list. */
18
+ export declare const noListMessage: (place: ListPlace) => string;
19
+ /**
20
+ * The array a vendor answer holds under `place.key`, or the answer itself
21
+ * when it has no key. Anything else is a `Provider` error that says what was
22
+ * expected.
23
+ */
24
+ export declare const listIn: (body: Json | undefined, place: ListPlace) => Json[];
@@ -0,0 +1,8 @@
1
+ /** A count for a sentence, with thousands separators and at most one decimal: `2,000`, `1.5`. */
2
+ export declare const count: (amount: number) => string;
3
+ /** A rate in percent points with at most one decimal and no sign: `0.0525` as `5.3`, `0.05` as `5`. */
4
+ export declare const points: (rate: number) => string;
5
+ /** A rate as a percent: `0.0525` as `5.3%`, `0.05` as `5%`. */
6
+ export declare const percentOf: (rate: number) => string;
7
+ /** `1 lead`, `2,000 leads`. Pass `many` when adding an `s` is wrong. */
8
+ export declare const plural: (amount: number, one: string, many?: string) => string;
@@ -11,6 +11,10 @@ export interface PageRequest {
11
11
  export interface ListSpec<Item, Filters> {
12
12
  readonly action: OperationKind;
13
13
  readonly schema: ZodType<Item>;
14
+ /** Every filter the listing takes. Any other key is refused, so a misspelt filter cannot widen the answer. */
15
+ readonly takes: {
16
+ readonly [Key in keyof Filters]-?: true;
17
+ };
14
18
  /** Checks the filters and the capabilities they need. Returns clean filters. */
15
19
  readonly prepare: (filters: Filters) => Filters;
16
20
  readonly toOperation: (filters: Filters, page: PageRequest) => Operation;
@@ -1,3 +1,4 @@
1
+ import type { Adapter } from "../adapter.ts";
1
2
  import type { NativeCatalog, NoNative } from "../native.ts";
2
3
  import { Outbound } from "./outbound.ts";
3
4
  import type { OutboundOptions } from "./outbound.ts";
@@ -6,11 +7,31 @@ type ExtensionOf<Plugin> = Plugin extends OutboundPlugin<infer Extension> ? unkn
6
7
  type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (value: infer Intersection) => void ? Intersection : never;
7
8
  /** The methods a list of plugins adds to the instance. */
8
9
  export type ExtensionsOf<Plugins extends readonly OutboundPlugin[]> = UnionToIntersection<ExtensionOf<Plugins[number]>>;
10
+ /**
11
+ * The type of an instance built with these plugins, for a function that
12
+ * takes one:
13
+ *
14
+ * ```ts
15
+ * const plugins = [insights(), exporter()];
16
+ * type MyOutbound = OutboundWith<typeof plugins>;
17
+ * const brief = async (outbound: MyOutbound) => outbound.insights.hotLeads({});
18
+ * ```
19
+ *
20
+ * `Outbound` alone is an instance with no plugins.
21
+ */
22
+ export type OutboundWith<Plugins extends readonly OutboundPlugin[] = [], Native extends NativeCatalog = NoNative> = Outbound<Native> & ExtensionsOf<Plugins>;
23
+ /**
24
+ * The native catalog of an adapter type. A union of adapters, as from
25
+ * `cond ? smartlead() : instantly()`, gives the union of their catalogs, so
26
+ * only the reads they share are typed.
27
+ */
28
+ export type NativeOf<Given> = Given extends Adapter<infer Native> ? Native : NoNative;
9
29
  /**
10
30
  * Creates the client. One instance wraps one adapter; `combine()` puts
11
31
  * several adapters behind one.
12
32
  */
13
- export declare const createOutbound: <const Plugins extends readonly OutboundPlugin[] = [], Native extends NativeCatalog = NoNative>(options: OutboundOptions<Native> & {
14
- readonly plugins?: Plugins | undefined;
15
- }) => Outbound<Native> & ExtensionsOf<Plugins>;
33
+ export declare const createOutbound: <const Plugins extends readonly OutboundPlugin[] = [], const Given extends Adapter<NativeCatalog> = Adapter>(options: Omit<OutboundOptions, "adapter"> & {
34
+ readonly adapter: Given;
35
+ readonly plugins?: Plugins | readonly Plugins[number][] | undefined;
36
+ }) => NoInfer<OutboundWith<Plugins, NativeOf<Given>>>;
16
37
  export {};
@@ -9,10 +9,24 @@ import type { Campaign, Lead, Message, Reply, Sender, Workspace } from "../entit
9
9
  import type { FieldCoverage } from "../fields.ts";
10
10
  import type { OutboundHooks } from "../hooks.ts";
11
11
  import type { NativeCatalog, NoNative } from "../native.ts";
12
+ import { CAPPED } from "../request-cap.ts";
13
+ import type { CappedAccess } from "../request-cap.ts";
12
14
  import type { CampaignFilters, CampaignHandle, Collection, Estimate, EstimateQuery, LeadFilters, LeadHandle, ListHandle, MessageFilters, NativeClient, OutboundApi, RawClient, ReadCollection, ReplyFilters, SenderFilters, SenderHandle, StatsResult, ThreadHandle, TopLevelStatsOptions, WebhookFilters } from "./api.ts";
13
15
  import type { OutboundPlugin } from "./plugins.ts";
14
- export interface OutboundOptions<Native extends NativeCatalog = NoNative> extends OperationOptions {
16
+ export interface OutboundOptions<Native extends NativeCatalog = NoNative> extends Omit<OperationOptions, "maxRequests"> {
15
17
  readonly adapter: Adapter<Native>;
18
+ /**
19
+ * The most vendor requests each SDK call may send, retries included. It is
20
+ * not a total for the instance: for that, use `budget({ maxRequests })`.
21
+ * A `maxRequests` on one call replaces it for that call.
22
+ */
23
+ readonly maxRequestsPerCall?: number | undefined;
24
+ /**
25
+ * @deprecated Use `maxRequestsPerCall`. On `createOutbound` this caps each
26
+ * call, not the whole run. It keeps working, with a warning, until a later
27
+ * minor version removes it.
28
+ */
29
+ readonly maxRequests?: number | undefined;
16
30
  /** `plugins[0]` is the outermost layer. */
17
31
  readonly plugins?: readonly OutboundPlugin[] | undefined;
18
32
  readonly hooks?: OutboundHooks | undefined;
@@ -42,7 +56,7 @@ export declare class Outbound<Native extends NativeCatalog = NoNative> implement
42
56
  readonly webhooks: Collection<WebhookSubscription, WebhookFilters>;
43
57
  readonly raw: RawClient;
44
58
  readonly native: NativeClient<Native>;
45
- constructor(options: OutboundOptions<Native>, engine?: RequestEngine);
59
+ constructor(options: OutboundOptions<Native>, engine?: RequestEngine, layers?: readonly OutboundPlugin[]);
46
60
  get provider(): string;
47
61
  get workspaceId(): string;
48
62
  get capabilities(): Capabilities;
@@ -61,6 +75,8 @@ export declare class Outbound<Native extends NativeCatalog = NoNative> implement
61
75
  * plugins and what they add, so `outbound.workspace(id).insights` works.
62
76
  */
63
77
  workspace(id: string): this;
78
+ /** For a cap shared across calls, as insights and tools use. Not public. */
79
+ get [CAPPED](): CappedAccess;
64
80
  stats(options?: TopLevelStatsOptions): Promise<StatsResult>;
65
81
  limits(): Promise<LimitsSnapshot[]>;
66
82
  estimate(query: EstimateQuery): Estimate;
@@ -2,4 +2,8 @@ import type { TimeRange } from "../adapter.ts";
2
2
  export declare const normalizeRange: (range: TimeRange) => TimeRange;
3
3
  export declare const assertDay: (value: string | undefined, name: string) => string | undefined;
4
4
  export declare const assertLimit: (limit: number | undefined) => number | undefined;
5
+ /** `max` for `listAll`: a positive integer, like `limit`. */
6
+ export declare const assertMax: (max: number | undefined) => number | undefined;
7
+ /** A plain JavaScript caller can pass anything as an id. */
8
+ export declare const assertIdIsString: (id: string, what: string) => string;
5
9
  export declare const assertId: (id: string, what: string) => string;
@@ -3,10 +3,11 @@ import type { ListAll, PageResult, ResultMeta } from "./api.ts";
3
3
  export interface WalkerOptions<Item> {
4
4
  readonly cursor: string | undefined;
5
5
  readonly max: number | undefined;
6
+ /** Starts the call's accounting, when the first page is asked for. */
7
+ readonly begin: () => CallState;
6
8
  /** Fetches one page. `state` is shared by every page of the walk. */
7
- readonly fetchPage: (cursor: string | undefined, state: CallState | undefined) => Promise<{
9
+ readonly fetchPage: (cursor: string | undefined, state: CallState) => Promise<{
8
10
  readonly page: PageResult<Item>;
9
- readonly state: CallState;
10
11
  }>;
11
12
  /** A stable key used to drop records a shifting page returned twice. */
12
13
  readonly keyOf: (item: Item) => string | undefined;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The word that goes with `amount`: `one` for exactly one, `many` otherwise.
3
+ * Works for verbs too: `noun(count, "is", "are")`.
4
+ */
5
+ export declare const noun: (amount: number, one: string, many?: string) => string;
6
+ /** `1 lead`, `3 leads`. Pass `many` when adding an `s` is wrong. */
7
+ export declare const plural: (amount: number, one: string, many?: string) => string;
8
+ /**
9
+ * A person key as a person reads it: `email:jo@example.com` is the address,
10
+ * `linkedin:jo-doe` the profile's address without `https://www.`.
11
+ */
12
+ export declare const shownKey: (key: string) => string;
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+ import type { ZodType } from "zod";
3
+ import type { Json } from "./json.ts";
4
+ /** The fields of an object schema, by name. */
5
+ type Fields = Readonly<Record<string, ZodType>>;
6
+ /**
7
+ * The old name of the field `to`. Pass the new field's schema without its
8
+ * default, so leaving the old name out does not set it.
9
+ */
10
+ export declare const renamed: <Schema extends ZodType>(to: string, base: Schema) => z.ZodOptional<Schema>;
11
+ /** The field names without the deprecated old names. */
12
+ export declare const liveKeys: (fields: Fields) => string[];
13
+ export type Renamed = {
14
+ readonly input: Json | undefined;
15
+ readonly notes: readonly string[];
16
+ } | {
17
+ readonly conflict: {
18
+ readonly from: string;
19
+ readonly to: string;
20
+ };
21
+ };
22
+ /**
23
+ * The input with each old name's value moved to its new name, and a note
24
+ * for each old name used. Both names at once is a conflict, since either
25
+ * value could be the one meant.
26
+ */
27
+ export declare const applyRenames: (fields: Fields, input: Json | undefined) => Renamed;
28
+ export {};