@dench.com/cli 2.8.7-staging.189 → 2.9.0-staging.193
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-comments.ts +303 -0
- package/crm.ts +100 -19
- package/dench.ts +101 -0
- package/email.ts +6 -2
- package/lib/api-schemas.ts +793 -1
- package/lib/command-registry.ts +506 -0
- package/lib/enrichment-gateway.ts +21 -1
- package/notifications.ts +262 -0
- package/package.json +4 -1
package/crm-comments.ts
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dench crm comments …`, `dench crm watch …`, `dench crm tasks …`
|
|
3
|
+
*
|
|
4
|
+
* Thin dispatchers over the Convex functions the entry panel itself uses
|
|
5
|
+
* (`functions/crm/comments`, `functions/crm/tasks`), so the CLI, the
|
|
6
|
+
* `/api/v1` surface, and the UI share one contract. Kept out of `crm.ts`
|
|
7
|
+
* only for file size.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { readFile } from "node:fs/promises";
|
|
11
|
+
import { makeFunctionReference } from "convex/server";
|
|
12
|
+
import {
|
|
13
|
+
assertNoUnknownFlags,
|
|
14
|
+
type CrmCliContext,
|
|
15
|
+
CrmCliError,
|
|
16
|
+
callMutation,
|
|
17
|
+
callQuery,
|
|
18
|
+
out,
|
|
19
|
+
shift,
|
|
20
|
+
} from "./crm";
|
|
21
|
+
import { getFlag, hasFlag } from "./lib/cli-args";
|
|
22
|
+
|
|
23
|
+
const api = {
|
|
24
|
+
comments: {
|
|
25
|
+
listForEntry: makeFunctionReference<"query">(
|
|
26
|
+
"functions/crm/comments:listForEntry",
|
|
27
|
+
),
|
|
28
|
+
listReplies: makeFunctionReference<"query">(
|
|
29
|
+
"functions/crm/comments:listReplies",
|
|
30
|
+
),
|
|
31
|
+
get: makeFunctionReference<"query">("functions/crm/comments:get"),
|
|
32
|
+
create: makeFunctionReference<"mutation">("functions/crm/comments:create"),
|
|
33
|
+
edit: makeFunctionReference<"mutation">("functions/crm/comments:edit"),
|
|
34
|
+
remove: makeFunctionReference<"mutation">("functions/crm/comments:remove"),
|
|
35
|
+
toggleReaction: makeFunctionReference<"mutation">(
|
|
36
|
+
"functions/crm/comments:toggleReaction",
|
|
37
|
+
),
|
|
38
|
+
getWatchState: makeFunctionReference<"query">(
|
|
39
|
+
"functions/crm/comments:getWatchState",
|
|
40
|
+
),
|
|
41
|
+
setWatching: makeFunctionReference<"mutation">(
|
|
42
|
+
"functions/crm/comments:setWatching",
|
|
43
|
+
),
|
|
44
|
+
},
|
|
45
|
+
tasks: {
|
|
46
|
+
listMyOpenTasks: makeFunctionReference<"query">(
|
|
47
|
+
"functions/crm/tasks:listMyOpenTasks",
|
|
48
|
+
),
|
|
49
|
+
listEntryTasks: makeFunctionReference<"query">(
|
|
50
|
+
"functions/crm/tasks:listEntryTasks",
|
|
51
|
+
),
|
|
52
|
+
createEntryTask: makeFunctionReference<"mutation">(
|
|
53
|
+
"functions/crm/tasks:createEntryTask",
|
|
54
|
+
),
|
|
55
|
+
completeTask: makeFunctionReference<"mutation">(
|
|
56
|
+
"functions/crm/tasks:completeTask",
|
|
57
|
+
),
|
|
58
|
+
reopenTask: makeFunctionReference<"mutation">(
|
|
59
|
+
"functions/crm/tasks:reopenTask",
|
|
60
|
+
),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const DENCH_MENTION = "[@Dench](/?member=dench)";
|
|
65
|
+
|
|
66
|
+
function paginationFlags(
|
|
67
|
+
args: string[],
|
|
68
|
+
defaultLimit: number,
|
|
69
|
+
): { numItems: number; cursor: string | null } {
|
|
70
|
+
const rawLimit = getFlag(args, "--limit");
|
|
71
|
+
const limit =
|
|
72
|
+
rawLimit === undefined ? defaultLimit : Number.parseInt(rawLimit, 10);
|
|
73
|
+
if (!Number.isFinite(limit) || limit < 1) {
|
|
74
|
+
throw new CrmCliError("--limit must be a positive integer");
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
numItems: Math.min(limit, 100),
|
|
78
|
+
cursor: getFlag(args, "--cursor") ?? null,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** `--body`, `--body-file`, or piped stdin — in that order. */
|
|
83
|
+
async function readBody(args: string[]): Promise<string> {
|
|
84
|
+
const inline = getFlag(args, "--body");
|
|
85
|
+
if (inline !== undefined) return inline;
|
|
86
|
+
const file = getFlag(args, "--body-file");
|
|
87
|
+
if (file) return await readFile(file, "utf8");
|
|
88
|
+
if (!process.stdin.isTTY) {
|
|
89
|
+
const chunks: Buffer[] = [];
|
|
90
|
+
for await (const chunk of process.stdin) {
|
|
91
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
92
|
+
}
|
|
93
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
94
|
+
if (text.trim()) return text;
|
|
95
|
+
}
|
|
96
|
+
throw new CrmCliError(
|
|
97
|
+
'A comment body is required: pass --body "…", --body-file <path>, or pipe markdown on stdin.',
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Repeated `--mention <userId>` flags. */
|
|
102
|
+
function collectMentions(args: string[]): string[] {
|
|
103
|
+
const ids: string[] = [];
|
|
104
|
+
for (;;) {
|
|
105
|
+
const value = getFlag(args, "--mention");
|
|
106
|
+
if (value === undefined) break;
|
|
107
|
+
if (value.trim()) ids.push(value.trim());
|
|
108
|
+
}
|
|
109
|
+
return ids;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function runCommentsCommand(ctx: CrmCliContext): Promise<void> {
|
|
113
|
+
const verb = ctx.args.shift();
|
|
114
|
+
switch (verb) {
|
|
115
|
+
case "list": {
|
|
116
|
+
const objectName = shift(ctx.args, "object name");
|
|
117
|
+
const entryId = shift(ctx.args, "entry id");
|
|
118
|
+
const paginationOpts = paginationFlags(ctx.args, 20);
|
|
119
|
+
const rawReplies = getFlag(ctx.args, "--replies");
|
|
120
|
+
const previewReplies =
|
|
121
|
+
rawReplies === undefined ? undefined : Number.parseInt(rawReplies, 10);
|
|
122
|
+
assertNoUnknownFlags(ctx.args, "crm comments list");
|
|
123
|
+
out(
|
|
124
|
+
ctx,
|
|
125
|
+
await callQuery(ctx, api.comments.listForEntry, {
|
|
126
|
+
objectName,
|
|
127
|
+
entryId,
|
|
128
|
+
paginationOpts,
|
|
129
|
+
...(previewReplies !== undefined && Number.isFinite(previewReplies)
|
|
130
|
+
? { previewReplies }
|
|
131
|
+
: {}),
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
case "replies": {
|
|
137
|
+
const rootCommentId = shift(ctx.args, "comment id");
|
|
138
|
+
const paginationOpts = paginationFlags(ctx.args, 50);
|
|
139
|
+
assertNoUnknownFlags(ctx.args, "crm comments replies");
|
|
140
|
+
out(
|
|
141
|
+
ctx,
|
|
142
|
+
await callQuery(ctx, api.comments.listReplies, {
|
|
143
|
+
rootCommentId,
|
|
144
|
+
paginationOpts,
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
case "get": {
|
|
150
|
+
const commentId = shift(ctx.args, "comment id");
|
|
151
|
+
assertNoUnknownFlags(ctx.args, "crm comments get");
|
|
152
|
+
out(ctx, await callQuery(ctx, api.comments.get, { commentId }));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
case "create": {
|
|
156
|
+
const objectName = shift(ctx.args, "object name");
|
|
157
|
+
const entryId = shift(ctx.args, "entry id");
|
|
158
|
+
let body = await readBody(ctx.args);
|
|
159
|
+
const parentCommentId = getFlag(ctx.args, "--reply-to");
|
|
160
|
+
const mentionUserIds = collectMentions(ctx.args);
|
|
161
|
+
const mentionDench = hasFlag(ctx.args, "--dench");
|
|
162
|
+
assertNoUnknownFlags(ctx.args, "crm comments create");
|
|
163
|
+
if (mentionDench && !body.includes("/?member=dench")) {
|
|
164
|
+
body = `${DENCH_MENTION} ${body}`;
|
|
165
|
+
}
|
|
166
|
+
out(
|
|
167
|
+
ctx,
|
|
168
|
+
await callMutation(ctx, api.comments.create, {
|
|
169
|
+
objectName,
|
|
170
|
+
entryId,
|
|
171
|
+
body,
|
|
172
|
+
...(parentCommentId ? { parentCommentId } : {}),
|
|
173
|
+
...(mentionUserIds.length > 0 ? { mentionUserIds } : {}),
|
|
174
|
+
...(mentionDench ? { mentionDench: true } : {}),
|
|
175
|
+
...(ctx.runId ? { runId: ctx.runId } : {}),
|
|
176
|
+
}),
|
|
177
|
+
);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
case "update": {
|
|
181
|
+
const commentId = shift(ctx.args, "comment id");
|
|
182
|
+
const body = await readBody(ctx.args);
|
|
183
|
+
assertNoUnknownFlags(ctx.args, "crm comments update");
|
|
184
|
+
out(ctx, await callMutation(ctx, api.comments.edit, { commentId, body }));
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
case "delete": {
|
|
188
|
+
const commentId = shift(ctx.args, "comment id");
|
|
189
|
+
assertNoUnknownFlags(ctx.args, "crm comments delete");
|
|
190
|
+
out(ctx, await callMutation(ctx, api.comments.remove, { commentId }));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
case "react": {
|
|
194
|
+
const commentId = shift(ctx.args, "comment id");
|
|
195
|
+
const emoji = shift(ctx.args, "emoji");
|
|
196
|
+
assertNoUnknownFlags(ctx.args, "crm comments react");
|
|
197
|
+
out(
|
|
198
|
+
ctx,
|
|
199
|
+
await callMutation(ctx, api.comments.toggleReaction, {
|
|
200
|
+
commentId,
|
|
201
|
+
emoji,
|
|
202
|
+
}),
|
|
203
|
+
);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
default:
|
|
207
|
+
throw new CrmCliError(
|
|
208
|
+
`Unknown comments verb: ${verb ?? "(none)"}. Use list | replies | get | create | update | delete | react.`,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export async function runWatchCommand(ctx: CrmCliContext): Promise<void> {
|
|
214
|
+
if (ctx.args[0] === "status") {
|
|
215
|
+
ctx.args.shift();
|
|
216
|
+
const objectName = shift(ctx.args, "object name");
|
|
217
|
+
const entryId = shift(ctx.args, "entry id");
|
|
218
|
+
assertNoUnknownFlags(ctx.args, "crm watch status");
|
|
219
|
+
void objectName;
|
|
220
|
+
out(ctx, await callQuery(ctx, api.comments.getWatchState, { entryId }));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const objectName = shift(ctx.args, "object name");
|
|
224
|
+
const entryId = shift(ctx.args, "entry id");
|
|
225
|
+
const off = hasFlag(ctx.args, "--off");
|
|
226
|
+
assertNoUnknownFlags(ctx.args, "crm watch");
|
|
227
|
+
void objectName;
|
|
228
|
+
out(
|
|
229
|
+
ctx,
|
|
230
|
+
await callMutation(ctx, api.comments.setWatching, {
|
|
231
|
+
entryId,
|
|
232
|
+
watching: !off,
|
|
233
|
+
}),
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export async function runTasksCommand(ctx: CrmCliContext): Promise<void> {
|
|
238
|
+
const verb = ctx.args.shift();
|
|
239
|
+
switch (verb) {
|
|
240
|
+
case "mine": {
|
|
241
|
+
const rawLimit = getFlag(ctx.args, "--limit");
|
|
242
|
+
assertNoUnknownFlags(ctx.args, "crm tasks mine");
|
|
243
|
+
out(
|
|
244
|
+
ctx,
|
|
245
|
+
await callQuery(ctx, api.tasks.listMyOpenTasks, {
|
|
246
|
+
...(rawLimit ? { limit: Number.parseInt(rawLimit, 10) } : {}),
|
|
247
|
+
}),
|
|
248
|
+
);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
case "list": {
|
|
252
|
+
const objectName = shift(ctx.args, "object name");
|
|
253
|
+
const entryId = shift(ctx.args, "entry id");
|
|
254
|
+
assertNoUnknownFlags(ctx.args, "crm tasks list");
|
|
255
|
+
out(
|
|
256
|
+
ctx,
|
|
257
|
+
await callQuery(ctx, api.tasks.listEntryTasks, { objectName, entryId }),
|
|
258
|
+
);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
case "create": {
|
|
262
|
+
const objectName = shift(ctx.args, "object name");
|
|
263
|
+
const entryId = shift(ctx.args, "entry id");
|
|
264
|
+
const name = getFlag(ctx.args, "--name");
|
|
265
|
+
const assigneeUserId = getFlag(ctx.args, "--assignee");
|
|
266
|
+
const dueDateKey = getFlag(ctx.args, "--due");
|
|
267
|
+
assertNoUnknownFlags(ctx.args, "crm tasks create");
|
|
268
|
+
if (!name?.trim()) throw new CrmCliError("--name is required");
|
|
269
|
+
if (dueDateKey && !/^\d{4}-\d{2}-\d{2}$/.test(dueDateKey)) {
|
|
270
|
+
throw new CrmCliError("--due must be YYYY-MM-DD");
|
|
271
|
+
}
|
|
272
|
+
out(
|
|
273
|
+
ctx,
|
|
274
|
+
await callMutation(ctx, api.tasks.createEntryTask, {
|
|
275
|
+
objectName,
|
|
276
|
+
entryId,
|
|
277
|
+
name: name.trim(),
|
|
278
|
+
...(assigneeUserId ? { assigneeUserId } : {}),
|
|
279
|
+
...(dueDateKey ? { dueDateKey } : {}),
|
|
280
|
+
}),
|
|
281
|
+
);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
case "complete":
|
|
285
|
+
case "reopen": {
|
|
286
|
+
const entryId = shift(ctx.args, "task entry id");
|
|
287
|
+
assertNoUnknownFlags(ctx.args, `crm tasks ${verb}`);
|
|
288
|
+
out(
|
|
289
|
+
ctx,
|
|
290
|
+
await callMutation(
|
|
291
|
+
ctx,
|
|
292
|
+
verb === "complete" ? api.tasks.completeTask : api.tasks.reopenTask,
|
|
293
|
+
{ entryId },
|
|
294
|
+
),
|
|
295
|
+
);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
default:
|
|
299
|
+
throw new CrmCliError(
|
|
300
|
+
`Unknown tasks verb: ${verb ?? "(none)"}. Use mine | list | create | complete | reopen.`,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
}
|
package/crm.ts
CHANGED
|
@@ -29,6 +29,11 @@
|
|
|
29
29
|
*/
|
|
30
30
|
import type { ConvexHttpClient } from "convex/browser";
|
|
31
31
|
import { makeFunctionReference } from "convex/server";
|
|
32
|
+
import {
|
|
33
|
+
runCommentsCommand,
|
|
34
|
+
runTasksCommand,
|
|
35
|
+
runWatchCommand,
|
|
36
|
+
} from "./crm-comments";
|
|
32
37
|
import {
|
|
33
38
|
assertNoUnknownFlags as assertNoUnknownFlagsRaw,
|
|
34
39
|
CliArgError,
|
|
@@ -65,7 +70,7 @@ type JsonRecord = Record<string, unknown>;
|
|
|
65
70
|
|
|
66
71
|
const CRM_BATCH_CHUNK_SIZE = 200;
|
|
67
72
|
|
|
68
|
-
type CrmCliContext = {
|
|
73
|
+
export type CrmCliContext = {
|
|
69
74
|
convex: ConvexHttpClient;
|
|
70
75
|
args: string[];
|
|
71
76
|
jsonOutput: boolean;
|
|
@@ -196,7 +201,7 @@ function withCrmEntryDeepLinks(
|
|
|
196
201
|
|
|
197
202
|
// Adapt the shared helpers to throw CrmCliError so existing call sites
|
|
198
203
|
// don't need to change their try/catch shape.
|
|
199
|
-
class CrmCliError extends Error {}
|
|
204
|
+
export class CrmCliError extends Error {}
|
|
200
205
|
|
|
201
206
|
function userFacingConvexErrorMessage(error: unknown): string | null {
|
|
202
207
|
if (!error || typeof error !== "object") return null;
|
|
@@ -224,7 +229,7 @@ function normalizeRpcError(error: unknown): Error {
|
|
|
224
229
|
);
|
|
225
230
|
}
|
|
226
231
|
|
|
227
|
-
function shift(args: string[], expected: string): string {
|
|
232
|
+
export function shift(args: string[], expected: string): string {
|
|
228
233
|
try {
|
|
229
234
|
return shiftRaw(args, expected);
|
|
230
235
|
} catch (error) {
|
|
@@ -307,7 +312,10 @@ function parseJson(value: string | undefined): unknown {
|
|
|
307
312
|
}
|
|
308
313
|
}
|
|
309
314
|
|
|
310
|
-
function assertNoUnknownFlags(
|
|
315
|
+
export function assertNoUnknownFlags(
|
|
316
|
+
args: readonly string[],
|
|
317
|
+
command: string,
|
|
318
|
+
): void {
|
|
311
319
|
try {
|
|
312
320
|
assertNoUnknownFlagsRaw(args, command);
|
|
313
321
|
} catch (error) {
|
|
@@ -512,6 +520,32 @@ type CrmBatchOp =
|
|
|
512
520
|
|
|
513
521
|
type CrmOnConflictPolicy = "skip" | "update" | "error";
|
|
514
522
|
|
|
523
|
+
export const CRM_OBJECT_VISIBILITY_FLAG_VALUES = [
|
|
524
|
+
"workspace",
|
|
525
|
+
"owner_only",
|
|
526
|
+
"owner_plus_members",
|
|
527
|
+
] as const;
|
|
528
|
+
type CrmObjectVisibilityFlag =
|
|
529
|
+
(typeof CRM_OBJECT_VISIBILITY_FLAG_VALUES)[number];
|
|
530
|
+
|
|
531
|
+
/** `--visibility` on `crm objects update`. Undefined when the flag is absent. */
|
|
532
|
+
export function parseObjectVisibilityFlag(
|
|
533
|
+
value: string | undefined,
|
|
534
|
+
): CrmObjectVisibilityFlag | undefined {
|
|
535
|
+
if (value === undefined) return undefined;
|
|
536
|
+
const normalized = value.trim().toLowerCase().replace(/-/g, "_");
|
|
537
|
+
if (
|
|
538
|
+
(CRM_OBJECT_VISIBILITY_FLAG_VALUES as readonly string[]).includes(
|
|
539
|
+
normalized,
|
|
540
|
+
)
|
|
541
|
+
) {
|
|
542
|
+
return normalized as CrmObjectVisibilityFlag;
|
|
543
|
+
}
|
|
544
|
+
throw new Error(
|
|
545
|
+
`--visibility must be one of ${CRM_OBJECT_VISIBILITY_FLAG_VALUES.join(", ")} (got "${value}")`,
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
|
|
515
549
|
function parseOnConflictFlag(raw: string | undefined): CrmOnConflictPolicy {
|
|
516
550
|
const value = raw ?? "skip";
|
|
517
551
|
if (value === "skip" || value === "update" || value === "error") {
|
|
@@ -652,7 +686,7 @@ async function assertKnownDataKeys(
|
|
|
652
686
|
);
|
|
653
687
|
}
|
|
654
688
|
|
|
655
|
-
async function callQuery(
|
|
689
|
+
export async function callQuery(
|
|
656
690
|
ctx: CrmCliContext,
|
|
657
691
|
fn: Parameters<ConvexHttpClient["query"]>[0],
|
|
658
692
|
args: Record<string, unknown> = {},
|
|
@@ -667,7 +701,7 @@ async function callQuery(
|
|
|
667
701
|
}
|
|
668
702
|
}
|
|
669
703
|
|
|
670
|
-
async function callMutation(
|
|
704
|
+
export async function callMutation(
|
|
671
705
|
ctx: CrmCliContext,
|
|
672
706
|
fn: Parameters<ConvexHttpClient["mutation"]>[0],
|
|
673
707
|
args: Record<string, unknown> = {},
|
|
@@ -720,7 +754,7 @@ async function suppressForwardedConvexLogs<T>(
|
|
|
720
754
|
}
|
|
721
755
|
}
|
|
722
756
|
|
|
723
|
-
function out(ctx: CrmCliContext, value: unknown): void {
|
|
757
|
+
export function out(ctx: CrmCliContext, value: unknown): void {
|
|
724
758
|
if (ctx.jsonOutput) {
|
|
725
759
|
console.log(JSON.stringify(value, null, 2));
|
|
726
760
|
return;
|
|
@@ -983,6 +1017,12 @@ export async function runCrmCommand(opts: {
|
|
|
983
1017
|
return await runEntriesCommand(ctx);
|
|
984
1018
|
case "history":
|
|
985
1019
|
return await runHistoryCommand(ctx);
|
|
1020
|
+
case "comments":
|
|
1021
|
+
return await runCommentsCommand(ctx);
|
|
1022
|
+
case "watch":
|
|
1023
|
+
return await runWatchCommand(ctx);
|
|
1024
|
+
case "tasks":
|
|
1025
|
+
return await runTasksCommand(ctx);
|
|
986
1026
|
case "cells":
|
|
987
1027
|
return await runCellsCommand(ctx);
|
|
988
1028
|
case "query":
|
|
@@ -1045,6 +1085,9 @@ const CRM_SUBCOMMANDS = [
|
|
|
1045
1085
|
"fields",
|
|
1046
1086
|
"entries",
|
|
1047
1087
|
"history",
|
|
1088
|
+
"comments",
|
|
1089
|
+
"watch",
|
|
1090
|
+
"tasks",
|
|
1048
1091
|
"cells",
|
|
1049
1092
|
"query",
|
|
1050
1093
|
"sql",
|
|
@@ -1328,18 +1371,28 @@ async function runObjectsCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
1328
1371
|
// Pass an empty string to clear back to the default label.
|
|
1329
1372
|
const displayName = getFlag(ctx.args, "--display-name");
|
|
1330
1373
|
const displayNameSingular = getFlag(ctx.args, "--display-name-singular");
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
ctx,
|
|
1334
|
-
await callMutation(ctx, api.objects.update, {
|
|
1335
|
-
name,
|
|
1336
|
-
description,
|
|
1337
|
-
defaultView,
|
|
1338
|
-
icon,
|
|
1339
|
-
displayName,
|
|
1340
|
-
displayNameSingular,
|
|
1341
|
-
}),
|
|
1374
|
+
// Who may read the object's records. Admin-only on the server.
|
|
1375
|
+
const visibility = parseObjectVisibilityFlag(
|
|
1376
|
+
getFlag(ctx.args, "--visibility"),
|
|
1342
1377
|
);
|
|
1378
|
+
assertNoUnknownFlags(ctx.args, "crm objects update");
|
|
1379
|
+
const updated = await callMutation(ctx, api.objects.update, {
|
|
1380
|
+
name,
|
|
1381
|
+
description,
|
|
1382
|
+
defaultView,
|
|
1383
|
+
icon,
|
|
1384
|
+
displayName,
|
|
1385
|
+
displayNameSingular,
|
|
1386
|
+
visibility,
|
|
1387
|
+
});
|
|
1388
|
+
if (visibility !== undefined && visibility !== "workspace") {
|
|
1389
|
+
process.stderr.write(
|
|
1390
|
+
`note: ${name} records created before this change have no owner and ` +
|
|
1391
|
+
"are hidden from everyone until one is set; switch back to " +
|
|
1392
|
+
"workspace to see them again.\n",
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
1395
|
+
out(ctx, updated);
|
|
1343
1396
|
return;
|
|
1344
1397
|
}
|
|
1345
1398
|
case "rename": {
|
|
@@ -4133,9 +4186,15 @@ Objects (CRM tables):
|
|
|
4133
4186
|
dench crm objects list [--json]
|
|
4134
4187
|
dench crm objects get <name>
|
|
4135
4188
|
dench crm objects create <name> [--description ...] [--default-view kanban] [--icon ...]
|
|
4136
|
-
dench crm objects update <name> [--default-view ...] [--icon ...] [--display-name "Clients"] [--display-name-singular "Client"]
|
|
4189
|
+
dench crm objects update <name> [--default-view ...] [--icon ...] [--display-name "Clients"] [--display-name-singular "Client"] [--visibility workspace|owner_only|owner_plus_members]
|
|
4137
4190
|
--display-name relabels the UI only; the canonical <name> stays the
|
|
4138
4191
|
command/API identifier (works on protected objects too).
|
|
4192
|
+
--visibility sets who can see the object's records: everyone in the
|
|
4193
|
+
workspace, only the record's owner, or the owner plus the members
|
|
4194
|
+
listed on the record. ADMIN-ONLY (a signed-in admin, not an org key);
|
|
4195
|
+
works on protected objects too. Records created before the switch
|
|
4196
|
+
have no owner and are hidden from everyone until one is set; switch
|
|
4197
|
+
back to workspace to see them again.
|
|
4139
4198
|
dench crm objects rename <from> <to>
|
|
4140
4199
|
dench crm objects delete <name>
|
|
4141
4200
|
dench crm objects archive <name> | unarchive <name>
|
|
@@ -4256,6 +4315,28 @@ Entries (rows):
|
|
|
4256
4315
|
dench crm entries list <object> [--limit N] [--with-meta] [--json]
|
|
4257
4316
|
dench crm entries get <object> <entryId>
|
|
4258
4317
|
dench crm history <object> <entryId> [--include-system] [--limit N] [--cursor CURSOR] [--json]
|
|
4318
|
+
|
|
4319
|
+
Comments (the record's Activity feed):
|
|
4320
|
+
dench crm comments list <object> <entryId> [--limit N] [--cursor CURSOR] [--replies N] [--json]
|
|
4321
|
+
dench crm comments replies <commentId> [--limit N] [--cursor CURSOR]
|
|
4322
|
+
dench crm comments get <commentId>
|
|
4323
|
+
dench crm comments create <object> <entryId> --body "markdown" [--body-file f.md] [--reply-to <commentId>] [--mention <userId>]... [--dench]
|
|
4324
|
+
Mention a member inline as [@Name](/?member=<userId>); --dench appends
|
|
4325
|
+
[@Dench](/?member=dench) so the agent replies in the thread. Returns
|
|
4326
|
+
{ id, denchRunId? } immediately — poll 'comments list' for the reply.
|
|
4327
|
+
dench crm comments update <commentId> --body "markdown"
|
|
4328
|
+
dench crm comments delete <commentId>
|
|
4329
|
+
dench crm comments react <commentId> <emoji> (toggles)
|
|
4330
|
+
dench crm watch <object> <entryId> [--off] (follow / unfollow activity)
|
|
4331
|
+
dench crm watch status <object> <entryId>
|
|
4332
|
+
|
|
4333
|
+
Tasks (shortcuts over the protected 'task' object):
|
|
4334
|
+
dench crm tasks mine [--limit N]
|
|
4335
|
+
dench crm tasks list <object> <entryId>
|
|
4336
|
+
dench crm tasks create <object> <entryId> --name "…" [--assignee <userId>] [--due YYYY-MM-DD]
|
|
4337
|
+
dench crm tasks complete <taskEntryId>
|
|
4338
|
+
dench crm tasks reopen <taskEntryId>
|
|
4339
|
+
|
|
4259
4340
|
dench crm entries create <object> --data '{"Field":"Value",...}' (alias: --fields) [--allow-unknown] [--idempotency-key <key>]
|
|
4260
4341
|
--idempotency-key upserts on (object, key): a retried create returns
|
|
4261
4342
|
the existing row with alreadyExisted: true instead of duplicating it.
|
package/dench.ts
CHANGED
|
@@ -244,6 +244,14 @@ function hasFlag(name: string) {
|
|
|
244
244
|
|
|
245
245
|
const BOOLEAN_FLAGS = new Set([
|
|
246
246
|
"--all",
|
|
247
|
+
"--allow-duplicates",
|
|
248
|
+
"--ack-linkedin-risk",
|
|
249
|
+
"--stop-on-reply",
|
|
250
|
+
"--no-stop-on-reply",
|
|
251
|
+
"--clear-start",
|
|
252
|
+
"--clear-end",
|
|
253
|
+
"--reverse",
|
|
254
|
+
"--with-meta",
|
|
247
255
|
"--compact",
|
|
248
256
|
"--dev",
|
|
249
257
|
"--follow",
|
|
@@ -362,6 +370,18 @@ function normalizeCliError(error: unknown): CliError {
|
|
|
362
370
|
],
|
|
363
371
|
});
|
|
364
372
|
}
|
|
373
|
+
if (message.includes("Sign in as a workspace member to run outreach")) {
|
|
374
|
+
return new CliError(
|
|
375
|
+
"Outreach needs a workspace member's credentials — sending accounts belong to a person, not the workspace",
|
|
376
|
+
{
|
|
377
|
+
code: "outreach_member_required",
|
|
378
|
+
nextActions: [
|
|
379
|
+
"Ask the person you are working for to run this from a chat in the Dench app, or to link their account in Slack, so the run carries their own identity. Connecting a sending account does not change whose credentials this run has.",
|
|
380
|
+
"In a terminal, run dench signin as a workspace member. An organization-only DENCH_API_KEY cannot run outreach.",
|
|
381
|
+
],
|
|
382
|
+
},
|
|
383
|
+
);
|
|
384
|
+
}
|
|
365
385
|
if (message.includes("Invalid Dench API key")) {
|
|
366
386
|
return new CliError("Invalid Dench API key", {
|
|
367
387
|
code: "invalid_api_key",
|
|
@@ -517,9 +537,18 @@ CRM (Daytona-native rewrite):
|
|
|
517
537
|
dench crm docs <list|create|link>
|
|
518
538
|
dench crm actions <list|run> ...
|
|
519
539
|
dench crm batch --file ops.jsonl
|
|
540
|
+
dench crm comments <list|get|replies|create|update|delete|react> ... (record Activity feed; --dench summons the agent)
|
|
541
|
+
dench crm watch <object> <entryId> [--off] (follow a record's activity)
|
|
542
|
+
dench crm tasks <mine|list|create|complete|reopen> ...
|
|
520
543
|
Batch write helpers: entries create-many/update-many, cells set-many
|
|
521
544
|
Help: dench crm help
|
|
522
545
|
|
|
546
|
+
Notifications (the bell's inbox):
|
|
547
|
+
dench notifications list [--filter inbox|unread|archived|all] [--limit N] [--json]
|
|
548
|
+
dench notifications count | read <id> [--unread] | read-all | archive <id>
|
|
549
|
+
dench notifications prefs [--set emailEnabled=false] [--set <kind>.email=false]
|
|
550
|
+
Help: dench notifications help
|
|
551
|
+
|
|
523
552
|
Workspace members (for CRM \`user\`-type fields):
|
|
524
553
|
dench members list [--json] (top-level alias)
|
|
525
554
|
dench crm members list [--json] (canonical CRM-scoped name)
|
|
@@ -571,6 +600,16 @@ Managed email campaigns:
|
|
|
571
600
|
dench email campaign status --campaign <id> [--json]
|
|
572
601
|
Help: dench email help
|
|
573
602
|
|
|
603
|
+
Outreach campaigns (email + LinkedIn steps on one schedule; leads move New → Contacted → Replied):
|
|
604
|
+
dench campaign list [--all] [--json]
|
|
605
|
+
dench campaign create --name "Founder outreach" [--timezone America/Los_Angeles] [--window "Mon-Fri 9-18"] [--daily-cap 30] [--json]
|
|
606
|
+
dench campaign steps set <campaign> --file steps.json [--json]
|
|
607
|
+
dench campaign add <campaign> --object lead --view "Q3 targets" [--json]
|
|
608
|
+
dench campaign launch <campaign> [--ack-linkedin-risk] [--json]
|
|
609
|
+
dench campaign get <campaign> [--json] (status, funnel, Now/Next, holds, people)
|
|
610
|
+
dench campaign pause|resume|archive <campaign> [--json]
|
|
611
|
+
Help: dench campaign help
|
|
612
|
+
|
|
574
613
|
Image generation / editing (via the Dench Gateway):
|
|
575
614
|
dench image generate "<prompt>" [--size 1024x1024] [--quality auto|low|medium|high] [--format png|jpeg|webp] [--save-path /workspace/path/file.png] [--output <local file>] [--no-write] [--json]
|
|
576
615
|
dench image edit "<prompt>" --input <path> [--input <path> ...] [--mask <path>] [--size ...] [--quality ...] [--format ...] [--save-path ...] [--output ...] [--json]
|
|
@@ -4569,6 +4608,41 @@ async function main() {
|
|
|
4569
4608
|
return;
|
|
4570
4609
|
}
|
|
4571
4610
|
|
|
4611
|
+
if (command === "notifications") {
|
|
4612
|
+
// The bell's inbox from the terminal. Same auth shape as `dench crm`:
|
|
4613
|
+
// agent sessions read their owner's inbox; org API keys are refused
|
|
4614
|
+
// server-side because there is no person behind them.
|
|
4615
|
+
const subArgs = stripRuntimeFlags(
|
|
4616
|
+
args.slice(args.indexOf("notifications") + 1),
|
|
4617
|
+
);
|
|
4618
|
+
const sub = subArgs[0];
|
|
4619
|
+
const { runNotificationsCommand } = await import("./notifications");
|
|
4620
|
+
if (!sub || sub === "help" || sub === "--help") {
|
|
4621
|
+
// biome-ignore lint/suspicious/noExplicitAny: harmless help-only stub
|
|
4622
|
+
await runNotificationsCommand({ convex: {} as any, args: subArgs });
|
|
4623
|
+
return;
|
|
4624
|
+
}
|
|
4625
|
+
const runtime = await getRuntime();
|
|
4626
|
+
if (runtime.mode === "dev") {
|
|
4627
|
+
await runNotificationsCommand({
|
|
4628
|
+
convex: runtime.client,
|
|
4629
|
+
args: subArgs,
|
|
4630
|
+
sessionToken: encodeDevCrmSessionToken(runtime.workspaceArgs),
|
|
4631
|
+
});
|
|
4632
|
+
return;
|
|
4633
|
+
}
|
|
4634
|
+
const authedRuntime = requireAuthenticatedRuntime(
|
|
4635
|
+
runtime,
|
|
4636
|
+
"dench notifications",
|
|
4637
|
+
);
|
|
4638
|
+
await runNotificationsCommand({
|
|
4639
|
+
convex: authedRuntime.client,
|
|
4640
|
+
args: subArgs,
|
|
4641
|
+
sessionToken: authedRuntime.sessionToken,
|
|
4642
|
+
});
|
|
4643
|
+
return;
|
|
4644
|
+
}
|
|
4645
|
+
|
|
4572
4646
|
if (command === "fs") {
|
|
4573
4647
|
await runFsCommand();
|
|
4574
4648
|
return;
|
|
@@ -4913,6 +4987,33 @@ async function main() {
|
|
|
4913
4987
|
return;
|
|
4914
4988
|
}
|
|
4915
4989
|
|
|
4990
|
+
// `dench campaign` — outreach campaigns (email + LinkedIn steps). Convex
|
|
4991
|
+
// RPC only, member-attributed auth (an organization-only key is refused
|
|
4992
|
+
// server-side; normalizeCliError explains what to do).
|
|
4993
|
+
if (command === "campaign" || command === "campaigns") {
|
|
4994
|
+
const subArgs = stripRuntimeFlags(args.slice(args.indexOf(command) + 1));
|
|
4995
|
+
const sub = subArgs[0];
|
|
4996
|
+
if (!sub || sub === "help" || sub === "--help" || sub === "-h") {
|
|
4997
|
+
const { runCampaignCommand } = await import("./campaign");
|
|
4998
|
+
// biome-ignore lint/suspicious/noExplicitAny: help-only stub, never queries
|
|
4999
|
+
await runCampaignCommand({ convex: {} as any, args: subArgs });
|
|
5000
|
+
return;
|
|
5001
|
+
}
|
|
5002
|
+
const { runCampaignCommand } = await import("./campaign");
|
|
5003
|
+
const runtime = await getRuntime();
|
|
5004
|
+
const authedRuntime = requireAuthenticatedRuntime(
|
|
5005
|
+
runtime,
|
|
5006
|
+
`dench ${command}`,
|
|
5007
|
+
);
|
|
5008
|
+
await runCampaignCommand({
|
|
5009
|
+
convex: authedRuntime.client,
|
|
5010
|
+
args: subArgs,
|
|
5011
|
+
jsonOutput: json,
|
|
5012
|
+
sessionToken: authedRuntime.sessionToken,
|
|
5013
|
+
});
|
|
5014
|
+
return;
|
|
5015
|
+
}
|
|
5016
|
+
|
|
4916
5017
|
// `dench routine` / `dench routines` are UI-friendly aliases for
|
|
4917
5018
|
// `dench cron`. Same dispatch, same auth, same handler — only the
|
|
4918
5019
|
// top-level command name differs to match the workspace UI rename.
|
package/email.ts
CHANGED
|
@@ -416,15 +416,19 @@ Sequences (automatic multi-step follow-ups):
|
|
|
416
416
|
dench email sequence enrollment pause|resume|stop --enrollment <id> [--json]
|
|
417
417
|
dench email sequence archive --sequence <id> [--json]
|
|
418
418
|
|
|
419
|
-
Email + LinkedIn multichannel sequences:
|
|
419
|
+
Email + LinkedIn multichannel sequences (see \`dench campaign\` — the fuller surface: schedule, steps round-trip, fill from a CRM view, Now/Next, per-person controls, activity):
|
|
420
420
|
dench email multichannel create --name "Founder outreach" [--timezone America/Los_Angeles] [--json]
|
|
421
421
|
dench email multichannel list [--all] [--json]
|
|
422
422
|
dench email multichannel status --sequence <id> [--json]
|
|
423
|
+
(--json adds per-person currentRuns[].hold / linkedinAction — why a LinkedIn step is waiting — lastTouches[] with the last delivered step,
|
|
424
|
+
and connectedEntries[].lead { entryId, status }: the Lead each person moves — Status advances New → Contacted → Replied on its own.
|
|
425
|
+
Every touch is also filed as an event on the lead's History tab; read them in the dashboard under the campaign's Activity feed.)
|
|
423
426
|
dench email multichannel flow --sequence <id> --file steps.json [--json]
|
|
424
427
|
dench email multichannel enroll --sequence <id> [--name Ada] [--email ada@x.com] [--linkedin-url https://linkedin.com/in/ada] [--json]
|
|
425
428
|
dench email multichannel enroll-from-object --sequence <id> --object lead --entries id1,id2 [--email-field Email] [--linkedin-field "POC LinkedIn URL"] [--relation-field Contact] [--reverse] [--allow-duplicates] [--json]
|
|
426
429
|
dench email multichannel launch --sequence <id> [--ack-linkedin-risk] [--json]
|
|
427
|
-
dench email multichannel pause|resume|archive --sequence <id> [--json]
|
|
430
|
+
dench email multichannel pause|resume|archive --sequence <id> [--json]
|
|
431
|
+
(see \`dench campaign help\` for the same campaigns with schedule, view-based add, launch checks and the Now/Next feed)`);
|
|
428
432
|
}
|
|
429
433
|
|
|
430
434
|
export async function runEmailCommand(ctx: EmailCliContext): Promise<void> {
|