outbound-sdk 0.0.0-stage → 0.1.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 (271) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +121 -2
  3. package/dist/alerts/index.d.ts +2 -0
  4. package/dist/alerts/index.js +136 -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 +70 -0
  10. package/dist/budget/index.d.ts +21 -0
  11. package/dist/budget/index.js +50 -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-7BCYLIDG.js +483 -0
  32. package/dist/chunks/chunk-B7V6EOAC.js +2273 -0
  33. package/dist/chunks/chunk-CMQ5ZHLZ.js +25 -0
  34. package/dist/chunks/chunk-F7MKFVIG.js +43 -0
  35. package/dist/chunks/chunk-FZF6CLPX.js +232 -0
  36. package/dist/chunks/chunk-GPEJG34O.js +53 -0
  37. package/dist/chunks/chunk-HEC7XFFH.js +65 -0
  38. package/dist/chunks/chunk-IBC52BX3.js +24 -0
  39. package/dist/chunks/chunk-LNCOGBMI.js +144 -0
  40. package/dist/chunks/chunk-LOXBLQ3I.js +180 -0
  41. package/dist/chunks/chunk-NAWZ73QS.js +22 -0
  42. package/dist/chunks/chunk-OCV66TS2.js +705 -0
  43. package/dist/chunks/chunk-Q465X22Y.js +548 -0
  44. package/dist/chunks/chunk-QTB747K4.js +100 -0
  45. package/dist/chunks/chunk-QZNNCXXD.js +92 -0
  46. package/dist/chunks/chunk-R6AM4GJR.js +105 -0
  47. package/dist/chunks/chunk-TIJKJJDW.js +6 -0
  48. package/dist/chunks/chunk-VURTOVGI.js +61 -0
  49. package/dist/chunks/chunk-WAM6N4OF.js +269 -0
  50. package/dist/chunks/chunk-WW746NJF.js +94 -0
  51. package/dist/chunks/chunk-XC6CZP73.js +80 -0
  52. package/dist/chunks/chunk-ZGHQYZEH.js +45 -0
  53. package/dist/cli/bin.d.ts +2 -0
  54. package/dist/cli/bin.js +34 -0
  55. package/dist/cli/commands.d.ts +16 -0
  56. package/dist/cli/index.d.ts +13 -0
  57. package/dist/cli/index.js +25 -0
  58. package/dist/cli/mcp.d.ts +14 -0
  59. package/dist/clients/index.d.ts +2 -0
  60. package/dist/clients/index.js +107 -0
  61. package/dist/clients/plugin.d.ts +42 -0
  62. package/dist/combine/account.d.ts +4 -0
  63. package/dist/combine/adapter.d.ts +9 -0
  64. package/dist/combine/index.d.ts +2 -0
  65. package/dist/combine/index.js +345 -0
  66. package/dist/combine/route.d.ts +17 -0
  67. package/dist/exporter/index.d.ts +29 -0
  68. package/dist/exporter/index.js +77 -0
  69. package/dist/failover/index.d.ts +11 -0
  70. package/dist/failover/index.js +45 -0
  71. package/dist/fixtures/index.d.ts +27 -0
  72. package/dist/fixtures/index.js +241 -0
  73. package/dist/fixtures/scrub.d.ts +5 -0
  74. package/dist/heyreach/account.d.ts +11 -0
  75. package/dist/heyreach/adapter.d.ts +5 -0
  76. package/dist/heyreach/capabilities.d.ts +68 -0
  77. package/dist/heyreach/client.d.ts +20 -0
  78. package/dist/heyreach/inbox.d.ts +7 -0
  79. package/dist/heyreach/index.d.ts +18 -0
  80. package/dist/heyreach/index.js +1708 -0
  81. package/dist/heyreach/lookup.d.ts +15 -0
  82. package/dist/heyreach/map-account.d.ts +25 -0
  83. package/dist/heyreach/map-sequence.d.ts +5 -0
  84. package/dist/heyreach/map-stats.d.ts +10 -0
  85. package/dist/heyreach/map.d.ts +35 -0
  86. package/dist/heyreach/native-organization.d.ts +128 -0
  87. package/dist/heyreach/native-voice.d.ts +106 -0
  88. package/dist/heyreach/native.d.ts +496 -0
  89. package/dist/heyreach/paging.d.ts +7 -0
  90. package/dist/heyreach/webhooks.d.ts +2 -0
  91. package/dist/identity/index.d.ts +3 -0
  92. package/dist/identity/index.js +148 -0
  93. package/dist/identity/keys.d.ts +9 -0
  94. package/dist/identity/plugin.d.ts +34 -0
  95. package/dist/index.d.ts +36 -0
  96. package/dist/index.js +119 -0
  97. package/dist/insights/copy/copy-audit.d.ts +55 -0
  98. package/dist/insights/copy/copy-checks.d.ts +44 -0
  99. package/dist/insights/copy/copy-reuse.d.ts +59 -0
  100. package/dist/insights/copy/index.d.ts +67 -0
  101. package/dist/insights/copy/reply-timing.d.ts +63 -0
  102. package/dist/insights/copy/shared.d.ts +53 -0
  103. package/dist/insights/copy/step-funnel.d.ts +66 -0
  104. package/dist/insights/copy/variant-test.d.ts +64 -0
  105. package/dist/insights/define.d.ts +98 -0
  106. package/dist/insights/index.d.ts +10 -0
  107. package/dist/insights/index.js +4873 -0
  108. package/dist/insights/ops/anomalies.d.ts +80 -0
  109. package/dist/insights/ops/campaign-diagnosis.d.ts +39 -0
  110. package/dist/insights/ops/campaign-ranking.d.ts +56 -0
  111. package/dist/insights/ops/channel-mix.d.ts +44 -0
  112. package/dist/insights/ops/client-report.d.ts +76 -0
  113. package/dist/insights/ops/diagnosis-checks.d.ts +48 -0
  114. package/dist/insights/ops/index.d.ts +135 -0
  115. package/dist/insights/ops/period-comparison.d.ts +86 -0
  116. package/dist/insights/ops/pipeline-forecast.d.ts +44 -0
  117. package/dist/insights/ops/shared.d.ts +149 -0
  118. package/dist/insights/ops/tag-rollup.d.ts +32 -0
  119. package/dist/insights/people/account-summary.d.ts +68 -0
  120. package/dist/insights/people/dropped-replies.d.ts +51 -0
  121. package/dist/insights/people/find.d.ts +18 -0
  122. package/dist/insights/people/hot-leads.d.ts +67 -0
  123. package/dist/insights/people/index.d.ts +88 -0
  124. package/dist/insights/people/lead-collisions.d.ts +43 -0
  125. package/dist/insights/people/person-summary.d.ts +46 -0
  126. package/dist/insights/people/personalization-gaps.d.ts +60 -0
  127. package/dist/insights/people/read.d.ts +40 -0
  128. package/dist/insights/people/suppression-check.d.ts +53 -0
  129. package/dist/insights/plugin.d.ts +40 -0
  130. package/dist/insights/registry.d.ts +335 -0
  131. package/dist/insights/senders/bounce-watch.d.ts +70 -0
  132. package/dist/insights/senders/domain-health.d.ts +69 -0
  133. package/dist/insights/senders/index.d.ts +74 -0
  134. package/dist/insights/senders/read.d.ts +37 -0
  135. package/dist/insights/senders/sender-capacity.d.ts +67 -0
  136. package/dist/insights/senders/sender-load.d.ts +52 -0
  137. package/dist/insights/senders/settings-audit.d.ts +48 -0
  138. package/dist/insights/senders/warmup-readiness.d.ts +39 -0
  139. package/dist/insights/stats.d.ts +45 -0
  140. package/dist/insights/tools.d.ts +16 -0
  141. package/dist/insights/types.d.ts +4 -0
  142. package/dist/instantly/adapter-account.d.ts +5 -0
  143. package/dist/instantly/adapter-mail.d.ts +3 -0
  144. package/dist/instantly/adapter.d.ts +7 -0
  145. package/dist/instantly/capabilities.d.ts +83 -0
  146. package/dist/instantly/client.d.ts +29 -0
  147. package/dist/instantly/index.d.ts +20 -0
  148. package/dist/instantly/index.js +2372 -0
  149. package/dist/instantly/map-account.d.ts +23 -0
  150. package/dist/instantly/map-lead.d.ts +18 -0
  151. package/dist/instantly/map-stats.d.ts +22 -0
  152. package/dist/instantly/map.d.ts +24 -0
  153. package/dist/instantly/native-agents-sales.d.ts +161 -0
  154. package/dist/instantly/native-agents.d.ts +156 -0
  155. package/dist/instantly/native-campaigns.d.ts +101 -0
  156. package/dist/instantly/native-leads.d.ts +93 -0
  157. package/dist/instantly/native-params.d.ts +24 -0
  158. package/dist/instantly/native-search.d.ts +82 -0
  159. package/dist/instantly/native-senders.d.ts +182 -0
  160. package/dist/instantly/native-supersearch.d.ts +149 -0
  161. package/dist/instantly/native-workspace.d.ts +170 -0
  162. package/dist/instantly/native.d.ts +1081 -0
  163. package/dist/instantly/pages.d.ts +29 -0
  164. package/dist/instantly/stats.d.ts +5 -0
  165. package/dist/instantly/webhooks.d.ts +2 -0
  166. package/dist/internal/adapter.d.ts +189 -0
  167. package/dist/internal/capabilities.d.ts +86 -0
  168. package/dist/internal/cursor.d.ts +10 -0
  169. package/dist/internal/engine/budget.d.ts +44 -0
  170. package/dist/internal/engine/engine.d.ts +45 -0
  171. package/dist/internal/engine/rate-store.d.ts +25 -0
  172. package/dist/internal/engine/request.d.ts +27 -0
  173. package/dist/internal/engine/retry.d.ts +21 -0
  174. package/dist/internal/engine/runtime.d.ts +13 -0
  175. package/dist/internal/entities-account.d.ts +135 -0
  176. package/dist/internal/entities.d.ts +389 -0
  177. package/dist/internal/env.d.ts +4 -0
  178. package/dist/internal/errors.d.ts +57 -0
  179. package/dist/internal/hooks.d.ts +55 -0
  180. package/dist/internal/json.d.ts +40 -0
  181. package/dist/internal/limits.d.ts +34 -0
  182. package/dist/internal/metrics.d.ts +52 -0
  183. package/dist/internal/native.d.ts +66 -0
  184. package/dist/internal/outbound/api.d.ts +267 -0
  185. package/dist/internal/outbound/collections.d.ts +31 -0
  186. package/dist/internal/outbound/core.d.ts +36 -0
  187. package/dist/internal/outbound/create.d.ts +16 -0
  188. package/dist/internal/outbound/handles.d.ts +7 -0
  189. package/dist/internal/outbound/native.d.ts +4 -0
  190. package/dist/internal/outbound/operation-shared.d.ts +28 -0
  191. package/dist/internal/outbound/operations-account.d.ts +29 -0
  192. package/dist/internal/outbound/operations.d.ts +42 -0
  193. package/dist/internal/outbound/outbound.d.ts +64 -0
  194. package/dist/internal/outbound/plugins.d.ts +40 -0
  195. package/dist/internal/outbound/raw.d.ts +9 -0
  196. package/dist/internal/outbound/specs-account.d.ts +16 -0
  197. package/dist/internal/outbound/specs.d.ts +14 -0
  198. package/dist/internal/outbound/stats.d.ts +7 -0
  199. package/dist/internal/outbound/validate.d.ts +5 -0
  200. package/dist/internal/outbound/walker.d.ts +22 -0
  201. package/dist/internal/record.d.ts +19 -0
  202. package/dist/internal/redact.d.ts +18 -0
  203. package/dist/internal/ref.d.ts +16 -0
  204. package/dist/internal/sha256.d.ts +4 -0
  205. package/dist/internal/text.d.ts +11 -0
  206. package/dist/internal/url.d.ts +9 -0
  207. package/dist/loader/index.d.ts +12 -0
  208. package/dist/loader/index.js +12 -0
  209. package/dist/memory/account-reads.d.ts +5 -0
  210. package/dist/memory/account.d.ts +67 -0
  211. package/dist/memory/adapter.d.ts +16 -0
  212. package/dist/memory/data.d.ts +122 -0
  213. package/dist/memory/demo.d.ts +7 -0
  214. package/dist/memory/index.d.ts +5 -0
  215. package/dist/memory/index.js +792 -0
  216. package/dist/memory/stats.d.ts +6 -0
  217. package/dist/memory/store.d.ts +18 -0
  218. package/dist/providers/index.d.ts +22 -0
  219. package/dist/providers/index.js +10 -0
  220. package/dist/reconcile/index.d.ts +2 -0
  221. package/dist/reconcile/index.js +72 -0
  222. package/dist/reconcile/plugin.d.ts +55 -0
  223. package/dist/redact/index.d.ts +2 -0
  224. package/dist/redact/index.js +192 -0
  225. package/dist/redact/plugin.d.ts +22 -0
  226. package/dist/redis/index.d.ts +41 -0
  227. package/dist/redis/index.js +114 -0
  228. package/dist/smartlead/account.d.ts +5 -0
  229. package/dist/smartlead/adapter.d.ts +5 -0
  230. package/dist/smartlead/capabilities.d.ts +85 -0
  231. package/dist/smartlead/client.d.ts +23 -0
  232. package/dist/smartlead/hmac.d.ts +9 -0
  233. package/dist/smartlead/index.d.ts +17 -0
  234. package/dist/smartlead/index.js +2170 -0
  235. package/dist/smartlead/leads.d.ts +6 -0
  236. package/dist/smartlead/lookup.d.ts +8 -0
  237. package/dist/smartlead/mail.d.ts +5 -0
  238. package/dist/smartlead/map-account.d.ts +22 -0
  239. package/dist/smartlead/map-messages.d.ts +31 -0
  240. package/dist/smartlead/map-stats.d.ts +37 -0
  241. package/dist/smartlead/map.d.ts +52 -0
  242. package/dist/smartlead/native-analytics.d.ts +242 -0
  243. package/dist/smartlead/native-campaigns.d.ts +211 -0
  244. package/dist/smartlead/native-inbox.d.ts +141 -0
  245. package/dist/smartlead/native-params.d.ts +33 -0
  246. package/dist/smartlead/native-services.d.ts +204 -0
  247. package/dist/smartlead/native.d.ts +785 -0
  248. package/dist/smartlead/shared.d.ts +28 -0
  249. package/dist/smartlead/stats.d.ts +5 -0
  250. package/dist/smartlead/webhooks.d.ts +2 -0
  251. package/dist/sync/index.d.ts +2 -0
  252. package/dist/sync/index.js +158 -0
  253. package/dist/sync/plugin.d.ts +58 -0
  254. package/dist/tools/account-tools.d.ts +21 -0
  255. package/dist/tools/ai-sdk.d.ts +8 -0
  256. package/dist/tools/ai-sdk.js +26 -0
  257. package/dist/tools/campaign-tools.d.ts +59 -0
  258. package/dist/tools/claude-agent.d.ts +18 -0
  259. package/dist/tools/claude-agent.js +40 -0
  260. package/dist/tools/index.d.ts +28 -0
  261. package/dist/tools/index.js +20 -0
  262. package/dist/tools/people-tools.d.ts +19 -0
  263. package/dist/tools/registry.d.ts +34 -0
  264. package/dist/tools/shared.d.ts +75 -0
  265. package/dist/tracing/index.d.ts +25 -0
  266. package/dist/tracing/index.js +69 -0
  267. package/dist/webhooks/index.d.ts +3 -0
  268. package/dist/webhooks/index.js +226 -0
  269. package/dist/webhooks/parse.d.ts +41 -0
  270. package/dist/webhooks/secret.d.ts +4 -0
  271. package/package.json +181 -4
