@dench.com/cli 0.4.9 → 2.0.1
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/README.md +1 -1
- package/crm.ts +60 -26
- package/dench.ts +870 -229
- package/host.ts +3 -3
- package/image.ts +49 -40
- package/lib/enrichment-gateway.ts +30 -13
- package/package.json +2 -2
- package/search.ts +56 -48
- package/tools.ts +59 -34
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ dench login --name "AI Agent - Billing Repo"
|
|
|
23
23
|
to lowercase snake_case before send (e.g. `--kind "Claude Code"` becomes
|
|
24
24
|
`claude_code`).
|
|
25
25
|
|
|
26
|
-
The default backend is `https://dench.
|
|
26
|
+
The default backend is `https://dench.com` (production). Use `dench backend`
|
|
27
27
|
to switch:
|
|
28
28
|
|
|
29
29
|
```bash
|
package/crm.ts
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* crm docs list / create / link
|
|
27
27
|
* crm actions list / run / runs
|
|
28
28
|
*/
|
|
29
|
-
import { ConvexHttpClient } from "convex/browser";
|
|
29
|
+
import type { ConvexHttpClient } from "convex/browser";
|
|
30
30
|
import { makeFunctionReference } from "convex/server";
|
|
31
31
|
import {
|
|
32
32
|
assertNoUnknownFlags as assertNoUnknownFlagsRaw,
|
|
@@ -40,18 +40,19 @@ import {
|
|
|
40
40
|
import {
|
|
41
41
|
autoDetectInputField,
|
|
42
42
|
detectEnrichmentCategory,
|
|
43
|
-
extractEnrichmentValue,
|
|
44
|
-
findEnrichmentColumn,
|
|
45
|
-
getRequiredFieldsForApolloPath,
|
|
46
43
|
type EnrichmentCategory,
|
|
47
44
|
type EnrichmentColumnDef,
|
|
45
|
+
extractEnrichmentValue,
|
|
48
46
|
type FieldCandidate,
|
|
47
|
+
findEnrichmentColumn,
|
|
48
|
+
getRequiredFieldsForApolloPath,
|
|
49
49
|
} from "./lib/crm-enrichment";
|
|
50
50
|
import {
|
|
51
51
|
aviatoEnrichCompany,
|
|
52
52
|
aviatoEnrichPerson,
|
|
53
|
-
enrichCompany,
|
|
54
53
|
EnrichmentGatewayError,
|
|
54
|
+
type EnrichmentGatewayOptions,
|
|
55
|
+
enrichCompany,
|
|
55
56
|
enrichPersonByIdentifier,
|
|
56
57
|
} from "./lib/enrichment-gateway";
|
|
57
58
|
|
|
@@ -82,6 +83,7 @@ type CrmCliContext = {
|
|
|
82
83
|
* organization context.
|
|
83
84
|
*/
|
|
84
85
|
sessionToken?: string;
|
|
86
|
+
enrichmentGateway?: Pick<EnrichmentGatewayOptions, "apiKey" | "baseUrl">;
|
|
85
87
|
};
|
|
86
88
|
|
|
87
89
|
// Adapt the shared helpers to throw CrmCliError so existing call sites
|
|
@@ -310,12 +312,14 @@ function out(ctx: CrmCliContext, value: unknown): void {
|
|
|
310
312
|
console.log(JSON.stringify(value, null, 2));
|
|
311
313
|
}
|
|
312
314
|
|
|
313
|
-
function getFieldEnrichmentFlag(args: string[]):
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
315
|
+
function getFieldEnrichmentFlag(args: string[]):
|
|
316
|
+
| {
|
|
317
|
+
category: EnrichmentCategory;
|
|
318
|
+
key: string;
|
|
319
|
+
apolloPath: string;
|
|
320
|
+
inputFieldName: string;
|
|
321
|
+
}
|
|
322
|
+
| undefined {
|
|
319
323
|
const category = parseCategoryFlag(getFlag(args, "--enrichment-category"));
|
|
320
324
|
const key = getFlag(args, "--enrichment-key");
|
|
321
325
|
const apolloPath = getFlag(args, "--apollo-path");
|
|
@@ -431,6 +435,7 @@ export async function runCrmCommand(opts: {
|
|
|
431
435
|
convex: ConvexHttpClient;
|
|
432
436
|
args: string[];
|
|
433
437
|
sessionToken?: string;
|
|
438
|
+
enrichmentGateway?: Pick<EnrichmentGatewayOptions, "apiKey" | "baseUrl">;
|
|
434
439
|
}): Promise<void> {
|
|
435
440
|
const args = [...opts.args];
|
|
436
441
|
const jsonOutput = hasFlag(args, "--json");
|
|
@@ -439,6 +444,7 @@ export async function runCrmCommand(opts: {
|
|
|
439
444
|
args,
|
|
440
445
|
jsonOutput,
|
|
441
446
|
sessionToken: opts.sessionToken,
|
|
447
|
+
enrichmentGateway: opts.enrichmentGateway,
|
|
442
448
|
};
|
|
443
449
|
const subcommand = args.shift();
|
|
444
450
|
if (!subcommand || subcommand === "help" || subcommand === "--help") {
|
|
@@ -1531,13 +1537,18 @@ type ObjectEnrichmentArgs = Omit<CellEnrichmentArgs, "entryId"> & {
|
|
|
1531
1537
|
limit?: number;
|
|
1532
1538
|
};
|
|
1533
1539
|
|
|
1534
|
-
function parseCategoryFlag(
|
|
1540
|
+
function parseCategoryFlag(
|
|
1541
|
+
value: string | undefined,
|
|
1542
|
+
): EnrichmentCategory | undefined {
|
|
1535
1543
|
if (value === undefined) return undefined;
|
|
1536
1544
|
if (value === "people" || value === "company") return value;
|
|
1537
1545
|
throw new CrmCliError("--category must be people or company");
|
|
1538
1546
|
}
|
|
1539
1547
|
|
|
1540
|
-
function parsePositiveInt(
|
|
1548
|
+
function parsePositiveInt(
|
|
1549
|
+
flag: string,
|
|
1550
|
+
value: string | undefined,
|
|
1551
|
+
): number | undefined {
|
|
1541
1552
|
if (value === undefined) return undefined;
|
|
1542
1553
|
const parsed = Number(value);
|
|
1543
1554
|
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
@@ -1556,7 +1567,9 @@ function asFields(value: unknown): CrmFieldForEnrichment[] {
|
|
|
1556
1567
|
.filter((field): field is CrmFieldForEnrichment => {
|
|
1557
1568
|
if (!field || typeof field !== "object") return false;
|
|
1558
1569
|
const candidate = field as Record<string, unknown>;
|
|
1559
|
-
return
|
|
1570
|
+
return (
|
|
1571
|
+
typeof candidate.name === "string" && typeof candidate.type === "string"
|
|
1572
|
+
);
|
|
1560
1573
|
})
|
|
1561
1574
|
.map((field) => ({
|
|
1562
1575
|
id: typeof field.id === "string" ? field.id : undefined,
|
|
@@ -1601,7 +1614,9 @@ function asEntry(value: unknown): CrmEntryForEnrichment | null {
|
|
|
1601
1614
|
|
|
1602
1615
|
function asEntries(value: unknown): CrmEntryForEnrichment[] {
|
|
1603
1616
|
if (!Array.isArray(value)) return [];
|
|
1604
|
-
return value
|
|
1617
|
+
return value
|
|
1618
|
+
.map(asEntry)
|
|
1619
|
+
.filter((entry): entry is CrmEntryForEnrichment => !!entry);
|
|
1605
1620
|
}
|
|
1606
1621
|
|
|
1607
1622
|
function resolveEnrichmentColumn(args: {
|
|
@@ -1668,7 +1683,8 @@ async function resolveEnrichmentTarget(
|
|
|
1668
1683
|
apolloPath: args.apolloPath ?? outputField.enrichment?.apolloPath,
|
|
1669
1684
|
});
|
|
1670
1685
|
|
|
1671
|
-
const inputFieldName =
|
|
1686
|
+
const inputFieldName =
|
|
1687
|
+
args.inputFieldName ?? outputField.enrichment?.inputFieldName;
|
|
1672
1688
|
const inputField = inputFieldName
|
|
1673
1689
|
? fields.find((field) => field.name === inputFieldName)
|
|
1674
1690
|
: autoDetectInputField(category, fields);
|
|
@@ -1693,6 +1709,7 @@ async function callEnrichmentGatewayForEntry(args: {
|
|
|
1693
1709
|
entry: CrmEntryForEnrichment;
|
|
1694
1710
|
/** Explicit provider override. Defaults: people=fullenrich, company=aviato. */
|
|
1695
1711
|
provider?: string;
|
|
1712
|
+
gateway?: Pick<EnrichmentGatewayOptions, "apiKey" | "baseUrl">;
|
|
1696
1713
|
}): Promise<Record<string, unknown>> {
|
|
1697
1714
|
const input = args.entry.fields[args.target.inputField.name];
|
|
1698
1715
|
if (!hasCellValue(input)) {
|
|
@@ -1702,7 +1719,8 @@ async function callEnrichmentGatewayForEntry(args: {
|
|
|
1702
1719
|
}
|
|
1703
1720
|
const inputValue = String(input);
|
|
1704
1721
|
const isCompany = args.target.category === "company";
|
|
1705
|
-
const resolvedProvider =
|
|
1722
|
+
const resolvedProvider =
|
|
1723
|
+
args.provider ?? (isCompany ? "aviato" : "fullenrich");
|
|
1706
1724
|
|
|
1707
1725
|
if (resolvedProvider === "aviato") {
|
|
1708
1726
|
// Guard: Aviato does not return phone or email.
|
|
@@ -1718,25 +1736,37 @@ async function callEnrichmentGatewayForEntry(args: {
|
|
|
1718
1736
|
const isLinkedin = /linkedin\.com/i.test(inputValue);
|
|
1719
1737
|
return aviatoEnrichCompany(
|
|
1720
1738
|
isLinkedin ? { linkedinUrl: inputValue } : { website: inputValue },
|
|
1739
|
+
args.gateway,
|
|
1721
1740
|
);
|
|
1722
1741
|
} else {
|
|
1723
1742
|
// For people, inputValue may be a LinkedIn URL, email, or LinkedIn ID
|
|
1724
1743
|
const isLinkedin = /linkedin\.com/i.test(inputValue);
|
|
1725
1744
|
const isEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(inputValue);
|
|
1726
|
-
if (isLinkedin)
|
|
1727
|
-
|
|
1728
|
-
|
|
1745
|
+
if (isLinkedin) {
|
|
1746
|
+
return aviatoEnrichPerson({ linkedinUrl: inputValue }, args.gateway);
|
|
1747
|
+
}
|
|
1748
|
+
if (isEmail) {
|
|
1749
|
+
return aviatoEnrichPerson({ email: inputValue }, args.gateway);
|
|
1750
|
+
}
|
|
1751
|
+
return aviatoEnrichPerson({ linkedinID: inputValue }, args.gateway);
|
|
1729
1752
|
}
|
|
1730
1753
|
}
|
|
1731
1754
|
|
|
1732
1755
|
// fullenrich path (default for people, explicit override for companies)
|
|
1733
1756
|
if (isCompany) {
|
|
1734
|
-
return enrichCompany(
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1757
|
+
return enrichCompany(
|
|
1758
|
+
{
|
|
1759
|
+
domain: inputValue,
|
|
1760
|
+
requiredFields: args.target.requiredFields,
|
|
1761
|
+
},
|
|
1762
|
+
args.gateway,
|
|
1763
|
+
);
|
|
1738
1764
|
}
|
|
1739
|
-
return enrichPersonByIdentifier(
|
|
1765
|
+
return enrichPersonByIdentifier(
|
|
1766
|
+
inputValue,
|
|
1767
|
+
args.target.requiredFields,
|
|
1768
|
+
args.gateway,
|
|
1769
|
+
);
|
|
1740
1770
|
}
|
|
1741
1771
|
|
|
1742
1772
|
async function enrichOneEntry(
|
|
@@ -1751,6 +1781,7 @@ async function enrichOneEntry(
|
|
|
1751
1781
|
target: args.target,
|
|
1752
1782
|
entry: args.entry,
|
|
1753
1783
|
provider: args.provider,
|
|
1784
|
+
gateway: ctx.enrichmentGateway,
|
|
1754
1785
|
});
|
|
1755
1786
|
const value = extractEnrichmentValue(payload, args.target.column);
|
|
1756
1787
|
if (value === null) {
|
|
@@ -1779,7 +1810,10 @@ async function enrichOneEntry(
|
|
|
1779
1810
|
...writeResult,
|
|
1780
1811
|
};
|
|
1781
1812
|
} catch (error) {
|
|
1782
|
-
if (
|
|
1813
|
+
if (
|
|
1814
|
+
error instanceof EnrichmentGatewayError ||
|
|
1815
|
+
error instanceof CrmCliError
|
|
1816
|
+
) {
|
|
1783
1817
|
return {
|
|
1784
1818
|
entryId: args.entry.id,
|
|
1785
1819
|
ok: false,
|