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,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OutboundError
|
|
3
|
+
} from "../chunks/chunk-LOXBLQ3I.js";
|
|
4
|
+
import "../chunks/chunk-QZNNCXXD.js";
|
|
5
|
+
|
|
6
|
+
// src/tracing/index.ts
|
|
7
|
+
var OK = 1;
|
|
8
|
+
var ERROR = 2;
|
|
9
|
+
var tracing = (options) => {
|
|
10
|
+
const { tracer } = options;
|
|
11
|
+
const now = options.now ?? (() => Date.now());
|
|
12
|
+
return {
|
|
13
|
+
hooks: {
|
|
14
|
+
// The request has already finished when the hook fires, so the span is
|
|
15
|
+
// created with the time it started.
|
|
16
|
+
onRequest: (event) => {
|
|
17
|
+
const span = tracer.startSpan(`outbound.http ${event.method}`, {
|
|
18
|
+
attributes: {
|
|
19
|
+
"http.request.method": event.method,
|
|
20
|
+
"outbound.attempt": event.attempt,
|
|
21
|
+
"outbound.lane": event.lane,
|
|
22
|
+
"outbound.provider": event.provider,
|
|
23
|
+
"url.full": event.url,
|
|
24
|
+
...event.status === null ? void 0 : { "http.response.status_code": event.status }
|
|
25
|
+
},
|
|
26
|
+
startTime: now() - event.durationMs
|
|
27
|
+
});
|
|
28
|
+
span.setStatus({
|
|
29
|
+
code: event.status !== null && event.status < 400 ? OK : ERROR
|
|
30
|
+
});
|
|
31
|
+
span.end();
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
name: "tracing",
|
|
35
|
+
wrap: async (operation, next, info) => {
|
|
36
|
+
const span = tracer.startSpan(`outbound.${operation.kind}`, {
|
|
37
|
+
attributes: {
|
|
38
|
+
"outbound.operation": operation.kind,
|
|
39
|
+
"outbound.provider": info.provider,
|
|
40
|
+
"outbound.workspace": info.workspaceId
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const before = info.state.requests;
|
|
44
|
+
try {
|
|
45
|
+
const output = await next(operation);
|
|
46
|
+
span.setAttribute("outbound.records", output.items.length);
|
|
47
|
+
span.setAttribute("outbound.evidence", output.evidence);
|
|
48
|
+
span.setStatus({ code: OK });
|
|
49
|
+
return output;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
span.setAttribute(
|
|
52
|
+
"outbound.error",
|
|
53
|
+
OutboundError.is(error) ? error.code : "Provider"
|
|
54
|
+
);
|
|
55
|
+
span.setStatus({
|
|
56
|
+
code: ERROR,
|
|
57
|
+
message: error instanceof Error ? error.message : String(error)
|
|
58
|
+
});
|
|
59
|
+
throw error;
|
|
60
|
+
} finally {
|
|
61
|
+
span.setAttribute("outbound.requests", info.state.requests - before);
|
|
62
|
+
span.end();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
tracing
|
|
69
|
+
};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import {
|
|
2
|
+
instantlyEvents
|
|
3
|
+
} from "../chunks/chunk-FZF6CLPX.js";
|
|
4
|
+
import {
|
|
5
|
+
smartleadEvents
|
|
6
|
+
} from "../chunks/chunk-Q465X22Y.js";
|
|
7
|
+
import {
|
|
8
|
+
heyreachEvents
|
|
9
|
+
} from "../chunks/chunk-R6AM4GJR.js";
|
|
10
|
+
import {
|
|
11
|
+
stableId
|
|
12
|
+
} from "../chunks/chunk-LNCOGBMI.js";
|
|
13
|
+
import "../chunks/chunk-IBC52BX3.js";
|
|
14
|
+
import {
|
|
15
|
+
SCHEMA_VERSION
|
|
16
|
+
} from "../chunks/chunk-WAM6N4OF.js";
|
|
17
|
+
import "../chunks/chunk-ZGHQYZEH.js";
|
|
18
|
+
import {
|
|
19
|
+
OutboundError
|
|
20
|
+
} from "../chunks/chunk-LOXBLQ3I.js";
|
|
21
|
+
import {
|
|
22
|
+
parseJson
|
|
23
|
+
} from "../chunks/chunk-QZNNCXXD.js";
|
|
24
|
+
|
|
25
|
+
// src/webhooks/secret.ts
|
|
26
|
+
var encoder = new TextEncoder();
|
|
27
|
+
var timingSafeEqual = (left, right) => {
|
|
28
|
+
const a = encoder.encode(left);
|
|
29
|
+
const b = encoder.encode(right);
|
|
30
|
+
let difference = Math.abs(a.length - b.length);
|
|
31
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
32
|
+
difference += Math.abs((a[index] ?? 0) - (b[index] ?? 0));
|
|
33
|
+
}
|
|
34
|
+
return difference === 0;
|
|
35
|
+
};
|
|
36
|
+
var QUERY_KEYS = ["secret", "token", "key"];
|
|
37
|
+
var HEADERS = ["x-webhook-secret", "x-outbound-secret"];
|
|
38
|
+
var isPresent = (value) => value !== void 0 && value !== null && value !== "";
|
|
39
|
+
var decoded = (segment) => {
|
|
40
|
+
try {
|
|
41
|
+
return decodeURIComponent(segment);
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var candidates = (url, headers) => {
|
|
47
|
+
const parsed = URL.canParse(url) ? new URL(url) : void 0;
|
|
48
|
+
const bearer = headers.get("authorization")?.replace(/^Bearer\s+/iu, "");
|
|
49
|
+
return [
|
|
50
|
+
...parsed?.pathname.split("/").map((segment) => decoded(segment)) ?? [],
|
|
51
|
+
...QUERY_KEYS.map((key) => parsed?.searchParams.get(key)),
|
|
52
|
+
...HEADERS.map((name) => headers.get(name)),
|
|
53
|
+
bearer
|
|
54
|
+
].filter((value) => isPresent(value));
|
|
55
|
+
};
|
|
56
|
+
var carriesSecret = (url, headers, secret) => {
|
|
57
|
+
let found = false;
|
|
58
|
+
for (const candidate of candidates(url, headers)) {
|
|
59
|
+
found = timingSafeEqual(candidate, secret) || found;
|
|
60
|
+
}
|
|
61
|
+
return found;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/webhooks/parse.ts
|
|
65
|
+
var FORMATS = /* @__PURE__ */ new Map([
|
|
66
|
+
["instantly", instantlyEvents("instantly")],
|
|
67
|
+
["smartlead", smartleadEvents("smartlead")],
|
|
68
|
+
["heyreach", heyreachEvents("heyreach")]
|
|
69
|
+
]);
|
|
70
|
+
var webhookProviders = () => [...FORMATS.keys()].toSorted();
|
|
71
|
+
var memoryDedupeStore = (maxIds = 1e4) => {
|
|
72
|
+
const seen = /* @__PURE__ */ new Set();
|
|
73
|
+
return {
|
|
74
|
+
claim: (id) => {
|
|
75
|
+
if (seen.has(id)) {
|
|
76
|
+
return Promise.resolve(false);
|
|
77
|
+
}
|
|
78
|
+
seen.add(id);
|
|
79
|
+
if (seen.size > maxIds) {
|
|
80
|
+
const [oldest] = seen;
|
|
81
|
+
if (oldest !== void 0) {
|
|
82
|
+
seen.delete(oldest);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return Promise.resolve(true);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
var read = async (request) => {
|
|
90
|
+
const rawBody = await request.text();
|
|
91
|
+
return {
|
|
92
|
+
body: parseJson(rawBody) ?? rawBody,
|
|
93
|
+
headers: request.headers,
|
|
94
|
+
rawBody,
|
|
95
|
+
url: request.url
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
var resolve = (webhook, provider) => {
|
|
99
|
+
if (provider !== "auto") {
|
|
100
|
+
const format = FORMATS.get(provider);
|
|
101
|
+
if (format === void 0) {
|
|
102
|
+
throw new OutboundError(
|
|
103
|
+
"Invalid",
|
|
104
|
+
`No webhook parser for "${provider}". Known providers: ${webhookProviders().join(", ")}`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return { format, provider };
|
|
108
|
+
}
|
|
109
|
+
const detected = [...FORMATS.entries()].find(
|
|
110
|
+
([, format]) => format.detect(webhook)
|
|
111
|
+
);
|
|
112
|
+
return detected === void 0 ? { format: void 0, provider: "unknown" } : { format: detected[1], provider: detected[0] };
|
|
113
|
+
};
|
|
114
|
+
var authenticate = (webhook, resolved, secret) => {
|
|
115
|
+
if (secret === void 0) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const signed = resolved.format?.verify;
|
|
119
|
+
const trusted = signed === void 0 ? carriesSecret(webhook.url, webhook.headers, secret) : signed(webhook, secret);
|
|
120
|
+
if (!trusted) {
|
|
121
|
+
throw new OutboundError(
|
|
122
|
+
"Unauthorized",
|
|
123
|
+
signed === void 0 ? "The webhook does not carry the shared secret" : "The webhook signature does not match",
|
|
124
|
+
{ provider: resolved.provider }
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
var unknownEvent = (webhook, workspaceId) => ({
|
|
129
|
+
campaignRef: null,
|
|
130
|
+
data: {},
|
|
131
|
+
id: stableId("unknown", webhook.rawBody),
|
|
132
|
+
leadRef: null,
|
|
133
|
+
messageRef: null,
|
|
134
|
+
occurredAt: null,
|
|
135
|
+
provider: "unknown",
|
|
136
|
+
raw: webhook.body,
|
|
137
|
+
schemaVersion: SCHEMA_VERSION,
|
|
138
|
+
senderRef: null,
|
|
139
|
+
type: "unknown",
|
|
140
|
+
workspaceId
|
|
141
|
+
});
|
|
142
|
+
var applyEventHooks = (plugins, event) => {
|
|
143
|
+
let current = event;
|
|
144
|
+
for (const plugin of plugins.toReversed()) {
|
|
145
|
+
if (current === null) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
current = plugin.event === void 0 ? current : plugin.event(current);
|
|
149
|
+
}
|
|
150
|
+
return current;
|
|
151
|
+
};
|
|
152
|
+
var verify = async (request, options) => {
|
|
153
|
+
const webhook = await read(request.clone());
|
|
154
|
+
try {
|
|
155
|
+
authenticate(
|
|
156
|
+
webhook,
|
|
157
|
+
resolve(webhook, options.provider ?? "auto"),
|
|
158
|
+
options.secret
|
|
159
|
+
);
|
|
160
|
+
return true;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (OutboundError.is(error) && error.code === "Unauthorized") {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var parse = async (request, options = {}) => {
|
|
169
|
+
const webhook = await read(request);
|
|
170
|
+
const workspaceId = options.workspaceId ?? "default";
|
|
171
|
+
const resolved = resolve(webhook, options.provider ?? "auto");
|
|
172
|
+
authenticate(webhook, resolved, options.secret);
|
|
173
|
+
const parsed = resolved.format?.parse(webhook, workspaceId) ?? [
|
|
174
|
+
unknownEvent(webhook, workspaceId)
|
|
175
|
+
];
|
|
176
|
+
const seen = /* @__PURE__ */ new Set();
|
|
177
|
+
const fresh = parsed.flatMap((event) => {
|
|
178
|
+
const rewritten = applyEventHooks(options.plugins ?? [], event);
|
|
179
|
+
if (rewritten === null || seen.has(rewritten.id)) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
seen.add(rewritten.id);
|
|
183
|
+
return [rewritten];
|
|
184
|
+
});
|
|
185
|
+
const { dedupe } = options;
|
|
186
|
+
if (dedupe === void 0) {
|
|
187
|
+
return fresh;
|
|
188
|
+
}
|
|
189
|
+
const claimed = await Promise.all(
|
|
190
|
+
fresh.map((event) => dedupe.claim(event.id))
|
|
191
|
+
);
|
|
192
|
+
return fresh.filter((_event, index) => claimed[index] === true);
|
|
193
|
+
};
|
|
194
|
+
var setupInstructions = (provider) => {
|
|
195
|
+
const instructions = /* @__PURE__ */ new Map([
|
|
196
|
+
[
|
|
197
|
+
"smartlead",
|
|
198
|
+
"Smartlead: Settings > Webhooks > Add webhook, per account, client or campaign (only one fires per event; the account-level one wins). Turn on signing for the webhook and pass its whsec_ secret as `secret`: the SDK then checks the Standard Webhooks signature and rejects anything older than five minutes. An unsigned Smartlead webhook fails verification."
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
"heyreach",
|
|
202
|
+
"HeyReach: Integrations > Webhooks > Create webhook, one per event type. HeyReach does not sign payloads, so put a secret in the URL (https://your.app/hooks/<secret>) or add it as a custom header named x-webhook-secret, and pass the same value as `secret`."
|
|
203
|
+
],
|
|
204
|
+
[
|
|
205
|
+
"instantly",
|
|
206
|
+
"Instantly: Settings > Integrations > Webhooks > Add webhook (Hyper Growth plan or above). Instantly does not sign payloads, so put a secret in the URL (https://your.app/hooks/<secret>) or add it as a custom header named x-webhook-secret, and pass the same value as `secret`."
|
|
207
|
+
]
|
|
208
|
+
]);
|
|
209
|
+
const found = instructions.get(provider);
|
|
210
|
+
if (found === void 0) {
|
|
211
|
+
throw new OutboundError(
|
|
212
|
+
"Invalid",
|
|
213
|
+
`No webhook setup instructions for "${provider}"`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
return found;
|
|
217
|
+
};
|
|
218
|
+
export {
|
|
219
|
+
carriesSecret,
|
|
220
|
+
memoryDedupeStore,
|
|
221
|
+
parse,
|
|
222
|
+
setupInstructions,
|
|
223
|
+
timingSafeEqual,
|
|
224
|
+
verify,
|
|
225
|
+
webhookProviders
|
|
226
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { OutboundEvent } from "../internal/entities.ts";
|
|
2
|
+
import type { OutboundPlugin } from "../internal/outbound/plugins.ts";
|
|
3
|
+
/** The providers whose webhooks can be parsed. */
|
|
4
|
+
export declare const webhookProviders: () => string[];
|
|
5
|
+
/** Remembers which events were already handled. Supply your own for more than one process. */
|
|
6
|
+
export interface DedupeStore {
|
|
7
|
+
/** Records the id and returns `true` when it had not been seen before. */
|
|
8
|
+
readonly claim: (id: string) => Promise<boolean>;
|
|
9
|
+
}
|
|
10
|
+
/** An in-memory dedupe store that forgets its oldest ids once it is full. */
|
|
11
|
+
export declare const memoryDedupeStore: (maxIds?: number) => DedupeStore;
|
|
12
|
+
export interface ParseOptions {
|
|
13
|
+
/** A provider id, or `auto` to detect it from the payload. Name it in production. */
|
|
14
|
+
readonly provider?: string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The vendor's signing secret when it signs payloads; otherwise a shared
|
|
17
|
+
* secret you put in the webhook URL (a path segment or `?secret=`) or in an
|
|
18
|
+
* `x-webhook-secret` or `Authorization: Bearer` header. When given, a
|
|
19
|
+
* request that fails the check is rejected with `Unauthorized`.
|
|
20
|
+
*/
|
|
21
|
+
readonly secret?: string | undefined;
|
|
22
|
+
/** The label of the workspace the webhook belongs to. Defaults to `default`. */
|
|
23
|
+
readonly workspaceId?: string | undefined;
|
|
24
|
+
/** Drops events already handled. Without it, only repeats inside one payload are dropped. */
|
|
25
|
+
readonly dedupe?: DedupeStore | undefined;
|
|
26
|
+
/** Plugins whose `event` hooks should run, in the same order as on the instance. */
|
|
27
|
+
readonly plugins?: readonly OutboundPlugin[] | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** `true` when the request is authentic for the provider and secret. Never throws for a bad signature. */
|
|
30
|
+
export declare const verify: (request: Request, options: {
|
|
31
|
+
readonly provider?: string | undefined;
|
|
32
|
+
readonly secret: string;
|
|
33
|
+
}) => Promise<boolean>;
|
|
34
|
+
/**
|
|
35
|
+
* Parses a webhook into events. Unknown events are returned with
|
|
36
|
+
* `type: "unknown"` and never dropped; redelivered events are dropped when a
|
|
37
|
+
* dedupe store is given.
|
|
38
|
+
*/
|
|
39
|
+
export declare const parse: (request: Request, options?: ParseOptions) => Promise<OutboundEvent[]>;
|
|
40
|
+
/** How to point a vendor's webhooks at your endpoint. The SDK is read-only and never registers one. */
|
|
41
|
+
export declare const setupInstructions: (provider: string) => string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** A comparison that takes the same time whether or not the strings match. */
|
|
2
|
+
export declare const timingSafeEqual: (left: string, right: string) => boolean;
|
|
3
|
+
/** `true` when the request carries the shared secret. */
|
|
4
|
+
export declare const carriesSecret: (url: string, headers: Headers, secret: string) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,183 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "outbound-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "One small, typed, read-only API over outbound sending tools.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cold-email",
|
|
7
|
+
"heyreach",
|
|
8
|
+
"instantly",
|
|
9
|
+
"linkedin",
|
|
10
|
+
"outbound",
|
|
11
|
+
"sdk",
|
|
12
|
+
"smartlead"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/orchidautomation/outbound-sdk#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/orchidautomation/outbound-sdk/issues"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/orchidautomation/outbound-sdk.git",
|
|
22
|
+
"directory": "packages/outbound-sdk"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"outbound": "./dist/cli/bin.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./memory": {
|
|
38
|
+
"types": "./dist/memory/index.d.ts",
|
|
39
|
+
"import": "./dist/memory/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./instantly": {
|
|
42
|
+
"types": "./dist/instantly/index.d.ts",
|
|
43
|
+
"import": "./dist/instantly/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./smartlead": {
|
|
46
|
+
"types": "./dist/smartlead/index.d.ts",
|
|
47
|
+
"import": "./dist/smartlead/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./heyreach": {
|
|
50
|
+
"types": "./dist/heyreach/index.d.ts",
|
|
51
|
+
"import": "./dist/heyreach/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./providers": {
|
|
54
|
+
"types": "./dist/providers/index.d.ts",
|
|
55
|
+
"import": "./dist/providers/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./loader": {
|
|
58
|
+
"types": "./dist/loader/index.d.ts",
|
|
59
|
+
"import": "./dist/loader/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./combine": {
|
|
62
|
+
"types": "./dist/combine/index.d.ts",
|
|
63
|
+
"import": "./dist/combine/index.js"
|
|
64
|
+
},
|
|
65
|
+
"./clients": {
|
|
66
|
+
"types": "./dist/clients/index.d.ts",
|
|
67
|
+
"import": "./dist/clients/index.js"
|
|
68
|
+
},
|
|
69
|
+
"./identity": {
|
|
70
|
+
"types": "./dist/identity/index.d.ts",
|
|
71
|
+
"import": "./dist/identity/index.js"
|
|
72
|
+
},
|
|
73
|
+
"./redact": {
|
|
74
|
+
"types": "./dist/redact/index.d.ts",
|
|
75
|
+
"import": "./dist/redact/index.js"
|
|
76
|
+
},
|
|
77
|
+
"./cache": {
|
|
78
|
+
"types": "./dist/cache/index.d.ts",
|
|
79
|
+
"import": "./dist/cache/index.js"
|
|
80
|
+
},
|
|
81
|
+
"./budget": {
|
|
82
|
+
"types": "./dist/budget/index.d.ts",
|
|
83
|
+
"import": "./dist/budget/index.js"
|
|
84
|
+
},
|
|
85
|
+
"./audit": {
|
|
86
|
+
"types": "./dist/audit/index.d.ts",
|
|
87
|
+
"import": "./dist/audit/index.js"
|
|
88
|
+
},
|
|
89
|
+
"./tracing": {
|
|
90
|
+
"types": "./dist/tracing/index.d.ts",
|
|
91
|
+
"import": "./dist/tracing/index.js"
|
|
92
|
+
},
|
|
93
|
+
"./webhooks": {
|
|
94
|
+
"types": "./dist/webhooks/index.d.ts",
|
|
95
|
+
"import": "./dist/webhooks/index.js"
|
|
96
|
+
},
|
|
97
|
+
"./tools": {
|
|
98
|
+
"types": "./dist/tools/index.d.ts",
|
|
99
|
+
"import": "./dist/tools/index.js"
|
|
100
|
+
},
|
|
101
|
+
"./tools/ai-sdk": {
|
|
102
|
+
"types": "./dist/tools/ai-sdk.d.ts",
|
|
103
|
+
"import": "./dist/tools/ai-sdk.js"
|
|
104
|
+
},
|
|
105
|
+
"./tools/claude-agent": {
|
|
106
|
+
"types": "./dist/tools/claude-agent.d.ts",
|
|
107
|
+
"import": "./dist/tools/claude-agent.js"
|
|
108
|
+
},
|
|
109
|
+
"./cli": {
|
|
110
|
+
"types": "./dist/cli/index.d.ts",
|
|
111
|
+
"import": "./dist/cli/index.js"
|
|
112
|
+
},
|
|
113
|
+
"./sync": {
|
|
114
|
+
"types": "./dist/sync/index.d.ts",
|
|
115
|
+
"import": "./dist/sync/index.js"
|
|
116
|
+
},
|
|
117
|
+
"./reconcile": {
|
|
118
|
+
"types": "./dist/reconcile/index.d.ts",
|
|
119
|
+
"import": "./dist/reconcile/index.js"
|
|
120
|
+
},
|
|
121
|
+
"./cards": {
|
|
122
|
+
"types": "./dist/cards/index.d.ts",
|
|
123
|
+
"import": "./dist/cards/index.js"
|
|
124
|
+
},
|
|
125
|
+
"./alerts": {
|
|
126
|
+
"types": "./dist/alerts/index.d.ts",
|
|
127
|
+
"import": "./dist/alerts/index.js"
|
|
128
|
+
},
|
|
129
|
+
"./benchmarks": {
|
|
130
|
+
"types": "./dist/benchmarks/index.d.ts",
|
|
131
|
+
"import": "./dist/benchmarks/index.js"
|
|
132
|
+
},
|
|
133
|
+
"./fixtures": {
|
|
134
|
+
"types": "./dist/fixtures/index.d.ts",
|
|
135
|
+
"import": "./dist/fixtures/index.js"
|
|
136
|
+
},
|
|
137
|
+
"./exporter": {
|
|
138
|
+
"types": "./dist/exporter/index.d.ts",
|
|
139
|
+
"import": "./dist/exporter/index.js"
|
|
140
|
+
},
|
|
141
|
+
"./failover": {
|
|
142
|
+
"types": "./dist/failover/index.d.ts",
|
|
143
|
+
"import": "./dist/failover/index.js"
|
|
144
|
+
},
|
|
145
|
+
"./insights": {
|
|
146
|
+
"types": "./dist/insights/index.d.ts",
|
|
147
|
+
"import": "./dist/insights/index.js"
|
|
148
|
+
},
|
|
149
|
+
"./redis": {
|
|
150
|
+
"types": "./dist/redis/index.d.ts",
|
|
151
|
+
"import": "./dist/redis/index.js"
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"publishConfig": {
|
|
155
|
+
"access": "public",
|
|
156
|
+
"provenance": true
|
|
157
|
+
},
|
|
158
|
+
"scripts": {
|
|
159
|
+
"build": "node ../../scripts/build.mjs"
|
|
160
|
+
},
|
|
161
|
+
"dependencies": {
|
|
162
|
+
"zod": "^4.6.7"
|
|
163
|
+
},
|
|
164
|
+
"devDependencies": {
|
|
165
|
+
"@anthropic-ai/claude-agent-sdk": "0.3.325",
|
|
166
|
+
"ai": "7.0.173"
|
|
167
|
+
},
|
|
168
|
+
"peerDependencies": {
|
|
169
|
+
"@anthropic-ai/claude-agent-sdk": ">=0.3.0 <1.0.0",
|
|
170
|
+
"ai": "^6.0.0 || ^7.0.0"
|
|
171
|
+
},
|
|
172
|
+
"peerDependenciesMeta": {
|
|
173
|
+
"@anthropic-ai/claude-agent-sdk": {
|
|
174
|
+
"optional": true
|
|
175
|
+
},
|
|
176
|
+
"ai": {
|
|
177
|
+
"optional": true
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
"engines": {
|
|
181
|
+
"node": ">=22"
|
|
182
|
+
}
|
|
183
|
+
}
|