@@ -0,0 +1,66 @@
1
+ import type { Json } from "./json.ts";
2
+ export interface NativeParam {
3
+ /** Where the value goes in the request. */
4
+ readonly in: "body" | "path" | "query";
5
+ /** `list` is several plain values: a repeated key in the query, an array in the body. */
6
+ readonly type: "boolean" | "json" | "list" | "number" | "string";
7
+ /** Path parameters are always required. */
8
+ readonly required?: boolean | undefined;
9
+ readonly description: string;
10
+ }
11
+ export interface NativeRead {
12
+ /** What the read answers, in one sentence. */
13
+ readonly description: string;
14
+ readonly method: "GET" | "POST";
15
+ /** The vendor's path, with `{name}` for each path parameter. */
16
+ readonly path: string;
17
+ readonly params?: Readonly<Record<string, NativeParam>> | undefined;
18
+ /** A rate lane declared in the adapter's limits. */
19
+ readonly lane?: string | undefined;
20
+ /** A different host, for a vendor's sister service. Defaults to the adapter's base URL. */
21
+ readonly baseUrl?: string | undefined;
22
+ /** The vendor's documentation page for the read. */
23
+ readonly docs?: string | undefined;
24
+ /**
25
+ * `true` when the response can hold a credential, for example the headers a
26
+ * webhook sends. The read stays available to code, and is left out of what
27
+ * the `vendor_read` agent tool lists and runs.
28
+ */
29
+ readonly sensitive?: boolean | undefined;
30
+ }
31
+ /** The reads by name. Names are camelCase, for example `inboxUnread`. */
32
+ export type NativeCatalog = Readonly<Record<string, NativeRead>>;
33
+ /** An adapter with no native reads. */
34
+ export type NoNative = Record<never, never>;
35
+ /** Keeps each read's name and parameters as literal types. */
36
+ export declare const defineNative: <const Catalog extends NativeCatalog>(catalog: Catalog) => Catalog;
37
+ interface ValueTypes {
38
+ readonly boolean: boolean;
39
+ readonly json: Json;
40
+ readonly list: readonly (boolean | number | string)[];
41
+ readonly number: number;
42
+ readonly string: string;
43
+ }
44
+ type Declared<Read> = Read extends {
45
+ readonly params: infer Params extends Readonly<Record<string, NativeParam>>;
46
+ } ? Params : NoNative;
47
+ type RequiredNames<Params> = {
48
+ [Name in keyof Params]: Params[Name] extends {
49
+ readonly required: true;
50
+ } | {
51
+ readonly in: "path";
52
+ } ? Name : never;
53
+ }[keyof Params];
54
+ type ValueOf<Param> = Param extends {
55
+ readonly type: infer Type;
56
+ } ? Type extends keyof ValueTypes ? ValueTypes[Type] : Json : Json;
57
+ type TypedParams<Params> = {
58
+ readonly [Name in RequiredNames<Params>]: ValueOf<Params[Name]>;
59
+ } & {
60
+ readonly [Name in Exclude<keyof Params, RequiredNames<Params>>]?: ValueOf<Params[Name]> | undefined;
61
+ };
62
+ /** The parameters one catalogued read takes, as a typed object. */
63
+ export type NativeParamsOf<Read> = TypedParams<Declared<Read>>;
64
+ /** `true` when the read cannot be called without parameters. */
65
+ export type NeedsParams<Read> = [RequiredNames<Declared<Read>>] extends [never] ? false : true;
66
+ export {};
@@ -0,0 +1,267 @@
1
+ import type { TimeRange } from "../adapter.ts";
2
+ import type { Capabilities } from "../capabilities.ts";
3
+ import type { LimitsSnapshot, OperationOptions } from "../engine/engine.ts";
4
+ import type { BlockEntry, CampaignSettings, LeadList, SenderHealth, Tag, WebhookSubscription } from "../entities-account.ts";
5
+ import type { Campaign, CampaignStatus, Evidence, Lead, Message, MetricRow, MetricScope, Reply, ReplyCategory, Sender, Sequence, Workspace } from "../entities.ts";
6
+ import type { OutboundError } from "../errors.ts";
7
+ import type { Json } from "../json.ts";
8
+ import type { NativeCatalog, NativeParamsOf, NeedsParams, NoNative } from "../native.ts";
9
+ export interface ResultMeta {
10
+ /** `exact` from the vendor, `sampled` when partial, `derived` when we computed or filtered it. */
11
+ readonly evidence: Evidence;
12
+ /** When the SDK got the answer, ISO 8601 UTC. */
13
+ readonly fetchedAt: string;
14
+ /** `false` when more pages exist or a filter could not see everything. */
15
+ readonly complete: boolean;
16
+ /** Milliseconds spent waiting for the rate budget. */
17
+ readonly throttledMs: number;
18
+ /** Vendor requests the call made. */
19
+ readonly requests: number;
20
+ readonly provider: string;
21
+ readonly workspaceId: string;
22
+ /** `true` when an older answer was served because the vendor was down. */
23
+ readonly stale: boolean;
24
+ }
25
+ export type WithMeta<Item> = Item & {
26
+ readonly meta: ResultMeta;
27
+ };
28
+ export interface PageResult<Item> {
29
+ readonly items: readonly Item[];
30
+ /** Pass back to `list` or `listAll` to continue. Absent on the last page. */
31
+ readonly cursor?: string | undefined;
32
+ readonly complete: boolean;
33
+ readonly meta: ResultMeta;
34
+ }
35
+ export interface ListOptions extends OperationOptions {
36
+ /** A page size hint. Adapters clamp it to what the vendor allows. */
37
+ readonly limit?: number | undefined;
38
+ /** A cursor from an earlier page of the same listing. */
39
+ readonly cursor?: string | undefined;
40
+ }
41
+ export interface ListAllOptions extends ListOptions {
42
+ /** Stop after this many records. */
43
+ readonly max?: number | undefined;
44
+ }
45
+ /** An async iterator over every page, with a cursor you can resume from. */
46
+ export interface ListAll<Item> extends AsyncIterable<Item> {
47
+ /** The cursor after the last page fetched. `undefined` before the first page and at the end. */
48
+ readonly cursor: string | undefined;
49
+ /** The meta of the last page fetched. */
50
+ readonly meta: ResultMeta | undefined;
51
+ /** `true` once `max` stopped the walk while more records existed. */
52
+ readonly truncated: boolean;
53
+ /** Collects every record into an array. */
54
+ readonly toArray: () => Promise<Item[]>;
55
+ }
56
+ export interface BulkOptions extends OperationOptions {
57
+ /** How many records to fetch at once. Defaults to 4. */
58
+ readonly concurrency?: number | undefined;
59
+ }
60
+ /** Partial failure is data, not an exception. */
61
+ export interface BulkResult<Item> {
62
+ readonly results: readonly {
63
+ readonly id: string;
64
+ readonly value: WithMeta<Item>;
65
+ }[];
66
+ readonly errors: readonly {
67
+ readonly id: string;
68
+ readonly error: OutboundError;
69
+ }[];
70
+ }
71
+ export interface ReadCollection<Item, Filters> {
72
+ /** One page. */
73
+ readonly list: (options?: Filters & ListOptions) => Promise<PageResult<Item>>;
74
+ /** Every page, fetched under the rate budget as you iterate. */
75
+ readonly listAll: (options?: Filters & ListAllOptions) => ListAll<Item>;
76
+ }
77
+ export interface Collection<Item, Filters> extends ReadCollection<Item, Filters> {
78
+ /** Throws `NotFound` for a missing record. */
79
+ readonly get: (id: string, options?: OperationOptions) => Promise<WithMeta<Item>>;
80
+ /** Never throws for a missing record. */
81
+ readonly exists: (id: string, options?: OperationOptions) => Promise<boolean>;
82
+ readonly getMany: (ids: readonly string[], options?: BulkOptions) => Promise<BulkResult<Item>>;
83
+ }
84
+ /** Fields that cost extra vendor requests and are fetched only when asked for. */
85
+ export type Include = "body";
86
+ export interface CampaignFilters {
87
+ readonly status?: CampaignStatus | undefined;
88
+ }
89
+ export interface SenderFilters {
90
+ readonly campaignId?: string | undefined;
91
+ }
92
+ export interface LeadFilters extends TimeRange {
93
+ readonly campaignId?: string | undefined;
94
+ /** A saved lead list. Not together with `campaignId`. */
95
+ readonly listId?: string | undefined;
96
+ /** Only the records of the person with exactly this email address. */
97
+ readonly email?: string | undefined;
98
+ /** Only the records of the person with exactly this LinkedIn profile. */
99
+ readonly linkedinUrl?: string | undefined;
100
+ }
101
+ export interface WebhookFilters {
102
+ readonly campaignId?: string | undefined;
103
+ }
104
+ export interface MessageFilters extends TimeRange {
105
+ readonly campaignId?: string | undefined;
106
+ readonly leadId?: string | undefined;
107
+ /** A `threadId` from an earlier message. */
108
+ readonly threadId?: string | undefined;
109
+ readonly include?: readonly Include[] | undefined;
110
+ }
111
+ export interface ReplyFilters extends TimeRange {
112
+ readonly campaignId?: string | undefined;
113
+ readonly category?: ReplyCategory | undefined;
114
+ readonly include?: readonly Include[] | undefined;
115
+ }
116
+ export interface StatsOptions extends OperationOptions {
117
+ /** Inclusive `YYYY-MM-DD`. */
118
+ readonly from?: string | undefined;
119
+ /** Inclusive `YYYY-MM-DD`. */
120
+ readonly to?: string | undefined;
121
+ /** `total` for one row over the range, `day` for one row per day. */
122
+ readonly by?: "day" | "total" | undefined;
123
+ }
124
+ export interface TopLevelStatsOptions extends StatsOptions {
125
+ readonly scope?: MetricScope | undefined;
126
+ /** The campaign or sender, for the `campaign`, `step` and `sender` scopes. */
127
+ readonly scopeId?: string | undefined;
128
+ }
129
+ export interface StatsResult {
130
+ readonly rows: readonly MetricRow[];
131
+ readonly meta: ResultMeta;
132
+ }
133
+ type Scoped<Filters, Key extends keyof Filters> = Omit<Filters, Key>;
134
+ export interface CampaignHandle {
135
+ readonly id: string;
136
+ readonly get: (options?: OperationOptions) => Promise<WithMeta<Campaign>>;
137
+ readonly sequence: (options?: OperationOptions) => Promise<WithMeta<Sequence>>;
138
+ /** The schedule, daily caps, tracking and stop rules. */
139
+ readonly settings: (options?: OperationOptions) => Promise<WithMeta<CampaignSettings>>;
140
+ /** The follow-up sequences attached to the campaign. */
141
+ readonly subsequences: ReadCollection<Sequence, Record<never, never>>;
142
+ readonly webhooks: ReadCollection<WebhookSubscription, Record<never, never>>;
143
+ readonly senders: ReadCollection<Sender, Scoped<SenderFilters, "campaignId">>;
144
+ readonly leads: ReadCollection<Lead, Scoped<LeadFilters, "campaignId" | "listId">>;
145
+ readonly messages: ReadCollection<Message, Scoped<MessageFilters, "campaignId">>;
146
+ readonly replies: ReadCollection<Reply, Scoped<ReplyFilters, "campaignId">>;
147
+ /** Totals, or one row per day or per step. */
148
+ readonly stats: (options?: StatsOptions & {
149
+ readonly scope?: "campaign" | "step" | undefined;
150
+ }) => Promise<StatsResult>;
151
+ }
152
+ export interface SenderHandle {
153
+ readonly id: string;
154
+ readonly get: (options?: OperationOptions) => Promise<WithMeta<Sender>>;
155
+ readonly stats: (options?: StatsOptions) => Promise<StatsResult>;
156
+ readonly warmup: (options?: OperationOptions) => Promise<NonNullable<Sender["warmup"]>>;
157
+ /** DNS records, connection state and warmup traffic. */
158
+ readonly health: (options?: OperationOptions) => Promise<WithMeta<SenderHealth>>;
159
+ }
160
+ export interface ListHandle {
161
+ readonly id: string;
162
+ readonly leads: ReadCollection<Lead, Scoped<LeadFilters, "campaignId" | "listId">>;
163
+ }
164
+ export interface ThreadHandle {
165
+ readonly id: string;
166
+ /** Every message of the conversation, oldest first. */
167
+ readonly messages: (options?: OperationOptions & {
168
+ readonly include?: readonly Include[] | undefined;
169
+ }) => Promise<PageResult<Message>>;
170
+ }
171
+ export interface LeadHandle {
172
+ readonly id: string;
173
+ readonly get: (options?: OperationOptions) => Promise<WithMeta<Lead>>;
174
+ /** Every message to and from the lead, oldest first. */
175
+ readonly timeline: (options?: OperationOptions & {
176
+ readonly include?: readonly Include[] | undefined;
177
+ }) => Promise<PageResult<Message>>;
178
+ }
179
+ export interface RawRequestOptions extends OperationOptions {
180
+ readonly query?: Readonly<Record<string, string | number | boolean | undefined>> | undefined;
181
+ readonly body?: Json | undefined;
182
+ readonly lane?: string | undefined;
183
+ }
184
+ /** The vendor's own API, for anything not normalized yet. Reads only unless `allowWrites` is set. */
185
+ export interface RawClient {
186
+ readonly provider: string;
187
+ readonly get: (path: string, options?: RawRequestOptions) => Promise<Json>;
188
+ readonly request: (method: "DELETE" | "GET" | "PATCH" | "POST" | "PUT", path: string, options?: RawRequestOptions) => Promise<Json>;
189
+ }
190
+ export type NativeParams = Readonly<Record<string, Json | undefined>>;
191
+ export interface NativeResult {
192
+ /** The vendor's response, as it was sent. Not normalized and not redacted. */
193
+ readonly data: Json;
194
+ readonly meta: ResultMeta;
195
+ }
196
+ type NativeArguments<Read> = NeedsParams<Read> extends true ? [params: NativeParamsOf<Read>, options?: OperationOptions] : [params?: NativeParamsOf<Read>, options?: OperationOptions];
197
+ /** One function per catalogued read, typed from the adapter's catalog. */
198
+ export type NativeReads<Native> = {
199
+ readonly [Name in keyof Native]: (...args: NativeArguments<Native[Name]>) => Promise<NativeResult>;
200
+ };
201
+ /**
202
+ * The vendor's own reads that have no normalized form. Every one is a read:
203
+ * the catalog holds nothing that changes vendor data. Each call is one vendor
204
+ * request; pass the vendor's own paging parameters to page.
205
+ */
206
+ export interface NativeClient<Native extends NativeCatalog = NoNative> {
207
+ readonly provider: string;
208
+ /** What this vendor offers beyond the normalized reads, with each read's parameters. */
209
+ readonly catalog: Native;
210
+ /** The reads as typed functions: `outbound.native.reads.inboxUnread({ limit: 20 })`. */
211
+ readonly reads: NativeReads<Native>;
212
+ /** A read by name, for callers that learn the name at run time. */
213
+ readonly read: (name: string, params?: NativeParams, options?: OperationOptions) => Promise<NativeResult>;
214
+ }
215
+ export interface EstimateQuery {
216
+ /** The listing or lookup to estimate, for example `leads.list`. */
217
+ readonly action: string;
218
+ /** How many records you expect to read. */
219
+ readonly records?: number | undefined;
220
+ readonly limit?: number | undefined;
221
+ }
222
+ export interface Estimate {
223
+ /** Expected vendor requests, or `null` when it cannot be known up front. */
224
+ readonly requests: number | null;
225
+ readonly basis: string;
226
+ }
227
+ export interface OutboundApi {
228
+ readonly provider: string;
229
+ readonly workspaceId: string;
230
+ /** What this instance can do, after plugins narrowed it. */
231
+ readonly capabilities: Capabilities;
232
+ /** How far the adapter has been verified. */
233
+ readonly maturity: "beta" | "stable" | "unverified";
234
+ /** What the adapter assumes and has not confirmed against the live API. */
235
+ readonly caveats: readonly string[];
236
+ readonly campaigns: Collection<Campaign, CampaignFilters>;
237
+ readonly senders: Collection<Sender, SenderFilters>;
238
+ readonly leads: Collection<Lead, LeadFilters>;
239
+ readonly messages: ReadCollection<Message, MessageFilters>;
240
+ readonly replies: ReadCollection<Reply, ReplyFilters>;
241
+ readonly workspaces: ReadCollection<Workspace, Record<never, never>>;
242
+ /** Saved lead lists. */
243
+ readonly lists: ReadCollection<LeadList, Record<never, never>>;
244
+ /** The addresses, domains and profiles the account never contacts. */
245
+ readonly blocklist: ReadCollection<BlockEntry, Record<never, never>>;
246
+ readonly tags: ReadCollection<Tag, Record<never, never>>;
247
+ /** The webhooks registered with the vendor. */
248
+ readonly webhooks: ReadCollection<WebhookSubscription, WebhookFilters>;
249
+ readonly raw: RawClient;
250
+ /** The vendor's own reads, by name, for what has no normalized form. */
251
+ readonly native: NativeClient;
252
+ readonly campaign: (id: string) => CampaignHandle;
253
+ readonly sender: (id: string) => SenderHandle;
254
+ readonly lead: (id: string) => LeadHandle;
255
+ /** One saved lead list. */
256
+ readonly list: (id: string) => ListHandle;
257
+ /** One conversation, by the `threadId` a message carries. */
258
+ readonly thread: (id: string) => ThreadHandle;
259
+ /** The same API scoped to one client or workspace. */
260
+ readonly workspace: (id: string) => OutboundApi;
261
+ readonly stats: (options?: TopLevelStatsOptions) => Promise<StatsResult>;
262
+ /** The current rate budget for this credential. */
263
+ readonly limits: () => Promise<LimitsSnapshot[]>;
264
+ /** How many vendor requests a read would cost, before making it. */
265
+ readonly estimate: (query: EstimateQuery) => Estimate;
266
+ }
267
+ export {};
@@ -0,0 +1,31 @@
1
+ import type { ZodType } from "zod";
2
+ import type { OperationOptions } from "../engine/engine.ts";
3
+ import type { Json } from "../json.ts";
4
+ import type { Collection, ListOptions, ReadCollection, WithMeta } from "./api.ts";
5
+ import type { Core } from "./core.ts";
6
+ import type { Operation, OperationKind } from "./operations.ts";
7
+ export interface PageRequest {
8
+ readonly limit: number | undefined;
9
+ readonly next: Json | undefined;
10
+ }
11
+ export interface ListSpec<Item, Filters> {
12
+ readonly action: OperationKind;
13
+ readonly schema: ZodType<Item>;
14
+ /** Checks the filters and the capabilities they need. Returns clean filters. */
15
+ readonly prepare: (filters: Filters) => Filters;
16
+ readonly toOperation: (filters: Filters, page: PageRequest) => Operation;
17
+ /** What makes a record the same record on a later page. The filters are given because they can change that. */
18
+ readonly keyOf: (item: Item, filters: Filters) => string | undefined;
19
+ }
20
+ export interface GetSpec<Item> {
21
+ readonly action: OperationKind;
22
+ readonly what: string;
23
+ readonly schema: ZodType<Item>;
24
+ /** Checks the capability the lookup needs. */
25
+ readonly prepare: () => void;
26
+ readonly toOperation: (id: string) => Operation;
27
+ }
28
+ export declare const makeReadCollection: <Item, Filters>(core: Core, spec: ListSpec<Item, Filters>) => ReadCollection<Item, Filters>;
29
+ export declare const makeGetter: <Item>(core: Core, spec: GetSpec<Item>) => (id: string, options?: OperationOptions) => Promise<WithMeta<Item>>;
30
+ export declare const makeCollection: <Item, Filters>(core: Core, listSpec: ListSpec<Item, Filters>, getSpec: GetSpec<Item>) => Collection<Item, Filters>;
31
+ export type { ListOptions };
@@ -0,0 +1,36 @@
1
+ import type { ZodType } from "zod";
2
+ import type { Adapter } from "../adapter.ts";
3
+ import type { CapabilityGate } from "../capabilities.ts";
4
+ import type { OperationOptions, RequestEngine } from "../engine/engine.ts";
5
+ import type { CallState } from "../engine/request.ts";
6
+ import type { Evidence } from "../entities.ts";
7
+ import { OutboundError } from "../errors.ts";
8
+ import type { ResultMeta } from "./api.ts";
9
+ import type { Operation, OperationOutput, OutboundRecord } from "./operations.ts";
10
+ import type { OperationInfo } from "./plugins.ts";
11
+ export interface Core {
12
+ readonly adapter: Adapter;
13
+ readonly engine: RequestEngine;
14
+ readonly gate: CapabilityGate;
15
+ readonly allowWrites: boolean;
16
+ /** One operation through every plugin and then the adapter. */
17
+ readonly run: (operation: Operation, info: OperationInfo) => Promise<OperationOutput>;
18
+ }
19
+ export declare const infoFor: (core: Core, state: CallState) => OperationInfo;
20
+ export declare const toOutboundError: (core: Core, cause: unknown) => OutboundError;
21
+ /** Runs one SDK call with accounting, hooks and error normalization around it. */
22
+ export declare const perform: <Result>(core: Core, action: string, options: OperationOptions | undefined, body: (state: CallState) => Promise<Result>, shared?: CallState,
23
+ /** Says whether a failure is an answer to the caller, not an error: `onError` is not told of it. */
24
+ isAnswer?: (error: OutboundError) => boolean) => Promise<Result>;
25
+ export interface MetaInput {
26
+ readonly evidence: Evidence;
27
+ readonly complete: boolean;
28
+ readonly stale?: boolean | undefined;
29
+ readonly fetchedAt?: string | undefined;
30
+ }
31
+ export declare const metaFor: (core: Core, state: CallState, input: MetaInput) => ResultMeta;
32
+ /**
33
+ * 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.
35
+ */
36
+ export declare const checked: <Item>(core: Core, schema: ZodType<Item>, records: readonly OutboundRecord[], action: string) => Item[];
@@ -0,0 +1,16 @@
1
+ import type { NativeCatalog, NoNative } from "../native.ts";
2
+ import { Outbound } from "./outbound.ts";
3
+ import type { OutboundOptions } from "./outbound.ts";
4
+ import type { OutboundPlugin } from "./plugins.ts";
5
+ type ExtensionOf<Plugin> = Plugin extends OutboundPlugin<infer Extension> ? unknown extends Extension ? Record<never, never> : Extension : never;
6
+ type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (value: infer Intersection) => void ? Intersection : never;
7
+ /** The methods a list of plugins adds to the instance. */
8
+ export type ExtensionsOf<Plugins extends readonly OutboundPlugin[]> = UnionToIntersection<ExtensionOf<Plugins[number]>>;
9
+ /**
10
+ * Creates the client. One instance wraps one adapter; `combine()` puts
11
+ * several adapters behind one.
12
+ */
13
+ export declare const createOutbound: <const Plugins extends readonly OutboundPlugin[] = [], Native extends NativeCatalog = NoNative>(options: OutboundOptions<Native> & {
14
+ readonly plugins?: Plugins | undefined;
15
+ }) => Outbound<Native> & ExtensionsOf<Plugins>;
16
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { CampaignHandle, LeadHandle, ListHandle, SenderHandle, ThreadHandle } from "./api.ts";
2
+ import type { Core } from "./core.ts";
3
+ export declare const makeCampaignHandle: (core: Core, id: string) => CampaignHandle;
4
+ export declare const makeSenderHandle: (core: Core, id: string) => SenderHandle;
5
+ export declare const makeLeadHandle: (core: Core, id: string) => LeadHandle;
6
+ export declare const makeListHandle: (core: Core, id: string) => ListHandle;
7
+ export declare const makeThreadHandle: (core: Core, id: string) => ThreadHandle;
@@ -0,0 +1,4 @@
1
+ import type { NativeCatalog } from "../native.ts";
2
+ import type { NativeClient } from "./api.ts";
3
+ import type { Core } from "./core.ts";
4
+ export declare const makeNativeClient: <Native extends NativeCatalog>(core: Core) => NativeClient<Native>;
@@ -0,0 +1,28 @@
1
+ import type { Adapter, AdapterContext, Page } from "../adapter.ts";
2
+ import type { Capabilities } from "../capabilities.ts";
3
+ import type { Entity } from "../entities-account.ts";
4
+ import type { Evidence, MetricRow } from "../entities.ts";
5
+ import { OutboundError } from "../errors.ts";
6
+ import type { Json } from "../json.ts";
7
+ /** A record an operation returns. */
8
+ export type OutboundRecord = Entity | MetricRow;
9
+ export interface OperationOutput {
10
+ readonly items: readonly OutboundRecord[];
11
+ /** The adapter's continuation value, when there is another page. */
12
+ readonly next?: Json | undefined;
13
+ readonly evidence: Evidence;
14
+ /** `true` when a plugin served an older answer because the vendor was down. */
15
+ readonly stale?: boolean | undefined;
16
+ /** When the answer was fetched, if a plugin served it from a store. ISO 8601 UTC. */
17
+ readonly fetchedAt?: string | undefined;
18
+ }
19
+ export declare const unsupported: (adapter: Adapter, kind: string) => OutboundError;
20
+ export declare const idFor: (adapter: Adapter, id: string) => string;
21
+ export declare const optionalId: (adapter: Adapter, id: string | undefined) => string | undefined;
22
+ export declare const output: (page: Page<OutboundRecord>, derived?: boolean) => OperationOutput;
23
+ export declare const single: (item: OutboundRecord) => OperationOutput;
24
+ export interface DispatchTarget {
25
+ readonly adapter: Adapter;
26
+ readonly capabilities: Capabilities;
27
+ readonly ctx: AdapterContext;
28
+ }
@@ -0,0 +1,29 @@
1
+ import type { PageQuery, SubsequenceQuery, WebhookQuery } from "../adapter.ts";
2
+ import type { DispatchTarget, OperationOutput } from "./operation-shared.ts";
3
+ export type AccountOperation = {
4
+ readonly kind: "blocklist.list";
5
+ readonly query: PageQuery;
6
+ } | {
7
+ readonly kind: "campaigns.settings";
8
+ readonly id: string;
9
+ } | {
10
+ readonly kind: "lists.list";
11
+ readonly query: PageQuery;
12
+ } | {
13
+ readonly kind: "senders.health";
14
+ readonly id: string;
15
+ } | {
16
+ readonly kind: "sequence.subsequences";
17
+ readonly query: SubsequenceQuery;
18
+ } | {
19
+ readonly kind: "tags.list";
20
+ readonly query: PageQuery;
21
+ } | {
22
+ readonly kind: "webhooks.list";
23
+ readonly query: WebhookQuery;
24
+ };
25
+ export declare const isAccountOperation: <Other extends {
26
+ readonly kind: string;
27
+ }>(operation: AccountOperation | Other) => operation is AccountOperation;
28
+ /** Hands one account-level operation to the adapter. */
29
+ export declare const dispatchAccount: (target: DispatchTarget, operation: AccountOperation) => Promise<OperationOutput>;
@@ -0,0 +1,42 @@
1
+ import type { CampaignQuery, LeadQuery, MessageQuery, PageQuery, ReplyQuery, SenderQuery, StatsQuery } from "../adapter.ts";
2
+ import type { DispatchTarget, OperationOutput } from "./operation-shared.ts";
3
+ import type { AccountOperation } from "./operations-account.ts";
4
+ export type { DispatchTarget, OperationOutput, OutboundRecord, } from "./operation-shared.ts";
5
+ type CoreOperation = {
6
+ readonly kind: "campaigns.get";
7
+ readonly id: string;
8
+ } | {
9
+ readonly kind: "campaigns.list";
10
+ readonly query: CampaignQuery;
11
+ } | {
12
+ readonly kind: "leads.get";
13
+ readonly id: string;
14
+ } | {
15
+ readonly kind: "leads.list";
16
+ readonly query: LeadQuery;
17
+ } | {
18
+ readonly kind: "messages.list";
19
+ readonly query: MessageQuery;
20
+ } | {
21
+ readonly kind: "replies.list";
22
+ readonly query: ReplyQuery;
23
+ } | {
24
+ readonly kind: "senders.get";
25
+ readonly id: string;
26
+ } | {
27
+ readonly kind: "senders.list";
28
+ readonly query: SenderQuery;
29
+ } | {
30
+ readonly kind: "sequence.get";
31
+ readonly id: string;
32
+ } | {
33
+ readonly kind: "stats";
34
+ readonly query: StatsQuery;
35
+ } | {
36
+ readonly kind: "workspaces.list";
37
+ readonly query: PageQuery;
38
+ };
39
+ export type Operation = AccountOperation | CoreOperation;
40
+ export type OperationKind = Operation["kind"];
41
+ /** The innermost step: hands one operation to the adapter. */
42
+ export declare const dispatch: (target: DispatchTarget, operation: Operation) => Promise<OperationOutput>;
@@ -0,0 +1,64 @@
1
+ import type { Adapter } from "../adapter.ts";
2
+ import type { Capabilities } from "../capabilities.ts";
3
+ import { RequestEngine } from "../engine/engine.ts";
4
+ import type { LimitsSnapshot, OperationOptions } from "../engine/engine.ts";
5
+ import type { RateLimitStore } from "../engine/rate-store.ts";
6
+ import type { Runtime } from "../engine/runtime.ts";
7
+ import type { BlockEntry, LeadList, Tag, WebhookSubscription } from "../entities-account.ts";
8
+ import type { Campaign, Lead, Message, Reply, Sender, Workspace } from "../entities.ts";
9
+ import type { OutboundHooks } from "../hooks.ts";
10
+ import type { NativeCatalog, NoNative } from "../native.ts";
11
+ import type { CampaignFilters, CampaignHandle, Collection, Estimate, EstimateQuery, LeadFilters, LeadHandle, ListHandle, MessageFilters, NativeClient, OutboundApi, RawClient, ReadCollection, ReplyFilters, SenderFilters, SenderHandle, StatsResult, ThreadHandle, TopLevelStatsOptions, WebhookFilters } from "./api.ts";
12
+ import type { OutboundPlugin } from "./plugins.ts";
13
+ export interface OutboundOptions<Native extends NativeCatalog = NoNative> extends OperationOptions {
14
+ readonly adapter: Adapter<Native>;
15
+ /** `plugins[0]` is the outermost layer. */
16
+ readonly plugins?: readonly OutboundPlugin[] | undefined;
17
+ readonly hooks?: OutboundHooks | undefined;
18
+ /** Where rate budgets are counted. Defaults to this process's memory. */
19
+ readonly rateLimitStore?: RateLimitStore | undefined;
20
+ /** The fraction of each vendor's published limit to use. Defaults to 0.5. */
21
+ readonly share?: number | undefined;
22
+ /** Lets `raw` send requests that are not reads. Off by default. */
23
+ readonly allowWrites?: boolean | undefined;
24
+ /** A replacement for the global `fetch`. */
25
+ readonly fetch?: typeof fetch | undefined;
26
+ /** Replaces the clock, timers and randomness. Meant for tests. */
27
+ readonly runtime?: Partial<Runtime> | undefined;
28
+ }
29
+ export declare class Outbound<Native extends NativeCatalog = NoNative> implements OutboundApi {
30
+ #private;
31
+ readonly campaigns: Collection<Campaign, CampaignFilters>;
32
+ readonly senders: Collection<Sender, SenderFilters>;
33
+ readonly leads: Collection<Lead, LeadFilters>;
34
+ readonly messages: ReadCollection<Message, MessageFilters>;
35
+ readonly replies: ReadCollection<Reply, ReplyFilters>;
36
+ readonly workspaces: ReadCollection<Workspace, Record<never, never>>;
37
+ readonly lists: ReadCollection<LeadList, Record<never, never>>;
38
+ readonly blocklist: ReadCollection<BlockEntry, Record<never, never>>;
39
+ readonly tags: ReadCollection<Tag, Record<never, never>>;
40
+ readonly webhooks: ReadCollection<WebhookSubscription, WebhookFilters>;
41
+ readonly raw: RawClient;
42
+ readonly native: NativeClient<Native>;
43
+ constructor(options: OutboundOptions<Native>, engine?: RequestEngine);
44
+ get provider(): string;
45
+ get workspaceId(): string;
46
+ get capabilities(): Capabilities;
47
+ get maturity(): Adapter["maturity"];
48
+ get caveats(): readonly string[];
49
+ /** The plugins on this instance, outermost first. */
50
+ get plugins(): readonly OutboundPlugin[];
51
+ campaign(id: string): CampaignHandle;
52
+ sender(id: string): SenderHandle;
53
+ lead(id: string): LeadHandle;
54
+ list(id: string): ListHandle;
55
+ thread(id: string): ThreadHandle;
56
+ /**
57
+ * The same instance scoped to one client or workspace. It keeps the
58
+ * plugins and what they add, so `outbound.workspace(id).insights` works.
59
+ */
60
+ workspace(id: string): this;
61
+ stats(options?: TopLevelStatsOptions): Promise<StatsResult>;
62
+ limits(): Promise<LimitsSnapshot[]>;
63
+ estimate(query: EstimateQuery): Estimate;
64
+ }
@@ -0,0 +1,40 @@
1
+ import type { Adapter } from "../adapter.ts";
2
+ import type { Capabilities, CapabilityKey } from "../capabilities.ts";
3
+ import type { CallState } from "../engine/request.ts";
4
+ import type { OutboundEvent } from "../entities.ts";
5
+ import type { OutboundHooks } from "../hooks.ts";
6
+ import type { OutboundApi } from "./api.ts";
7
+ import type { Operation, OperationOutput } from "./operations.ts";
8
+ export interface OperationInfo {
9
+ readonly provider: string;
10
+ readonly workspaceId: string;
11
+ readonly adapter: Adapter;
12
+ /** What the call has used so far. Plugins may read it and may add to it. */
13
+ readonly state: CallState;
14
+ }
15
+ export type NextOperation = (operation: Operation) => Promise<OperationOutput>;
16
+ export interface OutboundPlugin<Extension = unknown> {
17
+ /** Names the plugin in errors and diagnostics. */
18
+ readonly name: string;
19
+ /** Intercepts an operation. Call `next` to continue inward. */
20
+ readonly wrap?: (operation: Operation, next: NextOperation, info: OperationInfo) => Promise<OperationOutput>;
21
+ /** Returns the capabilities to advertise. Anything it widens is ignored. */
22
+ readonly capabilities?: (capabilities: Capabilities) => Capabilities;
23
+ /** Adds methods to the instance. A name that already exists is an error. */
24
+ readonly extend?: (outbound: OutboundApi) => Extension;
25
+ /** Observes calls and HTTP requests, alongside the instance's own hooks. */
26
+ readonly hooks?: OutboundHooks | undefined;
27
+ /** Rewrites a webhook event, or returns `null` to drop it. */
28
+ readonly event?: (event: OutboundEvent) => OutboundEvent | null;
29
+ }
30
+ export interface NarrowedCapabilities {
31
+ readonly capabilities: Capabilities;
32
+ readonly narrowedBy: ReadonlyMap<CapabilityKey, string>;
33
+ }
34
+ /** Applies each plugin's `capabilities` hook, recording who turned what off. */
35
+ export declare const narrowCapabilities: (declared: Capabilities, plugins: readonly OutboundPlugin[]) => NarrowedCapabilities;
36
+ /** Folds the plugins' `wrap` functions around the innermost step. */
37
+ export declare const composeOperations: (plugins: readonly OutboundPlugin[], innermost: (operation: Operation, info: OperationInfo) => Promise<OperationOutput>) => ((operation: Operation, info: OperationInfo) => Promise<OperationOutput>);
38
+ export declare const assertUniquePluginNames: (plugins: readonly OutboundPlugin[]) => void;
39
+ /** Defines on the instance what each plugin's `extend` returns. */
40
+ export declare const installExtensions: (outbound: OutboundApi, plugins: readonly OutboundPlugin[]) => void;
@@ -0,0 +1,9 @@
1
+ import type { RawClient } from "./api.ts";
2
+ import type { Core } from "./core.ts";
3
+ /**
4
+ * `nativeOffBy` names the plugin that turns the `native` capability off, when
5
+ * one does. It is asked for apart from the gate, because the gate records a
6
+ * plugin only for a capability the adapter declared, and raw exists on every
7
+ * adapter.
8
+ */
9
+ export declare const makeRawClient: (core: Core, nativeOffBy?: string | undefined) => RawClient;