@wirecat/cli-core 0.706.0 → 0.708.0

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.
@@ -57,7 +57,7 @@ export const LEADS_QUERY = { entity: "lead", backend: "native", fields: DEAL_FIE
57
57
  export const PIPELINES_QUERY = {
58
58
  entity: "pipeline",
59
59
  backend: "native",
60
- fields: [termField("kind", "enum", "kind:lead", { values: DEAL_KINDS })],
60
+ fields: [termField("kind", "enum", "kind:deal", { values: DEAL_KINDS })],
61
61
  };
62
62
  export const STAGES_QUERY = {
63
63
  entity: "stage",
@@ -211,14 +211,16 @@ const addCrmCommandsDefinition = (program, options) => {
211
211
  renderAnswer(command, outputFor(command), body, view);
212
212
  });
213
213
  const example = (command, ...lines) => annotate(command, { examples: lines.map((line) => `${options.app.command} work ${line}`) });
214
+ const hasLeads = options.leads !== false;
215
+ const dealsAndLeads = hasLeads ? "deals and leads" : "deals";
214
216
  example(answerEntity(annotate(program.command("sync"), { effects: FETCH, offline: false, cooperative: true, partial: true }), "crm_sync", crmSync)
215
- .description("bring the CRM's copy in the local store up to date: pipelines, companies, contacts, deals and leads that " +
217
+ .description(`bring the CRM's copy in the local store up to date: pipelines, companies, contacts, ${dealsAndLeads} that ` +
216
218
  "changed since the last sync, or everything with --rescan; a run stops before its deadline or " +
217
219
  "--max-pages and the next one goes on from there")
218
220
  // WireCat Desktop takes a summary of 300 characters at most; the settings' part is help only.
219
- .addHelpText("after", "\nWith the activities setting on, it also copies the activities and tasks on the deals and leads it keeps. " +
220
- "Then each deal or lead that moved into a stage the stage-tasks setting names opens a local task, once " +
221
- "per move."), "sync", "sync --rescan", "sync --max-pages 20")
221
+ .addHelpText("after", `\nWith the activities setting on, it also copies the activities and tasks on the ${dealsAndLeads} it keeps. ` +
222
+ `Then each ${hasLeads ? "deal or lead" : "deal"} that moved into a stage the stage-tasks setting names ` +
223
+ "opens a local task, once per move."), "sync", "sync --rescan", "sync --max-pages 20")
222
224
  .option("--rescan", "list everything again, every id too, dropping a round in progress")
223
225
  .option("--max-pages <pages>", "at most this many requests to the CRM in this run", integer(100_000))
224
226
  .action(async (opts, command) => {
@@ -291,7 +293,7 @@ const addCrmCommandsDefinition = (program, options) => {
291
293
  await within(command, async (run) => {
292
294
  const status = await crmStatus(run.store, run.account, { profile: run.profile, now: now() });
293
295
  if (await viewerOf(run))
294
- outputFor(command).renderer.note("stored counts the whole copy, more than the deals and leads you may read");
296
+ outputFor(command).renderer.note(`stored counts the whole copy, more than the ${dealsAndLeads} you may read`);
295
297
  return listOf(pathOf(command).join(" "), {
296
298
  items: status.items,
297
299
  limit: status.limit,
@@ -300,7 +302,8 @@ const addCrmCommandsDefinition = (program, options) => {
300
302
  });
301
303
  });
302
304
  });
303
- example(answerEntity(annotate(store.command("apply"), { effects: LOCAL_WRITE }), "crm_contacts_removed", crmContactsApplied).description("apply scope mine to the contacts already stored: remove those no deal or lead of the chosen users and no " +
305
+ example(answerEntity(annotate(store.command("apply"), { effects: LOCAL_WRITE }), "crm_contacts_removed", crmContactsApplied).description(`apply scope mine to the contacts already stored: remove those no ${hasLeads ? "deal or lead" : "deal"} ` +
306
+ "of the chosen users and no " +
304
307
  "kept company names, and the people they leave empty; counts only unless --yes, under scope all too. A " +
305
308
  "sync that narrows the scope, or sync --rescan under mine, does this itself"), "store apply", "store apply --yes")
306
309
  .option("--yes", "remove the contacts it counts; otherwise only count them")
@@ -499,7 +502,7 @@ const addCrmCommandsDefinition = (program, options) => {
499
502
  const run = (command, work) => within(command, (opened) => work(contextOf(opened, command)));
500
503
  const create = write("create", "create", `make a ${kind} in the CRM, then store the CRM's copy of it`);
501
504
  if (create)
502
- example(fields(create), `${plural} create --title "Example kitchen" --amount 15000 --currency EUR`, `${plural} create --title "Example office" --pipeline Sales --stage "Quote sent" --field UF_CRM_SOURCE=web`).action(async (opts, command) => {
505
+ example(fields(create), `${plural} create --title "Example kitchen" --amount 15000 --currency EUR`, `${plural} create --title "Example office" --pipeline Sales --stage "Quote sent" --field Source=web`).action(async (opts, command) => {
503
506
  await run(command, async (context) => {
504
507
  const done = await createCrmItem(context, kind, inputOf(opts), idOf(opts));
505
508
  return answered(done.operationId, done.item);
@@ -507,7 +510,7 @@ const addCrmCommandsDefinition = (program, options) => {
507
510
  });
508
511
  const update = write("update", "update", `change a ${kind} in the CRM; what is left out keeps its value; the CRM's copy is stored again`);
509
512
  if (update)
510
- example(fields(reference(update)), `${plural} update ${kind}:12 --amount 18000`, `${plural} update ${kind}:12 --field UF_CRM_SOURCE=`).action(async (ref, opts, command) => {
513
+ example(fields(reference(update)), `${plural} update ${kind}:12 --amount 18000`, `${plural} update ${kind}:12 --field Source=`).action(async (ref, opts, command) => {
511
514
  await run(command, async (context) => {
512
515
  const done = await updateCrmItem(context, kind, ref, inputOf(opts), idOf(opts));
513
516
  return answered(done.operationId, done.item);
@@ -555,7 +558,7 @@ const addCrmCommandsDefinition = (program, options) => {
555
558
  if (options.leads !== false)
556
559
  items("lead");
557
560
  const pipelines = annotate(program.command("pipelines"), { effects: NO_EFFECTS }).description("the CRM's pipelines and their stages, as last synced");
558
- example(withQuery(annotate(pipelines.command("list"), { effects: LOCAL_READ, output: { entity: "pipeline" } }).description("pipelines copied from the CRM, with their stages in order and how many are open in each"), PIPELINES_QUERY), "pipelines list --json", "pipelines list kind:lead").action(async (words, _opts, command) => {
561
+ example(withQuery(annotate(pipelines.command("list"), { effects: LOCAL_READ, output: { entity: "pipeline" } }).description("pipelines copied from the CRM, with their stages in order and how many are open in each"), PIPELINES_QUERY), "pipelines list --json", ...(hasLeads ? ["pipelines list kind:lead"] : [])).action(async (words, _opts, command) => {
559
562
  const terms = queryTerms(words, PIPELINES_QUERY, "pipelines list");
560
563
  await within(command, async (run) => {
561
564
  const found = await run.store.deals.pipelines({
@@ -594,7 +597,7 @@ const addCrmCommandsDefinition = (program, options) => {
594
597
  }, (body) => pipelineView(body, outputFor(command).color));
595
598
  });
596
599
  const stages = annotate(program.command("stages"), { effects: NO_EFFECTS }).description("the stages of the CRM's pipelines, as last synced");
597
- example(withQuery(annotate(stages.command("list"), { effects: LOCAL_READ, output: { entity: "stage" } }).description("every stage of the CRM's pipelines in order, with its outcome and how many are open in it"), STAGES_QUERY), "stages list --json", "stages list kind:lead").action(async (words, _opts, command) => {
600
+ example(withQuery(annotate(stages.command("list"), { effects: LOCAL_READ, output: { entity: "stage" } }).description("every stage of the CRM's pipelines in order, with its outcome and how many are open in it"), STAGES_QUERY), "stages list --json", ...(hasLeads ? ["stages list kind:lead"] : [])).action(async (words, _opts, command) => {
598
601
  const terms = queryTerms(words, STAGES_QUERY, "stages list");
599
602
  await within(command, async (run) => {
600
603
  const kind = terms.has("kind") ? terms.get("kind") : undefined;
@@ -639,6 +642,7 @@ const addCrmCommandsDefinition = (program, options) => {
639
642
  open: options.open,
640
643
  app: options.app,
641
644
  live: options.live ?? [],
645
+ ...(options.liveQuery ? { liveQuery: options.liveQuery } : {}),
642
646
  ...(writes ? { writes } : {}),
643
647
  now,
644
648
  });
@@ -646,7 +650,7 @@ const addCrmCommandsDefinition = (program, options) => {
646
650
  if (options.files)
647
651
  addCrmFileCommands(program, { ...options, within, example, now });
648
652
  const fieldKinds = Object.keys(FIELD_KINDS).filter((word) => word !== "leads" || options.leads !== false);
649
- const fields = annotate(program.command("fields"), { effects: NO_EFFECTS }).description("the CRM's own fields on deals, leads, people and organizations, as last synced");
653
+ const fields = annotate(program.command("fields"), { effects: NO_EFFECTS }).description(`the CRM's own fields on ${hasLeads ? "deals, leads" : "deals"}, people and organizations, as last synced`);
650
654
  example(withQuery(answerEntity(annotate(fields.command("list"), { effects: LOCAL_READ }), "crm_field", crmField)
651
655
  .description("the CRM's custom fields of one kind, in its order, with a list field's options")
652
656
  .argument("<kind>", fieldKinds.join(", "))
@@ -676,7 +680,7 @@ const addCrmCommandsDefinition = (program, options) => {
676
680
  });
677
681
  const search = program.commands.find((one) => one.name() === "search") ??
678
682
  annotate(program.command("search"), { effects: NO_EFFECTS }).description("search what the local store holds");
679
- addCrmSearchAll(search, { within, app: options.app, example, viewerOf });
683
+ addCrmSearchAll(search, { within, app: options.app, example, viewerOf, leads: hasLeads });
680
684
  };
681
685
  // honoursDryRun: a host program other than `run` would otherwise let a write through under --dry-run.
682
686
  export const addCrmCommands = honoursDryRun(sharedCommand(addCrmCommandsDefinition));
@@ -87,6 +87,8 @@ export interface CrmRecordCommandOptions {
87
87
  }) => Promise<CrmRun>;
88
88
  app: AppIdentity;
89
89
  live: readonly CrmLiveRecord[];
90
+ /** `words`: the live lists are the service's own search (a source from a manifest), which takes no field terms. */
91
+ liveQuery?: "fields" | "words";
90
92
  writes?: CrmWriteCapabilities;
91
93
  now: () => number;
92
94
  }
@@ -1,4 +1,4 @@
1
- import { CliError } from "@wirecat/cli-base";
1
+ import { CliError, isCliError } from "@wirecat/cli-base";
2
2
  import { annotate } from "@wirecat/cli-base/commands";
3
3
  import { defineQuery, queryFieldsOf } from "@wirecat/cli-base/query";
4
4
  import { isoTime } from "@wirecat/cli-base/standards";
@@ -7,7 +7,7 @@ import * as v from "valibot";
7
7
  import { answerEntity } from "../../cli/answer-entity.js";
8
8
  import { REMOTE_READ, REMOTE_WRITE } from "../../cli/effects.js";
9
9
  import { itemOf, listOf } from "../../cli/envelope.js";
10
- import { commandPath, listQuery, nativeTerms, searchText, typedQuery, withQuery } from "../../cli/list-query.js";
10
+ import { commandPath, listQuery, nativeTerms, searchText, typedQuery, withQuery, withWords, } from "../../cli/list-query.js";
11
11
  import { terminalAsker } from "../../cli/messenger/ask.js";
12
12
  import { foldName } from "../../resolve.js";
13
13
  import { foreignContacts, foreignContactsPathFor } from "../foreign-contacts.js";
@@ -197,18 +197,24 @@ export const addCrmRecordCommands = (program, options) => {
197
197
  const stored = await run.store.crm.fields(run.account, kind);
198
198
  return stored.length ? stored : ((await run.source().fields?.(kind)) ?? []);
199
199
  };
200
+ const words = options.liveQuery === "words";
200
201
  const records = (noun) => {
201
202
  const group = annotate(program.command(noun.noun), { effects: REMOTE_READ }).description(`the CRM's ${noun.what}, read live: the copy holds only your own`);
202
- example(withQuery(answerEntity(annotate(group.command("list"), { effects: REMOTE_READ, offline: false }), noun.entity, noun.schema), noun.query)
203
+ const query = words
204
+ ? { ...noun.query, fields: noun.query.fields.filter(({ name }) => name === "name") }
205
+ : noun.query;
206
+ const list = answerEntity(annotate(group.command("list"), { effects: REMOTE_READ, offline: false }), noun.entity, noun.schema);
207
+ example((words
208
+ ? withWords(list, query, `words the CRM's own search looks for in ${noun.what}`)
209
+ : withQuery(list, query).addHelpText("after", CUSTOM_HELP))
203
210
  .description(`${noun.what} in the CRM, newest first; another client is found here, never in the copy`)
204
211
  .option("--limit <n>", `${noun.what} per page, 1–${MOST}`, integer(MOST), 50)
205
212
  .option("--page <n>", "which page, starting at 1", integer(1_000_000), 1)
206
- .addOption(csvFormatOption())
207
- .addHelpText("after", CUSTOM_HELP), `${noun.noun} list`, `${noun.noun} list name:anna* --json`, `${noun.noun} list --format csv > ${noun.noun}.csv`).action(async (words, opts, command) => {
213
+ .addOption(csvFormatOption()), `${noun.noun} list`, words ? `${noun.noun} list anna --json` : `${noun.noun} list name:anna* --json`, `${noun.noun} list --format csv > ${noun.noun}.csv`).action(async (words, opts, command) => {
208
214
  const csv = opts.format === "csv";
209
215
  const path = commandPath(command);
210
216
  const text = typedQuery(words);
211
- const names = customNames(text, noun.query, path, "name");
217
+ const names = customNames(text, query, path, "name");
212
218
  const columns = command.optsWithGlobals().fields;
213
219
  const wanted = csv && columns === undefined ? "all" : wantedCodes(columns);
214
220
  const read = async (run) => {
@@ -216,7 +222,7 @@ export const addCrmRecordCommands = (program, options) => {
216
222
  const fields = names.length || wanted !== undefined || csv ? await liveFields(run, noun.kind) : [];
217
223
  const chosen = filterableFields(fields, names);
218
224
  selectedCodes(fields, wanted);
219
- const terms = nativeTerms(listQuery(text, withCustomFields(noun.query, chosen), path, { defaultField: "name" }), path);
225
+ const terms = nativeTerms(listQuery(text, withCustomFields(query, chosen), path, { defaultField: "name" }), path);
220
226
  const custom = customConditions(terms, chosen);
221
227
  const name = searchText(terms.get("name"));
222
228
  terms.delete("name");
@@ -264,9 +270,20 @@ export const addCrmRecordCommands = (program, options) => {
264
270
  users(program, options);
265
271
  };
266
272
  /** By the CRM's id first; else the one record whose whole name is the given one, folded. */
273
+ /** A service whose ids have a fixed shape refuses a word as one (Attio answers 400): the word is then a name. */
274
+ const byIdOrNone = async (run, noun, id) => {
275
+ try {
276
+ return await sourceWith(run, "get", noun.what).get(noun.kind, id);
277
+ }
278
+ catch (error) {
279
+ if (isCliError(error) && error.code === "validation_error")
280
+ return null;
281
+ throw error;
282
+ }
283
+ };
267
284
  const recordNamed = async (run, noun, given) => {
268
285
  const id = given.trim();
269
- const byId = RECORD_ID.test(id) ? await sourceWith(run, "get", noun.what).get(noun.kind, id) : null;
286
+ const byId = RECORD_ID.test(id) ? await byIdOrNone(run, noun, id) : null;
270
287
  if (byId)
271
288
  return byId;
272
289
  const want = foldName(id);
@@ -6,10 +6,12 @@ import type { CrmRun, CrmWithin } from "./index.js";
6
6
  * `search all` in a CRM CLI: the shared search over the store, its own deals and leads beside the messages, notes and
7
7
  * events other WireCat tools stored. A locked profile reads only its own account's deals.
8
8
  */
9
- export declare const addCrmSearchAll: (searches: Command, { within, app, example, viewerOf, }: {
9
+ export declare const addCrmSearchAll: (searches: Command, { within, app, example, viewerOf, leads, }: {
10
10
  within: CrmWithin;
11
11
  app: AppIdentity;
12
12
  example: (command: Command, ...lines: string[]) => Command;
13
13
  /** This profile's rule over its own account's copy, as the other reads of the copy take it. */
14
14
  viewerOf: (run: CrmRun) => Promise<CopyViewer | undefined>;
15
+ /** The CRM has leads. */
16
+ leads?: boolean;
15
17
  }) => void;
@@ -20,13 +20,14 @@ const DEFAULT_LIMIT = 20;
20
20
  * `search all` in a CRM CLI: the shared search over the store, its own deals and leads beside the messages, notes and
21
21
  * events other WireCat tools stored. A locked profile reads only its own account's deals.
22
22
  */
23
- export const addCrmSearchAll = (searches, { within, app, example, viewerOf, }) => {
23
+ export const addCrmSearchAll = (searches, { within, app, example, viewerOf, leads = true, }) => {
24
+ const deals = leads ? "deals and leads" : "deals";
24
25
  const all = annotate(new Command("all"), { effects: LOCAL_READ, partial: true, output: { entity: "hit" } })
25
- .summary("search stored deals and leads, messages, notes, calendar events and meetings")
26
- .description("search the CRM's deals and leads by the words of their title, company, contacts and activities, and the " +
26
+ .summary(`search stored ${deals}, messages, notes, calendar events and meetings`)
27
+ .description(`search the CRM's ${deals} by the words of their title, company, contacts and activities, and the ` +
27
28
  "messages, notes, calendar events and meetings other WireCat tools stored — best match first. Use it when " +
28
29
  "you do not know where something was written")
29
- .argument("<query...>", 'words and "phrases"; deals and leads match the words of their title, company, contacts and activities')
30
+ .argument("<query...>", `words and "phrases"; ${deals} match the words of their title, company, contacts and activities`)
30
31
  .addHelpText("after", SAVE_HELP);
31
32
  searches.addCommand(searchAllOptions(all, SEARCHED));
32
33
  example(all, "search all Example LLC", "search all website --only crm --json");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.706.0",
3
+ "version": "0.708.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",
@@ -326,7 +326,7 @@
326
326
  "@types/pngjs": "6.0.5",
327
327
  "@types/ssh2": "1.15.5",
328
328
  "@vitest/coverage-v8": "^5.0.5",
329
- "@wirecat/cli-base": "0.122.0",
329
+ "@wirecat/cli-base": "0.123.0",
330
330
  "@wirecat/cli-core-legacy-tags": "npm:@wirecat/cli-core@0.414.0",
331
331
  "ajv": "8.17.1",
332
332
  "commander": "15.0.0",