outbound-sdk 0.0.0-stage → 0.2.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 (284) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -2
  3. package/dist/alerts/index.d.ts +2 -0
  4. package/dist/alerts/index.js +140 -0
  5. package/dist/alerts/plugin.d.ts +58 -0
  6. package/dist/audit/index.d.ts +33 -0
  7. package/dist/audit/index.js +60 -0
  8. package/dist/benchmarks/index.d.ts +29 -0
  9. package/dist/benchmarks/index.js +72 -0
  10. package/dist/budget/index.d.ts +21 -0
  11. package/dist/budget/index.js +71 -0
  12. package/dist/cache/index.d.ts +31 -0
  13. package/dist/cache/index.js +11 -0
  14. package/dist/cards/content.d.ts +43 -0
  15. package/dist/cards/copy-cards.d.ts +2 -0
  16. package/dist/cards/format.d.ts +39 -0
  17. package/dist/cards/index.d.ts +9 -0
  18. package/dist/cards/index.js +2070 -0
  19. package/dist/cards/notify-cards.d.ts +14 -0
  20. package/dist/cards/ops-cards.d.ts +2 -0
  21. package/dist/cards/parts.d.ts +22 -0
  22. package/dist/cards/people-cards.d.ts +2 -0
  23. package/dist/cards/render.d.ts +28 -0
  24. package/dist/cards/sender-cards.d.ts +2 -0
  25. package/dist/cards/slack-rich.d.ts +19 -0
  26. package/dist/cards/slack-text.d.ts +10 -0
  27. package/dist/cards/slack.d.ts +21 -0
  28. package/dist/cards/spec.d.ts +86 -0
  29. package/dist/cards/tool-cards.d.ts +4 -0
  30. package/dist/chunks/chunk-4O2HRTTI.js +75 -0
  31. package/dist/chunks/chunk-4PSO6JEK.js +357 -0
  32. package/dist/chunks/chunk-6CVZOUHB.js +152 -0
  33. package/dist/chunks/chunk-AFU5E5QB.js +714 -0
  34. package/dist/chunks/chunk-DJ2IUQEU.js +111 -0
  35. package/dist/chunks/chunk-E7JHLNLG.js +187 -0
  36. package/dist/chunks/chunk-FHKSLCVW.js +154 -0
  37. package/dist/chunks/chunk-FKH5N47I.js +40 -0
  38. package/dist/chunks/chunk-HZCTYL22.js +29 -0
  39. package/dist/chunks/chunk-IPUYZD4O.js +25 -0
  40. package/dist/chunks/chunk-IVH3NMQZ.js +61 -0
  41. package/dist/chunks/chunk-LVYG7XZJ.js +45 -0
  42. package/dist/chunks/chunk-NAKXLBA6.js +30 -0
  43. package/dist/chunks/chunk-NAWZ73QS.js +22 -0
  44. package/dist/chunks/chunk-PMSSUWD7.js +636 -0
  45. package/dist/chunks/chunk-PURHK3JU.js +432 -0
  46. package/dist/chunks/chunk-R3Y56YVF.js +43 -0
  47. package/dist/chunks/chunk-RCZ7ZZFU.js +92 -0
  48. package/dist/chunks/chunk-SBIZDCRY.js +106 -0
  49. package/dist/chunks/chunk-U2D34ARZ.js +41 -0
  50. package/dist/chunks/chunk-UAT3JSJZ.js +331 -0
  51. package/dist/chunks/chunk-VQSCHOBV.js +111 -0
  52. package/dist/chunks/chunk-XC6CZP73.js +80 -0
  53. package/dist/chunks/chunk-XNFESPZH.js +2307 -0
  54. package/dist/chunks/chunk-YOTW5ESM.js +118 -0
  55. package/dist/cli/bin.d.ts +2 -0
  56. package/dist/cli/bin.js +35 -0
  57. package/dist/cli/commands.d.ts +19 -0
  58. package/dist/cli/config.d.ts +22 -0
  59. package/dist/cli/index.d.ts +17 -0
  60. package/dist/cli/index.js +30 -0
  61. package/dist/cli/mcp.d.ts +14 -0
  62. package/dist/cli/stdio.d.ts +9 -0
  63. package/dist/clients/index.d.ts +2 -0
  64. package/dist/clients/index.js +117 -0
  65. package/dist/clients/plugin.d.ts +42 -0
  66. package/dist/combine/account.d.ts +4 -0
  67. package/dist/combine/adapter.d.ts +9 -0
  68. package/dist/combine/index.d.ts +2 -0
  69. package/dist/combine/index.js +420 -0
  70. package/dist/combine/route.d.ts +24 -0
  71. package/dist/exporter/index.d.ts +29 -0
  72. package/dist/exporter/index.js +77 -0
  73. package/dist/failover/index.d.ts +11 -0
  74. package/dist/failover/index.js +45 -0
  75. package/dist/fixtures/index.d.ts +27 -0
  76. package/dist/fixtures/index.js +260 -0
  77. package/dist/fixtures/scrub.d.ts +5 -0
  78. package/dist/heyreach/account.d.ts +11 -0
  79. package/dist/heyreach/adapter.d.ts +5 -0
  80. package/dist/heyreach/capabilities.d.ts +70 -0
  81. package/dist/heyreach/client.d.ts +18 -0
  82. package/dist/heyreach/inbox.d.ts +7 -0
  83. package/dist/heyreach/index.d.ts +25 -0
  84. package/dist/heyreach/index.js +1931 -0
  85. package/dist/heyreach/leads.d.ts +4 -0
  86. package/dist/heyreach/lookup.d.ts +15 -0
  87. package/dist/heyreach/map-account.d.ts +31 -0
  88. package/dist/heyreach/map-sequence.d.ts +5 -0
  89. package/dist/heyreach/map-stats.d.ts +13 -0
  90. package/dist/heyreach/map.d.ts +37 -0
  91. package/dist/heyreach/native-organization.d.ts +128 -0
  92. package/dist/heyreach/native-voice.d.ts +106 -0
  93. package/dist/heyreach/native.d.ts +496 -0
  94. package/dist/heyreach/paging.d.ts +7 -0
  95. package/dist/heyreach/webhooks.d.ts +3 -0
  96. package/dist/identity/index.d.ts +3 -0
  97. package/dist/identity/index.js +159 -0
  98. package/dist/identity/keys.d.ts +9 -0
  99. package/dist/identity/plugin.d.ts +34 -0
  100. package/dist/index.d.ts +33 -0
  101. package/dist/index.js +131 -0
  102. package/dist/insights/copy/copy-audit.d.ts +55 -0
  103. package/dist/insights/copy/copy-checks.d.ts +44 -0
  104. package/dist/insights/copy/copy-reuse.d.ts +59 -0
  105. package/dist/insights/copy/index.d.ts +67 -0
  106. package/dist/insights/copy/reply-timing.d.ts +63 -0
  107. package/dist/insights/copy/shared.d.ts +53 -0
  108. package/dist/insights/copy/step-funnel.d.ts +66 -0
  109. package/dist/insights/copy/variant-test.d.ts +64 -0
  110. package/dist/insights/define.d.ts +98 -0
  111. package/dist/insights/index.d.ts +10 -0
  112. package/dist/insights/index.js +4937 -0
  113. package/dist/insights/ops/anomalies.d.ts +80 -0
  114. package/dist/insights/ops/campaign-diagnosis.d.ts +39 -0
  115. package/dist/insights/ops/campaign-ranking.d.ts +56 -0
  116. package/dist/insights/ops/channel-mix.d.ts +44 -0
  117. package/dist/insights/ops/client-report.d.ts +76 -0
  118. package/dist/insights/ops/diagnosis-checks.d.ts +48 -0
  119. package/dist/insights/ops/index.d.ts +135 -0
  120. package/dist/insights/ops/period-comparison.d.ts +86 -0
  121. package/dist/insights/ops/pipeline-forecast.d.ts +44 -0
  122. package/dist/insights/ops/shared.d.ts +155 -0
  123. package/dist/insights/ops/tag-rollup.d.ts +32 -0
  124. package/dist/insights/people/account-summary.d.ts +68 -0
  125. package/dist/insights/people/dropped-replies.d.ts +51 -0
  126. package/dist/insights/people/find.d.ts +18 -0
  127. package/dist/insights/people/hot-leads.d.ts +67 -0
  128. package/dist/insights/people/index.d.ts +88 -0
  129. package/dist/insights/people/lead-collisions.d.ts +43 -0
  130. package/dist/insights/people/person-summary.d.ts +46 -0
  131. package/dist/insights/people/personalization-gaps.d.ts +60 -0
  132. package/dist/insights/people/read.d.ts +40 -0
  133. package/dist/insights/people/suppression-check.d.ts +53 -0
  134. package/dist/insights/plugin.d.ts +40 -0
  135. package/dist/insights/registry.d.ts +335 -0
  136. package/dist/insights/senders/bounce-watch.d.ts +70 -0
  137. package/dist/insights/senders/domain-health.d.ts +69 -0
  138. package/dist/insights/senders/index.d.ts +74 -0
  139. package/dist/insights/senders/read.d.ts +37 -0
  140. package/dist/insights/senders/sender-capacity.d.ts +67 -0
  141. package/dist/insights/senders/sender-load.d.ts +52 -0
  142. package/dist/insights/senders/settings-audit.d.ts +48 -0
  143. package/dist/insights/senders/warmup-readiness.d.ts +39 -0
  144. package/dist/insights/stats.d.ts +45 -0
  145. package/dist/insights/tools.d.ts +16 -0
  146. package/dist/insights/types.d.ts +4 -0
  147. package/dist/instantly/adapter-account.d.ts +5 -0
  148. package/dist/instantly/adapter-mail.d.ts +3 -0
  149. package/dist/instantly/adapter.d.ts +7 -0
  150. package/dist/instantly/capabilities.d.ts +85 -0
  151. package/dist/instantly/client.d.ts +24 -0
  152. package/dist/instantly/index.d.ts +27 -0
  153. package/dist/instantly/index.js +2627 -0
  154. package/dist/instantly/map-account.d.ts +38 -0
  155. package/dist/instantly/map-lead.d.ts +18 -0
  156. package/dist/instantly/map-stats.d.ts +25 -0
  157. package/dist/instantly/map.d.ts +22 -0
  158. package/dist/instantly/native-agents-sales.d.ts +161 -0
  159. package/dist/instantly/native-agents.d.ts +156 -0
  160. package/dist/instantly/native-campaigns.d.ts +101 -0
  161. package/dist/instantly/native-leads.d.ts +93 -0
  162. package/dist/instantly/native-params.d.ts +7 -0
  163. package/dist/instantly/native-search.d.ts +82 -0
  164. package/dist/instantly/native-senders.d.ts +182 -0
  165. package/dist/instantly/native-supersearch.d.ts +149 -0
  166. package/dist/instantly/native-workspace.d.ts +170 -0
  167. package/dist/instantly/native.d.ts +1081 -0
  168. package/dist/instantly/pages.d.ts +29 -0
  169. package/dist/instantly/stats.d.ts +5 -0
  170. package/dist/instantly/webhooks.d.ts +3 -0
  171. package/dist/internal/adapter.d.ts +211 -0
  172. package/dist/internal/capabilities.d.ts +104 -0
  173. package/dist/internal/client.d.ts +15 -0
  174. package/dist/internal/concurrency.d.ts +8 -0
  175. package/dist/internal/cursor.d.ts +10 -0
  176. package/dist/internal/engine/budget.d.ts +44 -0
  177. package/dist/internal/engine/engine.d.ts +45 -0
  178. package/dist/internal/engine/rate-store.d.ts +25 -0
  179. package/dist/internal/engine/request.d.ts +34 -0
  180. package/dist/internal/engine/retry.d.ts +21 -0
  181. package/dist/internal/engine/runtime.d.ts +13 -0
  182. package/dist/internal/entities-account.d.ts +205 -0
  183. package/dist/internal/entities.d.ts +493 -0
  184. package/dist/internal/env.d.ts +4 -0
  185. package/dist/internal/errors.d.ts +62 -0
  186. package/dist/internal/fields.d.ts +462 -0
  187. package/dist/internal/hooks.d.ts +55 -0
  188. package/dist/internal/json.d.ts +49 -0
  189. package/dist/internal/lead-fields.d.ts +21 -0
  190. package/dist/internal/lead-status.d.ts +13 -0
  191. package/dist/internal/limits.d.ts +34 -0
  192. package/dist/internal/metrics.d.ts +64 -0
  193. package/dist/internal/native.d.ts +81 -0
  194. package/dist/internal/outbound/api.d.ts +292 -0
  195. package/dist/internal/outbound/collections.d.ts +31 -0
  196. package/dist/internal/outbound/core.d.ts +36 -0
  197. package/dist/internal/outbound/create.d.ts +16 -0
  198. package/dist/internal/outbound/handles.d.ts +7 -0
  199. package/dist/internal/outbound/native.d.ts +4 -0
  200. package/dist/internal/outbound/operation-shared.d.ts +28 -0
  201. package/dist/internal/outbound/operations-account.d.ts +41 -0
  202. package/dist/internal/outbound/operations.d.ts +42 -0
  203. package/dist/internal/outbound/outbound.d.ts +67 -0
  204. package/dist/internal/outbound/plugins.d.ts +40 -0
  205. package/dist/internal/outbound/raw.d.ts +9 -0
  206. package/dist/internal/outbound/specs-account.d.ts +20 -0
  207. package/dist/internal/outbound/specs.d.ts +14 -0
  208. package/dist/internal/outbound/stats.d.ts +7 -0
  209. package/dist/internal/outbound/validate.d.ts +5 -0
  210. package/dist/internal/outbound/walker.d.ts +22 -0
  211. package/dist/internal/page.d.ts +14 -0
  212. package/dist/internal/record.d.ts +36 -0
  213. package/dist/internal/records.d.ts +7 -0
  214. package/dist/internal/redact.d.ts +18 -0
  215. package/dist/internal/ref.d.ts +16 -0
  216. package/dist/internal/sequence.d.ts +14 -0
  217. package/dist/internal/sha256.d.ts +6 -0
  218. package/dist/internal/text.d.ts +11 -0
  219. package/dist/internal/url.d.ts +9 -0
  220. package/dist/loader/index.d.ts +24 -0
  221. package/dist/loader/index.js +16 -0
  222. package/dist/memory/account-reads.d.ts +5 -0
  223. package/dist/memory/account.d.ts +81 -0
  224. package/dist/memory/adapter.d.ts +16 -0
  225. package/dist/memory/data.d.ts +137 -0
  226. package/dist/memory/demo.d.ts +7 -0
  227. package/dist/memory/index.d.ts +5 -0
  228. package/dist/memory/index.js +867 -0
  229. package/dist/memory/stats.d.ts +6 -0
  230. package/dist/memory/store.d.ts +18 -0
  231. package/dist/providers/index.d.ts +22 -0
  232. package/dist/providers/index.js +10 -0
  233. package/dist/reconcile/index.d.ts +2 -0
  234. package/dist/reconcile/index.js +72 -0
  235. package/dist/reconcile/plugin.d.ts +55 -0
  236. package/dist/redact/index.d.ts +2 -0
  237. package/dist/redact/index.js +197 -0
  238. package/dist/redact/plugin.d.ts +22 -0
  239. package/dist/redis/index.d.ts +41 -0
  240. package/dist/redis/index.js +114 -0
  241. package/dist/smartlead/account.d.ts +5 -0
  242. package/dist/smartlead/adapter.d.ts +5 -0
  243. package/dist/smartlead/capabilities.d.ts +87 -0
  244. package/dist/smartlead/client.d.ts +18 -0
  245. package/dist/smartlead/hmac.d.ts +7 -0
  246. package/dist/smartlead/index.d.ts +24 -0
  247. package/dist/smartlead/index.js +2329 -0
  248. package/dist/smartlead/leads.d.ts +9 -0
  249. package/dist/smartlead/lookup.d.ts +8 -0
  250. package/dist/smartlead/mail.d.ts +5 -0
  251. package/dist/smartlead/map-account.d.ts +34 -0
  252. package/dist/smartlead/map-messages.d.ts +31 -0
  253. package/dist/smartlead/map-stats.d.ts +36 -0
  254. package/dist/smartlead/map.d.ts +62 -0
  255. package/dist/smartlead/native-analytics.d.ts +242 -0
  256. package/dist/smartlead/native-campaigns.d.ts +211 -0
  257. package/dist/smartlead/native-inbox.d.ts +141 -0
  258. package/dist/smartlead/native-params.d.ts +12 -0
  259. package/dist/smartlead/native-services.d.ts +204 -0
  260. package/dist/smartlead/native.d.ts +785 -0
  261. package/dist/smartlead/shared.d.ts +29 -0
  262. package/dist/smartlead/stats.d.ts +5 -0
  263. package/dist/smartlead/webhooks.d.ts +3 -0
  264. package/dist/sync/index.d.ts +2 -0
  265. package/dist/sync/index.js +158 -0
  266. package/dist/sync/plugin.d.ts +58 -0
  267. package/dist/tools/account-tools.d.ts +21 -0
  268. package/dist/tools/ai-sdk.d.ts +8 -0
  269. package/dist/tools/ai-sdk.js +28 -0
  270. package/dist/tools/campaign-tools.d.ts +59 -0
  271. package/dist/tools/claude-agent.d.ts +18 -0
  272. package/dist/tools/claude-agent.js +42 -0
  273. package/dist/tools/index.d.ts +28 -0
  274. package/dist/tools/index.js +22 -0
  275. package/dist/tools/people-tools.d.ts +19 -0
  276. package/dist/tools/registry.d.ts +34 -0
  277. package/dist/tools/shared.d.ts +75 -0
  278. package/dist/tracing/index.d.ts +25 -0
  279. package/dist/tracing/index.js +69 -0
  280. package/dist/webhooks/index.d.ts +3 -0
  281. package/dist/webhooks/index.js +227 -0
  282. package/dist/webhooks/parse.d.ts +41 -0
  283. package/dist/webhooks/secret.d.ts +4 -0
  284. package/package.json +181 -4
