outbound-sdk 0.2.1 → 0.4.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 (139) hide show
  1. package/dist/alerts/index.js +50 -19
  2. package/dist/alerts/plugin.d.ts +20 -3
  3. package/dist/audit/index.js +2 -2
  4. package/dist/benchmarks/index.js +5 -5
  5. package/dist/budget/index.d.ts +3 -2
  6. package/dist/budget/index.js +11 -10
  7. package/dist/cards/content.d.ts +6 -1
  8. package/dist/cards/format.d.ts +17 -2
  9. package/dist/cards/index.d.ts +1 -1
  10. package/dist/cards/index.js +297 -132
  11. package/dist/cards/parts.d.ts +9 -2
  12. package/dist/cards/render.d.ts +20 -3
  13. package/dist/chunks/{chunk-U2D34ARZ.js → chunk-2D42TQFU.js} +3 -3
  14. package/dist/chunks/chunk-4PA526S7.js +17 -0
  15. package/dist/chunks/{chunk-6CVZOUHB.js → chunk-5CFO3CXG.js} +24 -0
  16. package/dist/chunks/{chunk-XNFESPZH.js → chunk-5FVKRIEJ.js} +168 -31
  17. package/dist/chunks/{chunk-P3IJBJUI.js → chunk-7LNJJ2RO.js} +200 -57
  18. package/dist/chunks/{chunk-XC6CZP73.js → chunk-7ZDS6SZD.js} +7 -1
  19. package/dist/chunks/{chunk-SBIZDCRY.js → chunk-A6WVOCA4.js} +4 -4
  20. package/dist/chunks/{chunk-VQSCHOBV.js → chunk-BLCJHP5H.js} +11 -4
  21. package/dist/chunks/{chunk-4PSO6JEK.js → chunk-BOWXGMN3.js} +6 -21
  22. package/dist/chunks/{chunk-DJ2IUQEU.js → chunk-C4LS2HNV.js} +3 -3
  23. package/dist/chunks/{chunk-AFU5E5QB.js → chunk-E6DSDCPI.js} +98 -69
  24. package/dist/chunks/{chunk-IPUYZD4O.js → chunk-GFDNRWR3.js} +1 -1
  25. package/dist/chunks/{chunk-PURHK3JU.js → chunk-IZFTTMJP.js} +4 -4
  26. package/dist/chunks/{chunk-E7JHLNLG.js → chunk-J7DDZ4C2.js} +15 -2
  27. package/dist/chunks/{chunk-FKH5N47I.js → chunk-K4USHN4C.js} +1 -1
  28. package/dist/chunks/chunk-LVQUSKEX.js +17 -0
  29. package/dist/chunks/{chunk-YOTW5ESM.js → chunk-PQSTQKRD.js} +2 -2
  30. package/dist/chunks/chunk-PTZO4QXR.js +15 -0
  31. package/dist/chunks/{chunk-LVYG7XZJ.js → chunk-QAKJ76HB.js} +1 -1
  32. package/dist/chunks/chunk-QGRZDTX4.js +26 -0
  33. package/dist/chunks/{chunk-R3Y56YVF.js → chunk-Y5RAJ6PZ.js} +2 -2
  34. package/dist/chunks/{chunk-RCZ7ZZFU.js → chunk-ZFVHM5JI.js} +3 -3
  35. package/dist/chunks/{chunk-UAT3JSJZ.js → chunk-ZOAG2C6V.js} +2 -2
  36. package/dist/cli/bin.js +17 -13
  37. package/dist/cli/commands.d.ts +11 -0
  38. package/dist/cli/index.js +17 -13
  39. package/dist/cli/mcp.d.ts +5 -0
  40. package/dist/clients/index.d.ts +1 -1
  41. package/dist/clients/index.js +35 -10
  42. package/dist/clients/plugin.d.ts +9 -2
  43. package/dist/combine/index.js +7 -6
  44. package/dist/exporter/index.d.ts +5 -2
  45. package/dist/exporter/index.js +2 -2
  46. package/dist/failover/index.js +3 -3
  47. package/dist/fixtures/index.js +5 -4
  48. package/dist/heyreach/client.d.ts +2 -0
  49. package/dist/heyreach/index.js +71 -39
  50. package/dist/heyreach/map.d.ts +5 -2
  51. package/dist/identity/index.js +33 -17
  52. package/dist/identity/plugin.d.ts +2 -0
  53. package/dist/index.d.ts +2 -2
  54. package/dist/index.js +13 -10
  55. package/dist/insights/campaign.d.ts +3 -0
  56. package/dist/insights/capped.d.ts +29 -0
  57. package/dist/insights/copy/copy-audit.d.ts +2 -0
  58. package/dist/insights/copy/copy-reuse.d.ts +27 -3
  59. package/dist/insights/copy/index.d.ts +8 -8
  60. package/dist/insights/copy/reply-timing.d.ts +8 -0
  61. package/dist/insights/copy/reuse-base.d.ts +32 -0
  62. package/dist/insights/copy/shared.d.ts +39 -15
  63. package/dist/insights/copy/step-funnel.d.ts +16 -5
  64. package/dist/insights/copy/variant-test.d.ts +19 -8
  65. package/dist/insights/define.d.ts +56 -2
  66. package/dist/insights/fields.d.ts +16 -0
  67. package/dist/insights/index.d.ts +2 -1
  68. package/dist/insights/index.js +1494 -730
  69. package/dist/insights/inputs.generated.d.ts +951 -0
  70. package/dist/insights/ops/campaign-diagnosis.d.ts +3 -1
  71. package/dist/insights/ops/campaign-ranking.d.ts +12 -4
  72. package/dist/insights/ops/channel-mix.d.ts +2 -1
  73. package/dist/insights/ops/client-report.d.ts +18 -5
  74. package/dist/insights/ops/index.d.ts +6 -2
  75. package/dist/insights/ops/period-comparison.d.ts +14 -3
  76. package/dist/insights/ops/pipeline-forecast.d.ts +14 -4
  77. package/dist/insights/ops/shared.d.ts +29 -24
  78. package/dist/insights/ops/tag-rollup.d.ts +2 -1
  79. package/dist/insights/people/account-summary.d.ts +13 -0
  80. package/dist/insights/people/dropped-replies.d.ts +8 -0
  81. package/dist/insights/people/find.d.ts +7 -1
  82. package/dist/insights/people/hot-leads.d.ts +16 -1
  83. package/dist/insights/people/person-summary.d.ts +6 -0
  84. package/dist/insights/people/read.d.ts +26 -10
  85. package/dist/insights/people/suppression-check.d.ts +11 -2
  86. package/dist/insights/plugin.d.ts +7 -5
  87. package/dist/insights/ref.d.ts +6 -0
  88. package/dist/insights/registry.d.ts +28 -16
  89. package/dist/insights/senders/bounce-watch.d.ts +25 -8
  90. package/dist/insights/senders/capacity-sends.d.ts +22 -0
  91. package/dist/insights/senders/domain-health.d.ts +10 -4
  92. package/dist/insights/senders/index.d.ts +14 -6
  93. package/dist/insights/senders/read.d.ts +15 -14
  94. package/dist/insights/senders/sender-capacity.d.ts +5 -13
  95. package/dist/insights/senders/sender-load.d.ts +2 -0
  96. package/dist/insights/stats.d.ts +8 -0
  97. package/dist/insights/tools.d.ts +3 -2
  98. package/dist/instantly/client.d.ts +2 -0
  99. package/dist/instantly/index.js +44 -29
  100. package/dist/instantly/map.d.ts +6 -2
  101. package/dist/internal/engine/request.d.ts +5 -0
  102. package/dist/internal/entities.d.ts +3 -20
  103. package/dist/internal/errors.d.ts +44 -0
  104. package/dist/internal/fields.d.ts +1 -1
  105. package/dist/internal/json.d.ts +9 -2
  106. package/dist/internal/lists.d.ts +24 -0
  107. package/dist/internal/numbers.d.ts +8 -0
  108. package/dist/internal/outbound/collections.d.ts +4 -0
  109. package/dist/internal/outbound/create.d.ts +24 -3
  110. package/dist/internal/outbound/outbound.d.ts +13 -1
  111. package/dist/internal/outbound/validate.d.ts +4 -0
  112. package/dist/internal/outbound/walker.d.ts +3 -2
  113. package/dist/internal/plural.d.ts +12 -0
  114. package/dist/internal/renamed.d.ts +28 -0
  115. package/dist/internal/vocabulary.d.ts +20 -0
  116. package/dist/loader/index.js +5 -5
  117. package/dist/memory/adapter.d.ts +7 -0
  118. package/dist/memory/demo-stats.d.ts +3 -0
  119. package/dist/memory/demo.d.ts +14 -3
  120. package/dist/memory/index.d.ts +1 -0
  121. package/dist/memory/index.js +200 -95
  122. package/dist/providers/index.d.ts +72 -0
  123. package/dist/providers/index.js +3 -1
  124. package/dist/reconcile/index.js +5 -4
  125. package/dist/redact/index.js +10 -4
  126. package/dist/redact/plugin.d.ts +7 -0
  127. package/dist/smartlead/index.js +102 -49
  128. package/dist/smartlead/shared.d.ts +13 -0
  129. package/dist/sync/index.js +2 -2
  130. package/dist/tools/ai-sdk.js +8 -6
  131. package/dist/tools/campaign-tools.d.ts +1 -1
  132. package/dist/tools/claude-agent.js +8 -6
  133. package/dist/tools/index.js +9 -7
  134. package/dist/tools/input-problem.d.ts +8 -0
  135. package/dist/tools/registry.d.ts +7 -2
  136. package/dist/tools/shared.d.ts +7 -0
  137. package/dist/tracing/index.js +2 -2
  138. package/dist/webhooks/index.js +10 -9
  139. package/package.json +1 -1
