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.
- package/LICENSE +21 -0
- package/README.md +121 -2
- package/dist/alerts/index.d.ts +2 -0
- package/dist/alerts/index.js +136 -0
- package/dist/alerts/plugin.d.ts +58 -0
- package/dist/audit/index.d.ts +33 -0
- package/dist/audit/index.js +60 -0
- package/dist/benchmarks/index.d.ts +29 -0
- package/dist/benchmarks/index.js +70 -0
- package/dist/budget/index.d.ts +21 -0
- package/dist/budget/index.js +50 -0
- package/dist/cache/index.d.ts +31 -0
- package/dist/cache/index.js +11 -0
- package/dist/cards/content.d.ts +43 -0
- package/dist/cards/copy-cards.d.ts +2 -0
- package/dist/cards/format.d.ts +39 -0
- package/dist/cards/index.d.ts +9 -0
- package/dist/cards/index.js +2070 -0
- package/dist/cards/notify-cards.d.ts +14 -0
- package/dist/cards/ops-cards.d.ts +2 -0
- package/dist/cards/parts.d.ts +22 -0
- package/dist/cards/people-cards.d.ts +2 -0
- package/dist/cards/render.d.ts +28 -0
- package/dist/cards/sender-cards.d.ts +2 -0
- package/dist/cards/slack-rich.d.ts +19 -0
- package/dist/cards/slack-text.d.ts +10 -0
- package/dist/cards/slack.d.ts +21 -0
- package/dist/cards/spec.d.ts +86 -0
- package/dist/cards/tool-cards.d.ts +4 -0
- package/dist/chunks/chunk-4O2HRTTI.js +75 -0
- package/dist/chunks/chunk-7BCYLIDG.js +483 -0
- package/dist/chunks/chunk-B7V6EOAC.js +2273 -0
- package/dist/chunks/chunk-CMQ5ZHLZ.js +25 -0
- package/dist/chunks/chunk-F7MKFVIG.js +43 -0
- package/dist/chunks/chunk-FZF6CLPX.js +232 -0
- package/dist/chunks/chunk-GPEJG34O.js +53 -0
- package/dist/chunks/chunk-HEC7XFFH.js +65 -0
- package/dist/chunks/chunk-IBC52BX3.js +24 -0
- package/dist/chunks/chunk-LNCOGBMI.js +144 -0
- package/dist/chunks/chunk-LOXBLQ3I.js +180 -0
- package/dist/chunks/chunk-NAWZ73QS.js +22 -0
- package/dist/chunks/chunk-OCV66TS2.js +705 -0
- package/dist/chunks/chunk-Q465X22Y.js +548 -0
- package/dist/chunks/chunk-QTB747K4.js +100 -0
- package/dist/chunks/chunk-QZNNCXXD.js +92 -0
- package/dist/chunks/chunk-R6AM4GJR.js +105 -0
- package/dist/chunks/chunk-TIJKJJDW.js +6 -0
- package/dist/chunks/chunk-VURTOVGI.js +61 -0
- package/dist/chunks/chunk-WAM6N4OF.js +269 -0
- package/dist/chunks/chunk-WW746NJF.js +94 -0
- package/dist/chunks/chunk-XC6CZP73.js +80 -0
- package/dist/chunks/chunk-ZGHQYZEH.js +45 -0
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.js +34 -0
- package/dist/cli/commands.d.ts +16 -0
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.js +25 -0
- package/dist/cli/mcp.d.ts +14 -0
- package/dist/clients/index.d.ts +2 -0
- package/dist/clients/index.js +107 -0
- package/dist/clients/plugin.d.ts +42 -0
- package/dist/combine/account.d.ts +4 -0
- package/dist/combine/adapter.d.ts +9 -0
- package/dist/combine/index.d.ts +2 -0
- package/dist/combine/index.js +345 -0
- package/dist/combine/route.d.ts +17 -0
- package/dist/exporter/index.d.ts +29 -0
- package/dist/exporter/index.js +77 -0
- package/dist/failover/index.d.ts +11 -0
- package/dist/failover/index.js +45 -0
- package/dist/fixtures/index.d.ts +27 -0
- package/dist/fixtures/index.js +241 -0
- package/dist/fixtures/scrub.d.ts +5 -0
- package/dist/heyreach/account.d.ts +11 -0
- package/dist/heyreach/adapter.d.ts +5 -0
- package/dist/heyreach/capabilities.d.ts +68 -0
- package/dist/heyreach/client.d.ts +20 -0
- package/dist/heyreach/inbox.d.ts +7 -0
- package/dist/heyreach/index.d.ts +18 -0
- package/dist/heyreach/index.js +1708 -0
- package/dist/heyreach/lookup.d.ts +15 -0
- package/dist/heyreach/map-account.d.ts +25 -0
- package/dist/heyreach/map-sequence.d.ts +5 -0
- package/dist/heyreach/map-stats.d.ts +10 -0
- package/dist/heyreach/map.d.ts +35 -0
- package/dist/heyreach/native-organization.d.ts +128 -0
- package/dist/heyreach/native-voice.d.ts +106 -0
- package/dist/heyreach/native.d.ts +496 -0
- package/dist/heyreach/paging.d.ts +7 -0
- package/dist/heyreach/webhooks.d.ts +2 -0
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.js +148 -0
- package/dist/identity/keys.d.ts +9 -0
- package/dist/identity/plugin.d.ts +34 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +119 -0
- package/dist/insights/copy/copy-audit.d.ts +55 -0
- package/dist/insights/copy/copy-checks.d.ts +44 -0
- package/dist/insights/copy/copy-reuse.d.ts +59 -0
- package/dist/insights/copy/index.d.ts +67 -0
- package/dist/insights/copy/reply-timing.d.ts +63 -0
- package/dist/insights/copy/shared.d.ts +53 -0
- package/dist/insights/copy/step-funnel.d.ts +66 -0
- package/dist/insights/copy/variant-test.d.ts +64 -0
- package/dist/insights/define.d.ts +98 -0
- package/dist/insights/index.d.ts +10 -0
- package/dist/insights/index.js +4873 -0
- package/dist/insights/ops/anomalies.d.ts +80 -0
- package/dist/insights/ops/campaign-diagnosis.d.ts +39 -0
- package/dist/insights/ops/campaign-ranking.d.ts +56 -0
- package/dist/insights/ops/channel-mix.d.ts +44 -0
- package/dist/insights/ops/client-report.d.ts +76 -0
- package/dist/insights/ops/diagnosis-checks.d.ts +48 -0
- package/dist/insights/ops/index.d.ts +135 -0
- package/dist/insights/ops/period-comparison.d.ts +86 -0
- package/dist/insights/ops/pipeline-forecast.d.ts +44 -0
- package/dist/insights/ops/shared.d.ts +149 -0
- package/dist/insights/ops/tag-rollup.d.ts +32 -0
- package/dist/insights/people/account-summary.d.ts +68 -0
- package/dist/insights/people/dropped-replies.d.ts +51 -0
- package/dist/insights/people/find.d.ts +18 -0
- package/dist/insights/people/hot-leads.d.ts +67 -0
- package/dist/insights/people/index.d.ts +88 -0
- package/dist/insights/people/lead-collisions.d.ts +43 -0
- package/dist/insights/people/person-summary.d.ts +46 -0
- package/dist/insights/people/personalization-gaps.d.ts +60 -0
- package/dist/insights/people/read.d.ts +40 -0
- package/dist/insights/people/suppression-check.d.ts +53 -0
- package/dist/insights/plugin.d.ts +40 -0
- package/dist/insights/registry.d.ts +335 -0
- package/dist/insights/senders/bounce-watch.d.ts +70 -0
- package/dist/insights/senders/domain-health.d.ts +69 -0
- package/dist/insights/senders/index.d.ts +74 -0
- package/dist/insights/senders/read.d.ts +37 -0
- package/dist/insights/senders/sender-capacity.d.ts +67 -0
- package/dist/insights/senders/sender-load.d.ts +52 -0
- package/dist/insights/senders/settings-audit.d.ts +48 -0
- package/dist/insights/senders/warmup-readiness.d.ts +39 -0
- package/dist/insights/stats.d.ts +45 -0
- package/dist/insights/tools.d.ts +16 -0
- package/dist/insights/types.d.ts +4 -0
- package/dist/instantly/adapter-account.d.ts +5 -0
- package/dist/instantly/adapter-mail.d.ts +3 -0
- package/dist/instantly/adapter.d.ts +7 -0
- package/dist/instantly/capabilities.d.ts +83 -0
- package/dist/instantly/client.d.ts +29 -0
- package/dist/instantly/index.d.ts +20 -0
- package/dist/instantly/index.js +2372 -0
- package/dist/instantly/map-account.d.ts +23 -0
- package/dist/instantly/map-lead.d.ts +18 -0
- package/dist/instantly/map-stats.d.ts +22 -0
- package/dist/instantly/map.d.ts +24 -0
- package/dist/instantly/native-agents-sales.d.ts +161 -0
- package/dist/instantly/native-agents.d.ts +156 -0
- package/dist/instantly/native-campaigns.d.ts +101 -0
- package/dist/instantly/native-leads.d.ts +93 -0
- package/dist/instantly/native-params.d.ts +24 -0
- package/dist/instantly/native-search.d.ts +82 -0
- package/dist/instantly/native-senders.d.ts +182 -0
- package/dist/instantly/native-supersearch.d.ts +149 -0
- package/dist/instantly/native-workspace.d.ts +170 -0
- package/dist/instantly/native.d.ts +1081 -0
- package/dist/instantly/pages.d.ts +29 -0
- package/dist/instantly/stats.d.ts +5 -0
- package/dist/instantly/webhooks.d.ts +2 -0
- package/dist/internal/adapter.d.ts +189 -0
- package/dist/internal/capabilities.d.ts +86 -0
- package/dist/internal/cursor.d.ts +10 -0
- package/dist/internal/engine/budget.d.ts +44 -0
- package/dist/internal/engine/engine.d.ts +45 -0
- package/dist/internal/engine/rate-store.d.ts +25 -0
- package/dist/internal/engine/request.d.ts +27 -0
- package/dist/internal/engine/retry.d.ts +21 -0
- package/dist/internal/engine/runtime.d.ts +13 -0
- package/dist/internal/entities-account.d.ts +135 -0
- package/dist/internal/entities.d.ts +389 -0
- package/dist/internal/env.d.ts +4 -0
- package/dist/internal/errors.d.ts +57 -0
- package/dist/internal/hooks.d.ts +55 -0
- package/dist/internal/json.d.ts +40 -0
- package/dist/internal/limits.d.ts +34 -0
- package/dist/internal/metrics.d.ts +52 -0
- package/dist/internal/native.d.ts +66 -0
- package/dist/internal/outbound/api.d.ts +267 -0
- package/dist/internal/outbound/collections.d.ts +31 -0
- package/dist/internal/outbound/core.d.ts +36 -0
- package/dist/internal/outbound/create.d.ts +16 -0
- package/dist/internal/outbound/handles.d.ts +7 -0
- package/dist/internal/outbound/native.d.ts +4 -0
- package/dist/internal/outbound/operation-shared.d.ts +28 -0
- package/dist/internal/outbound/operations-account.d.ts +29 -0
- package/dist/internal/outbound/operations.d.ts +42 -0
- package/dist/internal/outbound/outbound.d.ts +64 -0
- package/dist/internal/outbound/plugins.d.ts +40 -0
- package/dist/internal/outbound/raw.d.ts +9 -0
- package/dist/internal/outbound/specs-account.d.ts +16 -0
- package/dist/internal/outbound/specs.d.ts +14 -0
- package/dist/internal/outbound/stats.d.ts +7 -0
- package/dist/internal/outbound/validate.d.ts +5 -0
- package/dist/internal/outbound/walker.d.ts +22 -0
- package/dist/internal/record.d.ts +19 -0
- package/dist/internal/redact.d.ts +18 -0
- package/dist/internal/ref.d.ts +16 -0
- package/dist/internal/sha256.d.ts +4 -0
- package/dist/internal/text.d.ts +11 -0
- package/dist/internal/url.d.ts +9 -0
- package/dist/loader/index.d.ts +12 -0
- package/dist/loader/index.js +12 -0
- package/dist/memory/account-reads.d.ts +5 -0
- package/dist/memory/account.d.ts +67 -0
- package/dist/memory/adapter.d.ts +16 -0
- package/dist/memory/data.d.ts +122 -0
- package/dist/memory/demo.d.ts +7 -0
- package/dist/memory/index.d.ts +5 -0
- package/dist/memory/index.js +792 -0
- package/dist/memory/stats.d.ts +6 -0
- package/dist/memory/store.d.ts +18 -0
- package/dist/providers/index.d.ts +22 -0
- package/dist/providers/index.js +10 -0
- package/dist/reconcile/index.d.ts +2 -0
- package/dist/reconcile/index.js +72 -0
- package/dist/reconcile/plugin.d.ts +55 -0
- package/dist/redact/index.d.ts +2 -0
- package/dist/redact/index.js +192 -0
- package/dist/redact/plugin.d.ts +22 -0
- package/dist/redis/index.d.ts +41 -0
- package/dist/redis/index.js +114 -0
- package/dist/smartlead/account.d.ts +5 -0
- package/dist/smartlead/adapter.d.ts +5 -0
- package/dist/smartlead/capabilities.d.ts +85 -0
- package/dist/smartlead/client.d.ts +23 -0
- package/dist/smartlead/hmac.d.ts +9 -0
- package/dist/smartlead/index.d.ts +17 -0
- package/dist/smartlead/index.js +2170 -0
- package/dist/smartlead/leads.d.ts +6 -0
- package/dist/smartlead/lookup.d.ts +8 -0
- package/dist/smartlead/mail.d.ts +5 -0
- package/dist/smartlead/map-account.d.ts +22 -0
- package/dist/smartlead/map-messages.d.ts +31 -0
- package/dist/smartlead/map-stats.d.ts +37 -0
- package/dist/smartlead/map.d.ts +52 -0
- package/dist/smartlead/native-analytics.d.ts +242 -0
- package/dist/smartlead/native-campaigns.d.ts +211 -0
- package/dist/smartlead/native-inbox.d.ts +141 -0
- package/dist/smartlead/native-params.d.ts +33 -0
- package/dist/smartlead/native-services.d.ts +204 -0
- package/dist/smartlead/native.d.ts +785 -0
- package/dist/smartlead/shared.d.ts +28 -0
- package/dist/smartlead/stats.d.ts +5 -0
- package/dist/smartlead/webhooks.d.ts +2 -0
- package/dist/sync/index.d.ts +2 -0
- package/dist/sync/index.js +158 -0
- package/dist/sync/plugin.d.ts +58 -0
- package/dist/tools/account-tools.d.ts +21 -0
- package/dist/tools/ai-sdk.d.ts +8 -0
- package/dist/tools/ai-sdk.js +26 -0
- package/dist/tools/campaign-tools.d.ts +59 -0
- package/dist/tools/claude-agent.d.ts +18 -0
- package/dist/tools/claude-agent.js +40 -0
- package/dist/tools/index.d.ts +28 -0
- package/dist/tools/index.js +20 -0
- package/dist/tools/people-tools.d.ts +19 -0
- package/dist/tools/registry.d.ts +34 -0
- package/dist/tools/shared.d.ts +75 -0
- package/dist/tracing/index.d.ts +25 -0
- package/dist/tracing/index.js +69 -0
- package/dist/webhooks/index.d.ts +3 -0
- package/dist/webhooks/index.js +226 -0
- package/dist/webhooks/parse.d.ts +41 -0
- package/dist/webhooks/secret.d.ts +4 -0
- package/package.json +181 -4
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import {
|
|
2
|
+
intersectCapabilities,
|
|
3
|
+
resolveCapabilities
|
|
4
|
+
} from "../chunks/chunk-QTB747K4.js";
|
|
5
|
+
import {
|
|
6
|
+
recordBase
|
|
7
|
+
} from "../chunks/chunk-IBC52BX3.js";
|
|
8
|
+
import "../chunks/chunk-WAM6N4OF.js";
|
|
9
|
+
import {
|
|
10
|
+
parseRef
|
|
11
|
+
} from "../chunks/chunk-ZGHQYZEH.js";
|
|
12
|
+
import {
|
|
13
|
+
OutboundError,
|
|
14
|
+
makeErrorMapper
|
|
15
|
+
} from "../chunks/chunk-LOXBLQ3I.js";
|
|
16
|
+
import {
|
|
17
|
+
count,
|
|
18
|
+
field
|
|
19
|
+
} from "../chunks/chunk-QZNNCXXD.js";
|
|
20
|
+
|
|
21
|
+
// src/combine/route.ts
|
|
22
|
+
var COMBINED = "combined";
|
|
23
|
+
var routeRef = (members, ctx, id, what) => {
|
|
24
|
+
const parts = parseRef(id);
|
|
25
|
+
const member = parts === null ? void 0 : members.find(
|
|
26
|
+
(candidate) => candidate.name === parts.provider && candidate.workspaceId === parts.workspaceId
|
|
27
|
+
);
|
|
28
|
+
if (parts === null || member === void 0) {
|
|
29
|
+
throw new OutboundError(
|
|
30
|
+
"Invalid",
|
|
31
|
+
`${what} "${id}" must be a ref (provider:workspace:id) of an adapter on this combined instance`,
|
|
32
|
+
{ provider: COMBINED }
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return { ctx: ctx.forAdapter(member), id: parts.sourceId, member };
|
|
36
|
+
};
|
|
37
|
+
var position = (next) => ({
|
|
38
|
+
index: count(field(next, "member")) ?? 0,
|
|
39
|
+
next: field(next, "next") ?? void 0
|
|
40
|
+
});
|
|
41
|
+
var pageAcross = async (members, ctx, query, read) => {
|
|
42
|
+
const at = position(query.next);
|
|
43
|
+
const member = members[at.index];
|
|
44
|
+
if (member === void 0) {
|
|
45
|
+
return { items: [] };
|
|
46
|
+
}
|
|
47
|
+
const page = await read(member, ctx.forAdapter(member), at.next);
|
|
48
|
+
if (page.next !== void 0) {
|
|
49
|
+
return { items: page.items, next: { member: at.index, next: page.next } };
|
|
50
|
+
}
|
|
51
|
+
return at.index + 1 < members.length ? { items: page.items, next: { member: at.index + 1 } } : { items: page.items };
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/combine/account.ts
|
|
55
|
+
var missing = (member, method) => new OutboundError(
|
|
56
|
+
"Unsupported",
|
|
57
|
+
`The ${member.name} adapter does not implement ${method}`,
|
|
58
|
+
{ provider: member.name }
|
|
59
|
+
);
|
|
60
|
+
var need = (member, method) => {
|
|
61
|
+
const found = member[method];
|
|
62
|
+
if (found === void 0) {
|
|
63
|
+
throw missing(member, method);
|
|
64
|
+
}
|
|
65
|
+
return found;
|
|
66
|
+
};
|
|
67
|
+
var accountReads = (members) => ({
|
|
68
|
+
getCampaignSettings: (id, ctx) => {
|
|
69
|
+
const routed = routeRef(members, ctx, id, "Campaign");
|
|
70
|
+
return need(routed.member, "getCampaignSettings")(routed.id, routed.ctx);
|
|
71
|
+
},
|
|
72
|
+
getSenderHealth: (id, ctx) => {
|
|
73
|
+
const routed = routeRef(members, ctx, id, "Sender");
|
|
74
|
+
return need(routed.member, "getSenderHealth")(routed.id, routed.ctx);
|
|
75
|
+
},
|
|
76
|
+
listBlocklist: (query, ctx) => pageAcross(
|
|
77
|
+
members,
|
|
78
|
+
ctx,
|
|
79
|
+
query,
|
|
80
|
+
(member, memberCtx, next) => need(member, "listBlocklist")({ ...query, next }, memberCtx)
|
|
81
|
+
),
|
|
82
|
+
listLists: (query, ctx) => pageAcross(
|
|
83
|
+
members,
|
|
84
|
+
ctx,
|
|
85
|
+
query,
|
|
86
|
+
(member, memberCtx, next) => need(member, "listLists")({ ...query, next }, memberCtx)
|
|
87
|
+
),
|
|
88
|
+
listSubsequences: (query, ctx) => {
|
|
89
|
+
const routed = routeRef(members, ctx, query.campaignId, "Campaign");
|
|
90
|
+
return need(routed.member, "listSubsequences")(
|
|
91
|
+
{ ...query, campaignId: routed.id },
|
|
92
|
+
routed.ctx
|
|
93
|
+
);
|
|
94
|
+
},
|
|
95
|
+
listTags: (query, ctx) => pageAcross(
|
|
96
|
+
members,
|
|
97
|
+
ctx,
|
|
98
|
+
query,
|
|
99
|
+
(member, memberCtx, next) => need(member, "listTags")({ ...query, next }, memberCtx)
|
|
100
|
+
),
|
|
101
|
+
listWebhooks: (query, ctx) => {
|
|
102
|
+
if (query.campaignId === void 0) {
|
|
103
|
+
return pageAcross(
|
|
104
|
+
members,
|
|
105
|
+
ctx,
|
|
106
|
+
query,
|
|
107
|
+
(member, memberCtx, next) => need(member, "listWebhooks")({ ...query, next }, memberCtx)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
const routed = routeRef(members, ctx, query.campaignId, "Campaign");
|
|
111
|
+
return need(routed.member, "listWebhooks")(
|
|
112
|
+
{ ...query, campaignId: routed.id },
|
|
113
|
+
routed.ctx
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// src/combine/adapter.ts
|
|
119
|
+
var MATURITY_ORDER = ["unverified", "beta", "stable"];
|
|
120
|
+
var weakestMaturity = (members) => MATURITY_ORDER.find(
|
|
121
|
+
(level) => members.some((member) => member.maturity === level)
|
|
122
|
+
) ?? "stable";
|
|
123
|
+
var assertDistinct = (members) => {
|
|
124
|
+
if (members.length === 0) {
|
|
125
|
+
throw new OutboundError("Invalid", "combine() needs at least one adapter", {
|
|
126
|
+
provider: COMBINED
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const seen = /* @__PURE__ */ new Set();
|
|
130
|
+
for (const member of members) {
|
|
131
|
+
const key = `${member.name}:${member.workspaceId}`;
|
|
132
|
+
if (member.members !== void 0) {
|
|
133
|
+
throw new OutboundError(
|
|
134
|
+
"Invalid",
|
|
135
|
+
"combine() cannot nest another combined adapter",
|
|
136
|
+
{
|
|
137
|
+
provider: COMBINED
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (seen.has(key)) {
|
|
142
|
+
throw new OutboundError(
|
|
143
|
+
"Invalid",
|
|
144
|
+
`Two adapters are both ${key}. Give each one its own workspaceId so their records stay apart`,
|
|
145
|
+
{ provider: COMBINED }
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
seen.add(key);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var missing2 = (member, method) => new OutboundError(
|
|
152
|
+
"Unsupported",
|
|
153
|
+
`The ${member.name} adapter does not implement ${method}`,
|
|
154
|
+
{
|
|
155
|
+
provider: member.name
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
var scopedOrAcross = (members, ctx, query, read) => {
|
|
159
|
+
if (query.campaignId === void 0) {
|
|
160
|
+
return pageAcross(
|
|
161
|
+
members,
|
|
162
|
+
ctx,
|
|
163
|
+
query,
|
|
164
|
+
(member, memberCtx, next) => read(member, memberCtx, { ...query, next })
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
const routed = routeRef(members, ctx, query.campaignId, "Campaign");
|
|
168
|
+
return read(routed.member, routed.ctx, { ...query, campaignId: routed.id });
|
|
169
|
+
};
|
|
170
|
+
var lists = (members) => ({
|
|
171
|
+
listCampaigns: (query, ctx) => pageAcross(
|
|
172
|
+
members,
|
|
173
|
+
ctx,
|
|
174
|
+
query,
|
|
175
|
+
(member, memberCtx, next) => member.listCampaigns({ ...query, next }, memberCtx)
|
|
176
|
+
),
|
|
177
|
+
listLeads: (query, ctx) => {
|
|
178
|
+
if (query.listId !== void 0) {
|
|
179
|
+
const routed = routeRef(members, ctx, query.listId, "List");
|
|
180
|
+
if (routed.member.listLeads === void 0) {
|
|
181
|
+
throw missing2(routed.member, "listLeads");
|
|
182
|
+
}
|
|
183
|
+
return routed.member.listLeads(
|
|
184
|
+
{ ...query, listId: routed.id },
|
|
185
|
+
routed.ctx
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
return scopedOrAcross(members, ctx, query, (member, memberCtx, scoped) => {
|
|
189
|
+
if (member.listLeads === void 0) {
|
|
190
|
+
throw missing2(member, "listLeads");
|
|
191
|
+
}
|
|
192
|
+
return member.listLeads(scoped, memberCtx);
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
listMessages: (query, ctx) => {
|
|
196
|
+
const lead = query.leadId === void 0 ? void 0 : routeRef(members, ctx, query.leadId, "Lead");
|
|
197
|
+
return scopedOrAcross(
|
|
198
|
+
lead === void 0 ? members : [lead.member],
|
|
199
|
+
ctx,
|
|
200
|
+
query,
|
|
201
|
+
(member, memberCtx, scoped) => {
|
|
202
|
+
if (member.listMessages === void 0) {
|
|
203
|
+
throw missing2(member, "listMessages");
|
|
204
|
+
}
|
|
205
|
+
return member.listMessages({ ...scoped, leadId: lead?.id }, memberCtx);
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
},
|
|
209
|
+
listReplies: (query, ctx) => scopedOrAcross(members, ctx, query, (member, memberCtx, scoped) => {
|
|
210
|
+
if (member.listReplies === void 0) {
|
|
211
|
+
throw missing2(member, "listReplies");
|
|
212
|
+
}
|
|
213
|
+
return member.listReplies(scoped, memberCtx);
|
|
214
|
+
}),
|
|
215
|
+
listSenders: (query, ctx) => scopedOrAcross(members, ctx, query, (member, memberCtx, scoped) => {
|
|
216
|
+
if (member.listSenders === void 0) {
|
|
217
|
+
throw missing2(member, "listSenders");
|
|
218
|
+
}
|
|
219
|
+
return member.listSenders(scoped, memberCtx);
|
|
220
|
+
}),
|
|
221
|
+
// One workspace per member, named by its label. No request is made.
|
|
222
|
+
listWorkspaces: () => Promise.resolve({
|
|
223
|
+
items: members.map((member) => ({
|
|
224
|
+
...recordBase(
|
|
225
|
+
{ provider: member.name, workspaceId: member.workspaceId },
|
|
226
|
+
member.workspaceId,
|
|
227
|
+
null
|
|
228
|
+
),
|
|
229
|
+
name: member.workspaceId
|
|
230
|
+
}))
|
|
231
|
+
})
|
|
232
|
+
});
|
|
233
|
+
var lookups = (members) => ({
|
|
234
|
+
getCampaign: (id, ctx) => {
|
|
235
|
+
const routed = routeRef(members, ctx, id, "Campaign");
|
|
236
|
+
return routed.member.getCampaign(routed.id, routed.ctx);
|
|
237
|
+
},
|
|
238
|
+
getLead: (id, ctx) => {
|
|
239
|
+
const routed = routeRef(members, ctx, id, "Lead");
|
|
240
|
+
if (routed.member.getLead === void 0) {
|
|
241
|
+
throw missing2(routed.member, "getLead");
|
|
242
|
+
}
|
|
243
|
+
return routed.member.getLead(routed.id, routed.ctx);
|
|
244
|
+
},
|
|
245
|
+
getSender: (id, ctx) => {
|
|
246
|
+
const routed = routeRef(members, ctx, id, "Sender");
|
|
247
|
+
if (routed.member.getSender === void 0) {
|
|
248
|
+
throw missing2(routed.member, "getSender");
|
|
249
|
+
}
|
|
250
|
+
return routed.member.getSender(routed.id, routed.ctx);
|
|
251
|
+
},
|
|
252
|
+
getSequence: (id, ctx) => {
|
|
253
|
+
const routed = routeRef(members, ctx, id, "Campaign");
|
|
254
|
+
if (routed.member.getSequence === void 0) {
|
|
255
|
+
throw missing2(routed.member, "getSequence");
|
|
256
|
+
}
|
|
257
|
+
return routed.member.getSequence(routed.id, routed.ctx);
|
|
258
|
+
},
|
|
259
|
+
stats: async (query, ctx) => {
|
|
260
|
+
if (query.scopeId !== void 0) {
|
|
261
|
+
const routed = routeRef(members, ctx, query.scopeId, "Stats scope");
|
|
262
|
+
if (routed.member.stats === void 0) {
|
|
263
|
+
throw missing2(routed.member, "stats");
|
|
264
|
+
}
|
|
265
|
+
return await routed.member.stats(
|
|
266
|
+
{ ...query, scopeId: routed.id },
|
|
267
|
+
routed.ctx
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
const perMember = await Promise.all(
|
|
271
|
+
members.map((member) => {
|
|
272
|
+
if (member.stats === void 0) {
|
|
273
|
+
throw missing2(member, "stats");
|
|
274
|
+
}
|
|
275
|
+
return member.stats(query, ctx.forAdapter(member));
|
|
276
|
+
})
|
|
277
|
+
);
|
|
278
|
+
return perMember.flat();
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
var combine = (members) => {
|
|
282
|
+
assertDistinct(members);
|
|
283
|
+
const [first, ...rest] = members.map(
|
|
284
|
+
(member) => resolveCapabilities(member.capabilities)
|
|
285
|
+
);
|
|
286
|
+
return {
|
|
287
|
+
...lists(members),
|
|
288
|
+
...lookups(members),
|
|
289
|
+
...accountReads(members),
|
|
290
|
+
capabilities: {
|
|
291
|
+
...intersectCapabilities(first ?? resolveCapabilities(), ...rest),
|
|
292
|
+
// A thread id is the vendor's own and names no member, so it cannot be routed.
|
|
293
|
+
"messages.byThread": false,
|
|
294
|
+
// A native read belongs to one vendor; reach it through workspace(id).
|
|
295
|
+
native: false,
|
|
296
|
+
// A combined instance always knows its workspaces: they are its members.
|
|
297
|
+
workspaces: true
|
|
298
|
+
},
|
|
299
|
+
caveats: members.flatMap(
|
|
300
|
+
(member) => (member.caveats ?? []).map(
|
|
301
|
+
(caveat) => `${member.name} (${member.workspaceId}): ${caveat}`
|
|
302
|
+
)
|
|
303
|
+
),
|
|
304
|
+
events: {
|
|
305
|
+
detect: (request) => members.some((member) => member.events?.detect(request) ?? false),
|
|
306
|
+
// The member whose format matches parses it, under its own workspace.
|
|
307
|
+
parse: (request) => {
|
|
308
|
+
const owner = members.find(
|
|
309
|
+
(member) => member.events?.detect(request) ?? false
|
|
310
|
+
);
|
|
311
|
+
return owner?.events?.parse(request, owner.workspaceId) ?? [];
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
// The combined adapter never sends a request itself; each member has its own budget.
|
|
315
|
+
limits: {
|
|
316
|
+
source: "combined instance: see each member's limits",
|
|
317
|
+
windows: []
|
|
318
|
+
},
|
|
319
|
+
mapError: makeErrorMapper(COMBINED, {
|
|
320
|
+
secrets: members.flatMap((member) => member.secrets)
|
|
321
|
+
}),
|
|
322
|
+
maturity: weakestMaturity(members),
|
|
323
|
+
members,
|
|
324
|
+
name: COMBINED,
|
|
325
|
+
raw: {
|
|
326
|
+
authorize: (spec) => spec,
|
|
327
|
+
baseUrl: "combined://",
|
|
328
|
+
isRead: () => false
|
|
329
|
+
},
|
|
330
|
+
// One client on two tools carries one label on both members, so scoping
|
|
331
|
+
// to the label keeps both. A label on one member is that member itself.
|
|
332
|
+
scope: (workspaceId) => {
|
|
333
|
+
const labelled = members.filter(
|
|
334
|
+
(member) => member.workspaceId === workspaceId || `${member.name}:${member.workspaceId}` === workspaceId
|
|
335
|
+
);
|
|
336
|
+
return labelled.length > 1 ? combine(labelled) : labelled[0];
|
|
337
|
+
},
|
|
338
|
+
secrets: members.flatMap((member) => member.secrets),
|
|
339
|
+
workspaceId: COMBINED
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
export {
|
|
343
|
+
COMBINED,
|
|
344
|
+
combine
|
|
345
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
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>>;
|
|
@@ -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-LOXBLQ3I.js";
|
|
4
|
+
import {
|
|
5
|
+
isJsonObject,
|
|
6
|
+
toJson
|
|
7
|
+
} from "../chunks/chunk-QZNNCXXD.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-VURTOVGI.js";
|
|
4
|
+
import "../chunks/chunk-LNCOGBMI.js";
|
|
5
|
+
import {
|
|
6
|
+
OutboundError
|
|
7
|
+
} from "../chunks/chunk-LOXBLQ3I.js";
|
|
8
|
+
import "../chunks/chunk-QZNNCXXD.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;
|