@dench.com/cli 2.8.8-staging.192 → 2.9.1-staging.200
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 +31 -0
- package/campaign.ts +2316 -0
- package/crm.ts +54 -12
- package/dench.ts +63 -1
- package/email.ts +6 -2
- package/lib/api-schemas.ts +655 -0
- package/lib/command-registry.ts +332 -0
- package/members.ts +274 -6
- package/package.json +2 -1
package/lib/command-registry.ts
CHANGED
|
@@ -1618,6 +1618,135 @@ const rawApiOperations = [
|
|
|
1618
1618
|
responseSchema: anyResponse,
|
|
1619
1619
|
backend: convex("query", "functions/crm/members:list"),
|
|
1620
1620
|
}),
|
|
1621
|
+
|
|
1622
|
+
// Member profiles — what the profile panel shows when a member is clicked.
|
|
1623
|
+
// Presence comes from the app's heartbeat; bearer callers never count.
|
|
1624
|
+
op({
|
|
1625
|
+
id: "members.presence",
|
|
1626
|
+
group: "members",
|
|
1627
|
+
summary: "Live presence (online / away / offline) for workspace members.",
|
|
1628
|
+
cli: "dench members presence",
|
|
1629
|
+
method: "GET",
|
|
1630
|
+
path: "/members/presence",
|
|
1631
|
+
requestSchema: noBody,
|
|
1632
|
+
responseSchema: anyResponse,
|
|
1633
|
+
backend: {
|
|
1634
|
+
...convex("query", "functions/memberProfiles:getPresence"),
|
|
1635
|
+
transformArgs: (input) => ({
|
|
1636
|
+
...(typeof input.userIds === "string" && input.userIds.length > 0
|
|
1637
|
+
? { userIds: input.userIds.split(",").map((id) => id.trim()) }
|
|
1638
|
+
: Array.isArray(input.userIds)
|
|
1639
|
+
? { userIds: input.userIds }
|
|
1640
|
+
: {}),
|
|
1641
|
+
}),
|
|
1642
|
+
},
|
|
1643
|
+
}),
|
|
1644
|
+
op({
|
|
1645
|
+
id: "members.get",
|
|
1646
|
+
group: "members",
|
|
1647
|
+
summary:
|
|
1648
|
+
"A member's profile: name, email, tagline, role, timezone, presence, open task count.",
|
|
1649
|
+
cli: "dench members get",
|
|
1650
|
+
method: "GET",
|
|
1651
|
+
path: "/members/{userId}",
|
|
1652
|
+
requestSchema: noBody,
|
|
1653
|
+
responseSchema: anyResponse,
|
|
1654
|
+
backend: convex("query", "functions/memberProfiles:getMemberProfile"),
|
|
1655
|
+
}),
|
|
1656
|
+
op({
|
|
1657
|
+
id: "members.activity",
|
|
1658
|
+
group: "members",
|
|
1659
|
+
summary:
|
|
1660
|
+
"A member's recent comments and record changes across the CRM, newest first.",
|
|
1661
|
+
cli: "dench members activity",
|
|
1662
|
+
method: "GET",
|
|
1663
|
+
path: "/members/{userId}/activity",
|
|
1664
|
+
requestSchema: noBody,
|
|
1665
|
+
responseSchema: anyResponse,
|
|
1666
|
+
backend: {
|
|
1667
|
+
...convex("query", "functions/memberProfiles:listMemberActivity"),
|
|
1668
|
+
transformArgs: (input) => ({
|
|
1669
|
+
userId: input.userId,
|
|
1670
|
+
...(typeof input.limit === "number" ? { limit: input.limit } : {}),
|
|
1671
|
+
...(typeof input.kinds === "string" && input.kinds.length > 0
|
|
1672
|
+
? { kinds: input.kinds.split(",").map((kind) => kind.trim()) }
|
|
1673
|
+
: Array.isArray(input.kinds)
|
|
1674
|
+
? { kinds: input.kinds }
|
|
1675
|
+
: {}),
|
|
1676
|
+
}),
|
|
1677
|
+
},
|
|
1678
|
+
}),
|
|
1679
|
+
op({
|
|
1680
|
+
id: "members.tasks",
|
|
1681
|
+
group: "members",
|
|
1682
|
+
summary: "Open tasks assigned to a member (plus ones completed today).",
|
|
1683
|
+
cli: "dench members tasks",
|
|
1684
|
+
method: "GET",
|
|
1685
|
+
path: "/members/{userId}/tasks",
|
|
1686
|
+
requestSchema: noBody,
|
|
1687
|
+
responseSchema: anyResponse,
|
|
1688
|
+
backend: convex("query", "functions/crm/tasks:listOpenTasksForMember"),
|
|
1689
|
+
}),
|
|
1690
|
+
op({
|
|
1691
|
+
id: "me.profile.get",
|
|
1692
|
+
group: "members",
|
|
1693
|
+
summary: "Your own member profile.",
|
|
1694
|
+
cli: "dench members me",
|
|
1695
|
+
method: "GET",
|
|
1696
|
+
path: "/me/profile",
|
|
1697
|
+
requestSchema: noBody,
|
|
1698
|
+
responseSchema: anyResponse,
|
|
1699
|
+
backend: convex("query", "functions/memberProfiles:getMyProfile"),
|
|
1700
|
+
}),
|
|
1701
|
+
op({
|
|
1702
|
+
id: "me.profile.update",
|
|
1703
|
+
group: "members",
|
|
1704
|
+
summary: "Update your name, tagline, avatar URL, or timezone.",
|
|
1705
|
+
cli: "dench members me --name … --tagline … --timezone …",
|
|
1706
|
+
method: "PATCH",
|
|
1707
|
+
path: "/me/profile",
|
|
1708
|
+
requestSchema: anyObject,
|
|
1709
|
+
responseSchema: anyResponse,
|
|
1710
|
+
backend: convex("mutation", "functions/memberProfiles:updateMyProfile"),
|
|
1711
|
+
}),
|
|
1712
|
+
op({
|
|
1713
|
+
id: "me.avatar.uploadUrl",
|
|
1714
|
+
group: "members",
|
|
1715
|
+
summary:
|
|
1716
|
+
"Get a one-time URL to POST an avatar image to; then PUT /me/avatar with the returned storageId.",
|
|
1717
|
+
cli: "dench members me --avatar <file>",
|
|
1718
|
+
method: "POST",
|
|
1719
|
+
path: "/me/avatar/upload-url",
|
|
1720
|
+
requestSchema: noBody,
|
|
1721
|
+
responseSchema: anyResponse,
|
|
1722
|
+
backend: convex(
|
|
1723
|
+
"mutation",
|
|
1724
|
+
"functions/memberProfiles:generateAvatarUploadUrl",
|
|
1725
|
+
),
|
|
1726
|
+
}),
|
|
1727
|
+
op({
|
|
1728
|
+
id: "me.avatar.set",
|
|
1729
|
+
group: "members",
|
|
1730
|
+
summary: "Set your avatar from an uploaded storageId.",
|
|
1731
|
+
cli: "dench members me --avatar <file>",
|
|
1732
|
+
method: "PUT",
|
|
1733
|
+
path: "/me/avatar",
|
|
1734
|
+
requestSchema: anyObject,
|
|
1735
|
+
responseSchema: anyResponse,
|
|
1736
|
+
backend: convex("mutation", "functions/memberProfiles:setMyAvatar"),
|
|
1737
|
+
}),
|
|
1738
|
+
op({
|
|
1739
|
+
id: "me.avatar.clear",
|
|
1740
|
+
group: "members",
|
|
1741
|
+
summary: "Remove your avatar.",
|
|
1742
|
+
cli: "dench members me --clear-avatar",
|
|
1743
|
+
method: "DELETE",
|
|
1744
|
+
path: "/me/avatar",
|
|
1745
|
+
requestSchema: noBody,
|
|
1746
|
+
responseSchema: anyResponse,
|
|
1747
|
+
backend: convex("mutation", "functions/memberProfiles:clearMyAvatar"),
|
|
1748
|
+
}),
|
|
1749
|
+
|
|
1621
1750
|
op({
|
|
1622
1751
|
id: "crm.reports.generate",
|
|
1623
1752
|
group: "crm",
|
|
@@ -2348,6 +2477,209 @@ const rawApiOperations = [
|
|
|
2348
2477
|
backend: convex("mutation", "functions/emailSequences:stopEnrollment"),
|
|
2349
2478
|
}),
|
|
2350
2479
|
|
|
2480
|
+
// Outreach campaigns (email + LinkedIn steps on one schedule): `dench campaign`.
|
|
2481
|
+
op({
|
|
2482
|
+
id: "campaigns.list",
|
|
2483
|
+
group: "campaigns",
|
|
2484
|
+
summary: "List outreach campaigns (archived ones on request).",
|
|
2485
|
+
cli: "dench campaign list",
|
|
2486
|
+
method: "GET",
|
|
2487
|
+
path: "/campaigns",
|
|
2488
|
+
requestSchema: anyObject,
|
|
2489
|
+
responseSchema: anyResponse,
|
|
2490
|
+
backend: convex("query", "functions/outreachSequences:listSequences"),
|
|
2491
|
+
}),
|
|
2492
|
+
op({
|
|
2493
|
+
id: "campaigns.create",
|
|
2494
|
+
group: "campaigns",
|
|
2495
|
+
summary:
|
|
2496
|
+
"Create a draft outreach campaign with a business-hours send window in the given timezone.",
|
|
2497
|
+
cli: "dench campaign create",
|
|
2498
|
+
method: "POST",
|
|
2499
|
+
path: "/campaigns",
|
|
2500
|
+
requestSchema: anyObject,
|
|
2501
|
+
responseSchema: anyResponse,
|
|
2502
|
+
backend: convex("mutation", "functions/outreachSequences:createSequence"),
|
|
2503
|
+
}),
|
|
2504
|
+
op({
|
|
2505
|
+
id: "campaigns.get",
|
|
2506
|
+
group: "campaigns",
|
|
2507
|
+
summary:
|
|
2508
|
+
"Read a campaign: settings, steps, people, their current step and hold, last touches, linked leads.",
|
|
2509
|
+
cli: "dench campaign get",
|
|
2510
|
+
method: "GET",
|
|
2511
|
+
path: "/campaigns/{sequenceId}",
|
|
2512
|
+
requestSchema: anyObject,
|
|
2513
|
+
responseSchema: anyResponse,
|
|
2514
|
+
backend: convex("query", "functions/outreachSequences:getSequence"),
|
|
2515
|
+
}),
|
|
2516
|
+
op({
|
|
2517
|
+
id: "campaigns.analytics",
|
|
2518
|
+
group: "campaigns",
|
|
2519
|
+
summary:
|
|
2520
|
+
"Campaign funnel: enrolled, contacted, invited, accepted, messaged, replied, opens and clicks.",
|
|
2521
|
+
cli: "dench campaign get",
|
|
2522
|
+
method: "GET",
|
|
2523
|
+
path: "/campaigns/{sequenceId}/analytics",
|
|
2524
|
+
requestSchema: anyObject,
|
|
2525
|
+
responseSchema: anyResponse,
|
|
2526
|
+
backend: convex(
|
|
2527
|
+
"query",
|
|
2528
|
+
"functions/outreachSequences:getSequenceAnalytics",
|
|
2529
|
+
),
|
|
2530
|
+
}),
|
|
2531
|
+
op({
|
|
2532
|
+
id: "campaigns.live",
|
|
2533
|
+
group: "campaigns",
|
|
2534
|
+
summary:
|
|
2535
|
+
"What the campaign is doing now, what comes next and when, and why it is holding.",
|
|
2536
|
+
cli: "dench campaign get",
|
|
2537
|
+
method: "GET",
|
|
2538
|
+
path: "/campaigns/{sequenceId}/live",
|
|
2539
|
+
requestSchema: anyObject,
|
|
2540
|
+
responseSchema: anyResponse,
|
|
2541
|
+
backend: convex("query", "functions/outreachSequences:getSequenceLive"),
|
|
2542
|
+
}),
|
|
2543
|
+
op({
|
|
2544
|
+
id: "campaigns.update",
|
|
2545
|
+
group: "campaigns",
|
|
2546
|
+
summary:
|
|
2547
|
+
"Change a campaign's name, send windows, daily email cap, stop-on-reply, start or end. Works until archived.",
|
|
2548
|
+
cli: "dench campaign set",
|
|
2549
|
+
method: "PATCH",
|
|
2550
|
+
path: "/campaigns/{sequenceId}",
|
|
2551
|
+
requestSchema: anyObject,
|
|
2552
|
+
responseSchema: anyResponse,
|
|
2553
|
+
backend: convex("mutation", "functions/outreachSequences:updateDraft"),
|
|
2554
|
+
}),
|
|
2555
|
+
op({
|
|
2556
|
+
id: "campaigns.steps.replace",
|
|
2557
|
+
group: "campaigns",
|
|
2558
|
+
summary:
|
|
2559
|
+
"Replace every step of a draft campaign (email, wait, LinkedIn visit, connection request, message).",
|
|
2560
|
+
cli: "dench campaign steps set",
|
|
2561
|
+
method: "PUT",
|
|
2562
|
+
path: "/campaigns/{sequenceId}/steps",
|
|
2563
|
+
requestSchema: anyObject,
|
|
2564
|
+
responseSchema: anyResponse,
|
|
2565
|
+
backend: convex("mutation", "functions/outreachSequences:replaceSteps"),
|
|
2566
|
+
}),
|
|
2567
|
+
op({
|
|
2568
|
+
id: "campaigns.people.addFromCrm",
|
|
2569
|
+
group: "campaigns",
|
|
2570
|
+
summary:
|
|
2571
|
+
"Add CRM records (up to 100 ids per call) to a campaign; returns how many were added and why others were skipped.",
|
|
2572
|
+
cli: "dench campaign add",
|
|
2573
|
+
method: "POST",
|
|
2574
|
+
path: "/campaigns/{sequenceId}/people",
|
|
2575
|
+
requestSchema: anyObject,
|
|
2576
|
+
responseSchema: anyResponse,
|
|
2577
|
+
backend: convex("mutation", "functions/outreachSequences:enrollFromCrm"),
|
|
2578
|
+
}),
|
|
2579
|
+
op({
|
|
2580
|
+
id: "campaigns.people.add",
|
|
2581
|
+
group: "campaigns",
|
|
2582
|
+
summary: "Add one person by email and/or LinkedIn profile URL.",
|
|
2583
|
+
cli: "dench campaign add --name",
|
|
2584
|
+
method: "POST",
|
|
2585
|
+
path: "/campaigns/{sequenceId}/person",
|
|
2586
|
+
requestSchema: anyObject,
|
|
2587
|
+
responseSchema: anyResponse,
|
|
2588
|
+
backend: convex("mutation", "functions/outreachSequences:addEnrollment"),
|
|
2589
|
+
}),
|
|
2590
|
+
op({
|
|
2591
|
+
id: "campaigns.launch.preview",
|
|
2592
|
+
group: "campaigns",
|
|
2593
|
+
summary:
|
|
2594
|
+
"Launch readiness: blockers grouped by problem, warnings, and the fingerprint `launch` requires.",
|
|
2595
|
+
cli: "dench campaign launch",
|
|
2596
|
+
method: "GET",
|
|
2597
|
+
path: "/campaigns/{sequenceId}/launch",
|
|
2598
|
+
requestSchema: anyObject,
|
|
2599
|
+
responseSchema: anyResponse,
|
|
2600
|
+
backend: convex("query", "functions/outreachSequences:previewLaunch"),
|
|
2601
|
+
}),
|
|
2602
|
+
op({
|
|
2603
|
+
id: "campaigns.launch",
|
|
2604
|
+
group: "campaigns",
|
|
2605
|
+
summary:
|
|
2606
|
+
"Launch a ready draft. Pass the fingerprint from the preview and acknowledge the LinkedIn notice when LinkedIn steps exist.",
|
|
2607
|
+
cli: "dench campaign launch",
|
|
2608
|
+
method: "POST",
|
|
2609
|
+
path: "/campaigns/{sequenceId}/launch",
|
|
2610
|
+
requestSchema: anyObject,
|
|
2611
|
+
responseSchema: anyResponse,
|
|
2612
|
+
backend: convex("mutation", "functions/outreachSequences:launch"),
|
|
2613
|
+
}),
|
|
2614
|
+
op({
|
|
2615
|
+
id: "campaigns.pause",
|
|
2616
|
+
group: "campaigns",
|
|
2617
|
+
summary: "Pause an active campaign.",
|
|
2618
|
+
cli: "dench campaign pause",
|
|
2619
|
+
method: "POST",
|
|
2620
|
+
path: "/campaigns/{sequenceId}/pause",
|
|
2621
|
+
requestSchema: anyObject,
|
|
2622
|
+
responseSchema: anyResponse,
|
|
2623
|
+
backend: convex("mutation", "functions/outreachSequences:pauseSequence"),
|
|
2624
|
+
}),
|
|
2625
|
+
op({
|
|
2626
|
+
id: "campaigns.resume",
|
|
2627
|
+
group: "campaigns",
|
|
2628
|
+
summary: "Resume a paused campaign.",
|
|
2629
|
+
cli: "dench campaign resume",
|
|
2630
|
+
method: "POST",
|
|
2631
|
+
path: "/campaigns/{sequenceId}/resume",
|
|
2632
|
+
requestSchema: anyObject,
|
|
2633
|
+
responseSchema: anyResponse,
|
|
2634
|
+
backend: convex("mutation", "functions/outreachSequences:resumeSequence"),
|
|
2635
|
+
}),
|
|
2636
|
+
op({
|
|
2637
|
+
id: "campaigns.archive",
|
|
2638
|
+
group: "campaigns",
|
|
2639
|
+
summary: "Archive a campaign and stop everyone still in flight.",
|
|
2640
|
+
cli: "dench campaign archive",
|
|
2641
|
+
method: "POST",
|
|
2642
|
+
path: "/campaigns/{sequenceId}/archive",
|
|
2643
|
+
requestSchema: anyObject,
|
|
2644
|
+
responseSchema: anyResponse,
|
|
2645
|
+
backend: convex("mutation", "functions/outreachSequences:archiveSequence"),
|
|
2646
|
+
}),
|
|
2647
|
+
op({
|
|
2648
|
+
id: "campaigns.events",
|
|
2649
|
+
group: "campaigns",
|
|
2650
|
+
summary:
|
|
2651
|
+
"The campaign's activity log, newest first (sent, accepted, replied, skipped, failed, paused, stopped).",
|
|
2652
|
+
cli: "dench campaign events",
|
|
2653
|
+
method: "GET",
|
|
2654
|
+
path: "/campaigns/{sequenceId}/events",
|
|
2655
|
+
requestSchema: anyObject,
|
|
2656
|
+
responseSchema: anyResponse,
|
|
2657
|
+
backend: convex("query", "functions/outreachSequences:listSequenceEvents"),
|
|
2658
|
+
}),
|
|
2659
|
+
op({
|
|
2660
|
+
id: "campaigns.people.stop",
|
|
2661
|
+
group: "campaigns",
|
|
2662
|
+
summary:
|
|
2663
|
+
"Stop one person: nothing more is sent to them from this campaign.",
|
|
2664
|
+
cli: "dench campaign stop",
|
|
2665
|
+
method: "POST",
|
|
2666
|
+
path: "/campaigns/people/{enrollmentId}/stop",
|
|
2667
|
+
requestSchema: anyObject,
|
|
2668
|
+
responseSchema: anyResponse,
|
|
2669
|
+
backend: convex("mutation", "functions/outreachSequences:stopEnrollment"),
|
|
2670
|
+
}),
|
|
2671
|
+
op({
|
|
2672
|
+
id: "campaigns.people.resume",
|
|
2673
|
+
group: "campaigns",
|
|
2674
|
+
summary: "Resume one paused person in an active campaign.",
|
|
2675
|
+
cli: "dench campaign resume-person",
|
|
2676
|
+
method: "POST",
|
|
2677
|
+
path: "/campaigns/people/{enrollmentId}/resume",
|
|
2678
|
+
requestSchema: anyObject,
|
|
2679
|
+
responseSchema: anyResponse,
|
|
2680
|
+
backend: convex("mutation", "functions/outreachSequences:resumeEnrollment"),
|
|
2681
|
+
}),
|
|
2682
|
+
|
|
2351
2683
|
// Routines.
|
|
2352
2684
|
op({
|
|
2353
2685
|
id: "cron.list",
|
package/members.ts
CHANGED
|
@@ -32,9 +32,11 @@
|
|
|
32
32
|
* Both surfaces share this implementation so the CLI auth + payload
|
|
33
33
|
* shape stays in lockstep.
|
|
34
34
|
*/
|
|
35
|
-
import {
|
|
35
|
+
import { readFile } from "node:fs/promises";
|
|
36
|
+
import { extname } from "node:path";
|
|
37
|
+
import type { ConvexHttpClient } from "convex/browser";
|
|
36
38
|
import { makeFunctionReference } from "convex/server";
|
|
37
|
-
import { CliArgError, hasFlag } from "./lib/cli-args";
|
|
39
|
+
import { CliArgError, getFlag, hasFlag, shift } from "./lib/cli-args";
|
|
38
40
|
|
|
39
41
|
class MembersCliError extends Error {}
|
|
40
42
|
|
|
@@ -58,6 +60,10 @@ type MemberRow = {
|
|
|
58
60
|
name: string | null;
|
|
59
61
|
email: string | null;
|
|
60
62
|
image: string | null;
|
|
63
|
+
tagline?: string | null;
|
|
64
|
+
timezone?: string | null;
|
|
65
|
+
presence?: "online" | "away" | "offline";
|
|
66
|
+
lastActiveAt?: number | null;
|
|
61
67
|
role: "ADMIN" | "MEMBER";
|
|
62
68
|
joinedAt: number;
|
|
63
69
|
};
|
|
@@ -73,6 +79,42 @@ const api = {
|
|
|
73
79
|
members: {
|
|
74
80
|
list: makeFunctionReference<"query">("functions/crm/members:list"),
|
|
75
81
|
},
|
|
82
|
+
profiles: {
|
|
83
|
+
get: makeFunctionReference<"query">(
|
|
84
|
+
"functions/memberProfiles:getMemberProfile",
|
|
85
|
+
),
|
|
86
|
+
me: makeFunctionReference<"query">("functions/memberProfiles:getMyProfile"),
|
|
87
|
+
activity: makeFunctionReference<"query">(
|
|
88
|
+
"functions/memberProfiles:listMemberActivity",
|
|
89
|
+
),
|
|
90
|
+
presence: makeFunctionReference<"query">(
|
|
91
|
+
"functions/memberProfiles:getPresence",
|
|
92
|
+
),
|
|
93
|
+
tasks: makeFunctionReference<"query">(
|
|
94
|
+
"functions/crm/tasks:listOpenTasksForMember",
|
|
95
|
+
),
|
|
96
|
+
updateMe: makeFunctionReference<"mutation">(
|
|
97
|
+
"functions/memberProfiles:updateMyProfile",
|
|
98
|
+
),
|
|
99
|
+
avatarUploadUrl: makeFunctionReference<"mutation">(
|
|
100
|
+
"functions/memberProfiles:generateAvatarUploadUrl",
|
|
101
|
+
),
|
|
102
|
+
setAvatar: makeFunctionReference<"mutation">(
|
|
103
|
+
"functions/memberProfiles:setMyAvatar",
|
|
104
|
+
),
|
|
105
|
+
clearAvatar: makeFunctionReference<"mutation">(
|
|
106
|
+
"functions/memberProfiles:clearMyAvatar",
|
|
107
|
+
),
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const AVATAR_TYPES: Record<string, string> = {
|
|
112
|
+
".png": "image/png",
|
|
113
|
+
".jpg": "image/jpeg",
|
|
114
|
+
".jpeg": "image/jpeg",
|
|
115
|
+
".webp": "image/webp",
|
|
116
|
+
".gif": "image/gif",
|
|
117
|
+
".avif": "image/avif",
|
|
76
118
|
};
|
|
77
119
|
|
|
78
120
|
export async function runMembersCommand(opts: {
|
|
@@ -96,6 +138,16 @@ export async function runMembersCommand(opts: {
|
|
|
96
138
|
switch (subcommand) {
|
|
97
139
|
case "list":
|
|
98
140
|
return await runListMembers(ctx);
|
|
141
|
+
case "get":
|
|
142
|
+
return await runGetMember(ctx);
|
|
143
|
+
case "activity":
|
|
144
|
+
return await runMemberActivity(ctx);
|
|
145
|
+
case "tasks":
|
|
146
|
+
return await runMemberTasks(ctx);
|
|
147
|
+
case "presence":
|
|
148
|
+
return await runPresence(ctx);
|
|
149
|
+
case "me":
|
|
150
|
+
return await runMe(ctx);
|
|
99
151
|
default:
|
|
100
152
|
throw new MembersCliError(
|
|
101
153
|
`Unknown members subcommand: ${subcommand}. Run \`dench members help\`.`,
|
|
@@ -128,12 +180,14 @@ async function runListMembers(ctx: MembersCliContext): Promise<void> {
|
|
|
128
180
|
// Plain table for human consumption — userIds are first column so the
|
|
129
181
|
// operator can copy/paste directly into a `dench crm cells set ...
|
|
130
182
|
// --field Owner --value <userId>` follow-up.
|
|
131
|
-
const headers = ["userId", "role", "name", "email"];
|
|
183
|
+
const headers = ["userId", "role", "name", "email", "presence", "timezone"];
|
|
132
184
|
const rows = members.map((m) => [
|
|
133
185
|
m.userId,
|
|
134
186
|
m.role,
|
|
135
187
|
m.name ?? "",
|
|
136
188
|
m.email ?? "",
|
|
189
|
+
m.presence ?? "",
|
|
190
|
+
m.timezone ?? "",
|
|
137
191
|
]);
|
|
138
192
|
const widths = headers.map((header, idx) =>
|
|
139
193
|
Math.max(header.length, ...rows.map((row) => row[idx].length)),
|
|
@@ -147,6 +201,207 @@ async function runListMembers(ctx: MembersCliContext): Promise<void> {
|
|
|
147
201
|
}
|
|
148
202
|
}
|
|
149
203
|
|
|
204
|
+
/**
|
|
205
|
+
* `<userId|email>` positional. Emails are resolved against the roster so a
|
|
206
|
+
* script can say `dench members get jane@acme.com`.
|
|
207
|
+
*/
|
|
208
|
+
async function resolveMemberId(
|
|
209
|
+
ctx: MembersCliContext,
|
|
210
|
+
raw: string,
|
|
211
|
+
): Promise<string> {
|
|
212
|
+
const value = raw.trim();
|
|
213
|
+
if (!value.includes("@")) return value;
|
|
214
|
+
const result = (await callQuery(ctx, api.members.list, {})) as
|
|
215
|
+
| ListMembersResult
|
|
216
|
+
| null
|
|
217
|
+
| undefined;
|
|
218
|
+
const match = (result?.members ?? []).find(
|
|
219
|
+
(member) => member.email?.toLowerCase() === value.toLowerCase(),
|
|
220
|
+
);
|
|
221
|
+
if (!match) {
|
|
222
|
+
throw new MembersCliError(
|
|
223
|
+
`No member with email ${value}. Run \`dench members list\` to see the roster.`,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
return match.userId;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function out(value: unknown): void {
|
|
230
|
+
console.log(JSON.stringify(value, null, 2));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function assertNoFlags(ctx: MembersCliContext, command: string): void {
|
|
234
|
+
const stray = ctx.args.find((arg) => arg.startsWith("--"));
|
|
235
|
+
if (stray) {
|
|
236
|
+
throw new MembersCliError(`Unknown flag for ${command}: ${stray}`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async function runGetMember(ctx: MembersCliContext): Promise<void> {
|
|
241
|
+
const target = shiftArg(ctx, "member id or email");
|
|
242
|
+
assertNoFlags(ctx, "dench members get");
|
|
243
|
+
const userId = await resolveMemberId(ctx, target);
|
|
244
|
+
const profile = await callQuery(ctx, api.profiles.get, { userId });
|
|
245
|
+
if (!profile) {
|
|
246
|
+
throw new MembersCliError(`No member ${target} in this workspace.`);
|
|
247
|
+
}
|
|
248
|
+
out(profile);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function runMemberActivity(ctx: MembersCliContext): Promise<void> {
|
|
252
|
+
const target = shiftArg(ctx, "member id or email");
|
|
253
|
+
const rawLimit = getFlag(ctx.args, "--limit");
|
|
254
|
+
const rawKinds = getFlag(ctx.args, "--kinds");
|
|
255
|
+
assertNoFlags(ctx, "dench members activity");
|
|
256
|
+
const limit =
|
|
257
|
+
rawLimit === undefined ? undefined : Number.parseInt(rawLimit, 10);
|
|
258
|
+
if (limit !== undefined && (!Number.isFinite(limit) || limit < 1)) {
|
|
259
|
+
throw new MembersCliError("--limit must be a positive integer");
|
|
260
|
+
}
|
|
261
|
+
const kinds = rawKinds
|
|
262
|
+
?.split(",")
|
|
263
|
+
.map((kind) => kind.trim())
|
|
264
|
+
.filter(Boolean);
|
|
265
|
+
for (const kind of kinds ?? []) {
|
|
266
|
+
if (kind !== "comments" && kind !== "changes") {
|
|
267
|
+
throw new MembersCliError("--kinds accepts comments,changes");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const userId = await resolveMemberId(ctx, target);
|
|
271
|
+
out(
|
|
272
|
+
await callQuery(ctx, api.profiles.activity, {
|
|
273
|
+
userId,
|
|
274
|
+
...(limit !== undefined ? { limit } : {}),
|
|
275
|
+
...(kinds && kinds.length > 0 ? { kinds } : {}),
|
|
276
|
+
}),
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function runMemberTasks(ctx: MembersCliContext): Promise<void> {
|
|
281
|
+
const target = shiftArg(ctx, "member id or email");
|
|
282
|
+
const rawLimit = getFlag(ctx.args, "--limit");
|
|
283
|
+
assertNoFlags(ctx, "dench members tasks");
|
|
284
|
+
const userId = await resolveMemberId(ctx, target);
|
|
285
|
+
const todayStart = new Date();
|
|
286
|
+
todayStart.setHours(0, 0, 0, 0);
|
|
287
|
+
out(
|
|
288
|
+
await callQuery(ctx, api.profiles.tasks, {
|
|
289
|
+
userId,
|
|
290
|
+
todayStartMs: todayStart.getTime(),
|
|
291
|
+
...(rawLimit ? { limit: Number.parseInt(rawLimit, 10) } : {}),
|
|
292
|
+
}),
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async function runPresence(ctx: MembersCliContext): Promise<void> {
|
|
297
|
+
const targets = ctx.args.filter((arg) => !arg.startsWith("--"));
|
|
298
|
+
ctx.args.splice(
|
|
299
|
+
0,
|
|
300
|
+
ctx.args.length,
|
|
301
|
+
...ctx.args.filter((arg) => arg.startsWith("--")),
|
|
302
|
+
);
|
|
303
|
+
assertNoFlags(ctx, "dench members presence");
|
|
304
|
+
const userIds = await Promise.all(
|
|
305
|
+
targets.map((target) => resolveMemberId(ctx, target)),
|
|
306
|
+
);
|
|
307
|
+
out(
|
|
308
|
+
await callQuery(ctx, api.profiles.presence, {
|
|
309
|
+
...(userIds.length > 0 ? { userIds } : {}),
|
|
310
|
+
}),
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** `dench members me [--name --tagline --timezone --image-url --avatar <file> --clear-avatar]` */
|
|
315
|
+
async function runMe(ctx: MembersCliContext): Promise<void> {
|
|
316
|
+
const name = getFlag(ctx.args, "--name");
|
|
317
|
+
const tagline = getFlag(ctx.args, "--tagline");
|
|
318
|
+
const timezone = getFlag(ctx.args, "--timezone");
|
|
319
|
+
const imageUrl = getFlag(ctx.args, "--image-url");
|
|
320
|
+
const avatarPath = getFlag(ctx.args, "--avatar");
|
|
321
|
+
const clearAvatar = hasFlag(ctx.args, "--clear-avatar");
|
|
322
|
+
const autoTimezone = hasFlag(ctx.args, "--auto-timezone");
|
|
323
|
+
assertNoFlags(ctx, "dench members me");
|
|
324
|
+
if (avatarPath && (clearAvatar || imageUrl !== undefined)) {
|
|
325
|
+
throw new MembersCliError(
|
|
326
|
+
"Pass one of --avatar <file>, --image-url <url>, or --clear-avatar.",
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const patch: Record<string, unknown> = {};
|
|
331
|
+
if (name !== undefined) patch.name = name;
|
|
332
|
+
if (tagline !== undefined) patch.tagline = tagline;
|
|
333
|
+
if (imageUrl !== undefined) patch.imageUrl = imageUrl;
|
|
334
|
+
if (timezone !== undefined) patch.timezone = timezone;
|
|
335
|
+
if (autoTimezone) patch.timezone = null;
|
|
336
|
+
if (Object.keys(patch).length > 0) {
|
|
337
|
+
await callMutation(ctx, api.profiles.updateMe, patch);
|
|
338
|
+
}
|
|
339
|
+
if (clearAvatar) await callMutation(ctx, api.profiles.clearAvatar, {});
|
|
340
|
+
if (avatarPath) await uploadAvatar(ctx, avatarPath);
|
|
341
|
+
|
|
342
|
+
out(await callQuery(ctx, api.profiles.me, {}));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function uploadAvatar(
|
|
346
|
+
ctx: MembersCliContext,
|
|
347
|
+
filePath: string,
|
|
348
|
+
): Promise<void> {
|
|
349
|
+
const contentType = AVATAR_TYPES[extname(filePath).toLowerCase()];
|
|
350
|
+
if (!contentType) {
|
|
351
|
+
throw new MembersCliError(
|
|
352
|
+
"--avatar must be a .png, .jpg, .jpeg, .webp, .gif, or .avif file",
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
const bytes = await readFile(filePath);
|
|
356
|
+
if (bytes.byteLength > 2 * 1024 * 1024) {
|
|
357
|
+
throw new MembersCliError("--avatar must be under 2 MB");
|
|
358
|
+
}
|
|
359
|
+
const uploadUrl = (await callMutation(
|
|
360
|
+
ctx,
|
|
361
|
+
api.profiles.avatarUploadUrl,
|
|
362
|
+
{},
|
|
363
|
+
)) as string;
|
|
364
|
+
const response = await fetch(uploadUrl, {
|
|
365
|
+
method: "POST",
|
|
366
|
+
headers: { "Content-Type": contentType },
|
|
367
|
+
body: new Uint8Array(bytes),
|
|
368
|
+
});
|
|
369
|
+
if (!response.ok) {
|
|
370
|
+
throw new MembersCliError(`Avatar upload failed (${response.status})`);
|
|
371
|
+
}
|
|
372
|
+
const { storageId } = (await response.json()) as { storageId: string };
|
|
373
|
+
await callMutation(ctx, api.profiles.setAvatar, { storageId });
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function shiftArg(ctx: MembersCliContext, expected: string): string {
|
|
377
|
+
try {
|
|
378
|
+
return shift(ctx.args, expected);
|
|
379
|
+
} catch (error) {
|
|
380
|
+
if (error instanceof CliArgError) throw new MembersCliError(error.message);
|
|
381
|
+
throw error;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
async function callMutation(
|
|
386
|
+
ctx: MembersCliContext,
|
|
387
|
+
fn: Parameters<ConvexHttpClient["mutation"]>[0],
|
|
388
|
+
args: Record<string, unknown> = {},
|
|
389
|
+
): Promise<unknown> {
|
|
390
|
+
try {
|
|
391
|
+
return await ctx.convex.mutation(fn, {
|
|
392
|
+
...args,
|
|
393
|
+
...(ctx.sessionToken ? { sessionToken: ctx.sessionToken } : {}),
|
|
394
|
+
} as never);
|
|
395
|
+
} catch (error) {
|
|
396
|
+
if (error instanceof CliArgError) throw new MembersCliError(error.message);
|
|
397
|
+
const data = (error as { data?: unknown } | null)?.data;
|
|
398
|
+
if (typeof data === "string" && data.trim()) {
|
|
399
|
+
throw new MembersCliError(data.trim());
|
|
400
|
+
}
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
150
405
|
async function callQuery(
|
|
151
406
|
ctx: MembersCliContext,
|
|
152
407
|
fn: Parameters<ConvexHttpClient["query"]>[0],
|
|
@@ -174,9 +429,22 @@ owner from the source data.
|
|
|
174
429
|
|
|
175
430
|
Subcommands:
|
|
176
431
|
dench members list [--json]
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
432
|
+
Every member as \`userId / role / name / email / presence / timezone\`.
|
|
433
|
+
--json adds tagline, lastActiveAt, organizationId / Slug / Name.
|
|
434
|
+
dench members get <userId|email>
|
|
435
|
+
One member's profile: name, email, tagline, role, joined, timezone,
|
|
436
|
+
presence (online / away / offline + lastActiveAt), open task count.
|
|
437
|
+
dench members activity <userId|email> [--limit N] [--kinds comments,changes]
|
|
438
|
+
What they did across the CRM, newest first: their comments and the
|
|
439
|
+
field changes they made (Dench / automations acting for them excluded).
|
|
440
|
+
dench members tasks <userId|email> [--limit N]
|
|
441
|
+
Open tasks assigned to them (plus ones completed today).
|
|
442
|
+
dench members presence [<userId|email>...]
|
|
443
|
+
Live presence for some or all members.
|
|
444
|
+
dench members me [--name "…"] [--tagline "…"] [--timezone <IANA>|--auto-timezone]
|
|
445
|
+
[--avatar ./photo.png | --image-url <https://…> | --clear-avatar]
|
|
446
|
+
Read (no flags) or update your own profile. Agent sessions act as their
|
|
447
|
+
owner; an org API key has no person behind it and is refused.
|
|
180
448
|
|
|
181
449
|
Alias:
|
|
182
450
|
dench crm members list [--json]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dench.com/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.1-staging.200",
|
|
4
4
|
"description": "Dench agent workspace CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"crm.ts",
|
|
28
28
|
"crm-comments.ts",
|
|
29
29
|
"email.ts",
|
|
30
|
+
"campaign.ts",
|
|
30
31
|
"members.ts",
|
|
31
32
|
"notifications.ts",
|
|
32
33
|
"cron.ts",
|