@@ -4,8 +4,13 @@ export declare const LEFT = "left";
4
4
  export declare const RIGHT = "right";
5
5
  /** A rate with `low` and `high` beside it, as the ops insights report one. */
6
6
  export declare const measured: (value: Json | undefined) => string;
7
- /** A rate with an `interval` object beside it, as the copy insights report one. */
8
- export declare const withInterval: (value: JsonObject, rateKey: string, intervalKey: string) => string;
7
+ /**
8
+ * A rate with `low` and `high` beside it, or the `interval` object a result
9
+ * stored before those carries.
10
+ */
11
+ export declare const withInterval: (value: JsonObject, rateKey?: string, intervalKey?: string) => string;
12
+ /** A row's `rates.replyRate`, or its older `replyRate` and `replyRateInterval`. */
13
+ export declare const replyRate: (value: JsonObject) => string;
9
14
  /** Sent, replies, positive and bounced, as fields. */
10
15
  export declare const totalStats: (totals: Json | undefined) => Stat[];
11
16
  /** `🔴 finding` for an item with a `severity` and a `finding`. */
@@ -20,3 +25,5 @@ export declare const verdict: (checked: number | null, problem: string | null, c
20
25
  export declare const range: (period: Json | undefined) => string;
21
26
  /** `4.2%` as a chart value: one decimal, or `null`. */
22
27
  export declare const percentPoint: (rate: number | null) => number | null;
28
+ /** Says an answer stopped at `max_campaigns` with more campaigns left, or nothing. */
29
+ export declare const campaignsCapped: (data: Json | undefined) => string[];
@@ -3,12 +3,29 @@ import type { CardOptions } from "./content.ts";
3
3
  import type { CardSpec } from "./spec.ts";
4
4
  /** Every tool and insight that has a card of its own. */
5
5
  export declare const CARD_NAMES: readonly string[];
6
+ /** An insight method's result, as `outbound.insights.hotLeads()` returns it. */
7
+ export interface InsightResultLike {
8
+ readonly insight?: string | undefined;
9
+ readonly data: unknown;
10
+ readonly meta: {
11
+ readonly evidence: string;
12
+ readonly requests: number;
13
+ readonly provider: string;
14
+ readonly complete?: boolean | undefined;
15
+ readonly notes?: readonly string[] | undefined;
16
+ };
17
+ }
18
+ /** What `cardFor` draws: a tool's result, or an insight method's result. */
19
+ export type CardInput = InsightResultLike | ToolResult;
6
20
  /**
7
21
  * The card for one tool or insight result. `name` is the tool's name, such as
8
- * `campaign_overview` or `hot_leads`. Never throws: a failed result becomes a
9
- * card that says what failed.
22
+ * `campaign_overview` or `hot_leads`. `result` is what the tool's `call`
23
+ * returned, or what the insight method returned, such as
24
+ * `await outbound.insights.hotLeads({})`. Never throws: a failed result
25
+ * becomes a card that says what failed, and anything else a card that says
26
+ * there is nothing to show.
10
27
  */
11
- export declare const cardFor: (name: string, result: ToolResult, options?: CardOptions) => CardSpec;
28
+ export declare const cardFor: (name: string, result: CardInput, options?: CardOptions) => CardSpec;
12
29
  export interface DigestSection {
13
30
  /** The tool's name, such as `bounce_watch`. */
14
31
  readonly name: string;
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  SCHEMA_VERSION
3
- } from "./chunk-4PSO6JEK.js";
3
+ } from "./chunk-QGRZDTX4.js";
4
4
  import {
5
5
  makeRef
6
- } from "./chunk-LVYG7XZJ.js";
6
+ } from "./chunk-QAKJ76HB.js";
7
7
  import {
8
8
  compactObject
9
- } from "./chunk-VQSCHOBV.js";
9
+ } from "./chunk-BLCJHP5H.js";
10
10
 
