outbound-sdk 0.7.1 → 0.9.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 (120) hide show
  1. package/dist/alerts/index.js +3 -3
  2. package/dist/audit/index.js +1 -1
  3. package/dist/benchmarks/index.js +3 -3
  4. package/dist/budget/index.d.ts +7 -0
  5. package/dist/budget/index.js +3 -3
  6. package/dist/cache/index.js +2 -2
  7. package/dist/cards/index.js +17 -5
  8. package/dist/chunks/{chunk-6NSCPTOY.js → chunk-4BH5LRCS.js} +691 -441
  9. package/dist/chunks/{chunk-MW4C6LTN.js → chunk-5XLR6XVV.js} +2 -2
  10. package/dist/chunks/{chunk-HIAK2GCI.js → chunk-A7DLJUA6.js} +6 -1
  11. package/dist/chunks/{chunk-M2VXGLLZ.js → chunk-CPACP4YD.js} +1 -1
  12. package/dist/chunks/{chunk-4AVYRVN5.js → chunk-FTK4JS65.js} +31 -10
  13. package/dist/chunks/{chunk-YW6FFVSZ.js → chunk-HXB2IOJJ.js} +1 -1
  14. package/dist/chunks/{chunk-FHKSLCVW.js → chunk-KVAG5GM2.js} +19 -0
  15. package/dist/chunks/{chunk-65YAGEWZ.js → chunk-MEEJIIIA.js} +178 -39
  16. package/dist/chunks/{chunk-7I3EPR23.js → chunk-MPE6VLLY.js} +3 -3
  17. package/dist/chunks/{chunk-UFQ4WMLU.js → chunk-NFWWA7MI.js} +1 -1
  18. package/dist/chunks/{chunk-GL7BABF2.js → chunk-OMCDMELK.js} +1 -1
  19. package/dist/chunks/{chunk-JRL3QRBS.js → chunk-OVTYA3IB.js} +88 -28
  20. package/dist/chunks/{chunk-T5MJMW3R.js → chunk-QTWJ5FO7.js} +1 -1
  21. package/dist/chunks/chunk-REDFBY74.js +7285 -0
  22. package/dist/chunks/{chunk-OK3GAZMT.js → chunk-SYUMA3CP.js} +12 -0
  23. package/dist/chunks/{chunk-LVZGIKNF.js → chunk-U5AK6OJM.js} +1 -1
  24. package/dist/chunks/{chunk-KTYTE2BU.js → chunk-UAHYPASH.js} +20 -11
  25. package/dist/chunks/{chunk-BNDHEDHD.js → chunk-UOJG4VYF.js} +3 -3
  26. package/dist/chunks/{chunk-LD6F46UT.js → chunk-UWD65SK7.js} +2 -2
  27. package/dist/chunks/{chunk-I7DXXGNZ.js → chunk-UZLFZZ2U.js} +5 -5
  28. package/dist/chunks/{chunk-DNPNTD5W.js → chunk-VVDBCQLK.js} +1 -1
  29. package/dist/chunks/{chunk-IVH3NMQZ.js → chunk-WROJO6XB.js} +1 -1
  30. package/dist/chunks/{chunk-QFC4ZHD3.js → chunk-XYHM4KHC.js} +1 -1
  31. package/dist/chunks/{chunk-NAWZ73QS.js → chunk-YFJ3OQZS.js} +8 -1
  32. package/dist/chunks/tools-ATY622UC.js +23 -0
  33. package/dist/cli/args.d.ts +48 -0
  34. package/dist/cli/bin.js +14 -14
  35. package/dist/cli/commands.d.ts +0 -7
  36. package/dist/cli/config.d.ts +31 -2
  37. package/dist/cli/envelope.d.ts +2 -0
  38. package/dist/cli/index.d.ts +4 -0
  39. package/dist/cli/index.js +19 -15
  40. package/dist/cli/listing.d.ts +5 -2
  41. package/dist/cli/mcp.d.ts +9 -0
  42. package/dist/cli/offered.d.ts +10 -0
  43. package/dist/cli/options.d.ts +6 -0
  44. package/dist/cli/progress.d.ts +27 -0
  45. package/dist/cli/serve.d.ts +17 -0
  46. package/dist/clients/index.js +3 -3
  47. package/dist/combine/index.js +154 -35
  48. package/dist/combine/newest.d.ts +18 -0
  49. package/dist/combine/route.d.ts +19 -5
  50. package/dist/emailbison/index.js +22 -14
  51. package/dist/emailbison/map-sequence.d.ts +2 -1
  52. package/dist/exporter/index.js +1 -1
  53. package/dist/failover/index.js +3 -3
  54. package/dist/fixtures/index.js +4 -4
  55. package/dist/heyreach/capabilities.d.ts +4 -0
  56. package/dist/heyreach/conversations.d.ts +23 -0
  57. package/dist/heyreach/inbox.d.ts +0 -1
  58. package/dist/heyreach/index.js +251 -92
  59. package/dist/identity/index.js +2 -2
  60. package/dist/index.js +7 -7
  61. package/dist/insights/capped.d.ts +6 -6
  62. package/dist/insights/copy/index.d.ts +2 -0
  63. package/dist/insights/copy/reply-timing.d.ts +4 -0
  64. package/dist/insights/cost.d.ts +11 -1
  65. package/dist/insights/define.d.ts +25 -16
  66. package/dist/insights/inbox.d.ts +12 -0
  67. package/dist/insights/index.js +42 -6578
  68. package/dist/insights/inputs.generated.d.ts +62 -26
  69. package/dist/insights/ops/anomalies.d.ts +9 -0
  70. package/dist/insights/ops/index.d.ts +2 -0
  71. package/dist/insights/ops/period-comparison.d.ts +7 -8
  72. package/dist/insights/ops/pipeline-forecast.d.ts +16 -0
  73. package/dist/insights/ops/shared.d.ts +6 -1
  74. package/dist/insights/people/auto-replies.d.ts +11 -7
  75. package/dist/insights/people/dropped-replies.d.ts +13 -4
  76. package/dist/insights/people/hot-leads-read.d.ts +31 -0
  77. package/dist/insights/people/hot-leads.d.ts +15 -3
  78. package/dist/insights/people/index.d.ts +10 -2
  79. package/dist/insights/people/read.d.ts +1 -1
  80. package/dist/insights/registry.d.ts +14 -2
  81. package/dist/insights/run-cap.d.ts +10 -0
  82. package/dist/insights/senders/read.d.ts +0 -3
  83. package/dist/insights/tools.d.ts +12 -0
  84. package/dist/insights/tracked-reads.d.ts +53 -0
  85. package/dist/instantly/capabilities.d.ts +13 -1
  86. package/dist/instantly/index.js +128 -46
  87. package/dist/instantly/map-account.d.ts +2 -1
  88. package/dist/instantly/map-lead.d.ts +1 -0
  89. package/dist/instantly/map.d.ts +4 -3
  90. package/dist/internal/adapter.d.ts +19 -0
  91. package/dist/internal/capabilities.d.ts +15 -0
  92. package/dist/internal/engine/budget.d.ts +9 -1
  93. package/dist/internal/engine/engine.d.ts +2 -1
  94. package/dist/internal/engine/request.d.ts +2 -0
  95. package/dist/internal/errors.d.ts +5 -0
  96. package/dist/internal/hooks.d.ts +11 -0
  97. package/dist/internal/notes.d.ts +16 -0
  98. package/dist/internal/outbound/api.d.ts +16 -0
  99. package/dist/internal/outbound/core.d.ts +4 -1
  100. package/dist/internal/outbound/operation-shared.d.ts +2 -0
  101. package/dist/internal/sha256.d.ts +2 -0
  102. package/dist/internal/url.d.ts +1 -0
  103. package/dist/loader/index.js +3 -3
  104. package/dist/memory/index.js +11 -16
  105. package/dist/redact/index.d.ts +1 -1
  106. package/dist/redact/index.js +107 -19
  107. package/dist/redact/plugin.d.ts +26 -3
  108. package/dist/smartlead/index.js +22 -13
  109. package/dist/smartlead/map.d.ts +3 -2
  110. package/dist/sync/index.js +2 -2
  111. package/dist/tools/ai-sdk.js +5 -5
  112. package/dist/tools/by-name.d.ts +9 -1
  113. package/dist/tools/campaign-tools.d.ts +3 -1
  114. package/dist/tools/claude-agent.js +5 -5
  115. package/dist/tools/index.js +6 -6
  116. package/dist/tools/registry.d.ts +6 -0
  117. package/dist/tools/shared.d.ts +5 -1
  118. package/dist/tracing/index.js +1 -1
  119. package/dist/webhooks/index.js +11 -11
  120. package/package.json +1 -1
