fullstackgtm 0.43.0 → 0.45.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/CHANGELOG.md +378 -1
- package/README.md +37 -14
- package/dist/audit.d.ts +3 -1
- package/dist/audit.js +29 -2
- package/dist/cli/audit.d.ts +15 -0
- package/dist/cli/audit.js +392 -0
- package/dist/cli/auth.d.ts +80 -0
- package/dist/cli/auth.js +500 -0
- package/dist/cli/call.d.ts +1 -0
- package/dist/cli/call.js +373 -0
- package/dist/cli/capabilities.d.ts +30 -0
- package/dist/cli/capabilities.js +197 -0
- package/dist/cli/draft.d.ts +7 -0
- package/dist/cli/draft.js +87 -0
- package/dist/cli/enrich.d.ts +8 -0
- package/dist/cli/enrich.js +788 -0
- package/dist/cli/fix.d.ts +33 -0
- package/dist/cli/fix.js +344 -0
- package/dist/cli/help.d.ts +25 -0
- package/dist/cli/help.js +609 -0
- package/dist/cli/icp.d.ts +7 -0
- package/dist/cli/icp.js +229 -0
- package/dist/cli/init.d.ts +7 -0
- package/dist/cli/init.js +58 -0
- package/dist/cli/market.d.ts +1 -0
- package/dist/cli/market.js +391 -0
- package/dist/cli/plans.d.ts +5 -0
- package/dist/cli/plans.js +454 -0
- package/dist/cli/schedule.d.ts +8 -0
- package/dist/cli/schedule.js +479 -0
- package/dist/cli/shared.d.ts +70 -0
- package/dist/cli/shared.js +331 -0
- package/dist/cli/signals.d.ts +7 -0
- package/dist/cli/signals.js +412 -0
- package/dist/cli/suggest.d.ts +49 -0
- package/dist/cli/suggest.js +135 -0
- package/dist/cli/tam.d.ts +9 -0
- package/dist/cli/tam.js +387 -0
- package/dist/cli/ui.d.ts +121 -0
- package/dist/cli/ui.js +375 -0
- package/dist/cli.d.ts +1 -57
- package/dist/cli.js +104 -4556
- package/dist/connector.d.ts +15 -0
- package/dist/connector.js +35 -0
- package/dist/connectors/hubspot.d.ts +3 -1
- package/dist/connectors/hubspot.js +10 -3
- package/dist/connectors/outboxChannel.d.ts +64 -0
- package/dist/connectors/outboxChannel.js +170 -0
- package/dist/connectors/prospectSources.d.ts +22 -0
- package/dist/connectors/prospectSources.js +43 -0
- package/dist/connectors/salesforce.d.ts +3 -1
- package/dist/connectors/salesforce.js +12 -5
- package/dist/connectors/signalSources.d.ts +105 -0
- package/dist/connectors/signalSources.js +264 -0
- package/dist/connectors/theirstack.d.ts +84 -0
- package/dist/connectors/theirstack.js +125 -0
- package/dist/icp.d.ts +52 -4
- package/dist/icp.js +112 -35
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/init.js +3 -0
- package/dist/judge.d.ts +2 -0
- package/dist/judge.js +6 -0
- package/dist/judgeEval.d.ts +7 -0
- package/dist/judgeEval.js +8 -1
- package/dist/marketClassify.d.ts +2 -0
- package/dist/marketClassify.js +7 -1
- package/dist/mcp-bin.js +2 -2
- package/dist/mcp.js +259 -166
- package/dist/runReport.d.ts +26 -0
- package/dist/runReport.js +15 -0
- package/dist/schedule.d.ts +80 -2
- package/dist/schedule.js +272 -5
- package/dist/signals.d.ts +54 -0
- package/dist/signals.js +64 -0
- package/dist/spoolFiles.d.ts +44 -0
- package/dist/spoolFiles.js +114 -0
- package/dist/tam.d.ts +225 -0
- package/dist/tam.js +470 -0
- package/dist/types.d.ts +11 -0
- package/docs/api.md +91 -11
- package/docs/outbox-format.md +92 -0
- package/docs/recipes.md +37 -0
- package/docs/roadmap-to-1.0.md +31 -1
- package/docs/signal-spool-format.md +175 -0
- package/docs/tam.md +195 -0
- package/llms.txt +83 -11
- package/package.json +1 -1
- package/skills/fullstackgtm/SKILL.md +4 -3
- package/src/audit.ts +27 -1
- package/src/cli/audit.ts +447 -0
- package/src/cli/auth.ts +549 -0
- package/src/cli/call.ts +398 -0
- package/src/cli/capabilities.ts +215 -0
- package/src/cli/draft.ts +101 -0
- package/src/cli/enrich.ts +885 -0
- package/src/cli/fix.ts +372 -0
- package/src/cli/help.ts +664 -0
- package/src/cli/icp.ts +265 -0
- package/src/cli/init.ts +65 -0
- package/src/cli/market.ts +423 -0
- package/src/cli/plans.ts +523 -0
- package/src/cli/schedule.ts +526 -0
- package/src/cli/shared.ts +375 -0
- package/src/cli/signals.ts +434 -0
- package/src/cli/suggest.ts +151 -0
- package/src/cli/tam.ts +435 -0
- package/src/cli/ui.ts +426 -0
- package/src/cli.ts +103 -5170
- package/src/connector.ts +46 -0
- package/src/connectors/hubspot.ts +14 -2
- package/src/connectors/outboxChannel.ts +202 -0
- package/src/connectors/prospectSources.ts +57 -0
- package/src/connectors/salesforce.ts +18 -2
- package/src/connectors/signalSources.ts +314 -0
- package/src/connectors/theirstack.ts +170 -0
- package/src/icp.ts +120 -34
- package/src/index.ts +32 -0
- package/src/init.ts +3 -0
- package/src/judge.ts +7 -0
- package/src/judgeEval.ts +8 -1
- package/src/marketClassify.ts +8 -1
- package/src/mcp-bin.ts +2 -2
- package/src/mcp.ts +130 -57
- package/src/runReport.ts +39 -0
- package/src/schedule.ts +330 -7
- package/src/signals.ts +90 -0
- package/src/spoolFiles.ts +116 -0
- package/src/tam.ts +654 -0
- package/src/types.ts +12 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source connectors for the `signals` layer — the connection-based intake that
|
|
3
|
+
* generalizes the no-auth ATS adapters (`atsBoards.ts`) and the hand-staged
|
|
4
|
+
* `--from <file.json>` path into one contract: a platform connection in, a list
|
|
5
|
+
* of evidence-bearing staged signal rows out.
|
|
6
|
+
*
|
|
7
|
+
* Design (see docs/spec-connectors-signals-outbound.md):
|
|
8
|
+
* - Zero runtime deps: global `fetch` only, injectable for tests.
|
|
9
|
+
* - Read-only: a source never writes a CRM record and never emits a
|
|
10
|
+
* PatchOperation. `signals fetch` stays read-only re: the CRM.
|
|
11
|
+
* - Verbatim evidence: every row carries a non-empty `quote`; a row that
|
|
12
|
+
* cannot ground a why-now is dropped, never faked. The central
|
|
13
|
+
* `stagedRowToSignal` gate enforces this again.
|
|
14
|
+
* - Secrets via the credential ladder: API keys come from
|
|
15
|
+
* `ctx.getApiKey(provider)` (login store -> env -> broker), NEVER from argv.
|
|
16
|
+
* `ctx.options` carries non-secret knobs only (a file path, a query term).
|
|
17
|
+
* - Per-source resilience: a connector's own failure yields `[]` (logged by
|
|
18
|
+
* the caller), it must never sink a multi-source run — the per-provider
|
|
19
|
+
* try/catch idiom of atsBoards/prospectSources.
|
|
20
|
+
*/
|
|
21
|
+
import { readFileSync, statSync } from "node:fs";
|
|
22
|
+
import { resolve } from "node:path";
|
|
23
|
+
import { SIGNAL_BUCKETS } from "../signals.js";
|
|
24
|
+
import { parseSpoolText, spoolFilesIn } from "../spoolFiles.js";
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// file — local JSON / JSONL intake (also the webhook landing-zone reader)
|
|
27
|
+
/**
|
|
28
|
+
* Read staged rows from a local path — the webhook landing-zone reader. The path
|
|
29
|
+
* (from `options.path`/`options.file`) may be:
|
|
30
|
+
* - a single FILE: a JSON array, or newline-delimited JSON (one row per line);
|
|
31
|
+
* - a DIRECTORY (the conventional spool): every `*.jsonl` / `*.json` file in
|
|
32
|
+
* it is read and concatenated (sorted by name), so multiple receivers can
|
|
33
|
+
* each append their own file (`rb2b.jsonl`, `hubspot.jsonl`) and they all
|
|
34
|
+
* land in one fetch.
|
|
35
|
+
* No auth. This is how every push platform (RB2B, Trigify, HubSpot webhooks)
|
|
36
|
+
* reaches the CLI: a receiver appends a row to the spool, this reads it on the
|
|
37
|
+
* next `signals fetch`. The CLI defaults the path to the conventional spool dir
|
|
38
|
+
* (`signalsSpoolDir`) when `--connector file` is used with no path; a bare
|
|
39
|
+
* library call with no path is inactive (returns []).
|
|
40
|
+
*
|
|
41
|
+
* Resilient: a missing path / unreadable file yields [] (an empty source, not a
|
|
42
|
+
* crash), and one unreadable file in a spool directory is skipped. A file that
|
|
43
|
+
* IS present but malformed throws — a corrupt spool is a real error to surface,
|
|
44
|
+
* not silent data loss. The central `stagedRowToSignal` gate validates rows.
|
|
45
|
+
*/
|
|
46
|
+
export const fileSource = {
|
|
47
|
+
id: "file",
|
|
48
|
+
bucket: "company",
|
|
49
|
+
shape: "pull",
|
|
50
|
+
auth: "none",
|
|
51
|
+
async fetch(ctx) {
|
|
52
|
+
const path = ctx.options?.path ?? ctx.options?.file;
|
|
53
|
+
if (!path)
|
|
54
|
+
return []; // no spool configured (the CLI fills the default dir)
|
|
55
|
+
const abs = resolve(process.cwd(), path);
|
|
56
|
+
let isDir;
|
|
57
|
+
try {
|
|
58
|
+
isDir = statSync(abs).isDirectory();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return []; // missing path: an empty source, not a crash
|
|
62
|
+
}
|
|
63
|
+
// Container parsing lives in the shared spool reader (src/spoolFiles.ts) so
|
|
64
|
+
// `signals fetch --from`, `enrich ingest`, and `market observe --from` read
|
|
65
|
+
// the same convention; the "file source" label keeps error text unchanged.
|
|
66
|
+
const files = isDir ? spoolFilesIn(abs) : [abs];
|
|
67
|
+
const rows = [];
|
|
68
|
+
for (const file of files) {
|
|
69
|
+
let raw;
|
|
70
|
+
try {
|
|
71
|
+
raw = readFileSync(file, "utf8");
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
continue; // one unreadable file in a spool dir must not sink the rest
|
|
75
|
+
}
|
|
76
|
+
rows.push(...parseSpoolText(raw, file, "file source"));
|
|
77
|
+
}
|
|
78
|
+
return rows.map((row) => coerceRow(row, this.bucket));
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// serpapi-news — funding/company signals from a news REST query (API key)
|
|
83
|
+
const SERPAPI_BASE_URL = "https://serpapi.com";
|
|
84
|
+
/**
|
|
85
|
+
* Pull recent news per watchlist account and stage funding/company signals. One
|
|
86
|
+
* query per account (`q="<domain>"`, Google News engine); each result becomes a
|
|
87
|
+
* row whose verbatim `quote` is the headline (+ source), so the downstream judge
|
|
88
|
+
* can ground a why-now on a real, linkable article. API key via the credential
|
|
89
|
+
* ladder (provider "serpapi"); no key -> [] (the source is simply inactive).
|
|
90
|
+
*
|
|
91
|
+
* Bucket defaults to `funding`; override per run with `--connector-opt bucket=company`.
|
|
92
|
+
*/
|
|
93
|
+
export const serpapiNewsSource = {
|
|
94
|
+
id: "serpapi-news",
|
|
95
|
+
bucket: "funding",
|
|
96
|
+
shape: "pull",
|
|
97
|
+
auth: "api_key",
|
|
98
|
+
async fetch(ctx) {
|
|
99
|
+
const apiKey = ctx.getApiKey ? await ctx.getApiKey("serpapi") : null;
|
|
100
|
+
if (!apiKey)
|
|
101
|
+
return [];
|
|
102
|
+
const fetchImpl = ctx.fetchImpl ?? fetch;
|
|
103
|
+
const base = (ctx.options?.apiBaseUrl ?? SERPAPI_BASE_URL).replace(/\/$/, "");
|
|
104
|
+
const bucket = pickBucket(ctx.options?.bucket, this.bucket);
|
|
105
|
+
const out = [];
|
|
106
|
+
for (const account of ctx.watchlist) {
|
|
107
|
+
const domain = account.domain.trim();
|
|
108
|
+
if (!domain)
|
|
109
|
+
continue;
|
|
110
|
+
try {
|
|
111
|
+
const url = `${base}/search.json?engine=google_news&q=${encodeURIComponent(`"${domain}"`)}` +
|
|
112
|
+
`&api_key=${encodeURIComponent(apiKey)}`;
|
|
113
|
+
const response = await fetchImpl(url, { headers: { Accept: "application/json" } });
|
|
114
|
+
if (!response.ok)
|
|
115
|
+
continue;
|
|
116
|
+
const data = (await response.json());
|
|
117
|
+
for (const item of data.news_results ?? []) {
|
|
118
|
+
const title = typeof item.title === "string" ? item.title.trim() : "";
|
|
119
|
+
if (!title)
|
|
120
|
+
continue; // no headline -> no verbatim evidence -> drop
|
|
121
|
+
const sourceName = typeof item.source === "string" ? item.source : item.source?.name ?? "";
|
|
122
|
+
const quote = sourceName ? `${title} — ${sourceName}` : title;
|
|
123
|
+
out.push({
|
|
124
|
+
bucket,
|
|
125
|
+
accountDomain: domain,
|
|
126
|
+
trigger: `news: ${title}`,
|
|
127
|
+
quote,
|
|
128
|
+
sourceUrl: typeof item.link === "string" ? item.link : "",
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
continue; // one account's outage must not sink the run
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// hubspot-forms — first-party demand from recent HubSpot form submissions
|
|
141
|
+
const HUBSPOT_BASE_URL = "https://api.hubapi.com";
|
|
142
|
+
/**
|
|
143
|
+
* Stage `demand` signals from recent HubSpot form submissions — the first real
|
|
144
|
+
* `demand`-bucket producer (a form fill is first-party demand). Reuses the
|
|
145
|
+
* EXISTING HubSpot credential via the ladder (provider "hubspot"); no separate
|
|
146
|
+
* login. Each submission whose email carries a company domain becomes a row
|
|
147
|
+
* whose verbatim `quote` is the form name + submitted email (the evidence a rep
|
|
148
|
+
* can verify). Submissions without a corporate domain (free-mail) are dropped —
|
|
149
|
+
* no account to attach demand to.
|
|
150
|
+
*
|
|
151
|
+
* Phase 1 is a pull over the Forms submissions API; the form-submission webhook
|
|
152
|
+
* (push) lands in Phase 2 via the spool + `file` source.
|
|
153
|
+
*/
|
|
154
|
+
export const hubspotFormsSource = {
|
|
155
|
+
id: "hubspot-forms",
|
|
156
|
+
bucket: "demand",
|
|
157
|
+
shape: "pull",
|
|
158
|
+
auth: "oauth",
|
|
159
|
+
async fetch(ctx) {
|
|
160
|
+
const token = ctx.getApiKey ? await ctx.getApiKey("hubspot") : null;
|
|
161
|
+
if (!token)
|
|
162
|
+
return [];
|
|
163
|
+
const fetchImpl = ctx.fetchImpl ?? fetch;
|
|
164
|
+
const base = (ctx.options?.apiBaseUrl ?? HUBSPOT_BASE_URL).replace(/\/$/, "");
|
|
165
|
+
const out = [];
|
|
166
|
+
let forms = [];
|
|
167
|
+
try {
|
|
168
|
+
const response = await fetchImpl(`${base}/marketing/v3/forms`, {
|
|
169
|
+
headers: { Authorization: `Bearer ${token}`, Accept: "application/json" },
|
|
170
|
+
});
|
|
171
|
+
if (!response.ok)
|
|
172
|
+
return [];
|
|
173
|
+
const data = (await response.json());
|
|
174
|
+
forms = data.results ?? [];
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
for (const form of forms) {
|
|
180
|
+
const formId = form.guid ?? form.id;
|
|
181
|
+
if (!formId)
|
|
182
|
+
continue;
|
|
183
|
+
const formName = typeof form.name === "string" && form.name ? form.name : "form";
|
|
184
|
+
try {
|
|
185
|
+
const response = await fetchImpl(`${base}/form-integrations/v1/submissions/forms/${encodeURIComponent(formId)}?limit=50`, { headers: { Authorization: `Bearer ${token}`, Accept: "application/json" } });
|
|
186
|
+
if (!response.ok)
|
|
187
|
+
continue;
|
|
188
|
+
const data = (await response.json());
|
|
189
|
+
for (const submission of data.results ?? []) {
|
|
190
|
+
const email = fieldValue(submission.values, "email");
|
|
191
|
+
const domain = corporateDomain(email);
|
|
192
|
+
if (!domain)
|
|
193
|
+
continue; // free-mail / no email: no account to attach to
|
|
194
|
+
const submittedAt = typeof submission.submittedAt === "number"
|
|
195
|
+
? new Date(submission.submittedAt).toISOString()
|
|
196
|
+
: undefined;
|
|
197
|
+
out.push({
|
|
198
|
+
bucket: "demand",
|
|
199
|
+
accountDomain: domain,
|
|
200
|
+
trigger: `form: ${formName}`,
|
|
201
|
+
quote: `Submitted "${formName}" — ${email}`,
|
|
202
|
+
sourceUrl: "",
|
|
203
|
+
...(submittedAt ? { firstSeen: submittedAt } : {}),
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
// Registry
|
|
216
|
+
const CONNECTORS = [fileSource, serpapiNewsSource, hubspotFormsSource];
|
|
217
|
+
const REGISTRY = new Map(CONNECTORS.map((c) => [c.id, c]));
|
|
218
|
+
/** All registered source connectors (stable order). */
|
|
219
|
+
export function listSignalSources() {
|
|
220
|
+
return [...CONNECTORS];
|
|
221
|
+
}
|
|
222
|
+
/** Resolve a connector by id, or null when unknown. */
|
|
223
|
+
export function getSignalSource(id) {
|
|
224
|
+
return REGISTRY.get(id) ?? null;
|
|
225
|
+
}
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
// Helpers
|
|
228
|
+
function coerceRow(row, defaultBucket) {
|
|
229
|
+
// Fill the bucket from the connector default when a file row omits it; the
|
|
230
|
+
// central validator still rejects an unknown bucket and an empty quote.
|
|
231
|
+
const bucket = row.bucket === undefined ? defaultBucket : row.bucket;
|
|
232
|
+
return { ...row, bucket };
|
|
233
|
+
}
|
|
234
|
+
function pickBucket(raw, fallback) {
|
|
235
|
+
if (raw && SIGNAL_BUCKETS.includes(raw))
|
|
236
|
+
return raw;
|
|
237
|
+
return fallback;
|
|
238
|
+
}
|
|
239
|
+
function fieldValue(values, name) {
|
|
240
|
+
for (const field of values ?? []) {
|
|
241
|
+
if (field.name === name && typeof field.value === "string")
|
|
242
|
+
return field.value.trim();
|
|
243
|
+
}
|
|
244
|
+
return "";
|
|
245
|
+
}
|
|
246
|
+
const FREE_MAIL = new Set([
|
|
247
|
+
"gmail.com",
|
|
248
|
+
"yahoo.com",
|
|
249
|
+
"hotmail.com",
|
|
250
|
+
"outlook.com",
|
|
251
|
+
"icloud.com",
|
|
252
|
+
"aol.com",
|
|
253
|
+
"proton.me",
|
|
254
|
+
"protonmail.com",
|
|
255
|
+
]);
|
|
256
|
+
/** Company domain from an email, or "" for free-mail / no email. */
|
|
257
|
+
function corporateDomain(email) {
|
|
258
|
+
if (!email.includes("@"))
|
|
259
|
+
return "";
|
|
260
|
+
const domain = email.split("@").at(-1).trim().toLowerCase();
|
|
261
|
+
if (!domain || FREE_MAIL.has(domain))
|
|
262
|
+
return "";
|
|
263
|
+
return domain;
|
|
264
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TheirStack — technographic company discovery.
|
|
3
|
+
*
|
|
4
|
+
* Explorium can only size a firmographic universe (NAICS/size/geo) and can't even
|
|
5
|
+
* return the list. For a CRM-hygiene/RevOps tool the real buying signal is
|
|
6
|
+
* "company runs a CRM", and the deliverable is an actual list of those companies.
|
|
7
|
+
* TheirStack does both: filter companies by the technology they use (Salesforce,
|
|
8
|
+
* HubSpot, Pipedrive, …) plus firmographics, and return real records (name,
|
|
9
|
+
* domain, employee_count, …). A cheap count sizes the market; a paged search
|
|
10
|
+
* materializes the list. Both cost ~3 credits per company RETURNED — counting
|
|
11
|
+
* still returns 1 row (the API rejects limit:0), so a count is ~3 credits, not
|
|
12
|
+
* free; a list pull is ~3 × the rows.
|
|
13
|
+
*
|
|
14
|
+
* API: POST https://api.theirstack.com/v1/companies/search, Bearer auth.
|
|
15
|
+
* Verified live (2026-06-29): filters company_technology_slug_or /
|
|
16
|
+
* company_country_code_or / min_employee_count / max_employee_count; the total is
|
|
17
|
+
* `metadata.total_results` with include_total_results:true; limit must be ≥ 1
|
|
18
|
+
* (limit:0 → 422, the count gotcha — cf. Explorium's `size`-caps-the-total).
|
|
19
|
+
*/
|
|
20
|
+
type FetchImpl = typeof fetch;
|
|
21
|
+
/** TheirStack charges per company RETURNED — verified live (a list pull of N
|
|
22
|
+
* companies spends 3N). The count (limit:1) returns 1 row, so it's ~3 credits. */
|
|
23
|
+
export declare const THEIRSTACK_CREDITS_PER_COMPANY = 3;
|
|
24
|
+
export type TheirStackCost = {
|
|
25
|
+
companies: number;
|
|
26
|
+
credits: number;
|
|
27
|
+
/** USD estimate — present ONLY when a per-credit rate is supplied (no
|
|
28
|
+
* fabricated default; TheirStack pricing varies ~$0.04–$0.11/credit by tier). */
|
|
29
|
+
usd?: number;
|
|
30
|
+
};
|
|
31
|
+
/** Deterministic cost of pulling `companies` records (the credits are the hard
|
|
32
|
+
* fact; the dollar figure needs an explicit rate). */
|
|
33
|
+
export declare function theirStackPullCost(companies: number, usdPerCredit?: number): TheirStackCost;
|
|
34
|
+
/** Firmographic + technographic filter for TheirStack company search. */
|
|
35
|
+
export type TheirStackFilters = {
|
|
36
|
+
/** technology slugs, OR-matched — e.g. ["salesforce","hubspot","pipedrive"]. */
|
|
37
|
+
company_technology_slug_or?: string[];
|
|
38
|
+
min_employee_count?: number;
|
|
39
|
+
max_employee_count?: number;
|
|
40
|
+
/** ISO2 country codes, OR-matched — e.g. ["US"]. */
|
|
41
|
+
company_country_code_or?: string[];
|
|
42
|
+
};
|
|
43
|
+
/** A real company record from TheirStack (the materialized list element). */
|
|
44
|
+
export type TheirStackCompany = {
|
|
45
|
+
name?: string;
|
|
46
|
+
domain?: string;
|
|
47
|
+
employeeCount?: number;
|
|
48
|
+
countryCode?: string;
|
|
49
|
+
city?: string;
|
|
50
|
+
linkedinUrl?: string;
|
|
51
|
+
/** the matched technology slugs that put this company in the list. */
|
|
52
|
+
technologies?: string[];
|
|
53
|
+
};
|
|
54
|
+
/** Read the total-match count from the response envelope (field name varies). */
|
|
55
|
+
export declare function readTheirStackTotal(body: unknown): number | null;
|
|
56
|
+
/**
|
|
57
|
+
* Count companies matching the technographic + firmographic filter — the real
|
|
58
|
+
* TAM size. Uses `limit: 1` (the API rejects `limit: 0` with a 422 — verified
|
|
59
|
+
* live) + `include_total_results`, and reads `metadata.total_results`. Costs the
|
|
60
|
+
* 1 returned company's credits; the total itself is the point.
|
|
61
|
+
* Returns null if the envelope carries no total.
|
|
62
|
+
*/
|
|
63
|
+
export declare function theirStackCountCompanies(opts: {
|
|
64
|
+
apiKey: string;
|
|
65
|
+
filters: TheirStackFilters;
|
|
66
|
+
apiBaseUrl?: string;
|
|
67
|
+
fetchImpl?: FetchImpl;
|
|
68
|
+
}): Promise<number | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Pull a page of real companies matching the filter — the materialized list.
|
|
71
|
+
* Returns the records plus the total (when the envelope reports it).
|
|
72
|
+
*/
|
|
73
|
+
export declare function theirStackSearchCompanies(opts: {
|
|
74
|
+
apiKey: string;
|
|
75
|
+
filters: TheirStackFilters;
|
|
76
|
+
limit?: number;
|
|
77
|
+
page?: number;
|
|
78
|
+
apiBaseUrl?: string;
|
|
79
|
+
fetchImpl?: FetchImpl;
|
|
80
|
+
}): Promise<{
|
|
81
|
+
companies: TheirStackCompany[];
|
|
82
|
+
total: number | null;
|
|
83
|
+
}>;
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TheirStack — technographic company discovery.
|
|
3
|
+
*
|
|
4
|
+
* Explorium can only size a firmographic universe (NAICS/size/geo) and can't even
|
|
5
|
+
* return the list. For a CRM-hygiene/RevOps tool the real buying signal is
|
|
6
|
+
* "company runs a CRM", and the deliverable is an actual list of those companies.
|
|
7
|
+
* TheirStack does both: filter companies by the technology they use (Salesforce,
|
|
8
|
+
* HubSpot, Pipedrive, …) plus firmographics, and return real records (name,
|
|
9
|
+
* domain, employee_count, …). A cheap count sizes the market; a paged search
|
|
10
|
+
* materializes the list. Both cost ~3 credits per company RETURNED — counting
|
|
11
|
+
* still returns 1 row (the API rejects limit:0), so a count is ~3 credits, not
|
|
12
|
+
* free; a list pull is ~3 × the rows.
|
|
13
|
+
*
|
|
14
|
+
* API: POST https://api.theirstack.com/v1/companies/search, Bearer auth.
|
|
15
|
+
* Verified live (2026-06-29): filters company_technology_slug_or /
|
|
16
|
+
* company_country_code_or / min_employee_count / max_employee_count; the total is
|
|
17
|
+
* `metadata.total_results` with include_total_results:true; limit must be ≥ 1
|
|
18
|
+
* (limit:0 → 422, the count gotcha — cf. Explorium's `size`-caps-the-total).
|
|
19
|
+
*/
|
|
20
|
+
/** TheirStack charges per company RETURNED — verified live (a list pull of N
|
|
21
|
+
* companies spends 3N). The count (limit:1) returns 1 row, so it's ~3 credits. */
|
|
22
|
+
export const THEIRSTACK_CREDITS_PER_COMPANY = 3;
|
|
23
|
+
/** Deterministic cost of pulling `companies` records (the credits are the hard
|
|
24
|
+
* fact; the dollar figure needs an explicit rate). */
|
|
25
|
+
export function theirStackPullCost(companies, usdPerCredit) {
|
|
26
|
+
const n = Math.max(0, Math.round(companies));
|
|
27
|
+
const credits = n * THEIRSTACK_CREDITS_PER_COMPANY;
|
|
28
|
+
return {
|
|
29
|
+
companies: n,
|
|
30
|
+
credits,
|
|
31
|
+
...(usdPerCredit && usdPerCredit > 0 ? { usd: Math.round(credits * usdPerCredit) } : {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async function safeText(res) {
|
|
35
|
+
try {
|
|
36
|
+
return (await res.text()).slice(0, 300);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const BASE = "https://api.theirstack.com";
|
|
43
|
+
const SEARCH_PATH = "/v1/companies/search";
|
|
44
|
+
function buildBody(filters, limit, page, includeTotal) {
|
|
45
|
+
// Drop undefined keys so we never send empty filters the API rejects.
|
|
46
|
+
const body = { limit, page };
|
|
47
|
+
if (includeTotal)
|
|
48
|
+
body.include_total_results = true;
|
|
49
|
+
if (filters.company_technology_slug_or?.length)
|
|
50
|
+
body.company_technology_slug_or = filters.company_technology_slug_or;
|
|
51
|
+
if (filters.company_country_code_or?.length)
|
|
52
|
+
body.company_country_code_or = filters.company_country_code_or;
|
|
53
|
+
if (typeof filters.min_employee_count === "number")
|
|
54
|
+
body.min_employee_count = filters.min_employee_count;
|
|
55
|
+
if (typeof filters.max_employee_count === "number")
|
|
56
|
+
body.max_employee_count = filters.max_employee_count;
|
|
57
|
+
return JSON.stringify(body);
|
|
58
|
+
}
|
|
59
|
+
/** Read the total-match count from the response envelope (field name varies). */
|
|
60
|
+
export function readTheirStackTotal(body) {
|
|
61
|
+
if (!body || typeof body !== "object")
|
|
62
|
+
return null;
|
|
63
|
+
const obj = body;
|
|
64
|
+
const meta = (obj.metadata ?? obj.meta ?? obj);
|
|
65
|
+
for (const key of ["total_results", "total_companies", "total_count", "total", "count"]) {
|
|
66
|
+
const v = meta[key];
|
|
67
|
+
if (typeof v === "number" && Number.isFinite(v) && v >= 0)
|
|
68
|
+
return Math.round(v);
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function mapCompany(row) {
|
|
73
|
+
const str = (v) => (typeof v === "string" && v.trim() ? v : undefined);
|
|
74
|
+
const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
|
|
75
|
+
const slugs = row.technology_slugs ?? row.technology_names;
|
|
76
|
+
return {
|
|
77
|
+
name: str(row.name),
|
|
78
|
+
domain: str(row.domain),
|
|
79
|
+
employeeCount: num(row.employee_count),
|
|
80
|
+
countryCode: str(row.country_code),
|
|
81
|
+
city: str(row.city),
|
|
82
|
+
linkedinUrl: str(row.linkedin_url),
|
|
83
|
+
technologies: Array.isArray(slugs) ? slugs.filter((s) => typeof s === "string") : undefined,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Count companies matching the technographic + firmographic filter — the real
|
|
88
|
+
* TAM size. Uses `limit: 1` (the API rejects `limit: 0` with a 422 — verified
|
|
89
|
+
* live) + `include_total_results`, and reads `metadata.total_results`. Costs the
|
|
90
|
+
* 1 returned company's credits; the total itself is the point.
|
|
91
|
+
* Returns null if the envelope carries no total.
|
|
92
|
+
*/
|
|
93
|
+
export async function theirStackCountCompanies(opts) {
|
|
94
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
95
|
+
const base = (opts.apiBaseUrl ?? BASE).replace(/\/$/, "");
|
|
96
|
+
const res = await fetchImpl(`${base}${SEARCH_PATH}`, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
headers: { Authorization: `Bearer ${opts.apiKey}`, "Content-Type": "application/json" },
|
|
99
|
+
body: buildBody(opts.filters, 1, 0, true),
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
throw new Error(`TheirStack count failed: HTTP ${res.status} ${await safeText(res)}`);
|
|
103
|
+
}
|
|
104
|
+
return readTheirStackTotal(await res.json());
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Pull a page of real companies matching the filter — the materialized list.
|
|
108
|
+
* Returns the records plus the total (when the envelope reports it).
|
|
109
|
+
*/
|
|
110
|
+
export async function theirStackSearchCompanies(opts) {
|
|
111
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
112
|
+
const base = (opts.apiBaseUrl ?? BASE).replace(/\/$/, "");
|
|
113
|
+
const limit = Math.min(Math.max(opts.limit ?? 25, 1), 100);
|
|
114
|
+
const res = await fetchImpl(`${base}${SEARCH_PATH}`, {
|
|
115
|
+
method: "POST",
|
|
116
|
+
headers: { Authorization: `Bearer ${opts.apiKey}`, "Content-Type": "application/json" },
|
|
117
|
+
body: buildBody(opts.filters, limit, opts.page ?? 0, true),
|
|
118
|
+
});
|
|
119
|
+
if (!res.ok) {
|
|
120
|
+
throw new Error(`TheirStack search failed: HTTP ${res.status} ${await safeText(res)}`);
|
|
121
|
+
}
|
|
122
|
+
const body = (await res.json());
|
|
123
|
+
const rows = body.data ?? body.results ?? [];
|
|
124
|
+
return { companies: rows.map(mapCompany), total: readTheirStackTotal(body) };
|
|
125
|
+
}
|
package/dist/icp.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ export type Icp = {
|
|
|
23
23
|
employeeBands?: string[];
|
|
24
24
|
/** ISO country codes, lowercased, e.g. ["us"] */
|
|
25
25
|
geos?: string[];
|
|
26
|
+
/** technographic targeting: technology slugs the account must use, e.g.
|
|
27
|
+
* ["salesforce","hubspot","pipedrive"] — the real CRM/MAP buying signal,
|
|
28
|
+
* consumed by TheirStack company search. OR-matched. */
|
|
29
|
+
technologies?: string[];
|
|
26
30
|
};
|
|
27
31
|
persona: {
|
|
28
32
|
/** seniority: "cxo","vp","director","manager","owner","senior" */
|
|
@@ -47,13 +51,57 @@ export declare function icpToExploriumFilters(icp: Icp): Record<string, {
|
|
|
47
51
|
values?: string[];
|
|
48
52
|
value?: boolean;
|
|
49
53
|
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Explorium /v1/businesses filters from the ICP — the COMPANY (account) side, for
|
|
56
|
+
* sizing the account universe (TAM). Firmographics only, no persona: the count is
|
|
57
|
+
* of matching companies. Field names differ from /v1/prospects (verified live):
|
|
58
|
+
* `country_code` (not company_country_code), `company_size` (same employee bands),
|
|
59
|
+
* `naics_category`. `/v1/businesses` total_results is a real count, capped at
|
|
60
|
+
* 60,000 (see EXPLORIUM_BUSINESS_COUNT_CAP in the connector).
|
|
61
|
+
*/
|
|
62
|
+
export declare function icpToExploriumBusinessFilters(icp: Icp): Record<string, {
|
|
63
|
+
values?: string[];
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Collapse provider-agnostic employee bands ("51-200","10001+") into a single
|
|
67
|
+
* {min,max} envelope for APIs that take integer bounds (TheirStack). An open
|
|
68
|
+
* top band ("10001+") leaves max undefined.
|
|
69
|
+
*/
|
|
70
|
+
export declare function employeeBandsToRange(bands: string[] | undefined): {
|
|
71
|
+
min?: number;
|
|
72
|
+
max?: number;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* TheirStack company-search filter from the ICP: the technographic targeting that
|
|
76
|
+
* Explorium can't do. `company_technology_slug_or` is the CRM/MAP buying signal
|
|
77
|
+
* (firmographics.technologies); employee bands become min/max bounds; geos become
|
|
78
|
+
* ISO2 codes (uppercased).
|
|
79
|
+
*/
|
|
80
|
+
export declare function icpToTheirStackFilters(icp: Icp): {
|
|
81
|
+
company_technology_slug_or?: string[];
|
|
82
|
+
min_employee_count?: number;
|
|
83
|
+
max_employee_count?: number;
|
|
84
|
+
company_country_code_or?: string[];
|
|
85
|
+
};
|
|
50
86
|
/**
|
|
51
87
|
* pipe0 Crustdata people-search config.filters from the ICP. `current_job_titles`
|
|
52
88
|
* matches real LinkedIn title strings (case-sensitive), so keywords are Title
|
|
53
|
-
* Cased.
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
89
|
+
* Cased. Industry is mapped to Crustdata's controlled vocab via the table above.
|
|
90
|
+
*
|
|
91
|
+
* LIVE FINDINGS (2026-06-26, re-confirmed 2026-07-02 with fresh credits):
|
|
92
|
+
* `current_job_titles` works; `current_title` is rejected (422). The culprit
|
|
93
|
+
* that zeroed the full ICP filter is `current_seniority_levels`: ANY non-empty
|
|
94
|
+
* `include` returns 0 results through pipe0's people:profiles:crustdata@1 —
|
|
95
|
+
* including Crustdata's own documented values ("CXO", "Director",
|
|
96
|
+
* "Vice President"), lowercase, and SNAKE_CASE variants — while the identical
|
|
97
|
+
* search without it returns results. (An array instead of the
|
|
98
|
+
* {include, exclude} object is a 422, so the shape was right; the filter is
|
|
99
|
+
* broken upstream.) So job levels are NOT sent to the provider: persona
|
|
100
|
+
* seniority is enforced by fit scoring (scoreProspectAgainstIcp weights
|
|
101
|
+
* jobLevels), which was always the precision backstop. `locations` and
|
|
102
|
+
* `current_employers_linkedin_industries` (both-taxonomy hedge) are live-
|
|
103
|
+
* verified working in combination with titles. Note fit-scoring backs up
|
|
104
|
+
* PERSONA precision but NOT industry, so the industry filter is load-bearing.
|
|
57
105
|
*/
|
|
58
106
|
export declare function icpToCrustdataFilters(icp: Icp): Record<string, unknown>;
|
|
59
107
|
export type IcpFit = {
|