@@ -0,0 +1,420 @@
1
+ import {
2
+ intersectCapabilities,
3
+ mergeFields,
4
+ resolveCapabilities,
5
+ resolveFields
6
+ } from "../chunks/chunk-UAT3JSJZ.js";
7
+ import {
8
+ recordBase
9
+ } from "../chunks/chunk-U2D34ARZ.js";
10
+ import "../chunks/chunk-4PSO6JEK.js";
11
+ import {
12
+ parseRef
13
+ } from "../chunks/chunk-LVYG7XZJ.js";
14
+ import {
15
+ OutboundError,
16
+ makeErrorMapper
17
+ } from "../chunks/chunk-E7JHLNLG.js";
18
+ import {
19
+ count,
20
+ field
21
+ } from "../chunks/chunk-VQSCHOBV.js";
22
+
23
+ // src/combine/route.ts
24
+ var COMBINED = "combined";
25
+ var routeRef = (members, ctx, id, what) => {
26
+ const parts = parseRef(id);
27
+ const member = parts === null ? void 0 : members.find(
28
+ (candidate) => candidate.name === parts.provider && candidate.workspaceId === parts.workspaceId
29
+ );
30
+ if (parts === null || member === void 0) {
31
+ throw new OutboundError(
32
+ "Invalid",
33
+ `${what} "${id}" must be a ref (provider:workspace:id) of an adapter on this combined instance`,
34
+ { provider: COMBINED }
35
+ );
36
+ }
37
+ return { ctx: ctx.forAdapter(member), id: parts.sourceId, member };
38
+ };
39
+ var position = (next) => ({
40
+ index: count(field(next, "member")) ?? 0,
41
+ next: field(next, "next") ?? void 0
42
+ });
43
+ var pageAcross = async (members, ctx, query, read) => {
44
+ const at = position(query.next);
45
+ const member = members[at.index];
46
+ if (member === void 0) {
47
+ return { items: [] };
48
+ }
49
+ const page = await read(member, ctx.forAdapter(member), at.next);
50
+ if (page.next !== void 0) {
51
+ return { items: page.items, next: { member: at.index, next: page.next } };
52
+ }
53
+ return at.index + 1 < members.length ? { items: page.items, next: { member: at.index + 1 } } : { items: page.items };
54
+ };
55
+ var waiting = (next, size) => {
56
+ const listed = field(next, "together");
57
+ if (!Array.isArray(listed)) {
58
+ return Array.from({ length: size }, (_, index) => ({
59
+ index,
60
+ next: void 0
61
+ }));
62
+ }
63
+ return listed.flatMap((entry) => {
64
+ const index = count(field(entry, "member"));
65
+ return index === null || index >= size ? [] : [{ index, next: field(entry, "next") ?? void 0 }];
66
+ });
67
+ };
68
+ var pageTogether = async (members, ctx, query, read) => {
69
+ const pages = await Promise.all(
70
+ waiting(query.next, members.length).flatMap((at) => {
71
+ const member = members[at.index];
72
+ return member === void 0 ? [] : [
73
+ read(member, ctx.forAdapter(member), at.next).then((page) => ({
74
+ index: at.index,
75
+ page
76
+ }))
77
+ ];
78
+ })
79
+ );
80
+ const unfinished = pages.flatMap(
81
+ ({ index, page }) => page.next === void 0 ? [] : [{ member: index, next: page.next }]
82
+ );
83
+ const items = pages.flatMap(({ page }) => page.items);
84
+ return unfinished.length === 0 ? { items } : { items, next: { together: unfinished } };
85
+ };
86
+
87
+ // src/combine/account.ts
88
+ var missing = (member, method) => new OutboundError(
89
+ "Unsupported",
90
+ `The ${member.name} adapter does not implement ${method}`,
91
+ { provider: member.name }
92
+ );
93
+ var need = (member, method) => {
94
+ const found = member[method];
95
+ if (found === void 0) {
96
+ throw missing(member, method);
97
+ }
98
+ return found;
99
+ };
100
+ var accountReads = (members) => ({
101
+ getCampaignProgress: (id, ctx) => {
102
+ const routed = routeRef(members, ctx, id, "Campaign");
103
+ return need(routed.member, "getCampaignProgress")(routed.id, routed.ctx);
104
+ },
105
+ getCampaignSettings: (id, ctx) => {
106
+ const routed = routeRef(members, ctx, id, "Campaign");
107
+ return need(routed.member, "getCampaignSettings")(routed.id, routed.ctx);
108
+ },
109
+ getList: (id, ctx) => {
110
+ const routed = routeRef(members, ctx, id, "List");
111
+ return need(routed.member, "getList")(routed.id, routed.ctx);
112
+ },
113
+ getSenderHealth: (id, ctx) => {
114
+ const routed = routeRef(members, ctx, id, "Sender");
115
+ return need(routed.member, "getSenderHealth")(routed.id, routed.ctx);
116
+ },
117
+ getWebhook: (id, ctx) => {
118
+ const routed = routeRef(members, ctx, id, "Webhook");
119
+ return need(routed.member, "getWebhook")(routed.id, routed.ctx);
120
+ },
121
+ listBlocklist: (query, ctx) => pageAcross(
122
+ members,
123
+ ctx,
124
+ query,
125
+ (member, memberCtx, next) => need(member, "listBlocklist")({ ...query, next }, memberCtx)
126
+ ),
127
+ listLists: (query, ctx) => pageAcross(
128
+ members,
129
+ ctx,
130
+ query,
131
+ (member, memberCtx, next) => need(member, "listLists")({ ...query, next }, memberCtx)
132
+ ),
133
+ listPlacementTests: (query, ctx) => pageAcross(
134
+ members,
135
+ ctx,
136
+ query,
137
+ (member, memberCtx, next) => need(member, "listPlacementTests")({ ...query, next }, memberCtx)
138
+ ),
139
+ listSubsequences: (query, ctx) => {
140
+ const routed = routeRef(members, ctx, query.campaignId, "Campaign");
141
+ return need(routed.member, "listSubsequences")(
142
+ { ...query, campaignId: routed.id },
143
+ routed.ctx
144
+ );
145
+ },
146
+ listTags: (query, ctx) => pageAcross(
147
+ members,
148
+ ctx,
149
+ query,
150
+ (member, memberCtx, next) => need(member, "listTags")({ ...query, next }, memberCtx)
151
+ ),
152
+ listWebhooks: (query, ctx) => {
153
+ if (query.campaignId === void 0) {
154
+ return pageAcross(
155
+ members,
156
+ ctx,
157
+ query,
158
+ (member, memberCtx, next) => need(member, "listWebhooks")({ ...query, next }, memberCtx)
159
+ );
160
+ }
161
+ const routed = routeRef(members, ctx, query.campaignId, "Campaign");
162
+ return need(routed.member, "listWebhooks")(
163
+ { ...query, campaignId: routed.id },
164
+ routed.ctx
165
+ );
166
+ }
167
+ });
168
+
169
+ // src/combine/adapter.ts
170
+ var MATURITY_ORDER = ["unverified", "beta", "stable"];
171
+ var weakestMaturity = (members) => MATURITY_ORDER.find(
172
+ (level) => members.some((member) => member.maturity === level)
173
+ ) ?? "stable";
174
+ var assertDistinct = (members) => {
175
+ if (members.length === 0) {
176
+ throw new OutboundError("Invalid", "combine() needs at least one adapter", {
177
+ provider: COMBINED
178
+ });
179
+ }
180
+ const seen = /* @__PURE__ */ new Set();
181
+ for (const member of members) {
182
+ const key = `${member.name}:${member.workspaceId}`;
183
+ if (member.members !== void 0) {
184
+ throw new OutboundError(
185
+ "Invalid",
186
+ "combine() cannot nest another combined adapter",
187
+ {
188
+ provider: COMBINED
189
+ }
190
+ );
191
+ }
192
+ if (seen.has(key)) {
193
+ throw new OutboundError(
194
+ "Invalid",
195
+ `Two adapters are both ${key}. Give each one its own workspaceId so their records stay apart`,
196
+ { provider: COMBINED }
197
+ );
198
+ }
199
+ seen.add(key);
200
+ }
201
+ };
202
+ var missing2 = (member, method) => new OutboundError(
203
+ "Unsupported",
204
+ `The ${member.name} adapter does not implement ${method}`,
205
+ {
206
+ provider: member.name
207
+ }
208
+ );
209
+ var scopedOrAcross = (members, ctx, query, read) => {
210
+ if (query.campaignId === void 0) {
211
+ return pageAcross(
212
+ members,
213
+ ctx,
214
+ query,
215
+ (member, memberCtx, next) => read(member, memberCtx, { ...query, next })
216
+ );
217
+ }
218
+ const routed = routeRef(members, ctx, query.campaignId, "Campaign");
219
+ return read(routed.member, routed.ctx, { ...query, campaignId: routed.id });
220
+ };
221
+ var lists = (members) => ({
222
+ listCampaigns: (query, ctx) => {
223
+ if (query.senderId !== void 0) {
224
+ const routed = routeRef(members, ctx, query.senderId, "Sender");
225
+ return routed.member.listCampaigns(
226
+ { ...query, senderId: routed.id },
227
+ routed.ctx
228
+ );
229
+ }
230
+ return pageAcross(
231
+ members,
232
+ ctx,
233
+ query,
234
+ (member, memberCtx, next) => member.listCampaigns({ ...query, next }, memberCtx)
235
+ );
236
+ },
237
+ listLeads: (query, ctx) => {
238
+ if (query.listId !== void 0) {
239
+ const routed = routeRef(members, ctx, query.listId, "List");
240
+ if (routed.member.listLeads === void 0) {
241
+ throw missing2(routed.member, "listLeads");
242
+ }
243
+ return routed.member.listLeads(
244
+ { ...query, listId: routed.id },
245
+ routed.ctx
246
+ );
247
+ }
248
+ const readLeads = (member, memberCtx, scoped) => {
249
+ if (member.listLeads === void 0) {
250
+ throw missing2(member, "listLeads");
251
+ }
252
+ return member.listLeads(scoped, memberCtx);
253
+ };
254
+ const lookup = query.email !== void 0 || query.linkedinUrl !== void 0;
255
+ if (lookup && query.campaignId === void 0) {
256
+ return pageTogether(
257
+ members,
258
+ ctx,
259
+ query,
260
+ async (member, memberCtx, next) => await readLeads(member, memberCtx, { ...query, next })
261
+ );
262
+ }
263
+ return scopedOrAcross(members, ctx, query, readLeads);
264
+ },
265
+ listMessages: (query, ctx) => {
266
+ const lead = query.leadId === void 0 ? void 0 : routeRef(members, ctx, query.leadId, "Lead");
267
+ return scopedOrAcross(
268
+ lead === void 0 ? members : [lead.member],
269
+ ctx,
270
+ query,
271
+ (member, memberCtx, scoped) => {
272
+ if (member.listMessages === void 0) {
273
+ throw missing2(member, "listMessages");
274
+ }
275
+ return member.listMessages({ ...scoped, leadId: lead?.id }, memberCtx);
276
+ }
277
+ );
278
+ },
279
+ listReplies: (query, ctx) => scopedOrAcross(members, ctx, query, (member, memberCtx, scoped) => {
280
+ if (member.listReplies === void 0) {
281
+ throw missing2(member, "listReplies");
282
+ }
283
+ return member.listReplies(scoped, memberCtx);
284
+ }),
285
+ listSenders: (query, ctx) => scopedOrAcross(members, ctx, query, (member, memberCtx, scoped) => {
286
+ if (member.listSenders === void 0) {
287
+ throw missing2(member, "listSenders");
288
+ }
289
+ return member.listSenders(scoped, memberCtx);
290
+ }),
291
+ // One workspace per member, named by its label. No request is made.
292
+ listWorkspaces: () => Promise.resolve({
293
+ items: members.map((member) => ({
294
+ ...recordBase(
295
+ { provider: member.name, workspaceId: member.workspaceId },
296
+ member.workspaceId,
297
+ null
298
+ ),
299
+ name: member.workspaceId
300
+ }))
301
+ })
302
+ });
303
+ var lookups = (members) => ({
304
+ getCampaign: (id, ctx) => {
305
+ const routed = routeRef(members, ctx, id, "Campaign");
306
+ return routed.member.getCampaign(routed.id, routed.ctx);
307
+ },
308
+ getLead: (id, ctx) => {
309
+ const routed = routeRef(members, ctx, id, "Lead");
310
+ if (routed.member.getLead === void 0) {
311
+ throw missing2(routed.member, "getLead");
312
+ }
313
+ return routed.member.getLead(routed.id, routed.ctx);
314
+ },
315
+ getSender: (id, ctx) => {
316
+ const routed = routeRef(members, ctx, id, "Sender");
317
+ if (routed.member.getSender === void 0) {
318
+ throw missing2(routed.member, "getSender");
319
+ }
320
+ return routed.member.getSender(routed.id, routed.ctx);
321
+ },
322
+ getSequence: (id, ctx) => {
323
+ const routed = routeRef(members, ctx, id, "Campaign");
324
+ if (routed.member.getSequence === void 0) {
325
+ throw missing2(routed.member, "getSequence");
326
+ }
327
+ return routed.member.getSequence(routed.id, routed.ctx);
328
+ },
329
+ stats: async (query, ctx) => {
330
+ if (query.scopeId !== void 0) {
331
+ const routed = routeRef(members, ctx, query.scopeId, "Stats scope");
332
+ if (routed.member.stats === void 0) {
333
+ throw missing2(routed.member, "stats");
334
+ }
335
+ return await routed.member.stats(
336
+ { ...query, scopeId: routed.id },
337
+ routed.ctx
338
+ );
339
+ }
340
+ const perMember = await Promise.all(
341
+ members.map((member) => {
342
+ if (member.stats === void 0) {
343
+ throw missing2(member, "stats");
344
+ }
345
+ return member.stats(query, ctx.forAdapter(member));
346
+ })
347
+ );
348
+ return perMember.flat();
349
+ }
350
+ });
351
+ var combine = (members) => {
352
+ assertDistinct(members);
353
+ const [first, ...rest] = members.map(
354
+ (member) => resolveCapabilities(member.capabilities)
355
+ );
356
+ return {
357
+ ...lists(members),
358
+ ...lookups(members),
359
+ ...accountReads(members),
360
+ capabilities: {
361
+ ...intersectCapabilities(first ?? resolveCapabilities(), ...rest),
362
+ // A thread id is the vendor's own and names no member, so it cannot be routed.
363
+ "messages.byThread": false,
364
+ // A native read belongs to one vendor; reach it through workspace(id).
365
+ native: false,
366
+ // A combined instance always knows its workspaces: they are its members.
367
+ workspaces: true
368
+ },
369
+ fieldCoverage: mergeFields(
370
+ members.map(
371
+ (member) => member.fieldCoverage ?? resolveFields(member.fields)
372
+ )
373
+ ),
374
+ caveats: members.flatMap(
375
+ (member) => (member.caveats ?? []).map(
376
+ (caveat) => `${member.name} (${member.workspaceId}): ${caveat}`
377
+ )
378
+ ),
379
+ events: {
380
+ detect: (request) => members.some((member) => member.events?.detect(request) ?? false),
381
+ // The member whose format matches parses it, under its own workspace.
382
+ parse: (request) => {
383
+ const owner = members.find(
384
+ (member) => member.events?.detect(request) ?? false
385
+ );
386
+ return owner?.events?.parse(request, owner.workspaceId) ?? [];
387
+ }
388
+ },
389
+ // The combined adapter never sends a request itself; each member has its own budget.
390
+ limits: {
391
+ source: "combined instance: see each member's limits",
392
+ windows: []
393
+ },
394
+ mapError: makeErrorMapper(COMBINED, {
395
+ secrets: members.flatMap((member) => member.secrets)
396
+ }),
397
+ maturity: weakestMaturity(members),
398
+ members,
399
+ name: COMBINED,
400
+ raw: {
401
+ authorize: (spec) => spec,
402
+ baseUrl: "combined://",
403
+ isRead: () => false
404
+ },
405
+ // One client on two tools carries one label on both members, so scoping
406
+ // to the label keeps both. A label on one member is that member itself.
407
+ scope: (workspaceId) => {
408
+ const labelled = members.filter(
409
+ (member) => member.workspaceId === workspaceId || `${member.name}:${member.workspaceId}` === workspaceId
410
+ );
411
+ return labelled.length > 1 ? combine(labelled) : labelled[0];
412
+ },
413
+ secrets: members.flatMap((member) => member.secrets),
414
+ workspaceId: COMBINED
415
+ };
416
+ };
417
+ export {
418
+ COMBINED,
419
+ combine
420
+ };
@@ -0,0 +1,24 @@
1
+ import type { Adapter, AdapterContext, Page, PageQuery } from "../internal/adapter.ts";
2
+ import type { Json } from "../internal/json.ts";
3
+ export declare const COMBINED = "combined";
4
+ export interface Routed {
5
+ readonly member: Adapter;
6
+ readonly ctx: AdapterContext;
7
+ /** The vendor's own id, without the provider and workspace. */
8
+ readonly id: string;
9
+ }
10
+ /** Finds the member a ref belongs to. A bare vendor id cannot be routed. */
11
+ export declare const routeRef: (members: readonly Adapter[], ctx: AdapterContext, id: string, what: string) => Routed;
12
+ /**
13
+ * One page of a listing that spans every member: the first member is read to
14
+ * its end, then the second, and so on. The cursor records which member the
15
+ * walk is in, so it resumes exactly.
16
+ */
17
+ export declare const pageAcross: <Item>(members: readonly Adapter[], ctx: AdapterContext, query: PageQuery, read: (member: Adapter, memberCtx: AdapterContext, next: Json | undefined) => Promise<Page<Item>>) => Promise<Page<Item>>;
18
+ /**
19
+ * One page of a listing read from every member at the same time, for reads
20
+ * that return few records, such as a lookup by exact address. Items keep the
21
+ * members' order. The cursor holds each member still to finish, so the next
22
+ * page asks only those, again side by side.
23
+ */
24
+ export declare const pageTogether: <Item>(members: readonly Adapter[], ctx: AdapterContext, query: PageQuery, read: (member: Adapter, memberCtx: AdapterContext, next: Json | undefined) => Promise<Page<Item>>) => Promise<Page<Item>>;
@@ -0,0 +1,29 @@
1
+ import type { JsonObject } from "../internal/json.ts";
2
+ import type { OutboundPlugin } from "../internal/outbound/plugins.ts";
3
+ /**
4
+ * Receives rows one at a time. Implement it to write Parquet, DuckDB or
5
+ * anything else. A row holds the export's columns and nothing else, and
6
+ * `close` is called once, also when the source fails or yields nothing.
7
+ */
8
+ export interface RowWriter {
9
+ readonly write: (row: JsonObject) => Promise<void>;
10
+ readonly close: () => Promise<void>;
11
+ }
12
+ export interface ExportOptions {
13
+ /** A file path ending in `.csv` or `.jsonl`, or a writer. */
14
+ readonly to: RowWriter | string;
15
+ /** The columns to write, in order. Defaults to the first record's fields without `raw`. */
16
+ readonly columns?: readonly string[] | undefined;
17
+ /** Include the vendor's raw payload when `columns` is not given. Defaults to `false`. */
18
+ readonly includeRaw?: boolean | undefined;
19
+ }
20
+ export interface ExportResult {
21
+ readonly rows: number;
22
+ readonly columns: readonly string[];
23
+ }
24
+ export interface ExporterExtension {
25
+ /** Writes every record of a listing, for example `outbound.leads.listAll()`. */
26
+ readonly export: <Item>(source: AsyncIterable<Item>, options: ExportOptions) => Promise<ExportResult>;
27
+ }
28
+ /** Adds `outbound.export()`. */
29
+ export declare const exporter: () => OutboundPlugin<ExporterExtension>;
@@ -0,0 +1,77 @@
1
+ import {
2
+ OutboundError
3
+ } from "../chunks/chunk-E7JHLNLG.js";
4
+ import {
5
+ isJsonObject,
6
+ toJson
7
+ } from "../chunks/chunk-VQSCHOBV.js";
8
+
9
+ // src/exporter/index.ts
10
+ import { open } from "node:fs/promises";
11
+ var isPath = (to) => typeof to === "string";
12
+ var csvCell = (value) => {
13
+ if (value === null || value === void 0) {
14
+ return "";
15
+ }
16
+ const text = isJsonObject(value) || Array.isArray(value) ? JSON.stringify(value) : String(value);
17
+ return /[",\n\r]/u.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
18
+ };
19
+ var fileWriter = async (file, columns) => {
20
+ const csv = file.endsWith(".csv");
21
+ if (!csv && !file.endsWith(".jsonl")) {
22
+ throw new OutboundError(
23
+ "Invalid",
24
+ "export() writes .csv or .jsonl files; pass a writer for other formats"
25
+ );
26
+ }
27
+ const handle = await open(file, "w");
28
+ if (csv && columns.length > 0) {
29
+ await handle.write(
30
+ `${columns.map((column) => csvCell(column)).join(",")}
31
+ `
32
+ );
33
+ }
34
+ return {
35
+ close: () => handle.close(),
36
+ write: async (row) => {
37
+ const line = csv ? columns.map((column) => csvCell(row[column])).join(",") : JSON.stringify(row);
38
+ await handle.write(`${line}
39
+ `);
40
+ }
41
+ };
42
+ };
43
+ var exportRows = async (source, options) => {
44
+ let writer;
45
+ let columns = options.columns ?? [];
46
+ let rows = 0;
47
+ try {
48
+ for await (const item of source) {
49
+ const row = toJson(item);
50
+ if (isJsonObject(row)) {
51
+ if (writer === void 0) {
52
+ columns = options.columns ?? Object.keys(row).filter(
53
+ (key) => options.includeRaw === true || key !== "raw"
54
+ );
55
+ writer = isPath(options.to) ? await fileWriter(options.to, columns) : options.to;
56
+ }
57
+ await writer.write(
58
+ Object.fromEntries(
59
+ columns.map((column) => [column, row[column] ?? null])
60
+ )
61
+ );
62
+ rows += 1;
63
+ }
64
+ }
65
+ writer ??= isPath(options.to) ? await fileWriter(options.to, columns) : options.to;
66
+ } finally {
67
+ await (writer ?? (isPath(options.to) ? void 0 : options.to))?.close();
68
+ }
69
+ return { columns, rows };
70
+ };
71
+ var exporter = () => ({
72
+ extend: () => ({ export: exportRows }),
73
+ name: "exporter"
74
+ });
75
+ export {
76
+ exporter
77
+ };
@@ -0,0 +1,11 @@
1
+ import type { CacheStore } from "../cache/index.ts";
2
+ import type { OutboundPlugin } from "../internal/outbound/plugins.ts";
3
+ export interface FailoverOptions {
4
+ readonly store: CacheStore;
5
+ /** How long a stored answer may be served, in seconds. Defaults to 7 days. */
6
+ readonly maxAge?: number | undefined;
7
+ /** The clock, for tests. */
8
+ readonly now?: (() => number) | undefined;
9
+ }
10
+ /** Serves the last good answer, marked stale, when the vendor is down. */
11
+ export declare const failover: (options: FailoverOptions) => OutboundPlugin;
@@ -0,0 +1,45 @@
1
+ import {
2
+ cacheKey
3
+ } from "../chunks/chunk-IVH3NMQZ.js";
4
+ import "../chunks/chunk-FHKSLCVW.js";
5
+ import {
6
+ OutboundError
7
+ } from "../chunks/chunk-E7JHLNLG.js";
8
+ import "../chunks/chunk-VQSCHOBV.js";
9
+
10
+ // src/failover/index.ts
11
+ var WEEK_SECONDS = 7 * 24 * 60 * 60;
12
+ var vendorIsDown = (cause) => OutboundError.is(cause) && !cause.aborted && (cause.code === "Provider" || cause.code === "RateLimited" && cause.status !== void 0);
13
+ var fetchedAtOf = (fetchedAt, now) => fetchedAt === void 0 ? now : Date.parse(fetchedAt);
14
+ var failover = (options) => {
15
+ const now = options.now ?? (() => Date.now());
16
+ const maxAgeMs = (options.maxAge ?? WEEK_SECONDS) * 1e3;
17
+ return {
18
+ name: "failover",
19
+ wrap: async (operation, next, info) => {
20
+ const key = `failover:${cacheKey(info, operation)}`;
21
+ try {
22
+ const output = await next(operation);
23
+ await options.store.set(
24
+ key,
25
+ { output, storedAt: fetchedAtOf(output.fetchedAt, now()) },
26
+ maxAgeMs
27
+ );
28
+ return output;
29
+ } catch (error) {
30
+ const saved = vendorIsDown(error) ? await options.store.get(key) : void 0;
31
+ if (saved === void 0 || now() - saved.storedAt > maxAgeMs) {
32
+ throw error;
33
+ }
34
+ return {
35
+ ...saved.output,
36
+ fetchedAt: new Date(saved.storedAt).toISOString(),
37
+ stale: true
38
+ };
39
+ }
40
+ }
41
+ };
42
+ };
43
+ export {
44
+ failover
45
+ };
@@ -0,0 +1,27 @@
1
+ import type { Operation } from "../internal/outbound/operations.ts";
2
+ import type { OutboundPlugin } from "../internal/outbound/plugins.ts";
3
+ export { createScrubber } from "./scrub.ts";
4
+ export type { Scrubber } from "./scrub.ts";
5
+ export interface FixturesOptions {
6
+ /** The folder to write to and read from. */
7
+ readonly dir: string;
8
+ /**
9
+ * `record` calls the vendor and saves the answer. `replay` answers from
10
+ * disk and never calls the vendor. `auto` replays when a file exists and
11
+ * records otherwise. Defaults to `auto`.
12
+ */
13
+ readonly mode?: "auto" | "record" | "replay" | undefined;
14
+ /** Replace personal data with placeholders before saving. Defaults to `true`. */
15
+ readonly scrub?: boolean | undefined;
16
+ }
17
+ export interface FixtureScope {
18
+ readonly provider: string;
19
+ readonly workspaceId: string;
20
+ }
21
+ /**
22
+ * The file one operation is saved to. The workspace is part of the name and
23
+ * of the hash, so two workspaces of one provider never share a file.
24
+ */
25
+ export declare const fixtureFile: (dir: string, scope: FixtureScope, operation: Operation) => string;
26
+ /** Records operations to disk and replays them. */
27
+ export declare const fixtures: (options: FixturesOptions) => OutboundPlugin;