@@ -40,6 +40,7 @@ export declare class RequestEngine {
40
40
  now(): number;
41
41
  /** Starts the accounting for one SDK call. */
42
42
  begin(options?: OperationOptions): CallState;
43
- contextFor(adapter: Adapter, state: CallState): AdapterContext;
43
+ /** `notes` collects what the adapter says it left out; the call's own by default. */
44
+ contextFor(adapter: Adapter, state: CallState, notes?: string[]): AdapterContext;
44
45
  limits(adapter: Adapter): Promise<LimitsSnapshot>;
45
46
  }
@@ -27,6 +27,8 @@ export interface CallState {
27
27
  * the one already set.
28
28
  */
29
29
  beforeRequest: (() => void) | undefined;
30
+ /** What the adapter left out of the answer, and why. Each note once. */
31
+ readonly notes: string[];
30
32
  }
31
33
  export interface RequestEnvironment {
32
34
  readonly adapter: Adapter;
@@ -47,6 +47,11 @@ export interface OutboundErrorOptions {
47
47
  readonly limit?: RequestLimit | undefined;
48
48
  /** What a `toArray()` walk had fetched when it stopped. */
49
49
  readonly partial?: PartialWalk | undefined;
50
+ /**
51
+ * `true` when the same call fails the same way again, whatever the code:
52
+ * for example a `Provider` error for a vendor record the SDK cannot read.
53
+ */
54
+ readonly permanent?: boolean | undefined;
50
55
  /** Secrets to strip from the message. */
51
56
  readonly secrets?: readonly string[] | undefined;
52
57
  }
@@ -27,6 +27,17 @@ export interface ThrottleEvent {
27
27
  readonly provider: string;
28
28
  readonly lane: string;
29
29
  readonly waitMs: number;
30
+ /**
31
+ * `budget`: the SDK's own rate budget for the lane is full. `vendor`: the
32
+ * vendor answered 429, often because another process or tool on the same
33
+ * workspace spent the limit.
34
+ */
35
+ readonly cause: "budget" | "vendor";
36
+ /** The windows the SDK keeps the lane inside, after `share` and any slowdown. */
37
+ readonly windows: readonly {
38
+ readonly requests: number;
39
+ readonly perMs: number;
40
+ }[];
30
41
  }
31
42
  export interface RequestEvent {
32
43
  readonly provider: string;
@@ -0,0 +1,16 @@
1
+ /** Says what an adapter left out of a record, and why. */
2
+ export type Note = (text: string) => void;
3
+ export interface NegativeContext {
4
+ readonly note: Note;
5
+ /** The vendor's name as people know it, for example `Instantly`. */
6
+ readonly vendor: string;
7
+ /** What the value is, for example `Step 4's delay`. */
8
+ readonly what: string;
9
+ /** Written after the value in the note, for example `days`. */
10
+ readonly unit?: string | undefined;
11
+ }
12
+ /**
13
+ * A number the normalized record holds as 0 or more. A negative one is
14
+ * `null`, with a note that names it.
15
+ */
16
+ export declare const notNegative: (value: number | null, { note, unit, vendor, what }: NegativeContext) => number | null;
@@ -22,6 +22,8 @@ export interface ResultMeta {
22
22
  readonly workspaceId: string;
23
23
  /** `true` when an older answer was served because the vendor was down. */
24
24
  readonly stale: boolean;
25
+ /** What the adapter left out, and why: a vendor value it could not use, mapped to `null`. */
26
+ readonly notes: readonly string[];
25
27
  }
26
28
  export type WithMeta<Item> = Item & {
27
29
  readonly meta: ResultMeta;
@@ -102,6 +104,12 @@ export interface LeadFilters extends TimeRange {
102
104
  readonly linkedinUrl?: string | undefined;
103
105
  /** Only the records whose email address is at exactly this domain, such as `acme.com`. Needs `leads.byDomain`. */
104
106
  readonly domain?: string | undefined;
107
+ /** Only the records of the people with exactly these email addresses, read in one listing. Needs `leads.lookupMany`. */
108
+ readonly emails?: readonly string[] | undefined;
109
+ /** `positive`: only the leads the vendor labels positive (`interestCategory` `positive`). Needs `leads.byInterest`. */
110
+ readonly interest?: "positive" | undefined;
111
+ /** `active`: only the leads still in the sequence (`status` `active`). Needs `leads.byStatus`. Not together with `interest`. */
112
+ readonly status?: "active" | undefined;
105
113
  }
106
114
  export interface WebhookFilters {
107
115
  readonly campaignId?: string | undefined;
@@ -111,6 +119,8 @@ export interface MessageFilters extends TimeRange {
111
119
  readonly leadId?: string | undefined;
112
120
  /** A `threadId` from an earlier message. */
113
121
  readonly threadId?: string | undefined;
122
+ /** `true` for the messages a person sent by hand only, leaving out the ones a campaign sent. Needs `messages.byHand`. */
123
+ readonly byHand?: true | undefined;
114
124
  readonly include?: readonly Include[] | undefined;
115
125
  }
116
126
  export interface ReplyFilters extends TimeRange {
@@ -118,6 +128,12 @@ export interface ReplyFilters extends TimeRange {
118
128
  readonly category?: ReplyCategory | undefined;
119
129
  /** `true` for unread replies only, `false` for read ones only. */
120
130
  readonly unread?: boolean | undefined;
131
+ /**
132
+ * Also return replies from conversations that belong to no campaign, such
133
+ * as a LinkedIn inbox's own messages. Only adapters whose `replies.inbox`
134
+ * capability is true leave any out; on the others this changes nothing.
135
+ */
136
+ readonly includeInbox?: boolean | undefined;
121
137
  readonly include?: readonly Include[] | undefined;
122
138
  }
123
139
  export interface StatsOptions extends OperationOptions {
@@ -27,10 +27,13 @@ export interface MetaInput {
27
27
  readonly complete: boolean;
28
28
  readonly stale?: boolean | undefined;
29
29
  readonly fetchedAt?: string | undefined;
30
+ /** The output's notes. They join the call's, so a walk keeps every page's. */
31
+ readonly notes?: readonly string[] | undefined;
30
32
  }
31
33
  export declare const metaFor: (core: Core, state: CallState, input: MetaInput) => ResultMeta;
32
34
  /**
33
35
  * Checks what came back against the schema. An adapter or plugin that
34
- * returns a malformed record fails here, loudly, and not in the caller.
36
+ * returns a malformed record fails here, loudly, and not in the caller. The
37
+ * error is permanent: the vendor returns the same record on every retry.
35
38
  */
36
39
  export declare const checked: <Item>(core: Core, schema: ZodType<Item>, records: readonly OutboundRecord[], action: string) => Item[];
@@ -15,6 +15,8 @@ export interface OperationOutput {
15
15
  readonly stale?: boolean | undefined;
16
16
  /** When the answer was fetched, if a plugin served it from a store. ISO 8601 UTC. */
17
17
  readonly fetchedAt?: string | undefined;
18
+ /** What the adapter left out of these records, and why. */
19
+ readonly notes?: readonly string[] | undefined;
18
20
  }
19
21
  export declare const unsupported: (adapter: Adapter, kind: string) => OutboundError;
20
22
  export declare const idFor: (adapter: Adapter, id: string) => string;
@@ -2,5 +2,7 @@
2
2
  export declare const sha256: (bytes: Uint8Array) => Uint8Array;
3
3
  /** The SHA-256 digest of a UTF-8 string, as lowercase hex. */
4
4
  export declare const sha256Hex: (input: string) => string;
5
+ /** HMAC-SHA-256 (RFC 2104) of a UTF-8 message under `key`, as lowercase hex. */
6
+ export declare const hmacSha256Hex: (key: Uint8Array, message: string) => string;
5
7
  /** A short stable id derived from the parts, for refs, event ids and cache keys. */
6
8
  export declare const stableId: (...parts: (string | number | null | undefined)[]) => string;
@@ -5,5 +5,6 @@ export declare const buildUrl: (baseUrl: string, path: string, query?: Readonly<
5
5
  * The part of a LinkedIn profile URL that names the person, lowercased, or
6
6
  * `null` when the text is not a profile URL. Two URLs for the same person can
7
7
  * differ in scheme, host prefix, trailing slash and query; the slug does not.
8
+ * A slug that is not valid percent-encoding is kept undecoded.
8
9
  */
9
10
  export declare const profileSlug: (url: string | null | undefined) => string | null;
@@ -3,9 +3,9 @@ import {
3
3
  configuredProviders,
4
4
  fromEnv,
5
5
  loadableProviders
6
- } from "../chunks/chunk-MW4C6LTN.js";
7
- import "../chunks/chunk-UFQ4WMLU.js";
8
- import "../chunks/chunk-QFC4ZHD3.js";
6
+ } from "../chunks/chunk-5XLR6XVV.js";
7
+ import "../chunks/chunk-NFWWA7MI.js";
8
+ import "../chunks/chunk-XYHM4KHC.js";
9
9
  import "../chunks/chunk-45TXPJW7.js";
10
10
  import "../chunks/chunk-WH6V3YNN.js";
11
11
  export {
@@ -2,31 +2,31 @@ import {
2
2
  recordBase,
3
3
  refTo,
4
4
  refsTo
5
- } from "../chunks/chunk-LVZGIKNF.js";
5
+ } from "../chunks/chunk-U5AK6OJM.js";
6
6
  import {
7
7
  leadProgressSchema
8
8
  } from "../chunks/chunk-POBAY3TI.js";
9
9
  import {
10
10
  emptyCounts,
11
11
  sumCounts
12
- } from "../chunks/chunk-M2VXGLLZ.js";
12
+ } from "../chunks/chunk-CPACP4YD.js";
13
13
  import {
14
14
  SCHEMA_VERSION
15
15
  } from "../chunks/chunk-QGRZDTX4.js";
16
16
  import {
17
17
  assertWorkspaceId,
18
18
  makeRef
19
- } from "../chunks/chunk-YW6FFVSZ.js";
19
+ } from "../chunks/chunk-HXB2IOJJ.js";
20
20
  import {
21
21
  profileSlug
22
- } from "../chunks/chunk-NAWZ73QS.js";
22
+ } from "../chunks/chunk-YFJ3OQZS.js";
23
23
  import {
24
24
  stableId
25
- } from "../chunks/chunk-FHKSLCVW.js";
25
+ } from "../chunks/chunk-KVAG5GM2.js";
26
26
  import {
27
27
  OutboundError,
28
28
  makeErrorMapper
29
- } from "../chunks/chunk-QFC4ZHD3.js";
29
+ } from "../chunks/chunk-XYHM4KHC.js";
30
30
  import {
31
31
  isNumber
32
32
  } from "../chunks/chunk-45TXPJW7.js";
@@ -424,6 +424,7 @@ var FULL_CAPABILITIES = {
424
424
  "campaigns.status": "server",
425
425
  "leads.byCampaign": true,
426
426
  "leads.byDomain": true,
427
+ "leads.byStatus": true,
427
428
  "leads.engagement": true,
428
429
  "leads.get": true,
429
430
  "leads.list": true,
@@ -468,6 +469,9 @@ var selectMessages = (store, query, key) => (store.data.messages ?? []).filter(
468
469
  var selectLeads = (store, query) => (store.data.leads ?? []).filter(
469
470
  (lead) => (query.campaignId === void 0 || lead.campaignId === query.campaignId) && (query.listId === void 0 || (lead.listIds ?? []).includes(query.listId)) && (query.email === void 0 || lead.email?.trim().toLowerCase() === query.email) && (query.domain === void 0 || lead.email?.trim().toLowerCase().split("@").at(-1) === query.domain) && (query.linkedinUrl === void 0 || profileSlug(lead.linkedinUrl) !== null && profileSlug(lead.linkedinUrl) === profileSlug(query.linkedinUrl)) && (!filtersByTime(store, "leads.since") || within(lead.createdAt, query))
470
471
  );
472
+ var selectedLeads = (store, query) => selectLeads(store, query).map((seed) => toLead(store.identity, seed)).filter(
473
+ (lead) => query.status === void 0 || lead.status === query.status
474
+ );
471
475
  var getters = (store) => {
472
476
  const { data, identity } = store;
473
477
  return {
@@ -503,16 +507,7 @@ var listers = (store) => {
503
507
  pageSize
504
508
  )
505
509
  ),
506
- listLeads: (query) => {
507
- const seeds = selectLeads(store, query);
508
- return Promise.resolve(
509
- paginate(
510
- seeds.map((seed) => toLead(identity, seed)),
511
- query,
512
- pageSize
513
- )
514
- );
515
- },
510
+ listLeads: (query) => Promise.resolve(paginate(selectedLeads(store, query), query, pageSize)),
516
511
  listMessages: (query) => Promise.resolve(
517
512
  paginate(
518
513
  selectMessages(store, query, "messages.since").map(
@@ -1,2 +1,2 @@
1
- export { ALL_FIELDS, MASK, redact } from "./plugin.ts";
1
+ export { ALL_FIELDS, KNOWN_TOKENS, MASK, redact } from "./plugin.ts";
2
2
  export type { RedactExtension, RedactField, RedactOptions } from "./plugin.ts";
@@ -1,16 +1,17 @@
1
1
  import {
2
2
  makeRef,
3
3
  parseRef
4
- } from "../chunks/chunk-YW6FFVSZ.js";
4
+ } from "../chunks/chunk-HXB2IOJJ.js";
5
5
  import {
6
6
  profileSlug
7
- } from "../chunks/chunk-NAWZ73QS.js";
7
+ } from "../chunks/chunk-YFJ3OQZS.js";
8
8
  import {
9
+ hmacSha256Hex,
9
10
  stableId
10
- } from "../chunks/chunk-FHKSLCVW.js";
11
+ } from "../chunks/chunk-KVAG5GM2.js";
11
12
  import {
12
13
  OutboundError
13
- } from "../chunks/chunk-QFC4ZHD3.js";
14
+ } from "../chunks/chunk-XYHM4KHC.js";
14
15
  import {
15
16
  isJsonArray,
16
17
  isJsonObject,
@@ -35,6 +36,65 @@ var replacer = (strategy) => (value) => {
35
36
  }
36
37
  return strategy === "mask" ? MASK : `redacted:${stableId(value).slice(0, 16)}`;
37
38
  };
39
+ var keyedToken = () => {
40
+ const key = crypto.getRandomValues(new Uint8Array(32));
41
+ return (value) => `redacted:${hmacSha256Hex(key, value).slice(0, 16)}`;
42
+ };
43
+ var KNOWN_TOKENS = 1e4;
44
+ var TOKEN = /redacted:[0-9a-f]{16}/gu;
45
+ var knownTokens = () => {
46
+ const values = /* @__PURE__ */ new Map();
47
+ return {
48
+ kindOf: (token) => values.get(token)?.kind ?? null,
49
+ remask: (text) => {
50
+ let result = text;
51
+ for (const [token, { value }] of values) {
52
+ result = result.replaceAll(value, token);
53
+ }
54
+ return result;
55
+ },
56
+ remember: (token, kind, value) => {
57
+ values.delete(token);
58
+ values.set(token, { kind, value });
59
+ if (values.size > KNOWN_TOKENS) {
60
+ const [oldest] = values.keys();
61
+ if (oldest !== void 0) {
62
+ values.delete(oldest);
63
+ }
64
+ }
65
+ return token;
66
+ },
67
+ unmask: (text) => text.replaceAll(TOKEN, (token) => values.get(token)?.value ?? token)
68
+ };
69
+ };
70
+ var maskIdentifier = (masks, field, value) => masks.has(field) ? masks.identifier(field, value) : value;
71
+ var masksFor = (fields, strategy) => {
72
+ const replace = replacer(strategy);
73
+ const has = (field) => fields.has(field);
74
+ const known = knownTokens();
75
+ if (strategy === "hash") {
76
+ return {
77
+ has,
78
+ identifier: (field, value) => value === null ? null : known.remember(replace(value) ?? MASK, field, value),
79
+ known,
80
+ replace,
81
+ token: (kind, value, original = value) => known.remember(replace(value) ?? MASK, kind, original)
82
+ };
83
+ }
84
+ const keyed = keyedToken();
85
+ const token = (kind, value, original = value) => known.remember(keyed(value), kind, original);
86
+ return {
87
+ has,
88
+ identifier: (field, value) => value === null ? null : token(
89
+ field,
90
+ field === "email" ? value.toLowerCase() : profileSlug(value) ?? value,
91
+ value
92
+ ),
93
+ known,
94
+ replace,
95
+ token
96
+ };
97
+ };
38
98
  var maskIf = (masks, field, value) => masks.has(field) ? masks.replace(value) : value;
39
99
  var maskCustom = (masks, custom) => masks.has("custom") ? Object.fromEntries(
40
100
  Object.keys(custom).map((key) => [
@@ -46,11 +106,11 @@ var EMAIL_IN_ID = /[^\s@:/]+@[^\s@:/]+\.[^\s@:/]+/gu;
46
106
  var maskId = (masks, id) => {
47
107
  const slug = masks.has("linkedin") ? profileSlug(id) : null;
48
108
  if (slug !== null) {
49
- return masks.replace(slug) ?? MASK;
109
+ return masks.token("linkedin", slug, id);
50
110
  }
51
111
  return masks.has("email") ? id.replaceAll(
52
112
  EMAIL_IN_ID,
53
- (address) => masks.replace(address.toLowerCase()) ?? MASK
113
+ (address) => masks.token("email", address.toLowerCase(), address)
54
114
  ) : id;
55
115
  };
56
116
  var maskRef = (masks, ref) => {
@@ -60,7 +120,7 @@ var maskRef = (masks, ref) => {
60
120
  var KEY_FIELDS = ["email", "linkedin"];
61
121
  var maskKey = (masks, key) => {
62
122
  const field = KEY_FIELDS.find((name) => key.startsWith(`${name}:`));
63
- return field === void 0 || !masks.has(field) ? key : `${field}:${masks.replace(key.slice(field.length + 1)) ?? MASK}`;
123
+ return field === void 0 || !masks.has(field) ? key : `${field}:${masks.token(field, key.slice(field.length + 1))}`;
64
124
  };
65
125
  var maskEach = (value, mask) => {
66
126
  if (isString(value)) {
@@ -105,10 +165,10 @@ var redactFields = (masks, record) => {
105
165
  // The company's LinkedIn page and its website name the company too.
106
166
  companyLinkedinUrl: maskIf(masks, "company", record.companyLinkedinUrl),
107
167
  custom: maskCustom(masks, record.custom),
108
- email: maskIf(masks, "email", record.email),
168
+ email: maskIdentifier(masks, "email", record.email),
109
169
  firstName: maskIf(masks, "name", record.firstName),
110
170
  lastName: maskIf(masks, "name", record.lastName),
111
- linkedinUrl: maskIf(masks, "linkedin", record.linkedinUrl),
171
+ linkedinUrl: maskIdentifier(masks, "linkedin", record.linkedinUrl),
112
172
  phone: maskIf(masks, "phone", record.phone),
113
173
  raw: null,
114
174
  website: maskIf(masks, "company", record.website)
@@ -119,7 +179,7 @@ var redactFields = (masks, record) => {
119
179
  return {
120
180
  ...record,
121
181
  raw: null,
122
- value: blocked === void 0 ? record.value : maskIf(masks, blocked, record.value) ?? MASK
182
+ value: blocked === void 0 ? record.value : maskIdentifier(masks, blocked, record.value) ?? MASK
123
183
  };
124
184
  }
125
185
  if ("steps" in record || "inProgress" in record || "nextRunAt" in record || "schedule" in record || "dns" in record || "size" in record || "url" in record || "description" in record) {
@@ -128,8 +188,8 @@ var redactFields = (masks, record) => {
128
188
  if ("kind" in record) {
129
189
  return {
130
190
  ...record,
131
- address: maskIf(masks, "email", record.address),
132
- linkedinUrl: maskIf(masks, "linkedin", record.linkedinUrl),
191
+ address: maskIdentifier(masks, "email", record.address),
192
+ linkedinUrl: maskIdentifier(masks, "linkedin", record.linkedinUrl),
133
193
  name: maskIf(masks, "name", record.name),
134
194
  raw: null
135
195
  };
@@ -143,6 +203,7 @@ var redactFields = (masks, record) => {
143
203
  );
144
204
  };
145
205
  var redactRecord = (masks, record) => maskIdentifiers(masks, redactFields(masks, record));
206
+ var maskEventField = (masks, field, value) => field === "email" || field === "linkedin" ? maskIdentifier(masks, field, value) : maskIf(masks, field, value);
146
207
  var EVENT_FIELDS = /* @__PURE__ */ new Map([
147
208
  ["leadEmail", "email"],
148
209
  ["leadName", "name"],
@@ -157,18 +218,31 @@ var redactEventData = (masks, data) => {
157
218
  if (field === void 0) {
158
219
  result[key] = isJsonObject(value) || Array.isArray(value) ? MASK : value;
159
220
  } else {
160
- result[key] = isString(value) ? maskIf(masks, field, value) : null;
221
+ result[key] = isString(value) ? maskEventField(masks, field, value) : null;
161
222
  }
162
223
  }
163
224
  return result;
164
225
  };
226
+ var remasked = (known, error) => new OutboundError(error.code, known.remask(error.message), {
227
+ aborted: error.aborted,
228
+ limit: error.limit,
229
+ permanent: error.permanent,
230
+ provider: error.provider,
231
+ retryAfterMs: error.retryAfterMs,
232
+ status: error.status,
233
+ timedOut: error.timedOut
234
+ });
235
+ var unmasked = (known, operation) => {
236
+ if (!("id" in operation)) {
237
+ return operation;
238
+ }
239
+ const id = known.unmask(operation.id);
240
+ return id === operation.id ? operation : { ...operation, id };
241
+ };
165
242
  var redact = (options = {}) => {
166
243
  const fields = new Set(options.fields ?? ALL_FIELDS);
167
244
  const strategy = options.strategy ?? "mask";
168
- const masks = {
169
- has: (field) => fields.has(field),
170
- replace: replacer(strategy)
171
- };
245
+ const masks = masksFor(fields, strategy);
172
246
  return {
173
247
  // Asking for bodies while they are being removed is a contradiction, so
174
248
  // the capability is turned off and the request is refused up front.
@@ -179,16 +253,29 @@ var redact = (options = {}) => {
179
253
  data: redactEventData(masks, event.data),
180
254
  raw: null
181
255
  }),
182
- extend: () => ({
256
+ extend: (outbound) => ({
183
257
  redacted: {
184
258
  fields: [...fields].toSorted(),
185
259
  hash: (value) => masks.replace(value) ?? MASK,
260
+ leadsByToken: (tokens, campaign) => {
261
+ const emails = tokens.flatMap(
262
+ (token) => masks.known.kindOf(token) === "email" ? masks.known.unmask(token) : []
263
+ );
264
+ return campaign === null ? outbound.leads.listAll({ emails }) : outbound.campaign(campaign).leads.listAll({ emails });
265
+ },
266
+ resolves: (token) => masks.known.kindOf(token),
186
267
  strategy
187
268
  }
188
269
  }),
189
270
  name: "redact",
190
271
  wrap: async (operation, next) => {
191
- const output = await next(operation);
272
+ const sent = unmasked(masks.known, operation);
273
+ let output;
274
+ try {
275
+ output = await next(sent);
276
+ } catch (error) {
277
+ throw sent !== operation && OutboundError.is(error) ? remasked(masks.known, error) : error;
278
+ }
192
279
  return {
193
280
  ...output,
194
281
  items: output.items.map((record) => redactRecord(masks, record))
@@ -198,6 +285,7 @@ var redact = (options = {}) => {
198
285
  };
199
286
  export {
200
287
  ALL_FIELDS,
288
+ KNOWN_TOKENS,
201
289
  MASK,
202
290
  redact
203
291
  };
@@ -1,11 +1,15 @@
1
+ import type { Lead } from "../internal/entities.ts";
2
+ import type { ListAll } from "../internal/outbound/api.ts";
1
3
  import type { OutboundPlugin } from "../internal/outbound/plugins.ts";
2
4
  export type RedactField = "body" | "company" | "custom" | "email" | "linkedin" | "name" | "phone" | "subject";
3
5
  export interface RedactOptions {
4
6
  /** What to mask. Defaults to everything. */
5
7
  readonly fields?: readonly RedactField[] | undefined;
6
8
  /**
7
- * `mask` replaces a value with `[redacted]`. `hash` replaces it with a
8
- * stable token, so the same person can still be counted and joined.
9
+ * `mask` replaces a value with `[redacted]`, and an address or a profile
10
+ * with a token keyed for this plugin, so people can still be counted and
11
+ * joined while it lives. `hash` replaces every value with a stable token,
12
+ * so the same person gets the same token from one run to the next.
9
13
  */
10
14
  readonly strategy?: "hash" | "mask" | undefined;
11
15
  }
@@ -20,10 +24,29 @@ export interface RedactExtension {
20
24
  * What this redact writes in place of `value` in a masked field: the
21
25
  * stable token under `hash`, so a caller can find a known address among
22
26
  * hashed records without the records holding it; `[redacted]` under
23
- * `mask`.
27
+ * `mask`, whose tokens for addresses and profiles are keyed and never
28
+ * given out.
24
29
  */
25
30
  readonly hash: (value: string) => string;
31
+ /**
32
+ * What a token this redact wrote for an address or a profile stands for,
33
+ * `email` or `linkedin`, or `null` when it wrote no such token. The
34
+ * value itself is never given out: a call that names the token, in a ref
35
+ * or a field, reaches the vendor with the value in its place, and its
36
+ * answer comes back masked.
37
+ */
38
+ readonly resolves: (token: string) => Identifier | null;
39
+ /**
40
+ * The leads behind the address tokens given, in one campaign or all,
41
+ * read with the addresses in their place and returned masked. A token
42
+ * this redact did not write for an address is left out.
43
+ */
44
+ readonly leadsByToken: (tokens: readonly string[], campaign: string | null) => ListAll<Lead>;
26
45
  };
27
46
  }
47
+ type Identifier = "email" | "linkedin";
48
+ /** The most tokens one redact remembers the value of; the oldest go first. */
49
+ export declare const KNOWN_TOKENS = 10000;
28
50
  /** Masks emails, names, companies, LinkedIn URLs, custom fields and message text. */
29
51
  export declare const redact: (options?: RedactOptions) => OutboundPlugin<RedactExtension>;
52
+ export {};
@@ -13,15 +13,15 @@ import {
13
13
  toWorkspace,
14
14
  unwrap,
15
15
  withoutSecrets
16
- } from "../chunks/chunk-KTYTE2BU.js";
16
+ } from "../chunks/chunk-UAHYPASH.js";
17
17
  import {
18
18
  applyTracking,
19
19
  ownTracking,
20
20
  unlessFailed
21
- } from "../chunks/chunk-DNPNTD5W.js";
21
+ } from "../chunks/chunk-VVDBCQLK.js";
22
22
  import {
23
23
  detectAutoReply
24
- } from "../chunks/chunk-OK3GAZMT.js";
24
+ } from "../chunks/chunk-SYUMA3CP.js";
25
25
  import {
26
26
  flatMapPage,
27
27
  mapPage,
@@ -32,7 +32,7 @@ import {
32
32
  createVendorClient,
33
33
  fromOne,
34
34
  listIn
35
- } from "../chunks/chunk-BNDHEDHD.js";
35
+ } from "../chunks/chunk-UOJG4VYF.js";
36
36
  import {
37
37
  normalizeBody
38
38
  } from "../chunks/chunk-FALWG5U3.js";
@@ -49,31 +49,31 @@ import {
49
49
  recordBase,
50
50
  refTo,
51
51
  refsTo
52
- } from "../chunks/chunk-LVZGIKNF.js";
52
+ } from "../chunks/chunk-U5AK6OJM.js";
53
53
  import "../chunks/chunk-POBAY3TI.js";
54
54
  import {
55
55
  emptyCounts,
56
56
  metricRow
57
- } from "../chunks/chunk-M2VXGLLZ.js";
57
+ } from "../chunks/chunk-CPACP4YD.js";
58
58
  import {
59
59
  replyCategorySchema
60
60
  } from "../chunks/chunk-QGRZDTX4.js";
61
61
  import {
62
62
  assertWorkspaceId
63
- } from "../chunks/chunk-YW6FFVSZ.js";
64
- import "../chunks/chunk-NAWZ73QS.js";
63
+ } from "../chunks/chunk-HXB2IOJJ.js";
64
+ import "../chunks/chunk-YFJ3OQZS.js";
65
65
  import {
66
66
  stableId
67
- } from "../chunks/chunk-FHKSLCVW.js";
67
+ } from "../chunks/chunk-KVAG5GM2.js";
68
68
  import {
69
69
  readEnv,
70
70
  requireCredential
71
- } from "../chunks/chunk-UFQ4WMLU.js";
71
+ } from "../chunks/chunk-NFWWA7MI.js";
72
72
  import {
73
73
  OutboundError,
74
74
  makeErrorMapper,
75
75
  requireObject
76
- } from "../chunks/chunk-QFC4ZHD3.js";
76
+ } from "../chunks/chunk-XYHM4KHC.js";
77
77
  import {
78
78
  count,
79
79
  emailAddress,
@@ -786,7 +786,15 @@ var listSubsequences = async (client, ctx, query) => {
786
786
  }
787
787
  const steps = await client.get(ctx, `/campaigns/${segment(id)}/sequences`);
788
788
  return {
789
- items: [toSubsequence(client.identity, query.campaignId, current, steps)],
789
+ items: [
790
+ toSubsequence(
791
+ client.identity,
792
+ query.campaignId,
793
+ current,
794
+ steps,
795
+ ctx.note
796
+ )
797
+ ],
790
798
  next: rest.length > 0 ? { subsequences: rest } : void 0
791
799
  };
792
800
  };
@@ -1587,7 +1595,8 @@ var readers = (client) => {
1587
1595
  getSequence: async (id, ctx) => toSequence(
1588
1596
  identity,
1589
1597
  id,
1590
- await client.get(ctx, `/campaigns/${segment(id)}/sequences`)
1598
+ await client.get(ctx, `/campaigns/${segment(id)}/sequences`),
1599
+ ctx.note
1591
1600
  ),
1592
1601
  listCampaigns: async (query, ctx) => {
1593
1602
  const { senderId } = query;
@@ -1,5 +1,6 @@
1
1
  import type { Campaign, CampaignStatus, Lead, ReplyCategory, Sender, Sequence, Workspace } from "../internal/entities.ts";
2
2
  import type { Json, JsonObject } from "../internal/json.ts";
3
+ import type { Note } from "../internal/notes.ts";
3
4
  import type { Identity } from "../internal/record.ts";
4
5
  /**
5
6
  * Several endpoints are documented both bare and wrapped in
@@ -14,12 +15,12 @@ export declare const withoutSecrets: (value: Json) => Json;
14
15
  export declare const campaignStatus: (value: Json | undefined) => CampaignStatus;
15
16
  export declare const toCampaign: (identity: Identity, raw: JsonObject) => Campaign;
16
17
  /** `GET /campaigns/{id}/sequences`: an array of steps, bare or wrapped. */
17
- export declare const toSequence: (identity: Identity, campaignId: string, body: Json) => Sequence;
18
+ export declare const toSequence: (identity: Identity, campaignId: string, body: Json, note: Note) => Sequence;
18
19
  /**
19
20
  * A subsequence is a child campaign: `campaign` is its row in the campaign
20
21
  * list and `body` is its own `GET /campaigns/{id}/sequences`.
21
22
  */
22
- export declare const toSubsequence: (identity: Identity, parentId: string, campaign: JsonObject, body: Json) => Sequence;
23
+ export declare const toSubsequence: (identity: Identity, parentId: string, campaign: JsonObject, body: Json, note: Note) => Sequence;
23
24
  export declare const reputation: (value: Json | undefined) => number | null;
24
25
  /** A mailbox. `raw` is the payload without its SMTP and IMAP passwords. */
25
26
  export declare const toSender: (identity: Identity, raw: JsonObject) => Sender;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  stableId
3
- } from "../chunks/chunk-FHKSLCVW.js";
3
+ } from "../chunks/chunk-KVAG5GM2.js";
4
4
  import {
5
5
  OutboundError
6
- } from "../chunks/chunk-QFC4ZHD3.js";
6
+ } from "../chunks/chunk-XYHM4KHC.js";
7
7
  import "../chunks/chunk-45TXPJW7.js";
8
8
 
9
9
  // src/sync/plugin.ts