@wirecat/cli-core 0.640.0 → 0.641.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.
- package/CHANGELOG.md +50 -0
- package/dist/cli/messenger/backfill-command.js +16 -1
- package/dist/cli/messenger/search-answers.js +2 -0
- package/dist/cli/store-settings.d.ts +4 -1
- package/dist/cli/store-settings.js +26 -9
- package/dist/crm/cli/csv.js +2 -0
- package/dist/crm/cli/index.js +8 -2
- package/dist/crm/cli/search-all.js +4 -4
- package/dist/crm/stage-tasks.d.ts +8 -0
- package/dist/crm/stage-tasks.js +42 -0
- package/dist/domain/crm.d.ts +6 -0
- package/dist/entities/deal.d.ts +6 -0
- package/dist/entities/deal.js +3 -0
- package/dist/entities/index.d.ts +4 -0
- package/dist/runs/events.d.ts +9 -1
- package/dist/runs/events.js +5 -1
- package/dist/runs/log-events.js +2 -0
- package/dist/services/deal-context.js +17 -0
- package/dist/services/message-resolution.d.ts +1 -1
- package/dist/services/message-resolution.js +2 -2
- package/dist/services/messages-search.js +12 -5
- package/dist/services/search-all.d.ts +10 -3
- package/dist/services/search-all.js +10 -4
- package/dist/store/index.d.ts +1 -1
- package/dist/store/sqlite/crm-rows.js +2 -0
- package/dist/store/sqlite/crm-settings.d.ts +26 -1
- package/dist/store/sqlite/crm-settings.js +104 -1
- package/dist/store/sqlite/crm.d.ts +12 -0
- package/dist/store/sqlite/crm.js +4 -1
- package/dist/store/sqlite/deals.d.ts +28 -5
- package/dist/store/sqlite/deals.js +158 -14
- package/dist/store/sqlite/lucene-fields.js +56 -3
- package/dist/store/sqlite/tasks.js +9 -8
- package/dist/tasks/model.d.ts +6 -2
- package/dist/tasks/service.d.ts +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,56 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.641.0 — 11.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **A deal or a lead keeps the person and company its CRM holds on the item itself.** A lead often has no contact or
|
|
13
|
+
company linked yet; its own name and company were all it said of who it is, and they were dropped. `CrmItem` takes
|
|
14
|
+
`contactName` and `companyName`, the store keeps them, `deals show` and `leads show` answer them as `contact_name`
|
|
15
|
+
and `company_name` (marked untrusted, as a CRM's users or a web form wrote them), the CSV export has both columns, and
|
|
16
|
+
`search all` finds the item by them, the name as a contact and the company as a company. See
|
|
17
|
+
[ARCHITECTURE.md](docs/dev/ARCHITECTURE.md).
|
|
18
|
+
- **A deal or lead entering a stage opens a local task.** The owner's setting `crm.<provider>:<account>.stage-tasks`
|
|
19
|
+
maps a stage to a task, `{"<stage id>": {"title": "…", "due_days": 2}}`, a lead's stage as `lead:<stage id>`. After
|
|
20
|
+
each CRM `sync`, every move into such a stage since the last sync opens one task, due that many days later, whose
|
|
21
|
+
description names the deal, the stage and the responsible user. A move counts once: a dismissed task never comes
|
|
22
|
+
back, and entering the stage again opens a new one. Moves made before the setting was first saved, and a new row's
|
|
23
|
+
first stage, open none. The sync answer's `stage_tasks` says how many it opened, a deal's context lists them, and
|
|
24
|
+
an agent cannot change the setting. See
|
|
25
|
+
[KNOWLEDGE.md, "Relationships a source reports"](docs/dev/KNOWLEDGE.md#relationships-a-source-reports).
|
|
26
|
+
- **`NewTask.title` and `description`.** A rule that knows what to do gives its task a title and a description.
|
|
27
|
+
- **A part inside a word in chat messages.** `*договор*` without a field, or under `text:` or `exact:`, finds «Договор», «ДОГОВОРЫ» and «переговоры» through the store's index of three-letter pieces of message text, which every store already has. A large archive no longer refuses it, and it works inside `AND`/`OR`/`NOT`, groups, and with `chat:` and `date:`. Case does not matter, and ё and е are one letter; other letters match as typed. The part needs three letters in a row. `*вор`, `*дог*вор` and `*гов?р*` use the same index and are then checked word by word; a part found in too many messages is `query.too-large`, which `chat:`, `date:` or `*part*` avoid. Mail, transcripts and file text keep the word list and its `word*` hint.
|
|
28
|
+
- **A run's log keeps the progress of `messages sync`.** Each progress line is also a `sync.progress` event with its counts, whatever the output format, so `runs show` tells what a desktop app's bar showed and when ([reference](docs/REFERENCE.md)).
|
|
29
|
+
|
|
30
|
+
### Changed — may break callers
|
|
31
|
+
|
|
32
|
+
- **`Deal` has two more fields, `contactName` and `companyName` (`string | null`).** A caller that builds a whole
|
|
33
|
+
`Deal` adds both; the `deal` and `lead` entities require `contact_name` and `company_name`. The CSV export of deals
|
|
34
|
+
and leads has the two new columns after `organization`, so a reader that takes columns by position moves past them.
|
|
35
|
+
- **`*part*` in chat-message text no longer folds й/и or accents.** Through the word list, `*мои*` also found «мой» and `*cafe*` found «café»; through the trigram index the part matches as typed, except case and ё/е. Write the letter as the text has it, or search the whole word (`мой`), which still folds them.
|
|
36
|
+
- **CRM search no longer matches inside a word.** `cement` no longer finds `replacement`, nor «кто» «Вектор». A query
|
|
37
|
+
word shorter than four letters matches only a whole word.
|
|
38
|
+
- **`search all stage:won` skips deals and leads with the reason** instead of finding none and calling the answer
|
|
39
|
+
complete; so do `status:` and `pipeline:`. `deals list stage:<name>` lists them by stage.
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
|
|
43
|
+
- **A search over chats and mail together says when mail was left out.** Mail refused for a reason other than a messenger field (such as `*word*` over a large mailbox) used to drop out silently, so the answer looked complete; it is now listed under `skipped` with the reason.
|
|
44
|
+
- **`to:`, `cc:` and `bcc:` name themselves when nobody matches.** The error said `from:owner — nobody matches` for `to:owner`.
|
|
45
|
+
- **`list:` in a search without a mail account is refused** as `subject:` and `to:` are (`query.unsupported-field`, "list: is a mail field"), instead of finding nothing.
|
|
46
|
+
- **`search all` finds deals and leads by any form of a word, and by their company and contacts.** A query word
|
|
47
|
+
matches a stored word it begins or one of the same stem, so «поставки цемента» finds «Поставка цемента» and
|
|
48
|
+
`repairs` finds `Forklift repair`. A deal's or a lead's company name and its contacts' names, e-mails and phones are
|
|
49
|
+
searched too, never the owner's, and a CRM copy only by what its own CRM holds of them, so a locked profile learns
|
|
50
|
+
nothing of a person's other accounts; `+79161234567` finds `+7 916 123-45-67`. `found_by` stays `title` when the title
|
|
51
|
+
matched and is `words` when only the company or a contact did. `deals.find` gives each hit's `matched` parts. See
|
|
52
|
+
[ARCHITECTURE.md](docs/dev/ARCHITECTURE.md).
|
|
53
|
+
- **A misspelt CRM search is corrected once.** When nothing matches as typed, a word is corrected to the nearest
|
|
54
|
+
stored words, as messages search does, and those hits carry `match: "corrected"` and `corrections`. `--exact` turns
|
|
55
|
+
forms, word beginnings and correction off.
|
|
56
|
+
- **`messages sync --all` reports progress while a chat is read.** Its progress line on stderr came only when a chat was finished, so a chat of many paced pages showed the same count for minutes, and a desktop app's bar stood still at the first chat. Every page now updates `fetched`, with the chat totals of `--all`.
|
|
57
|
+
|
|
8
58
|
## 0.640.0 — 11.11.2026
|
|
9
59
|
|
|
10
60
|
### Added
|
|
@@ -7,6 +7,7 @@ import { Command } from "commander";
|
|
|
7
7
|
import { parseDuration } from "../../domain/duration.js";
|
|
8
8
|
import { isCliFailure } from "../../errors/failures.js";
|
|
9
9
|
import { envName } from "../../ports/app.js";
|
|
10
|
+
import { runEvent } from "../../runs/scope.js";
|
|
10
11
|
import { FETCHING } from "../../services/archive.js";
|
|
11
12
|
import { JOBS_QUERY, jobItems } from "../../services/job-query.js";
|
|
12
13
|
import { dateWindow } from "../../services/moment.js";
|
|
@@ -172,6 +173,8 @@ export const syncCommand = (messenger) => {
|
|
|
172
173
|
const stop = stopOnSignal(this);
|
|
173
174
|
// A background job keeps its log as it was; its progress is the job file.
|
|
174
175
|
const progress = syncProgress(stepLines(context.streams.diagnostic, !jobId && context.format !== "pretty"));
|
|
176
|
+
// One chat of --all can take minutes of paced pages: its pages move the count, not only its end.
|
|
177
|
+
let walked = { chats: 0, done: 0, fetched: 0 };
|
|
175
178
|
try {
|
|
176
179
|
const options = {
|
|
177
180
|
limit,
|
|
@@ -189,8 +192,13 @@ export const syncCommand = (messenger) => {
|
|
|
189
192
|
updateJob(jobs, jobId, { progress: { ...page, at: new Date().toISOString() } });
|
|
190
193
|
if (chat !== undefined)
|
|
191
194
|
progress({ chats: null, chats_done: null, fetched: page.fetched });
|
|
195
|
+
else
|
|
196
|
+
progress({ chats: walked.chats, chats_done: walked.done, fetched: walked.fetched + page.fetched });
|
|
197
|
+
},
|
|
198
|
+
onChat: (counts) => {
|
|
199
|
+
walked = counts;
|
|
200
|
+
progress({ chats: counts.chats, chats_done: counts.done, fetched: counts.fetched }, counts.done === 0 || counts.done === counts.chats);
|
|
192
201
|
},
|
|
193
|
-
onChat: ({ chats, done, fetched }) => progress({ chats, chats_done: done, fetched }, done === 0 || done === chats),
|
|
194
202
|
};
|
|
195
203
|
const result = await context.withServices((services) => chat === undefined ? services.archive.fetchAll(options) : services.archive.fetch(chat, options));
|
|
196
204
|
if (jobId)
|
|
@@ -258,6 +266,7 @@ const PROGRESS_EVERY_MS = 500;
|
|
|
258
266
|
/**
|
|
259
267
|
* `messages sync`'s progress for a window to draw a bar by: counts only, because the lines reach a desktop app and
|
|
260
268
|
* its logs — never a chat's id or title. `always` keeps the first and the last line of `--all` through the throttle.
|
|
269
|
+
* The run's log gets the same counts as `sync.progress`, whatever the output format.
|
|
261
270
|
*/
|
|
262
271
|
const syncProgress = (emit) => {
|
|
263
272
|
let last = Number.NEGATIVE_INFINITY;
|
|
@@ -267,6 +276,12 @@ const syncProgress = (emit) => {
|
|
|
267
276
|
return;
|
|
268
277
|
last = now;
|
|
269
278
|
emit({ event: "progress", step: "sync", ...counts });
|
|
279
|
+
runEvent({
|
|
280
|
+
event: "progress",
|
|
281
|
+
operation: "sync.progress",
|
|
282
|
+
kind: "progress",
|
|
283
|
+
counts: Object.fromEntries(Object.entries(counts).filter((entry) => entry[1] !== null)),
|
|
284
|
+
});
|
|
270
285
|
};
|
|
271
286
|
};
|
|
272
287
|
/**
|
|
@@ -332,6 +332,8 @@ export const allHitItem = (item) => item.kind === "meeting"
|
|
|
332
332
|
sender_is_me: item.senderIsMe,
|
|
333
333
|
sender_ref: item.from?.ref,
|
|
334
334
|
found_by: item.foundBy,
|
|
335
|
+
match: item.match,
|
|
336
|
+
corrections: item.corrections,
|
|
335
337
|
review: item.review,
|
|
336
338
|
source_record: item.sourceRecord === undefined
|
|
337
339
|
? undefined
|
|
@@ -7,7 +7,10 @@ export declare const STORE_SETTINGS: string[];
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const storeSettingsOf: (app: Pick<AppIdentity, "messenger">) => string[];
|
|
9
9
|
export declare const offersStoreSetting: (app: Pick<AppIdentity, "messenger">, setting: string) => boolean;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Whose deals a CRM copy holds and what opens the owner's tasks: the owner's to set; an agent's run is stopped from
|
|
12
|
+
* changing them by mistake.
|
|
13
|
+
*/
|
|
11
14
|
export declare const isOwnerOnlyStoreSetting: (setting: string) => boolean;
|
|
12
15
|
export declare const isStoreSetting: (setting: string) => boolean;
|
|
13
16
|
export declare const changeStoreSetting: (app: AppIdentity, env: NodeJS.ProcessEnv, setting: string, value: string | undefined) => Promise<{
|
|
@@ -33,10 +33,10 @@ export const STORE_SETTINGS = [
|
|
|
33
33
|
];
|
|
34
34
|
const GROUP_PREFIX = `${ACCOUNT_GROUPS_SETTING}.`;
|
|
35
35
|
/**
|
|
36
|
-
* A CRM account's: whether what it reports is a relationship or waits for review, what its company types mean,
|
|
37
|
-
*
|
|
36
|
+
* A CRM account's: whether what it reports is a relationship or waits for review, what its company types mean, whose
|
|
37
|
+
* deals and leads its sync copies, and which stages open a task.
|
|
38
38
|
*/
|
|
39
|
-
const CRM_SETTINGS = ["links", "company-types", "scope", "unassigned", "self"].map((name) => `crm.<provider>:<account>.${name}`);
|
|
39
|
+
const CRM_SETTINGS = ["links", "company-types", "scope", "unassigned", "self", "stage-tasks"].map((name) => `crm.<provider>:<account>.${name}`);
|
|
40
40
|
/**
|
|
41
41
|
* The store settings a CLI offers. Phone countries, task rules and account groups belong to messages; a CLI that is
|
|
42
42
|
* not a messenger would change them for tg and MAX without reading them itself.
|
|
@@ -45,10 +45,13 @@ export const storeSettingsOf = (app) => app.messenger === false
|
|
|
45
45
|
? [...Object.keys(SCRIPTS), OWNER_LANGUAGES, ...CRM_SETTINGS]
|
|
46
46
|
: [...STORE_SETTINGS, `${GROUP_PREFIX}<name>`, ...CRM_SETTINGS];
|
|
47
47
|
export const offersStoreSetting = (app, setting) => app.messenger !== false || setting in SCRIPTS || setting === OWNER_LANGUAGES || parseCrmSetting(setting) !== undefined;
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Whose deals a CRM copy holds and what opens the owner's tasks: the owner's to set; an agent's run is stopped from
|
|
50
|
+
* changing them by mistake.
|
|
51
|
+
*/
|
|
49
52
|
export const isOwnerOnlyStoreSetting = (setting) => {
|
|
50
53
|
const name = parseCrmSetting(setting)?.name;
|
|
51
|
-
return name === "scope" || name === "self" || name === "unassigned";
|
|
54
|
+
return name === "scope" || name === "self" || name === "unassigned" || name === "stage-tasks";
|
|
52
55
|
};
|
|
53
56
|
export const isStoreSetting = (setting) => setting in SCRIPTS ||
|
|
54
57
|
setting === OWNER_LANGUAGES ||
|
|
@@ -261,10 +264,19 @@ const crmValueText = (value) => typeof value === "string"
|
|
|
261
264
|
? value
|
|
262
265
|
: Array.isArray(value)
|
|
263
266
|
? value.join(",")
|
|
264
|
-
: Object.
|
|
265
|
-
.
|
|
266
|
-
.
|
|
267
|
-
|
|
267
|
+
: Object.values(value).some((one) => typeof one === "object")
|
|
268
|
+
? JSON.stringify(value)
|
|
269
|
+
: Object.entries(value)
|
|
270
|
+
.map(([type, meaning]) => `${type}=${meaning}`)
|
|
271
|
+
.join(",");
|
|
272
|
+
const CRM_DEFAULTS = {
|
|
273
|
+
links: "reported",
|
|
274
|
+
"company-types": {},
|
|
275
|
+
scope: "mine",
|
|
276
|
+
unassigned: [],
|
|
277
|
+
self: "",
|
|
278
|
+
"stage-tasks": {},
|
|
279
|
+
};
|
|
268
280
|
const crmNote = (name, now) => {
|
|
269
281
|
if (name === "links")
|
|
270
282
|
return `store-wide — the next sync of that account writes what it reports as ${now === "review" ? "proposals for the owner to review" : "reported relationships"}; relationships already stored stay`;
|
|
@@ -277,6 +289,11 @@ const crmNote = (name, now) => {
|
|
|
277
289
|
"of the unassigned users, and marks the others deleted here; contacts and companies stay whole";
|
|
278
290
|
if (name === "unassigned")
|
|
279
291
|
return "store-wide — with scope mine, the next sync also copies the deals and leads of these users";
|
|
292
|
+
if (name === "stage-tasks")
|
|
293
|
+
return Object.keys(now).length === 0
|
|
294
|
+
? "store-wide — no stage opens a task"
|
|
295
|
+
: "store-wide — from now on, each sync opens a local task for every deal or lead that moved into one of these " +
|
|
296
|
+
"stages since the last sync; moves made before the rules were first set open none";
|
|
280
297
|
return now === ""
|
|
281
298
|
? "store-wide — the next sync gives the account's copy to its sign-in's user, and narrows it to that user's deals"
|
|
282
299
|
: "store-wide — the account's copy holds this user's deals; a sync signed in as another user is refused";
|
package/dist/crm/cli/csv.js
CHANGED
package/dist/crm/cli/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import { DEAL_KINDS, DEAL_STATUSES } from "../../domain/deals.js";
|
|
|
15
15
|
import { deal as dealEntity } from "../../entities/deal.js";
|
|
16
16
|
import { count, text } from "../../entities/fields.js";
|
|
17
17
|
import { CRM_SCOPES, crmSettingKey } from "../../store/sqlite/crm-settings.js";
|
|
18
|
+
import { openStageTasks } from "../stage-tasks.js";
|
|
18
19
|
import { crmStatus, syncCrm } from "../sync.js";
|
|
19
20
|
import { closeCrmItem, createCrmItem, fieldPairsOf, moveCrmItem, pipelineOf, removeCrmItem, updateCrmItem, } from "../writes.js";
|
|
20
21
|
import { csvFormatOption, renderCsv } from "./csv.js";
|
|
@@ -53,6 +54,8 @@ const DEAL_UNTRUSTED = [
|
|
|
53
54
|
"stage",
|
|
54
55
|
"pipeline_name",
|
|
55
56
|
"organization.name",
|
|
57
|
+
"contact_name",
|
|
58
|
+
"company_name",
|
|
56
59
|
"people.name",
|
|
57
60
|
"provider_metadata",
|
|
58
61
|
];
|
|
@@ -76,6 +79,7 @@ const crmSync = v.strictObject({
|
|
|
76
79
|
users: v.optional(count),
|
|
77
80
|
skipped_owner_rejected: count,
|
|
78
81
|
contacts_removed: v.optional(crmContactsRemoved),
|
|
82
|
+
stage_tasks: count,
|
|
79
83
|
synced: v.array(v.strictObject({
|
|
80
84
|
kind: v.picklist(CRM_KINDS),
|
|
81
85
|
round: v.picklist(["full", "changes"]),
|
|
@@ -184,7 +188,8 @@ const addCrmCommandsDefinition = (program, options) => {
|
|
|
184
188
|
const example = (command, ...lines) => annotate(command, { examples: lines.map((line) => `${options.app.command} work ${line}`) });
|
|
185
189
|
example(answerEntity(annotate(program.command("sync"), { effects: FETCH, offline: false, cooperative: true, partial: true }), "crm_sync", crmSync).description("bring the CRM's copy in the local store up to date: pipelines, companies, contacts, deals and leads that " +
|
|
186
190
|
"changed since the last sync, or everything with --rescan; a run stops before its deadline or --max-pages " +
|
|
187
|
-
"and the next one goes on from there
|
|
191
|
+
"and the next one goes on from there. Then each deal or lead that moved into a stage the stage-tasks setting " +
|
|
192
|
+
"names opens a local task, once per move"), "sync", "sync --rescan", "sync --max-pages 20")
|
|
188
193
|
.option("--rescan", "list everything again, every id too, dropping a round in progress")
|
|
189
194
|
.option("--max-pages <pages>", "at most this many requests to the CRM in this run", integer(100_000))
|
|
190
195
|
.action(async (opts, command) => {
|
|
@@ -196,6 +201,7 @@ const addCrmCommandsDefinition = (program, options) => {
|
|
|
196
201
|
...(signal ? { signal } : {}),
|
|
197
202
|
...(opts.rescan ? { rescan: true } : {}),
|
|
198
203
|
});
|
|
204
|
+
const stageTasks = await openStageTasks(run.store, run.account, now());
|
|
199
205
|
const failed = report.synced.filter((one) => one.error !== undefined);
|
|
200
206
|
// A kind that failed on a setting fails the same way again until the owner changes it: no retry is offered.
|
|
201
207
|
const retried = failed.filter((one) => one.setting === undefined);
|
|
@@ -241,7 +247,7 @@ const addCrmCommandsDefinition = (program, options) => {
|
|
|
241
247
|
})),
|
|
242
248
|
];
|
|
243
249
|
const partial = report.state === "partial" || issues.length > 0;
|
|
244
|
-
return itemOf(snakeKeys({ ...rest, ...(hint === undefined ? {} : { hint }) }), {
|
|
250
|
+
return itemOf(snakeKeys({ ...rest, stageTasks, ...(hint === undefined ? {} : { hint }) }), {
|
|
245
251
|
...(partial ? { meta: { complete: false, ...(issues.length ? { issues } : {}) } } : {}),
|
|
246
252
|
...(next ? { next } : {}),
|
|
247
253
|
});
|
|
@@ -22,10 +22,10 @@ const DEFAULT_LIMIT = 20;
|
|
|
22
22
|
export const addCrmSearchAll = (searches, { within, app, example, }) => {
|
|
23
23
|
const all = annotate(new Command("all"), { effects: LOCAL_READ, partial: true, output: { entity: "hit" } })
|
|
24
24
|
.summary("search stored deals and leads, messages, notes, calendar events and meetings")
|
|
25
|
-
.description("search the CRM's deals and leads by the words of their title, and messages, notes,
|
|
26
|
-
"meetings other WireCat tools stored — best match first. Use it when you do not know
|
|
27
|
-
"written")
|
|
28
|
-
.argument("<query...>", 'words and "phrases"; deals and leads match the words of their title')
|
|
25
|
+
.description("search the CRM's deals and leads by the words of their title, company and contacts, and messages, notes, " +
|
|
26
|
+
"calendar events and meetings other WireCat tools stored — best match first. Use it when you do not know " +
|
|
27
|
+
"where something was written")
|
|
28
|
+
.argument("<query...>", 'words and "phrases"; deals and leads match the words of their title, company and contacts')
|
|
29
29
|
.addHelpText("after", SAVE_HELP);
|
|
30
30
|
searches.addCommand(searchAllOptions(all, SEARCHED));
|
|
31
31
|
example(all, "search all Example LLC", "search all website --only crm --json");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MessageStore } from "../store/store.js";
|
|
2
|
+
import type { AccountKey } from "../store/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Opens the owner's task for each stage a deal or lead of the account entered that its `stage-tasks` setting names:
|
|
5
|
+
* one per entry, so a dismissed task never comes back and a later entry into the same stage opens a new one.
|
|
6
|
+
* Answers how many it opened.
|
|
7
|
+
*/
|
|
8
|
+
export declare const openStageTasks: (store: MessageStore, account: AccountKey, now: number) => Promise<number>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { taskAccount } from "../services/task-rules.js";
|
|
2
|
+
import { createTaskService } from "../tasks/index.js";
|
|
3
|
+
const DAY = 86_400_000;
|
|
4
|
+
/**
|
|
5
|
+
* Opens the owner's task for each stage a deal or lead of the account entered that its `stage-tasks` setting names:
|
|
6
|
+
* one per entry, so a dismissed task never comes back and a later entry into the same stage opens a new one.
|
|
7
|
+
* Answers how many it opened.
|
|
8
|
+
*/
|
|
9
|
+
export const openStageTasks = async (store, account, now) => {
|
|
10
|
+
const rules = await store.crm.stageTasks(account);
|
|
11
|
+
if (Object.keys(rules.deal).length + Object.keys(rules.lead).length === 0)
|
|
12
|
+
return 0;
|
|
13
|
+
const { moves, through } = await store.crm.stageMoves(account);
|
|
14
|
+
// Every deal entering a stage gets the same title, so the duplicate review would pair tasks of different deals.
|
|
15
|
+
const { reviewDuplicates: _review, ...tasks } = store.tasks;
|
|
16
|
+
const service = createTaskService({ store: tasks, now: () => new Date(now) });
|
|
17
|
+
let opened = 0;
|
|
18
|
+
for (const move of moves) {
|
|
19
|
+
const rule = rules[move.kind][move.stage];
|
|
20
|
+
if (!rule)
|
|
21
|
+
continue;
|
|
22
|
+
const item = await store.deals.get(move.ref);
|
|
23
|
+
const responsible = item.people.find((one) => one.role === "owner")?.name ??
|
|
24
|
+
(item.assignee === null ? "nobody" : `CRM user ${item.assignee.split("/").at(-1)}`);
|
|
25
|
+
const { created } = await service.add({
|
|
26
|
+
source: `${move.ref}/move/${move.id}`,
|
|
27
|
+
sourceKind: move.kind,
|
|
28
|
+
account: taskAccount(account),
|
|
29
|
+
group: move.ref,
|
|
30
|
+
kind: "request",
|
|
31
|
+
origin: "rule",
|
|
32
|
+
dueAt: new Date(now + rule.dueDays * DAY),
|
|
33
|
+
title: rule.title,
|
|
34
|
+
description: `${item.title} (${move.ref}) entered the stage ${move.stageName} of the pipeline ${move.pipelineName}. ` +
|
|
35
|
+
`Responsible: ${responsible}.`,
|
|
36
|
+
});
|
|
37
|
+
if (created)
|
|
38
|
+
opened += 1;
|
|
39
|
+
}
|
|
40
|
+
await store.crm.markStageMoves(account, through);
|
|
41
|
+
return opened;
|
|
42
|
+
};
|
package/dist/domain/crm.d.ts
CHANGED
|
@@ -40,6 +40,12 @@ export interface CrmItem {
|
|
|
40
40
|
closedReason?: string | null;
|
|
41
41
|
/** A company's id. */
|
|
42
42
|
organization?: string | null;
|
|
43
|
+
/**
|
|
44
|
+
* A lead's own person and company, as the CRM keeps them on the item itself: a lead often has no contact or company
|
|
45
|
+
* linked yet, and these are then all it says of who it is.
|
|
46
|
+
*/
|
|
47
|
+
contactName?: string | null;
|
|
48
|
+
companyName?: string | null;
|
|
43
49
|
/**
|
|
44
50
|
* Contacts on it, by their id, the part each plays and whether the CRM marks one its main contact. Left out, the CRM
|
|
45
51
|
* did not say who is on it, and the people stored stay.
|
package/dist/entities/deal.d.ts
CHANGED
|
@@ -24,6 +24,9 @@ export declare const deal: v.StrictObjectSchema<{
|
|
|
24
24
|
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
25
25
|
readonly owner: v.BooleanSchema<undefined>;
|
|
26
26
|
}, undefined>, undefined>;
|
|
27
|
+
/** A CRM copy's own person and company as the CRM keeps them on it, such as a lead's with nobody linked yet. */
|
|
28
|
+
readonly contact_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
29
|
+
readonly company_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
27
30
|
readonly currency: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
28
31
|
readonly amount: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
29
32
|
readonly close_date: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>;
|
|
@@ -90,6 +93,9 @@ export declare const lead: v.StrictObjectSchema<{
|
|
|
90
93
|
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
91
94
|
readonly owner: v.BooleanSchema<undefined>;
|
|
92
95
|
}, undefined>, undefined>;
|
|
96
|
+
/** A CRM copy's own person and company as the CRM keeps them on it, such as a lead's with nobody linked yet. */
|
|
97
|
+
readonly contact_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
98
|
+
readonly company_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
93
99
|
readonly currency: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
94
100
|
readonly amount: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
95
101
|
readonly close_date: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>;
|
package/dist/entities/deal.js
CHANGED
|
@@ -24,6 +24,9 @@ export const deal = v.strictObject({
|
|
|
24
24
|
base_stage: v.nullable(v.strictObject({ ref: reference, name: text })),
|
|
25
25
|
status: outcome,
|
|
26
26
|
organization: v.nullable(party),
|
|
27
|
+
/** A CRM copy's own person and company as the CRM keeps them on it, such as a lead's with nobody linked yet. */
|
|
28
|
+
contact_name: nullableText,
|
|
29
|
+
company_name: nullableText,
|
|
27
30
|
currency: nullableText,
|
|
28
31
|
amount: nullableText,
|
|
29
32
|
close_date: day,
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -256,6 +256,8 @@ export declare const ENTITIES: {
|
|
|
256
256
|
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
257
257
|
readonly owner: v.BooleanSchema<undefined>;
|
|
258
258
|
}, undefined>, undefined>;
|
|
259
|
+
readonly contact_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
260
|
+
readonly company_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
259
261
|
readonly currency: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
260
262
|
readonly amount: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
261
263
|
readonly close_date: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>;
|
|
@@ -315,6 +317,8 @@ export declare const ENTITIES: {
|
|
|
315
317
|
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
316
318
|
readonly owner: v.BooleanSchema<undefined>;
|
|
317
319
|
}, undefined>, undefined>;
|
|
320
|
+
readonly contact_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
321
|
+
readonly company_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
318
322
|
readonly currency: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
319
323
|
readonly amount: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
320
324
|
readonly close_date: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>;
|
package/dist/runs/events.d.ts
CHANGED
|
@@ -73,7 +73,15 @@ export interface StoreEvent {
|
|
|
73
73
|
op: "insert" | "update" | "delete";
|
|
74
74
|
n: number;
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
/** What a long command showed as its progress, so a run's log says what its window drew: counts, never a name. */
|
|
77
|
+
export interface ProgressEvent {
|
|
78
|
+
event: "progress";
|
|
79
|
+
/** `sync.progress`: the step that drew it. */
|
|
80
|
+
operation: string;
|
|
81
|
+
kind: "progress";
|
|
82
|
+
counts: Record<string, number>;
|
|
83
|
+
}
|
|
84
|
+
export type DiagnosticEvent = RequestEvent | CacheEvent | WarningEvent | StoreEvent | ProgressEvent;
|
|
77
85
|
export type EventSink = (event: DiagnosticEvent) => void;
|
|
78
86
|
/** A sentence for a person, and the warning event it stands for when there is one: a log record keeps only the event. */
|
|
79
87
|
export type Warn = (message: string, warning?: WarningEvent) => void;
|
package/dist/runs/events.js
CHANGED
|
@@ -11,6 +11,10 @@ export const providerErrorKey = (value) => typeof value === "string" && /^[A-Za-
|
|
|
11
11
|
export const renderEvent = (event) => {
|
|
12
12
|
if (event.event === "store")
|
|
13
13
|
return `${MARK.store} ${event.operation.padEnd(16)} ${event.table} ${event.op} ${event.n}`;
|
|
14
|
+
if (event.event === "progress")
|
|
15
|
+
return `${MARK.progress} ${event.operation.padEnd(16)} ${Object.entries(event.counts)
|
|
16
|
+
.map(([field, count]) => `${count} ${field}`)
|
|
17
|
+
.join(" ")}`;
|
|
14
18
|
if (event.event === "warning") {
|
|
15
19
|
const counts = Object.entries(event.counts ?? {}).map(([field, count]) => `${count} ${field}`);
|
|
16
20
|
return [`${MARK.warning} ${(event.operation ?? "").padEnd(16)} ${event.code}`, ...counts, event.detail]
|
|
@@ -55,6 +59,6 @@ export const renderEvent = (event) => {
|
|
|
55
59
|
}
|
|
56
60
|
return `${MARK[event.event]} ${event.operation.padEnd(16)} ${parts.join(" ")}`.trimEnd();
|
|
57
61
|
};
|
|
58
|
-
const MARK = { request: "→", response: "←", cache: "•", warning: "!", store: "+" };
|
|
62
|
+
const MARK = { request: "→", response: "←", cache: "•", warning: "!", store: "+", progress: "…" };
|
|
59
63
|
const age = (ms) => (ms < 1000 ? `${ms}ms` : `${Math.round(ms / 1000)}s`);
|
|
60
64
|
const size = (bytes) => (bytes < 1000 ? `${bytes} B` : `${(bytes / 1000).toFixed(1)} kB`);
|
package/dist/runs/log-events.js
CHANGED
|
@@ -10,6 +10,7 @@ export const CORE_LOG_EVENTS = defineLogEvents([
|
|
|
10
10
|
keys: ["operation", "reason"],
|
|
11
11
|
},
|
|
12
12
|
{ id: "store.write", meaning: "a committed write changed rows of one store table", keys: ["table", "op", "n"] },
|
|
13
|
+
{ id: "sync.progress", meaning: "what a sync's progress line showed: chats and messages so far", keys: ["counts"] },
|
|
13
14
|
{ id: "command.crashed", meaning: "a command failed on a bug; where, never what", keys: ["error_class", "frames"] },
|
|
14
15
|
{
|
|
15
16
|
id: "events.dropped",
|
|
@@ -34,4 +35,5 @@ export const DIAGNOSTIC_LOG_EVENTS = {
|
|
|
34
35
|
warning: "client.warning",
|
|
35
36
|
cache: "cache.answered",
|
|
36
37
|
store: "store.write",
|
|
38
|
+
progress: "sync.progress",
|
|
37
39
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { isUsable } from "../domain/relations.js";
|
|
3
|
+
import { isClosedState } from "../tasks/index.js";
|
|
3
4
|
import { coverageFor, edgesOf, grouped, namesOf, notRejected, organizationCategories, SECTION_LIMIT, STORE_PAGE, scopeOf, sectionOf, } from "./business-context.js";
|
|
4
5
|
import { communicationsOf } from "./communications.js";
|
|
5
6
|
import { moneyOf } from "./money-context.js";
|
|
@@ -74,6 +75,22 @@ export const dealContext = async (store, reference, { accounts, limit = SECTION_
|
|
|
74
75
|
const said = talks.counts.messages + talks.counts.mail + talks.counts.meetings;
|
|
75
76
|
const stages = await store.deals.stages(deal.ref);
|
|
76
77
|
const tasks = await openTasksOf(store, project ? [{ ref: project.ref, key: project.key }] : []);
|
|
78
|
+
const opened = await store.tasks.find({
|
|
79
|
+
where: { sql: "t.source_group = ?", params: [deal.ref] },
|
|
80
|
+
limit: STORE_PAGE,
|
|
81
|
+
});
|
|
82
|
+
for (const task of opened)
|
|
83
|
+
if (!isClosedState(task.status) && !tasks.tasks.some((one) => one.ref === task.ref))
|
|
84
|
+
tasks.tasks.push({
|
|
85
|
+
ref: task.ref,
|
|
86
|
+
key: task.key,
|
|
87
|
+
title: task.title,
|
|
88
|
+
status: task.status,
|
|
89
|
+
project: task.project,
|
|
90
|
+
dueAt: task.dueAt,
|
|
91
|
+
});
|
|
92
|
+
tasks.full ||= opened.length >= STORE_PAGE;
|
|
93
|
+
tasks.tasks.sort((a, b) => (a.dueAt ?? "~").localeCompare(b.dueAt ?? "~") || a.ref.localeCompare(b.ref));
|
|
77
94
|
return {
|
|
78
95
|
deal,
|
|
79
96
|
stages: sectionOf(stages, limit, null, { newest: true }),
|
|
@@ -30,7 +30,7 @@ export declare const chatAmong: (messenger: Saved, store: MessageStore, accounts
|
|
|
30
30
|
chatId: Id;
|
|
31
31
|
}>;
|
|
32
32
|
/** A sender, through the names each messenger's accounts have seen; `from:` names one person. */
|
|
33
|
-
export declare const senderAmong: (store: MessageStore, accounts: AccountKey[], reference: string) => Promise<{
|
|
33
|
+
export declare const senderAmong: (store: MessageStore, accounts: AccountKey[], reference: string, field?: string) => Promise<{
|
|
34
34
|
provider: string;
|
|
35
35
|
id: string;
|
|
36
36
|
}>;
|
|
@@ -149,7 +149,7 @@ export const chatAmong = async (messenger, store, accounts, reference) => {
|
|
|
149
149
|
})));
|
|
150
150
|
};
|
|
151
151
|
/** A sender, through the names each messenger's accounts have seen; `from:` names one person. */
|
|
152
|
-
export const senderAmong = async (store, accounts, reference) => {
|
|
152
|
+
export const senderAmong = async (store, accounts, reference, field = "from") => {
|
|
153
153
|
const providers = [...new Set(accounts.map(({ provider }) => provider))];
|
|
154
154
|
const [only] = accounts;
|
|
155
155
|
try {
|
|
@@ -175,7 +175,7 @@ export const senderAmong = async (store, accounts, reference) => {
|
|
|
175
175
|
}
|
|
176
176
|
catch (error) {
|
|
177
177
|
if (error instanceof CliError && error.code === "not_found") {
|
|
178
|
-
throw new CliError("not_found",
|
|
178
|
+
throw new CliError("not_found", `${field}:${reference} — ${error.message}`);
|
|
179
179
|
}
|
|
180
180
|
throw error;
|
|
181
181
|
}
|
|
@@ -14,7 +14,7 @@ import { mailAround, mergeMail, withMailThreads } from "./mail-search.js";
|
|
|
14
14
|
import { chatAmong, chatsMatchingIn, senderAmong, sendersMatching } from "./message-resolution.js";
|
|
15
15
|
import { accountsOfKind, listedAccounts, MAIL } from "./search-kind.js";
|
|
16
16
|
const PERSON_FIELDS = new Set(["from", "to", "cc", "bcc"]);
|
|
17
|
-
const MAIL_FIELDS = new Set(["to", "cc", "bcc", "subject", "mailbox", "label", "is"]);
|
|
17
|
+
const MAIL_FIELDS = new Set(["to", "cc", "bcc", "subject", "mailbox", "label", "is", "list"]);
|
|
18
18
|
import { dateRange, parseLucene, timezoneOf, walkQuery, } from "@wirecat/cli-base/query";
|
|
19
19
|
import { MESSAGE_PARSING, searchError } from "../search/lucene/types.js";
|
|
20
20
|
const positiveSources = (node) => node.kind === "predicate"
|
|
@@ -110,7 +110,7 @@ export const prepareLucene = async (store, account, request, messenger) => {
|
|
|
110
110
|
if (person && node.operator === "wildcard")
|
|
111
111
|
return anyOf(node, await sendersMatching(store, scopeAccounts, node.field, node.value), (sender) => ({ sender }));
|
|
112
112
|
if (person)
|
|
113
|
-
return { ...node, resolution: { sender: await senderAmong(store, scopeAccounts, node.value) } };
|
|
113
|
+
return { ...node, resolution: { sender: await senderAmong(store, scopeAccounts, node.value, node.field) } };
|
|
114
114
|
if (node.field === "from")
|
|
115
115
|
return { ...node, resolution: { outgoing: true } };
|
|
116
116
|
if (node.field === "date")
|
|
@@ -324,14 +324,19 @@ export const searchLucene = async (store, account, request, messenger = {}) => {
|
|
|
324
324
|
const prepared = await prepareLucene(store, account, request, messenger);
|
|
325
325
|
const execute = store.queries.matchQuery.bind(store.queries);
|
|
326
326
|
const mailAccounts = prepared.scopeAccounts.filter(({ provider }) => provider === MAIL);
|
|
327
|
+
let mailLeftOut;
|
|
327
328
|
const inMailTables = async () => {
|
|
328
329
|
try {
|
|
329
330
|
return await execute({ ...prepared.execution, accounts: mailAccounts, corpus: "mail" });
|
|
330
331
|
}
|
|
331
332
|
catch (error) {
|
|
332
|
-
// A messenger field (`kind:`, `topic:`) leaves mail out of a search that names messenger accounts too
|
|
333
|
-
|
|
333
|
+
// A messenger field (`kind:`, `topic:`) leaves mail out of a search that names messenger accounts too; any
|
|
334
|
+
// other refusal (`*word*` over a large mailbox) is said, or the answer would look complete.
|
|
335
|
+
if (request.kind !== "mail" && error instanceof CliError && error.code === "validation_error") {
|
|
336
|
+
if (error.details.reason !== "query.unsupported-field")
|
|
337
|
+
mailLeftOut = { source: MAIL, code: "validation_error", reason: error.message };
|
|
334
338
|
return { items: [], hasMore: false };
|
|
339
|
+
}
|
|
335
340
|
throw error;
|
|
336
341
|
}
|
|
337
342
|
};
|
|
@@ -367,7 +372,9 @@ export const searchLucene = async (store, account, request, messenger = {}) => {
|
|
|
367
372
|
completeness,
|
|
368
373
|
query: queryOf(prepared.timezone, request.newest, prepared.stemming),
|
|
369
374
|
...(coverage ? { coverage } : {}),
|
|
370
|
-
...(prepared.skipped
|
|
375
|
+
...(prepared.skipped || mailLeftOut
|
|
376
|
+
? { skipped: [...(prepared.skipped ?? []), ...(mailLeftOut ? [mailLeftOut] : [])] }
|
|
377
|
+
: {}),
|
|
371
378
|
...(request.kind === "mail"
|
|
372
379
|
? { accounts: mailAccounts.map(({ provider, account }) => ({ resource: "mail", provider, account })) }
|
|
373
380
|
: {}),
|
|
@@ -38,8 +38,15 @@ export interface SearchAllRecordItem {
|
|
|
38
38
|
email?: MailFields;
|
|
39
39
|
/** A message's or a mail's files, as `search messages` names them. */
|
|
40
40
|
attachments?: HitFile[];
|
|
41
|
-
/** Which search found it: words, meaning or both. */
|
|
41
|
+
/** Which search found it: words, meaning or both; a deal or a lead by `title`, or `words` of its company or contacts. */
|
|
42
42
|
foundBy: ("title" | "words" | "meaning")[];
|
|
43
|
+
/** A deal's or a lead's: `corrected` when it matched only once a misspelt query word was corrected. */
|
|
44
|
+
match?: "corrected";
|
|
45
|
+
/** For a `corrected` hit, the stored words each corrected query word became. */
|
|
46
|
+
corrections?: {
|
|
47
|
+
from: string;
|
|
48
|
+
to: string[];
|
|
49
|
+
}[];
|
|
43
50
|
/** A business hit's: whether the owner confirmed it, or it waits for him. */
|
|
44
51
|
review?: "proposed" | "confirmed";
|
|
45
52
|
/** A business hit's source record, when an import made it. */
|
|
@@ -155,8 +162,8 @@ export type SearchAllMessenger = Partial<Pick<MessengerTraits, "savedChatId" | "
|
|
|
155
162
|
hintCommand?: string | null;
|
|
156
163
|
};
|
|
157
164
|
/**
|
|
158
|
-
* What a deal or a lead is found by: words or phrases
|
|
159
|
-
*
|
|
165
|
+
* What a deal or a lead is found by: plain words or phrases, all of them, or any with OR. Anything else is refused,
|
|
166
|
+
* so `search all` skips deals with the reason instead of matching a field they do not have.
|
|
160
167
|
*/
|
|
161
168
|
export declare const titleWords: (text: string, refused?: string) => {
|
|
162
169
|
words: string[];
|