@dench.com/cli 3.4.0-staging.317 → 3.5.1-staging.328
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/app-sdk.d.ts +126 -0
- package/crm-comments.ts +446 -1
- package/crm-detections.ts +261 -0
- package/crm.ts +223 -13
- package/cron.ts +54 -15
- package/dench.ts +37 -0
- package/lib/api-schemas.ts +73 -0
- package/lib/app-sdk-catalog.generated.ts +16 -0
- package/lib/command-registry.ts +297 -0
- package/package.json +3 -1
- package/settings.ts +229 -0
package/crm-comments.ts
CHANGED
|
@@ -44,6 +44,28 @@ const api = {
|
|
|
44
44
|
"functions/crm/comments:setWatching",
|
|
45
45
|
),
|
|
46
46
|
},
|
|
47
|
+
brief: {
|
|
48
|
+
getForEntry: makeFunctionReference<"query">(
|
|
49
|
+
"functions/crm/intelligence:getForEntry",
|
|
50
|
+
),
|
|
51
|
+
ensure: makeFunctionReference<"mutation">(
|
|
52
|
+
"functions/crm/intelligence:ensure",
|
|
53
|
+
),
|
|
54
|
+
regenerate: makeFunctionReference<"mutation">(
|
|
55
|
+
"functions/crm/intelligence:regenerate",
|
|
56
|
+
),
|
|
57
|
+
},
|
|
58
|
+
activity: {
|
|
59
|
+
listForEntry: makeFunctionReference<"query">(
|
|
60
|
+
"functions/crm/activity:listForEntry",
|
|
61
|
+
),
|
|
62
|
+
countForEntry: makeFunctionReference<"query">(
|
|
63
|
+
"functions/crm/activity:countForEntry",
|
|
64
|
+
),
|
|
65
|
+
listNotesForEntry: makeFunctionReference<"query">(
|
|
66
|
+
"functions/crm/activity:listNotesForEntry",
|
|
67
|
+
),
|
|
68
|
+
},
|
|
47
69
|
tasks: {
|
|
48
70
|
pageAssigned: makeFunctionReference<"query">(
|
|
49
71
|
"functions/crm/tasks:pageAssignedTasks",
|
|
@@ -202,6 +224,8 @@ export async function runCommentsCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
202
224
|
const rawReplies = getFlag(ctx.args, "--replies");
|
|
203
225
|
const previewReplies =
|
|
204
226
|
rawReplies === undefined ? undefined : Number.parseInt(rawReplies, 10);
|
|
227
|
+
const kind = readKindFlag(ctx.args);
|
|
228
|
+
const order = readOrderFlag(ctx.args);
|
|
205
229
|
assertNoUnknownFlags(ctx.args, "crm comments list");
|
|
206
230
|
out(
|
|
207
231
|
ctx,
|
|
@@ -212,6 +236,8 @@ export async function runCommentsCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
212
236
|
...(previewReplies !== undefined && Number.isFinite(previewReplies)
|
|
213
237
|
? { previewReplies }
|
|
214
238
|
: {}),
|
|
239
|
+
...(kind ? { kind } : {}),
|
|
240
|
+
...(order ? { order } : {}),
|
|
215
241
|
}),
|
|
216
242
|
);
|
|
217
243
|
return;
|
|
@@ -242,6 +268,8 @@ export async function runCommentsCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
242
268
|
const parentCommentId = getFlag(ctx.args, "--reply-to");
|
|
243
269
|
const mentionUserIds = collectMentions(ctx.args);
|
|
244
270
|
const mentionDench = hasFlag(ctx.args, "--dench");
|
|
271
|
+
const kind = readKindFlag(ctx.args);
|
|
272
|
+
const title = getFlag(ctx.args, "--title");
|
|
245
273
|
assertNoUnknownFlags(ctx.args, "crm comments create");
|
|
246
274
|
if (mentionDench && !body.includes("/?member=dench")) {
|
|
247
275
|
body = `${DENCH_MENTION} ${body}`;
|
|
@@ -255,6 +283,8 @@ export async function runCommentsCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
255
283
|
...(parentCommentId ? { parentCommentId } : {}),
|
|
256
284
|
...(mentionUserIds.length > 0 ? { mentionUserIds } : {}),
|
|
257
285
|
...(mentionDench ? { mentionDench: true } : {}),
|
|
286
|
+
...(kind ? { kind } : {}),
|
|
287
|
+
...(title !== undefined ? { title } : {}),
|
|
258
288
|
...(ctx.runId ? { runId: ctx.runId } : {}),
|
|
259
289
|
}),
|
|
260
290
|
);
|
|
@@ -263,8 +293,16 @@ export async function runCommentsCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
263
293
|
case "update": {
|
|
264
294
|
const commentId = shift(ctx.args, "comment id");
|
|
265
295
|
const body = await readBody(ctx.args);
|
|
296
|
+
const title = getFlag(ctx.args, "--title");
|
|
266
297
|
assertNoUnknownFlags(ctx.args, "crm comments update");
|
|
267
|
-
out(
|
|
298
|
+
out(
|
|
299
|
+
ctx,
|
|
300
|
+
await callMutation(ctx, api.comments.edit, {
|
|
301
|
+
commentId,
|
|
302
|
+
body,
|
|
303
|
+
...(title !== undefined ? { title } : {}),
|
|
304
|
+
}),
|
|
305
|
+
);
|
|
268
306
|
return;
|
|
269
307
|
}
|
|
270
308
|
case "delete": {
|
|
@@ -293,6 +331,413 @@ export async function runCommentsCommand(ctx: CrmCliContext): Promise<void> {
|
|
|
293
331
|
}
|
|
294
332
|
}
|
|
295
333
|
|
|
334
|
+
function readKindFlag(args: string[]): "comment" | "note" | undefined {
|
|
335
|
+
const raw = getFlag(args, "--kind");
|
|
336
|
+
if (raw === undefined) return undefined;
|
|
337
|
+
if (raw === "comment" || raw === "note") return raw;
|
|
338
|
+
throw new CrmCliError("--kind must be `comment` or `note`");
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function readOrderFlag(args: string[]): "asc" | "desc" | undefined {
|
|
342
|
+
const raw = getFlag(args, "--order");
|
|
343
|
+
if (raw === undefined) return undefined;
|
|
344
|
+
if (raw === "asc" || raw === "desc") return raw;
|
|
345
|
+
throw new CrmCliError("--order must be `asc` or `desc`");
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const ACTIVITY_KINDS = [
|
|
349
|
+
"comment",
|
|
350
|
+
"note",
|
|
351
|
+
"change",
|
|
352
|
+
"email_in",
|
|
353
|
+
"email_out",
|
|
354
|
+
"calendar_event",
|
|
355
|
+
"calendar_notice",
|
|
356
|
+
"meeting",
|
|
357
|
+
"slack_message",
|
|
358
|
+
"linkedin_in",
|
|
359
|
+
"linkedin_out",
|
|
360
|
+
"linkedin_connection",
|
|
361
|
+
] as const;
|
|
362
|
+
type ActivityKind = (typeof ACTIVITY_KINDS)[number];
|
|
363
|
+
|
|
364
|
+
/** `--kind email,meeting` — accepts the ledger kinds plus family aliases. */
|
|
365
|
+
function readActivityKinds(args: string[]): ActivityKind[] | undefined {
|
|
366
|
+
const raw = getFlag(args, "--kind");
|
|
367
|
+
if (raw === undefined) return undefined;
|
|
368
|
+
const out = new Set<ActivityKind>();
|
|
369
|
+
for (const token of raw.split(",").map((part) => part.trim())) {
|
|
370
|
+
if (!token) continue;
|
|
371
|
+
switch (token) {
|
|
372
|
+
case "email":
|
|
373
|
+
case "emails":
|
|
374
|
+
out.add("email_in");
|
|
375
|
+
out.add("email_out");
|
|
376
|
+
break;
|
|
377
|
+
case "meetings":
|
|
378
|
+
out.add("calendar_event");
|
|
379
|
+
out.add("calendar_notice");
|
|
380
|
+
out.add("meeting");
|
|
381
|
+
break;
|
|
382
|
+
case "linkedin":
|
|
383
|
+
out.add("linkedin_in");
|
|
384
|
+
out.add("linkedin_out");
|
|
385
|
+
out.add("linkedin_connection");
|
|
386
|
+
break;
|
|
387
|
+
case "slack":
|
|
388
|
+
out.add("slack_message");
|
|
389
|
+
break;
|
|
390
|
+
case "changes":
|
|
391
|
+
out.add("change");
|
|
392
|
+
break;
|
|
393
|
+
case "comments":
|
|
394
|
+
out.add("comment");
|
|
395
|
+
break;
|
|
396
|
+
case "notes":
|
|
397
|
+
out.add("note");
|
|
398
|
+
break;
|
|
399
|
+
default:
|
|
400
|
+
if ((ACTIVITY_KINDS as readonly string[]).includes(token)) {
|
|
401
|
+
out.add(token as ActivityKind);
|
|
402
|
+
} else {
|
|
403
|
+
throw new CrmCliError(
|
|
404
|
+
`Unknown activity kind "${token}". Use one of: ${ACTIVITY_KINDS.join(", ")} (or email, meetings, linkedin, slack, changes, comments, notes).`,
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return out.size > 0 ? [...out] : undefined;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/** `--since 30d | 12h | 2026-09-01` → epoch ms. */
|
|
413
|
+
export function readSince(args: string[]): number | undefined {
|
|
414
|
+
const raw = getFlag(args, "--since");
|
|
415
|
+
if (raw === undefined) return undefined;
|
|
416
|
+
const rel = /^(\d+)([dhwm])$/i.exec(raw.trim());
|
|
417
|
+
if (rel) {
|
|
418
|
+
const n = Number.parseInt(rel[1], 10);
|
|
419
|
+
const unit = rel[2].toLowerCase();
|
|
420
|
+
const ms =
|
|
421
|
+
unit === "h"
|
|
422
|
+
? 3_600_000
|
|
423
|
+
: unit === "d"
|
|
424
|
+
? 86_400_000
|
|
425
|
+
: unit === "w"
|
|
426
|
+
? 7 * 86_400_000
|
|
427
|
+
: 30 * 86_400_000;
|
|
428
|
+
return Date.now() - n * ms;
|
|
429
|
+
}
|
|
430
|
+
const parsed = Date.parse(raw);
|
|
431
|
+
if (Number.isNaN(parsed)) {
|
|
432
|
+
throw new CrmCliError("--since must look like 30d, 12h, 2w, 3m or a date");
|
|
433
|
+
}
|
|
434
|
+
return parsed;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* `dench crm activity <object> <entryId>` — the record's ledger, newest first
|
|
439
|
+
* by default (the agent wants the latest touch on top), with the Notes
|
|
440
|
+
* document appended last so one call answers "what is going on here".
|
|
441
|
+
*/
|
|
442
|
+
export async function runActivityCommand(ctx: CrmCliContext): Promise<void> {
|
|
443
|
+
const objectName = shift(ctx.args, "object name");
|
|
444
|
+
const entryId = shift(ctx.args, "entry id");
|
|
445
|
+
const kinds = readActivityKinds(ctx.args);
|
|
446
|
+
const order = readOrderFlag(ctx.args) ?? "desc";
|
|
447
|
+
const since = readSince(ctx.args);
|
|
448
|
+
const rawLimit = getFlag(ctx.args, "--limit");
|
|
449
|
+
const limit = rawLimit === undefined ? 40 : Number.parseInt(rawLimit, 10);
|
|
450
|
+
if (!Number.isFinite(limit) || limit < 1 || limit > 200) {
|
|
451
|
+
throw new CrmCliError("--limit must be an integer between 1 and 200");
|
|
452
|
+
}
|
|
453
|
+
const before = getFlag(ctx.args, "--before");
|
|
454
|
+
const after = getFlag(ctx.args, "--after");
|
|
455
|
+
const includeSystem = hasFlag(ctx.args, "--include-system");
|
|
456
|
+
const withNotes = !hasFlag(ctx.args, "--no-notes");
|
|
457
|
+
const withBrief = !hasFlag(ctx.args, "--no-brief");
|
|
458
|
+
assertNoUnknownFlags(ctx.args, "crm activity");
|
|
459
|
+
|
|
460
|
+
const page = (await callQuery(ctx, api.activity.listForEntry, {
|
|
461
|
+
objectName,
|
|
462
|
+
entryId,
|
|
463
|
+
order,
|
|
464
|
+
limit,
|
|
465
|
+
includeSystem,
|
|
466
|
+
...(kinds ? { kinds } : {}),
|
|
467
|
+
...(since !== undefined ? { after: since } : {}),
|
|
468
|
+
...(before !== undefined ? { before: Number(before) } : {}),
|
|
469
|
+
...(after !== undefined ? { after: Number(after) } : {}),
|
|
470
|
+
})) as {
|
|
471
|
+
items: Array<Record<string, unknown>>;
|
|
472
|
+
hasMore: boolean;
|
|
473
|
+
nextBoundary: number | null;
|
|
474
|
+
};
|
|
475
|
+
const counts = await callQuery(ctx, api.activity.countForEntry, {
|
|
476
|
+
objectName,
|
|
477
|
+
entryId,
|
|
478
|
+
includeSystem,
|
|
479
|
+
...(kinds ? { kinds } : {}),
|
|
480
|
+
});
|
|
481
|
+
let brief: BriefResponse | null = null;
|
|
482
|
+
if (withBrief) {
|
|
483
|
+
brief = await readBrief(ctx, objectName, entryId);
|
|
484
|
+
}
|
|
485
|
+
let notes: unknown;
|
|
486
|
+
if (withNotes) {
|
|
487
|
+
const entry = (await callQuery(
|
|
488
|
+
ctx,
|
|
489
|
+
makeFunctionReference<"query">("functions/crm/entries:get"),
|
|
490
|
+
{ objectName, entryId },
|
|
491
|
+
)) as { data?: Record<string, unknown> } | null;
|
|
492
|
+
const raw = entry?.data?.Notes ?? entry?.data?.notes;
|
|
493
|
+
notes = typeof raw === "string" && raw.trim() ? raw : null;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
if (ctx.jsonOutput) {
|
|
497
|
+
out(ctx, {
|
|
498
|
+
order,
|
|
499
|
+
...(withBrief ? { brief } : {}),
|
|
500
|
+
...page,
|
|
501
|
+
counts,
|
|
502
|
+
...(withNotes ? { notes } : {}),
|
|
503
|
+
});
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const lines: string[] = [];
|
|
507
|
+
lines.push(
|
|
508
|
+
`Activity for ${objectName}/${entryId} (${order === "desc" ? "newest first" : "oldest first"}, ${(counts as { total: number; capped: boolean }).total}${(counts as { capped: boolean }).capped ? "+" : ""} total)`,
|
|
509
|
+
);
|
|
510
|
+
if (withBrief) {
|
|
511
|
+
lines.push(...formatBriefLines(brief));
|
|
512
|
+
lines.push("");
|
|
513
|
+
}
|
|
514
|
+
for (const item of page.items) lines.push(formatActivityLine(item));
|
|
515
|
+
if (page.hasMore && page.nextBoundary !== null) {
|
|
516
|
+
lines.push(
|
|
517
|
+
`… more — continue with --${order === "desc" ? "before" : "after"} ${page.nextBoundary}`,
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
if (withNotes) {
|
|
521
|
+
lines.push("");
|
|
522
|
+
lines.push("Notes document:");
|
|
523
|
+
lines.push(typeof notes === "string" ? notes : "(empty)");
|
|
524
|
+
}
|
|
525
|
+
out(ctx, lines.join("\n"));
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
type BriefRow = {
|
|
529
|
+
scope: "shared" | "private";
|
|
530
|
+
status: "generating" | "ready" | "failed";
|
|
531
|
+
headline?: string;
|
|
532
|
+
body?: string;
|
|
533
|
+
facets?: {
|
|
534
|
+
relationshipStatus?: string;
|
|
535
|
+
awaitingReplyFrom: "us" | "them" | "none";
|
|
536
|
+
health: string;
|
|
537
|
+
openCommitments: number;
|
|
538
|
+
};
|
|
539
|
+
provenance?: { counts: Record<string, number> };
|
|
540
|
+
generatedAt?: number;
|
|
541
|
+
stale: boolean;
|
|
542
|
+
error?: string;
|
|
543
|
+
};
|
|
544
|
+
type BriefResponse = {
|
|
545
|
+
shared: BriefRow | null;
|
|
546
|
+
private: BriefRow | null;
|
|
547
|
+
hasMaterial: boolean;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
async function readBrief(
|
|
551
|
+
ctx: CrmCliContext,
|
|
552
|
+
objectName: string,
|
|
553
|
+
entryId: string,
|
|
554
|
+
): Promise<BriefResponse | null> {
|
|
555
|
+
try {
|
|
556
|
+
// Opening the record warms it and starts a Brief when there is none.
|
|
557
|
+
await callMutation(ctx, api.brief.ensure, { objectName, entryId });
|
|
558
|
+
} catch {
|
|
559
|
+
/* read-only sessions still get whatever exists */
|
|
560
|
+
}
|
|
561
|
+
return (await callQuery(ctx, api.brief.getForEntry, {
|
|
562
|
+
objectName,
|
|
563
|
+
entryId,
|
|
564
|
+
})) as BriefResponse;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function formatBriefLines(brief: BriefResponse | null): string[] {
|
|
568
|
+
const lead = brief?.shared ?? brief?.private ?? null;
|
|
569
|
+
if (!brief?.hasMaterial) return ["Brief: nothing on this record yet."];
|
|
570
|
+
if (!lead || (lead.status === "generating" && !lead.body)) {
|
|
571
|
+
return [
|
|
572
|
+
"Brief: preparing — re-run in a minute (dench crm brief <object> <id>).",
|
|
573
|
+
];
|
|
574
|
+
}
|
|
575
|
+
const lines: string[] = [];
|
|
576
|
+
const facets = lead.facets
|
|
577
|
+
? ` [${lead.facets.health} · awaiting: ${lead.facets.awaitingReplyFrom} · ${lead.facets.openCommitments} open commitment${lead.facets.openCommitments === 1 ? "" : "s"}]`
|
|
578
|
+
: "";
|
|
579
|
+
const when = lead.generatedAt
|
|
580
|
+
? ` (${new Date(lead.generatedAt).toISOString()}${lead.stale ? ", newer activity exists" : ""})`
|
|
581
|
+
: "";
|
|
582
|
+
lines.push(`Brief${facets}${when}`);
|
|
583
|
+
if (lead.headline) lines.push(lead.headline);
|
|
584
|
+
if (lead.body) lines.push(lead.body);
|
|
585
|
+
if (brief.private?.body && brief.shared) {
|
|
586
|
+
lines.push("", "Private addendum (your inbox only):");
|
|
587
|
+
if (brief.private.headline) lines.push(brief.private.headline);
|
|
588
|
+
lines.push(brief.private.body);
|
|
589
|
+
}
|
|
590
|
+
return lines;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* `dench crm brief <object> <entryId>` — the record's generated Brief, the
|
|
595
|
+
* agent's first read before `crm activity`. `--regenerate` rebuilds it.
|
|
596
|
+
*/
|
|
597
|
+
export async function runBriefCommand(ctx: CrmCliContext): Promise<void> {
|
|
598
|
+
const objectName = shift(ctx.args, "object name");
|
|
599
|
+
const entryId = shift(ctx.args, "entry id");
|
|
600
|
+
const regenerate = hasFlag(ctx.args, "--regenerate");
|
|
601
|
+
assertNoUnknownFlags(ctx.args, "crm brief");
|
|
602
|
+
if (regenerate) {
|
|
603
|
+
await callMutation(ctx, api.brief.regenerate, { objectName, entryId });
|
|
604
|
+
}
|
|
605
|
+
const brief = await readBrief(ctx, objectName, entryId);
|
|
606
|
+
if (ctx.jsonOutput) {
|
|
607
|
+
out(ctx, brief);
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
out(ctx, formatBriefLines(brief).join("\n"));
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function formatActivityLine(item: Record<string, unknown>): string {
|
|
614
|
+
const at = new Date(item.at as number).toISOString();
|
|
615
|
+
if (item.type === "comment") {
|
|
616
|
+
const c = item.comment as {
|
|
617
|
+
kind: string;
|
|
618
|
+
title?: string;
|
|
619
|
+
body: string;
|
|
620
|
+
actor: { displayName?: string; label: string };
|
|
621
|
+
replyCount: number;
|
|
622
|
+
};
|
|
623
|
+
const who = c.actor.displayName ?? c.actor.label;
|
|
624
|
+
const head = c.kind === "note" ? `NOTE ${c.title ?? ""}`.trim() : "COMMENT";
|
|
625
|
+
const body = c.body.replace(/\s+/g, " ").trim();
|
|
626
|
+
const replies = c.replyCount > 0 ? ` (+${c.replyCount} replies)` : "";
|
|
627
|
+
return `${at} ${head} ${who}: ${body.slice(0, 300)}${replies}`;
|
|
628
|
+
}
|
|
629
|
+
if (item.type === "change") {
|
|
630
|
+
const row = item.row as {
|
|
631
|
+
actor: { displayName?: string; label: string };
|
|
632
|
+
changeKind: string;
|
|
633
|
+
changes: Array<{ fieldName: string }>;
|
|
634
|
+
};
|
|
635
|
+
const who = row.actor.displayName ?? row.actor.label;
|
|
636
|
+
const fields = row.changes.map((c) => c.fieldName).join(", ");
|
|
637
|
+
return `${at} CHANGE ${who} ${row.changeKind}${fields ? `: ${fields}` : ""}`;
|
|
638
|
+
}
|
|
639
|
+
// A conversation: one line per thread, at its newest message.
|
|
640
|
+
const t = item.thread as {
|
|
641
|
+
kind: string;
|
|
642
|
+
title: string;
|
|
643
|
+
summary: string;
|
|
644
|
+
messageCount: number;
|
|
645
|
+
role: "direct" | "copied";
|
|
646
|
+
participants: Array<{ label: string }>;
|
|
647
|
+
visibility: string;
|
|
648
|
+
};
|
|
649
|
+
const who = t.participants
|
|
650
|
+
.map((p) => p.label)
|
|
651
|
+
.slice(0, 3)
|
|
652
|
+
.join(", ");
|
|
653
|
+
const tags = [
|
|
654
|
+
t.visibility === "workspace" ? "" : "private",
|
|
655
|
+
t.role === "copied" ? "cc only" : "",
|
|
656
|
+
t.messageCount > 1 ? `${t.messageCount} msgs` : "",
|
|
657
|
+
]
|
|
658
|
+
.filter(Boolean)
|
|
659
|
+
.join(", ");
|
|
660
|
+
return `${at} ${t.kind.toUpperCase()}${tags ? ` [${tags}]` : ""} ${who ? `${who} — ` : ""}${t.title}${t.summary ? ` — ${t.summary}` : ""}`;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/** `dench crm notes …` — sugar over comments with `kind: note`. */
|
|
664
|
+
export async function runNotesCommand(ctx: CrmCliContext): Promise<void> {
|
|
665
|
+
const verb = ctx.args.shift();
|
|
666
|
+
switch (verb) {
|
|
667
|
+
case "list": {
|
|
668
|
+
const objectName = shift(ctx.args, "object name");
|
|
669
|
+
const entryId = shift(ctx.args, "entry id");
|
|
670
|
+
const rawLimit = getFlag(ctx.args, "--limit");
|
|
671
|
+
const limit = rawLimit === undefined ? 50 : Number.parseInt(rawLimit, 10);
|
|
672
|
+
if (!Number.isFinite(limit) || limit < 1) {
|
|
673
|
+
throw new CrmCliError("--limit must be a positive integer");
|
|
674
|
+
}
|
|
675
|
+
assertNoUnknownFlags(ctx.args, "crm notes list");
|
|
676
|
+
out(
|
|
677
|
+
ctx,
|
|
678
|
+
await callQuery(ctx, api.activity.listNotesForEntry, {
|
|
679
|
+
objectName,
|
|
680
|
+
entryId,
|
|
681
|
+
limit,
|
|
682
|
+
}),
|
|
683
|
+
);
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
case "get": {
|
|
687
|
+
const commentId = shift(ctx.args, "note id");
|
|
688
|
+
assertNoUnknownFlags(ctx.args, "crm notes get");
|
|
689
|
+
out(ctx, await callQuery(ctx, api.comments.get, { commentId }));
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
case "create": {
|
|
693
|
+
const objectName = shift(ctx.args, "object name");
|
|
694
|
+
const entryId = shift(ctx.args, "entry id");
|
|
695
|
+
const body = await readBody(ctx.args);
|
|
696
|
+
const title = getFlag(ctx.args, "--title");
|
|
697
|
+
const mentionUserIds = collectMentions(ctx.args);
|
|
698
|
+
assertNoUnknownFlags(ctx.args, "crm notes create");
|
|
699
|
+
out(
|
|
700
|
+
ctx,
|
|
701
|
+
await callMutation(ctx, api.comments.create, {
|
|
702
|
+
objectName,
|
|
703
|
+
entryId,
|
|
704
|
+
body,
|
|
705
|
+
kind: "note",
|
|
706
|
+
...(title !== undefined ? { title } : {}),
|
|
707
|
+
...(mentionUserIds.length > 0 ? { mentionUserIds } : {}),
|
|
708
|
+
...(ctx.runId ? { runId: ctx.runId } : {}),
|
|
709
|
+
}),
|
|
710
|
+
);
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
case "update": {
|
|
714
|
+
const commentId = shift(ctx.args, "note id");
|
|
715
|
+
const body = await readBody(ctx.args);
|
|
716
|
+
const title = getFlag(ctx.args, "--title");
|
|
717
|
+
assertNoUnknownFlags(ctx.args, "crm notes update");
|
|
718
|
+
out(
|
|
719
|
+
ctx,
|
|
720
|
+
await callMutation(ctx, api.comments.edit, {
|
|
721
|
+
commentId,
|
|
722
|
+
body,
|
|
723
|
+
...(title !== undefined ? { title } : {}),
|
|
724
|
+
}),
|
|
725
|
+
);
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
case "delete": {
|
|
729
|
+
const commentId = shift(ctx.args, "note id");
|
|
730
|
+
assertNoUnknownFlags(ctx.args, "crm notes delete");
|
|
731
|
+
out(ctx, await callMutation(ctx, api.comments.remove, { commentId }));
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
default:
|
|
735
|
+
throw new CrmCliError(
|
|
736
|
+
`Unknown notes verb: ${verb ?? "(none)"}. Use list | get | create | update | delete.`,
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
296
741
|
export async function runWatchCommand(ctx: CrmCliContext): Promise<void> {
|
|
297
742
|
if (ctx.args[0] === "status") {
|
|
298
743
|
ctx.args.shift();
|