11
11
  // src/internal/record.ts
12
12
  var recordBase = (identity, sourceId, raw) => ({
@@ -0,0 +1,17 @@
1
+ import {
2
+ noun
3
+ } from "./chunk-PTZO4QXR.js";
4
+
5
+ // src/internal/numbers.ts
6
+ var NUMBER = new Intl.NumberFormat("en-US", { maximumFractionDigits: 1 });
7
+ var count = (amount) => NUMBER.format(amount);
8
+ var points = (rate) => NUMBER.format(Math.round(rate * 1e3) / 10);
9
+ var percentOf = (rate) => `${points(rate)}%`;
10
+ var plural = (amount, one, many = `${one}s`) => `${count(amount)} ${noun(amount, one, many)}`;
11
+
12
+ export {
13
+ count,
14
+ points,
15
+ percentOf,
16
+ plural
17
+ };
@@ -1,6 +1,13 @@
1
1
  import {
2
2
  buildUrl
3
3
  } from "./chunk-NAWZ73QS.js";
4
+ import {
5
+ OutboundError
6
+ } from "./chunk-J7DDZ4C2.js";
7
+ import {
8
+ isJsonArray,
9
+ isJsonObject
10
+ } from "./chunk-BLCJHP5H.js";
4
11
 
5
12
  // src/internal/lead-fields.ts
6
13
  var MAPPABLE = [
@@ -67,6 +74,22 @@ var flatMapPage = (page, toItems) => ({
67
74
  next: page.next
68
75
  });
69
76
 
77
+ // src/internal/lists.ts
78
+ var requireList = (value, provider, message) => {
79
+ if (!isJsonArray(value)) {
80
+ throw new OutboundError("Provider", message, { provider, status: 200 });
81
+ }
82
+ return value;
83
+ };
84
+ var noListMessage = (place) => `${place.vendor} returned no list for ${place.path}: expected ${place.key === void 0 ? "a JSON array" : `a JSON object with an array in \`${place.key}\``}`;
85
+ var listIn = (body, place) => {
86
+ let rows = body;
87
+ if (place.key !== void 0) {
88
+ rows = isJsonObject(body) ? body[place.key] : void 0;
89
+ }
90
+ return requireList(rows, place.provider, noListMessage(place));
91
+ };
92
+
70
93
  // src/internal/client.ts
71
94
  var createVendorClient = (baseUrl, authorize) => ({
72
95
  get: async (ctx, path, options = {}) => {
@@ -147,6 +170,7 @@ export {
147
170
  withMappedFields,
148
171
  mapPage,
149
172
  flatMapPage,
173
+ listIn,
150
174
  normalizeBody,
151
175
  createVendorClient
152
176
  };
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  defaultRateLimitStore
3
3
  } from "./chunk-4O2HRTTI.js";
4
+ import {
5
+ plural
6
+ } from "./chunk-PTZO4QXR.js";
4
7
  import {
5
8
  buildUrl
6
9
  } from "./chunk-NAWZ73QS.js";
@@ -21,7 +24,7 @@ import {
21
24
  senderHealthSchema,
22
25
  tagSchema,
23
26
  webhookSubscriptionSchema
24
- } from "./chunk-UAT3JSJZ.js";
27
+ } from "./chunk-ZOAG2C6V.js";
25
28
  import {
26
29
  campaignSchema,
27
30
  leadSchema,
@@ -31,21 +34,22 @@ import {
31
34
  senderSchema,
32
35
  sequenceSchema,
33
36
  workspaceSchema
34
- } from "./chunk-4PSO6JEK.js";
37
+ } from "./chunk-BOWXGMN3.js";
35
38
  import {
36
39
  sourceIdFor
37
- } from "./chunk-LVYG7XZJ.js";
40
+ } from "./chunk-QAKJ76HB.js";
38
41
  import {
39
42
  OutboundError,
40
43
  redactUrl
41
- } from "./chunk-E7JHLNLG.js";
44
+ } from "./chunk-J7DDZ4C2.js";
42
45
  import {
43
46
  count,
44
47
  field,
45
48
  isJsonObject,
46
49
  isString,
47
- parseJson
48
- } from "./chunk-VQSCHOBV.js";
50
+ parseJson,
51
+ strayKey
52
+ } from "./chunk-BLCJHP5H.js";
49
53
 
50
54
  // src/internal/limits.ts
51
55
  var DEFAULT_CONCURRENCY = 8;
@@ -273,7 +277,12 @@ var Budget = class {
273
277
  throw new OutboundError(
274
278
  "RateLimited",
275
279
  `${provider} rate budget is full and the deadline would pass before it frees up`,
276
- { provider, retryAfterMs: waitMs, timedOut: true }
280
+ {
281
+ limit: "deadline",
282
+ provider,
283
+ retryAfterMs: waitMs,
284
+ timedOut: true
285
+ }
277
286
  );
278
287
  }
279
288
  fire(hooks.onThrottle, { lane, provider, waitMs });
@@ -473,15 +482,17 @@ var attempt = async (spec, environment, attemptNumber) => {
473
482
  var assertRequestBudget = (environment) => {
474
483
  const { adapter, state } = environment;
475
484
  if (state.maxRequests !== void 0 && state.requests >= state.maxRequests) {
485
+ const setBy = state.maxRequestsSetBy ?? "maxRequests";
476
486
  throw new OutboundError(
477
487
  "RateLimited",
478
- `The call used its budget of ${state.maxRequests} request(s) to ${adapter.name}`,
479
- { provider: adapter.name }
488
+ `The call used its budget of ${plural(state.maxRequests, "request")} to ${adapter.name}. Raise ${setBy} or ask for less in one call.`,
489
+ { limit: "call", provider: adapter.name }
480
490
  );
481
491
  }
482
492
  };
483
493
  var exhausted = (error, timedOut) => timedOut ? new OutboundError(error.code, error.message, {
484
494
  cause: error.cause,
495
+ limit: error.limit,
485
496
  provider: error.provider,
486
497
  retryAfterMs: error.retryAfterMs,
487
498
  status: error.status,
@@ -575,6 +586,8 @@ var RequestEngine = class {
575
586
  beforeRequest: void 0,
576
587
  deadlineAt: merged.deadline === void 0 ? void 0 : this.now() + merged.deadline,
577
588
  maxRequests: merged.maxRequests,
589
+ // A cap from the instance is named by the option that set it there.
590
+ maxRequestsSetBy: options.maxRequests === void 0 && this.#defaults.maxRequests !== void 0 ? "maxRequestsPerCall" : void 0,
578
591
  requests: 0,
579
592
  retry: resolveRetryPolicy(merged.retries),
580
593
  signal: merged.signal,
@@ -721,11 +734,13 @@ var checked = (core, schema, records, action) => {
721
734
  // src/internal/outbound/validate.ts
722
735
  var DATE = /^\d{4}-\d{2}-\d{2}$/u;
723
736
  var invalid = (message) => new OutboundError("Invalid", message);
737
+ var DAY_MS = 864e5;
724
738
  var normalizeInstant = (value, name) => {
725
739
  if (value === void 0) {
726
740
  return void 0;
727
741
  }
728
- const time = Date.parse(value);
742
+ const parsed = Date.parse(value);
743
+ const time = name === "until" && DATE.test(value) ? parsed + DAY_MS - 1 : parsed;
729
744
  if (Number.isNaN(time)) {
730
745
  throw invalid(
731
746
  `${name} must be an ISO 8601 date or timestamp, got "${value}"`
@@ -753,8 +768,20 @@ var assertLimit = (limit) => {
753
768
  }
754
769
  return limit;
755
770
  };
771
+ var assertMax = (max) => {
772
+ if (max !== void 0 && (!Number.isInteger(max) || max < 1)) {
773
+ throw invalid(`max must be a positive integer, got ${max}`);
774
+ }
775
+ return max;
776
+ };
777
+ var assertIdIsString = (id, what) => {
778
+ if (typeof id !== "string") {
779
+ throw invalid(`${what} id must be a string, got ${String(id)}`);
780
+ }
781
+ return id;
782
+ };
756
783
  var assertId = (id, what) => {
757
- if (id.trim() === "") {
784
+ if (assertIdIsString(id, what).trim() === "") {
758
785
  throw invalid(`${what} id must not be empty`);
759
786
  }
760
787
  return id;
@@ -766,6 +793,7 @@ var PageWalker = class {
766
793
  #cursor;
767
794
  #meta;
768
795
  #truncated = false;
796
+ #state;
769
797
  constructor(options) {
770
798
  this.#options = options;
771
799
  this.#cursor = options.cursor;
@@ -780,13 +808,13 @@ var PageWalker = class {
780
808
  return this.#truncated;
781
809
  }
782
810
  async *[Symbol.asyncIterator]() {
783
- const { fetchPage: fetchPage2, keyOf, max } = this.#options;
811
+ const { begin, fetchPage: fetchPage2, keyOf, max } = this.#options;
784
812
  const seen = /* @__PURE__ */ new Set();
785
- let state;
813
+ const state = begin();
814
+ this.#state = state;
786
815
  let yielded = 0;
787
816
  for (; ; ) {
788
817
  const fetched = await fetchPage2(this.#cursor, state);
789
- ({ state } = fetched);
790
818
  this.#meta = fetched.page.meta;
791
819
  for (const item of fetched.page.items) {
792
820
  const key = keyOf(item);
@@ -814,8 +842,28 @@ var PageWalker = class {
814
842
  }
815
843
  async toArray() {
816
844
  const items = [];
817
- for await (const item of this) {
818
- items.push(item);
845
+ try {
846
+ for await (const item of this) {
847
+ items.push(item);
848
+ }
849
+ } catch (error) {
850
+ if (!OutboundError.is(error)) {
851
+ throw error;
852
+ }
853
+ throw new OutboundError(error.code, error.message, {
854
+ aborted: error.aborted,
855
+ cause: error,
856
+ limit: error.limit,
857
+ partial: {
858
+ cursor: this.#cursor,
859
+ items,
860
+ requests: this.#state?.requests ?? 0
861
+ },
862
+ provider: error.provider,
863
+ retryAfterMs: error.retryAfterMs,
864
+ status: error.status,
865
+ timedOut: error.timedOut
866
+ });
819
867
  }
820
868
  return items;
821
869
  }
@@ -823,6 +871,28 @@ var PageWalker = class {
823
871
 
824
872
  // src/internal/outbound/collections.ts
825
873
  var DEFAULT_BULK_CONCURRENCY = 4;
874
+ var LIST_ALL_KEYS = Object.keys({
875
+ cursor: true,
876
+ deadline: true,
877
+ limit: true,
878
+ max: true,
879
+ maxRequests: true,
880
+ retries: true,
881
+ signal: true,
882
+ timeout: true
883
+ });
884
+ var LIST_KEYS = LIST_ALL_KEYS.filter((key) => key !== "max");
885
+ var refuseUnknown = (spec, options, optionKeys) => {
886
+ const given = Object.entries(options ?? {}).filter(([, value]) => value !== void 0).map(([key]) => key);
887
+ const stray = strayKey(
888
+ [...Object.keys(spec.takes), ...optionKeys],
889
+ given,
890
+ "an option"
891
+ );
892
+ if (stray !== void 0) {
893
+ throw new OutboundError("Invalid", `${spec.action}: ${stray}`);
894
+ }
895
+ };
826
896
  var cursorScope = (core, action) => ({
827
897
  action,
828
898
  provider: core.adapter.name,
@@ -857,6 +927,7 @@ var fetchPage = (core, spec, request, options, shared) => perform(
857
927
  );
858
928
  var makeReadCollection = (core, spec) => ({
859
929
  list: async (options) => {
930
+ refuseUnknown(spec, options, LIST_KEYS);
860
931
  const filters = spec.prepare(options ?? {});
861
932
  const limit = assertLimit(options?.limit);
862
933
  const { page } = await fetchPage(
@@ -868,10 +939,13 @@ var makeReadCollection = (core, spec) => ({
868
939
  return page;
869
940
  },
870
941
  listAll: (options) => {
942
+ refuseUnknown(spec, options, LIST_ALL_KEYS);
871
943
  const filters = spec.prepare(options ?? {});
872
944
  const limit = assertLimit(options?.limit);
945
+ assertMax(options?.max);
873
946
  const walkOptions = options;
874
947
  return new PageWalker({
948
+ begin: () => core.engine.begin(options),
875
949
  cursor: walkOptions?.cursor,
876
950
  fetchPage: (cursor, state) => fetchPage(core, spec, { cursor, filters, limit }, options, state),
877
951
  keyOf: (item) => spec.keyOf(item, filters),
@@ -918,31 +992,39 @@ var makeGetter = (core, spec) => async (id, options) => {
918
992
  };
919
993
  var getMany = async (core, spec, ids, options) => {
920
994
  spec.prepare();
995
+ for (const id of ids) {
996
+ assertIdIsString(id, spec.what);
997
+ }
921
998
  const state = core.engine.begin(options);
922
- const results = [];
923
- const errors = [];
924
- const queue = [...ids];
999
+ const distinct = [...new Set(ids)];
1000
+ const answers = /* @__PURE__ */ new Map();
1001
+ const queue = [...distinct];
925
1002
  const worker = async () => {
926
1003
  for (let id = queue.shift(); id !== void 0; id = queue.shift()) {
927
1004
  try {
928
1005
  const value = await getOne(core, spec, id, options, state, true);
929
- results.push({ id, value });
1006
+ answers.set(id, { value });
930
1007
  } catch (error) {
931
- errors.push({ error: toOutboundError(core, error), id });
1008
+ answers.set(id, { error: toOutboundError(core, error) });
932
1009
  }
933
1010
  }
934
1011
  };
935
1012
  const workers = Math.max(
936
1013
  1,
937
- Math.min(options?.concurrency ?? DEFAULT_BULK_CONCURRENCY, ids.length)
1014
+ Math.min(options?.concurrency ?? DEFAULT_BULK_CONCURRENCY, distinct.length)
938
1015
  );
939
1016
  await Promise.all(Array.from({ length: workers }, worker));
940
- const order = new Map(ids.map((id, index) => [id, index]));
941
- const byOrder = (left, right) => (order.get(left.id) ?? 0) - (order.get(right.id) ?? 0);
942
- return {
943
- errors: errors.toSorted(byOrder),
944
- results: results.toSorted(byOrder)
945
- };
1017
+ const results = [];
1018
+ const errors = [];
1019
+ for (const id of ids) {
1020
+ const answer = answers.get(id);
1021
+ if (answer !== void 0 && "value" in answer) {
1022
+ results.push({ id, value: answer.value });
1023
+ } else if (answer !== void 0) {
1024
+ errors.push({ error: answer.error, id });
1025
+ }
1026
+ }
1027
+ return { errors, results };
946
1028
  };
947
1029
  var makeCollection = (core, listSpec, getSpec) => ({
948
1030
  ...makeReadCollection(core, listSpec),
@@ -1001,6 +1083,7 @@ var healthGet = (core) => ({
1001
1083
  });
1002
1084
  var subsequenceList = (core) => ({
1003
1085
  action: "sequence.subsequences",
1086
+ takes: { campaignId: true },
1004
1087
  keyOf: refOf,
1005
1088
  prepare: (filters) => {
1006
1089
  requireCapability(
@@ -1023,6 +1106,7 @@ var subsequenceList = (core) => ({
1023
1106
  });
1024
1107
  var listList = (core) => ({
1025
1108
  action: "lists.list",
1109
+ takes: {},
1026
1110
  keyOf: refOf,
1027
1111
  prepare: () => {
1028
1112
  requireCapability(core.gate, "lists.list", "Listing lead lists");
@@ -1051,6 +1135,7 @@ var webhookGet = (core) => ({
1051
1135
  });
1052
1136
  var blocklistList = (core) => ({
1053
1137
  action: "blocklist.list",
1138
+ takes: {},
1054
1139
  keyOf: refOf,
1055
1140
  prepare: () => {
1056
1141
  requireCapability(core.gate, "blocklist", "Listing the block list");
@@ -1061,6 +1146,7 @@ var blocklistList = (core) => ({
1061
1146
  });
1062
1147
  var placementTestList = (core) => ({
1063
1148
  action: "placementTests.list",
1149
+ takes: {},
1064
1150
  keyOf: refOf,
1065
1151
  prepare: () => {
1066
1152
  requireCapability(
@@ -1078,6 +1164,7 @@ var placementTestList = (core) => ({
1078
1164
  });
1079
1165
  var tagList = (core) => ({
1080
1166
  action: "tags.list",
1167
+ takes: {},
1081
1168
  keyOf: refOf,
1082
1169
  prepare: () => {
1083
1170
  requireCapability(core.gate, "tags", "Listing tags");
@@ -1088,6 +1175,7 @@ var tagList = (core) => ({
1088
1175
  });
1089
1176
  var webhookList = (core) => ({
1090
1177
  action: "webhooks.list",
1178
+ takes: { campaignId: true },
1091
1179
  keyOf: refOf,
1092
1180
  prepare: (filters) => {
1093
1181
  requireCapability(core.gate, "webhooks.list", "Listing webhooks");
@@ -1106,6 +1194,7 @@ var hasRange = (filters) => filters.since !== void 0 || filters.until !== void 0
1106
1194
  var refOf2 = (item) => item.ref;
1107
1195
  var campaignList = (core) => ({
1108
1196
  action: "campaigns.list",
1197
+ takes: { senderId: true, status: true },
1109
1198
  keyOf: refOf2,
1110
1199
  prepare: (filters) => {
1111
1200
  if (filters.status !== void 0) {
@@ -1149,6 +1238,7 @@ var sequenceGet = (core) => ({
1149
1238
  });
1150
1239
  var senderList = (core) => ({
1151
1240
  action: "senders.list",
1241
+ takes: { campaignId: true },
1152
1242
  keyOf: refOf2,
1153
1243
  prepare: (filters) => {
1154
1244
  if (filters.campaignId === void 0) {
@@ -1179,6 +1269,14 @@ var senderGet = (core) => ({
1179
1269
  });
1180
1270
  var leadList = (core) => ({
1181
1271
  action: "leads.list",
1272
+ takes: {
1273
+ campaignId: true,
1274
+ email: true,
1275
+ linkedinUrl: true,
1276
+ listId: true,
1277
+ since: true,
1278
+ until: true
1279
+ },
1182
1280
  // A lookup returns one record per campaign the person is in. On a vendor
1183
1281
  // whose lead id is the same in every campaign those records share a ref,
1184
1282
  // so the campaign is part of what tells them apart.
@@ -1237,6 +1335,14 @@ var leadGet = (core) => ({
1237
1335
  });
1238
1336
  var messageList = (core) => ({
1239
1337
  action: "messages.list",
1338
+ takes: {
1339
+ campaignId: true,
1340
+ include: true,
1341
+ leadId: true,
1342
+ since: true,
1343
+ threadId: true,
1344
+ until: true
1345
+ },
1240
1346
  keyOf: refOf2,
1241
1347
  prepare: (filters) => {
1242
1348
  requireCapability(core.gate, "messages.list", "Listing messages");
@@ -1281,6 +1387,14 @@ var messageList = (core) => ({
1281
1387
  });
1282
1388
  var replyList = (core) => ({
1283
1389
  action: "replies.list",
1390
+ takes: {
1391
+ campaignId: true,
1392
+ category: true,
1393
+ include: true,
1394
+ since: true,
1395
+ unread: true,
1396
+ until: true
1397
+ },
1284
1398
  keyOf: refOf2,
1285
1399
  prepare: (filters) => {
1286
1400
  requireCapability(core.gate, "replies.list", "Listing replies");
@@ -1332,6 +1446,7 @@ var replyList = (core) => ({
1332
1446
  });
1333
1447
  var workspaceList = (core) => ({
1334
1448
  action: "workspaces.list",
1449
+ takes: {},
1335
1450
  keyOf: refOf2,
1336
1451
  prepare: () => {
1337
1452
  requireCapability(core.gate, "workspaces", "Listing workspaces");
@@ -2098,10 +2213,29 @@ var makeRawClient = (core, nativeOffBy) => {
2098
2213
  };
2099
2214
 
2100
2215
  // src/internal/outbound/outbound.ts
2216
+ var warnedMaxRequests = false;
2217
+ var perCallCap = (options) => {
2218
+ if (options.maxRequests === void 0) {
2219
+ return options.maxRequestsPerCall;
2220
+ }
2221
+ if (options.maxRequestsPerCall !== void 0) {
2222
+ throw new OutboundError(
2223
+ "Invalid",
2224
+ "Set maxRequestsPerCall or maxRequests on createOutbound, not both. maxRequests is the old name."
2225
+ );
2226
+ }
2227
+ if (!warnedMaxRequests) {
2228
+ warnedMaxRequests = true;
2229
+ console.warn(
2230
+ "outbound-sdk: maxRequests on createOutbound is deprecated. Rename it to maxRequestsPerCall: it caps each call, not the whole run. For a total, use budget({ maxRequests })."
2231
+ );
2232
+ }
2233
+ return options.maxRequests;
2234
+ };
2101
2235
  var engineFor = (options) => new RequestEngine({
2102
2236
  defaults: {
2103
2237
  deadline: options.deadline,
2104
- maxRequests: options.maxRequests,
2238
+ maxRequests: perCallCap(options),
2105
2239
  retries: options.retries,
2106
2240
  signal: options.signal,
2107
2241
  timeout: options.timeout
@@ -2281,12 +2415,15 @@ var Outbound = class _Outbound {
2281
2415
  }
2282
2416
  const pageSize = query.limit ?? cost.pageSize;
2283
2417
  if (query.records === void 0 || pageSize === void 0) {
2284
- return { basis: `${cost.perPage} request(s) per page`, requests: null };
2418
+ return {
2419
+ basis: `${plural(cost.perPage, "request")} per page`,
2420
+ requests: null
2421
+ };
2285
2422
  }
2286
2423
  const pages = Math.max(1, Math.ceil(query.records / pageSize));
2287
2424
  const requests = pages * cost.perPage + query.records * (cost.perRecord ?? 0);
2288
2425
  return {
2289
- basis: `${pages} page(s) of ${pageSize} at ${cost.perPage} request(s) each, plus ${cost.perRecord ?? 0} per record`,
2426
+ basis: `${plural(pages, "page")} of ${pageSize} at ${plural(cost.perPage, "request")} each, plus ${cost.perRecord ?? 0} per record`,
2290
2427
  requests
2291
2428
  };
2292
2429
  }