@dench.com/cli 2.9.0-staging.193 → 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/dench.ts +6 -1
- package/lib/api-schemas.ts +187 -0
- package/lib/command-registry.ts +129 -0
- package/members.ts +274 -6
- package/package.json +1 -1
package/dench.ts
CHANGED
|
@@ -549,12 +549,17 @@ Notifications (the bell's inbox):
|
|
|
549
549
|
dench notifications prefs [--set emailEnabled=false] [--set <kind>.email=false]
|
|
550
550
|
Help: dench notifications help
|
|
551
551
|
|
|
552
|
-
Workspace members (for CRM \`user\`-type fields):
|
|
552
|
+
Workspace members (for CRM \`user\`-type fields, and who's doing what):
|
|
553
553
|
dench members list [--json] (top-level alias)
|
|
554
554
|
dench crm members list [--json] (canonical CRM-scoped name)
|
|
555
555
|
Look up real userIds for the active org so \`Owner\` / \`Assignee\`
|
|
556
556
|
cells assign to real members instead of being stored as unlinked
|
|
557
557
|
display-name strings. See \`dench members help\`.
|
|
558
|
+
dench members get <userId|email> profile: tagline, timezone, presence, open tasks
|
|
559
|
+
dench members activity <userId|email> their comments + record changes, newest first
|
|
560
|
+
dench members tasks <userId|email> open tasks assigned to them
|
|
561
|
+
dench members presence [<userId|email>...] online / away / offline
|
|
562
|
+
dench members me [--name --tagline --timezone --avatar <file>] your own profile
|
|
558
563
|
|
|
559
564
|
Live web search (Exa via the Dench Gateway, auths with the active \`dench signin\` agent session or DENCH_API_KEY):
|
|
560
565
|
dench search "<query>" [--num-results N] [--type auto|fast|deep|deep-reasoning|neural] [--category news|company|people|...] [--include-domains a.com,b.com] [--exclude-domains c.com] [--max-chars 800] [--json]
|
package/lib/api-schemas.ts
CHANGED
|
@@ -827,15 +827,82 @@ const crmBatchResults = z.object({
|
|
|
827
827
|
count: z.number(),
|
|
828
828
|
});
|
|
829
829
|
|
|
830
|
+
const presenceState = z.enum(["online", "away", "offline"]);
|
|
831
|
+
|
|
830
832
|
const memberShape = z.object({
|
|
831
833
|
userId: z.string(),
|
|
832
834
|
name: z.string().nullable(),
|
|
833
835
|
email: z.string().nullable(),
|
|
834
836
|
image: z.string().nullable(),
|
|
837
|
+
tagline: z.string().nullable(),
|
|
838
|
+
timezone: z
|
|
839
|
+
.string()
|
|
840
|
+
.nullable()
|
|
841
|
+
.describe("IANA zone, when the member set one."),
|
|
842
|
+
presence: presenceState,
|
|
843
|
+
lastActiveAt: z.number().nullable(),
|
|
835
844
|
role: z.string(),
|
|
836
845
|
joinedAt: z.number(),
|
|
837
846
|
});
|
|
838
847
|
|
|
848
|
+
const memberProfileShape = z.object({
|
|
849
|
+
userId: z.string(),
|
|
850
|
+
name: z.string().nullable(),
|
|
851
|
+
email: z.string().nullable(),
|
|
852
|
+
image: z.string().nullable(),
|
|
853
|
+
tagline: z.string().nullable(),
|
|
854
|
+
role: z.enum(["ADMIN", "MEMBER"]),
|
|
855
|
+
joinedAt: z.number(),
|
|
856
|
+
timezone: z
|
|
857
|
+
.object({
|
|
858
|
+
value: z.string(),
|
|
859
|
+
source: z.enum(["auto", "manual", "agent"]),
|
|
860
|
+
updatedAt: z.number(),
|
|
861
|
+
})
|
|
862
|
+
.nullable(),
|
|
863
|
+
presence: z.object({
|
|
864
|
+
state: presenceState,
|
|
865
|
+
lastActiveAt: z.number().nullable(),
|
|
866
|
+
}),
|
|
867
|
+
openTaskCount: z.number(),
|
|
868
|
+
commentCount: z.number().describe("Capped at 200."),
|
|
869
|
+
changeCount: z.number().describe("Capped at 200."),
|
|
870
|
+
lastContributionAt: z.number().nullable(),
|
|
871
|
+
isSelf: z.boolean(),
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
const memberActivityRow = z.union([
|
|
875
|
+
z.object({
|
|
876
|
+
kind: z.literal("comment"),
|
|
877
|
+
id: z.string(),
|
|
878
|
+
entryId: z.string(),
|
|
879
|
+
objectName: z.string(),
|
|
880
|
+
entryLabel: z.string(),
|
|
881
|
+
body: z.string(),
|
|
882
|
+
parentCommentId: z.string().optional(),
|
|
883
|
+
deleted: z.boolean(),
|
|
884
|
+
at: z.number(),
|
|
885
|
+
}),
|
|
886
|
+
z
|
|
887
|
+
.object({
|
|
888
|
+
kind: z.literal("change"),
|
|
889
|
+
id: z.string(),
|
|
890
|
+
entryId: z.string(),
|
|
891
|
+
objectName: z.string(),
|
|
892
|
+
entryLabel: z.string(),
|
|
893
|
+
changeKind: z.enum(["create", "update", "delete"]),
|
|
894
|
+
changes: z.array(
|
|
895
|
+
z.object({
|
|
896
|
+
fieldName: z.string(),
|
|
897
|
+
before: z.unknown().optional(),
|
|
898
|
+
after: z.unknown().optional(),
|
|
899
|
+
}),
|
|
900
|
+
),
|
|
901
|
+
at: z.number(),
|
|
902
|
+
})
|
|
903
|
+
.passthrough(),
|
|
904
|
+
]);
|
|
905
|
+
|
|
839
906
|
// -- routines ------------------------------------------------------------------
|
|
840
907
|
|
|
841
908
|
const cronJobShape = z
|
|
@@ -2282,6 +2349,47 @@ export const requestSchemas: Record<string, ZodTypeAny> = {
|
|
|
2282
2349
|
"crm.tasks.complete": z.object({ entryId: z.string() }),
|
|
2283
2350
|
"crm.tasks.reopen": z.object({ entryId: z.string() }),
|
|
2284
2351
|
|
|
2352
|
+
// Members + my profile
|
|
2353
|
+
"members.presence": z.object({
|
|
2354
|
+
userIds: z
|
|
2355
|
+
.string()
|
|
2356
|
+
.optional()
|
|
2357
|
+
.describe("Comma-separated user ids; omit for every member."),
|
|
2358
|
+
}),
|
|
2359
|
+
"members.get": z.object({ userId: z.string() }),
|
|
2360
|
+
"members.activity": z.object({
|
|
2361
|
+
userId: z.string(),
|
|
2362
|
+
limit: z.coerce.number().int().min(1).max(100).optional(),
|
|
2363
|
+
kinds: z
|
|
2364
|
+
.string()
|
|
2365
|
+
.optional()
|
|
2366
|
+
.describe("Comma-separated subset of comments,changes."),
|
|
2367
|
+
}),
|
|
2368
|
+
"members.tasks": z.object({
|
|
2369
|
+
userId: z.string(),
|
|
2370
|
+
limit: z.coerce.number().int().min(1).max(50).optional(),
|
|
2371
|
+
todayStartMs: z.coerce.number().optional(),
|
|
2372
|
+
}),
|
|
2373
|
+
"me.profile.get": noInput,
|
|
2374
|
+
"me.profile.update": z.object({
|
|
2375
|
+
name: z.string().min(1).max(80).optional(),
|
|
2376
|
+
tagline: z.string().max(160).optional().describe("Empty string clears."),
|
|
2377
|
+
imageUrl: z
|
|
2378
|
+
.string()
|
|
2379
|
+
.optional()
|
|
2380
|
+
.describe("http(s) image URL; empty string clears the avatar."),
|
|
2381
|
+
timezone: z
|
|
2382
|
+
.string()
|
|
2383
|
+
.nullable()
|
|
2384
|
+
.optional()
|
|
2385
|
+
.describe("IANA zone; null returns to browser detection."),
|
|
2386
|
+
}),
|
|
2387
|
+
"me.avatar.uploadUrl": noInput,
|
|
2388
|
+
"me.avatar.set": z.object({
|
|
2389
|
+
storageId: z.string().describe("storageId returned by the upload POST."),
|
|
2390
|
+
}),
|
|
2391
|
+
"me.avatar.clear": noInput,
|
|
2392
|
+
|
|
2285
2393
|
// CRM cells
|
|
2286
2394
|
"crm.cells.get": z.object({
|
|
2287
2395
|
objectName: z.string(),
|
|
@@ -3337,6 +3445,30 @@ export const responseSchemas: Record<string, ZodTypeAny> = {
|
|
|
3337
3445
|
organizationSlug: z.string().nullable(),
|
|
3338
3446
|
organizationName: z.string(),
|
|
3339
3447
|
}),
|
|
3448
|
+
"members.presence": z.array(
|
|
3449
|
+
z.object({
|
|
3450
|
+
userId: z.string(),
|
|
3451
|
+
state: presenceState,
|
|
3452
|
+
lastActiveAt: z.number().nullable(),
|
|
3453
|
+
}),
|
|
3454
|
+
),
|
|
3455
|
+
"members.get": memberProfileShape.nullable(),
|
|
3456
|
+
"members.activity": z.array(memberActivityRow),
|
|
3457
|
+
"members.tasks": z.array(
|
|
3458
|
+
z.object({
|
|
3459
|
+
id: z.string(),
|
|
3460
|
+
name: z.string(),
|
|
3461
|
+
status: z.string().nullable(),
|
|
3462
|
+
dueDate: z.number().nullable(),
|
|
3463
|
+
dueDateKey: z.string().nullable(),
|
|
3464
|
+
done: z.boolean(),
|
|
3465
|
+
}),
|
|
3466
|
+
),
|
|
3467
|
+
"me.profile.get": memberProfileShape.nullable(),
|
|
3468
|
+
"me.profile.update": memberProfileShape,
|
|
3469
|
+
"me.avatar.uploadUrl": z.string().describe("One-time upload URL."),
|
|
3470
|
+
"me.avatar.set": z.object({ image: z.string() }),
|
|
3471
|
+
"me.avatar.clear": okResponse,
|
|
3340
3472
|
"crm.reports.generate": z.object({
|
|
3341
3473
|
spec: z.object({
|
|
3342
3474
|
objectName: z.string(),
|
|
@@ -3866,6 +3998,11 @@ export const requestExamples: Record<string, unknown> = {
|
|
|
3866
3998
|
emailEnabled: true,
|
|
3867
3999
|
perKind: { entry_activity: { email: false } },
|
|
3868
4000
|
},
|
|
4001
|
+
"me.profile.update": {
|
|
4002
|
+
tagline: "Head of Ops",
|
|
4003
|
+
timezone: "America/New_York",
|
|
4004
|
+
},
|
|
4005
|
+
"me.avatar.set": { storageId: "kg2abc123def456" },
|
|
3869
4006
|
"crm.entries.createMany": {
|
|
3870
4007
|
entries: [
|
|
3871
4008
|
{ Name: "Jane", Email: "jane@example.com" },
|
|
@@ -4654,6 +4791,10 @@ export const responseExamples: Record<string, unknown> = {
|
|
|
4654
4791
|
name: "Jane Doe",
|
|
4655
4792
|
email: "jane@acme.com",
|
|
4656
4793
|
image: null,
|
|
4794
|
+
tagline: "Head of Ops",
|
|
4795
|
+
timezone: "America/New_York",
|
|
4796
|
+
presence: "online",
|
|
4797
|
+
lastActiveAt: 1765612790000,
|
|
4657
4798
|
role: "ADMIN",
|
|
4658
4799
|
joinedAt: 1765440000000,
|
|
4659
4800
|
},
|
|
@@ -4662,6 +4803,52 @@ export const responseExamples: Record<string, unknown> = {
|
|
|
4662
4803
|
organizationSlug: "acme",
|
|
4663
4804
|
organizationName: "Acme",
|
|
4664
4805
|
},
|
|
4806
|
+
"members.get": {
|
|
4807
|
+
userId: "us_xyz789",
|
|
4808
|
+
name: "Jane Doe",
|
|
4809
|
+
email: "jane@acme.com",
|
|
4810
|
+
image: null,
|
|
4811
|
+
tagline: "Head of Ops",
|
|
4812
|
+
role: "ADMIN",
|
|
4813
|
+
joinedAt: 1765440000000,
|
|
4814
|
+
timezone: {
|
|
4815
|
+
value: "America/New_York",
|
|
4816
|
+
source: "manual",
|
|
4817
|
+
updatedAt: 1765440000000,
|
|
4818
|
+
},
|
|
4819
|
+
presence: { state: "online", lastActiveAt: 1765612790000 },
|
|
4820
|
+
openTaskCount: 4,
|
|
4821
|
+
commentCount: 31,
|
|
4822
|
+
changeCount: 118,
|
|
4823
|
+
lastContributionAt: 1765612800000,
|
|
4824
|
+
isSelf: false,
|
|
4825
|
+
},
|
|
4826
|
+
"members.activity": [
|
|
4827
|
+
{
|
|
4828
|
+
kind: "comment",
|
|
4829
|
+
id: "cmt_01",
|
|
4830
|
+
entryId: "ent_lead99",
|
|
4831
|
+
objectName: "company",
|
|
4832
|
+
entryLabel: "Ramp",
|
|
4833
|
+
body: "Kickoff went well.",
|
|
4834
|
+
deleted: false,
|
|
4835
|
+
at: 1765612800000,
|
|
4836
|
+
},
|
|
4837
|
+
{
|
|
4838
|
+
kind: "change",
|
|
4839
|
+
id: "hist_01",
|
|
4840
|
+
entryId: "ent_lead99",
|
|
4841
|
+
objectName: "company",
|
|
4842
|
+
entryLabel: "Ramp",
|
|
4843
|
+
changeKind: "update",
|
|
4844
|
+
changes: [{ fieldName: "Status", before: "New", after: "Qualified" }],
|
|
4845
|
+
at: 1765612700000,
|
|
4846
|
+
},
|
|
4847
|
+
],
|
|
4848
|
+
"members.presence": [
|
|
4849
|
+
{ userId: "us_xyz789", state: "online", lastActiveAt: 1765612790000 },
|
|
4850
|
+
{ userId: "us_abc123", state: "offline", lastActiveAt: null },
|
|
4851
|
+
],
|
|
4665
4852
|
"crm.reports.generate": {
|
|
4666
4853
|
spec: {
|
|
4667
4854
|
objectName: "lead",
|
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",
|
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]
|