@wirecat/cli-core 0.634.0 → 0.635.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 +66 -0
- package/dist/domain/display-names.d.ts +4 -2
- package/dist/domain/display-names.js +5 -2
- package/dist/errors/reasons.js +5 -0
- package/dist/search/groups.d.ts +2 -0
- package/dist/search/groups.js +1 -0
- package/dist/services/account-groups.d.ts +30 -1
- package/dist/services/account-groups.js +27 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/metadata.d.ts +1 -1
- package/dist/store/accounts.d.ts +10 -1
- package/dist/store/accounts.js +3 -2
- package/dist/store/chats.d.ts +5 -0
- package/dist/store/chats.js +6 -0
- package/dist/store/exports.d.ts +1 -1
- package/dist/store/identity-links.d.ts +21 -0
- package/dist/store/identity-splits.d.ts +2 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/keys.d.ts +1 -1
- package/dist/store/keys.js +1 -1
- package/dist/store/people.d.ts +10 -4
- package/dist/store/sqlite/accounts.d.ts +12 -2
- package/dist/store/sqlite/accounts.js +42 -3
- package/dist/store/sqlite/address-organization.d.ts +18 -0
- package/dist/store/sqlite/address-organization.js +48 -0
- package/dist/store/sqlite/chats.d.ts +3 -1
- package/dist/store/sqlite/chats.js +8 -0
- package/dist/store/sqlite/identity-link-rows.d.ts +5 -1
- package/dist/store/sqlite/identity-link-rows.js +9 -3
- package/dist/store/sqlite/identity-proposals.d.ts +5 -3
- package/dist/store/sqlite/identity-proposals.js +66 -7
- package/dist/store/sqlite/identity-split-proposals.js +3 -1
- package/dist/store/sqlite/mail-findings.js +10 -44
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/migrations.generated.js +6 -0
- package/dist/store/sqlite/name-traces.d.ts +5 -2
- package/dist/store/sqlite/name-traces.js +8 -5
- package/dist/store/sqlite/open-store.js +2 -0
- package/dist/store/sqlite/people-list.js +7 -3
- package/dist/store/sqlite/person-doubts.d.ts +4 -1
- package/dist/store/sqlite/person-doubts.js +4 -2
- package/dist/store/sqlite/person-links.d.ts +7 -2
- package/dist/store/sqlite/person-links.js +26 -1
- package/dist/store/sqlite/person-match-scan.js +74 -4
- package/dist/store/sqlite/person-merges.js +3 -7
- package/dist/store/sqlite/task-titles.d.ts +12 -1
- package/dist/store/sqlite/task-titles.js +42 -1
- package/dist/store/sqlite/tasks.js +6 -1
- package/dist/store/types.d.ts +4 -0
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isEmailAddress, isNoReplyAddress, isRoleAddress } from "../../domain/addresses.js";
|
|
2
|
+
import { variantKey } from "../../domain/name-variants.js";
|
|
2
3
|
import { BARE_INTERNATIONAL_PROVIDERS, storedPhone } from "../../domain/phones.js";
|
|
3
4
|
import { linkIndex, settleLinks } from "./identity-link-rows.js";
|
|
4
5
|
import { openIdentityLink } from "./identity-proposals.js";
|
|
@@ -15,6 +16,13 @@ export const RULE = { bot: "rule", kind: "rule" };
|
|
|
15
16
|
/** More people than this on one number or address is a shared line or mailbox: nobody is proposed from it. */
|
|
16
17
|
const MOST_SHARING = 6;
|
|
17
18
|
const CURSOR = "people.scan";
|
|
19
|
+
/** Raised when a rule changes what a pass finds in values nobody touched: the next pass then reads everything once. */
|
|
20
|
+
const RULES = 2;
|
|
21
|
+
/**
|
|
22
|
+
* NEED-2526: a shared mailbox says little alone, so its proposal is scored by what else the two people have in common.
|
|
23
|
+
* The role word itself does not move the score: the list does not tell a department's inbox from a company's.
|
|
24
|
+
*/
|
|
25
|
+
const SHARED_SCORE = { alone: 0.1, name: 0.4, trace: 0.3, weakTrace: 0.2 };
|
|
18
26
|
/**
|
|
19
27
|
* NEED-2445, safe option until the owner rules: a number two people share joins them only when a messenger, which
|
|
20
28
|
* keeps its user's own number, holds it; a CRM's or a card's number is someone's word and waits as a proposal.
|
|
@@ -54,10 +62,12 @@ const cursorNow = (database) => ({
|
|
|
54
62
|
revision: maxOf(database, "SELECT max(id) AS n FROM identity_revisions"),
|
|
55
63
|
participant: maxOf(database, "SELECT max(id) AS n FROM meeting_participants"),
|
|
56
64
|
at: maxOf(database, "SELECT max(updated_at) AS n FROM identities"),
|
|
65
|
+
rules: RULES,
|
|
57
66
|
});
|
|
58
67
|
const savedCursor = (database) => {
|
|
59
68
|
const value = database.prepare("SELECT value FROM store_settings WHERE key = ?").get(CURSOR)?.value;
|
|
60
|
-
|
|
69
|
+
const cursor = value === undefined ? undefined : JSON.parse(String(value));
|
|
70
|
+
return cursor?.rules === RULES ? cursor : undefined;
|
|
61
71
|
};
|
|
62
72
|
/** The identities changed since `since`: new ones, moved ones, edited ones and ones a new meeting guest row names. */
|
|
63
73
|
const changedSince = (database, since) => new Set(database
|
|
@@ -218,9 +228,63 @@ const samePhone = (pass, holders) => {
|
|
|
218
228
|
else
|
|
219
229
|
proposeEachPair(pass, people, "phone");
|
|
220
230
|
};
|
|
231
|
+
const nameOf = ({ database }, person) => {
|
|
232
|
+
const name = database.prepare("SELECT name FROM persons WHERE id = ?").get(person)?.name;
|
|
233
|
+
return typeof name === "string" ? name : null;
|
|
234
|
+
};
|
|
235
|
+
const TRACE_WORDS = {
|
|
236
|
+
phone: "the same phone",
|
|
237
|
+
email: "another address only they have",
|
|
238
|
+
chat: "a chat they are both in",
|
|
239
|
+
"email-domain": "mail at the same company",
|
|
240
|
+
};
|
|
241
|
+
/** What two people on one shared mailbox have in common besides it, as a score and the words that say why. */
|
|
242
|
+
const sharedMailboxCase = (context, address, from, to) => {
|
|
243
|
+
const reasons = [`both have the shared mailbox ${address}`];
|
|
244
|
+
let score = SHARED_SCORE.alone;
|
|
245
|
+
const name = nameOf(context, from);
|
|
246
|
+
const key = variantKey(name);
|
|
247
|
+
if (key !== null && key === variantKey(nameOf(context, to))) {
|
|
248
|
+
score += SHARED_SCORE.name;
|
|
249
|
+
reasons.push(`the same name «${name}»`);
|
|
250
|
+
}
|
|
251
|
+
let evidence = [];
|
|
252
|
+
for (const trace of sharedTraces(context.database, from, to, name ?? "", address))
|
|
253
|
+
if (!(trace.kind === "email" && isRoleAddress(trace.value ?? "")) && strongEnough(context, from, to, trace)) {
|
|
254
|
+
score += trace.value === undefined ? SHARED_SCORE.weakTrace : SHARED_SCORE.trace;
|
|
255
|
+
reasons.push(TRACE_WORDS[trace.kind]);
|
|
256
|
+
evidence = trace.evidence;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
return { score: Math.round(score * 10) / 10, reason: reasons.join("; "), evidence };
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* NEED-2526: a shared mailbox never joins anyone (SEC-177), but each pair on it is proposed to the owner, scored by
|
|
263
|
+
* what else they share.
|
|
264
|
+
*/
|
|
265
|
+
const proposeShared = (pass, { address, holders, shared }) => {
|
|
266
|
+
const people = peopleOf(pass.context, holders);
|
|
267
|
+
if (people.size < 2)
|
|
268
|
+
return;
|
|
269
|
+
const persons = [...people.keys()].sort((a, b) => a - b);
|
|
270
|
+
for (const [at, from] of persons.entries())
|
|
271
|
+
for (const to of persons.slice(at + 1))
|
|
272
|
+
propose(pass, {
|
|
273
|
+
identity: people.get(from),
|
|
274
|
+
with: people.get(to),
|
|
275
|
+
from,
|
|
276
|
+
to,
|
|
277
|
+
joins: "person",
|
|
278
|
+
signal: "email",
|
|
279
|
+
candidates: persons,
|
|
280
|
+
shared,
|
|
281
|
+
mailbox: address,
|
|
282
|
+
...sharedMailboxCase(pass.context, address, from, to),
|
|
283
|
+
});
|
|
284
|
+
};
|
|
221
285
|
/**
|
|
222
286
|
* One address is one person in any scope (NEED-2382), unless more than two people have it (NEED-2446). A no-reply
|
|
223
|
-
* address is no one's
|
|
287
|
+
* address is no one's. A role address such as `info@` and a company's mailbox only propose (NEED-2526).
|
|
224
288
|
*/
|
|
225
289
|
const sameEmail = (pass, address, holders) => {
|
|
226
290
|
if (isNoReplyAddress(address))
|
|
@@ -228,8 +292,11 @@ const sameEmail = (pass, address, holders) => {
|
|
|
228
292
|
const people = peopleOf(pass.context, holders);
|
|
229
293
|
if (people.size < 2 || tooMany(pass, people, "identity.shared-email", "email"))
|
|
230
294
|
return;
|
|
231
|
-
|
|
232
|
-
|
|
295
|
+
const role = isRoleAddress(address);
|
|
296
|
+
if (role || sharedLine(pass.context, holders)) {
|
|
297
|
+
pass.shared.push({ address, holders, shared: role ? "role" : "line" });
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
233
300
|
if (!addressGroupJoins(people.size))
|
|
234
301
|
return proposeEachPair(pass, people, "email");
|
|
235
302
|
const contact = holders.find(({ provider }) => provider === "email");
|
|
@@ -343,6 +410,7 @@ export const scanMatches = (context, { full = false } = {}) => {
|
|
|
343
410
|
context,
|
|
344
411
|
index: linkIndex(database),
|
|
345
412
|
result: { full: changed === undefined, merged: [], proposed: [], skipped: [] },
|
|
413
|
+
shared: [],
|
|
346
414
|
};
|
|
347
415
|
for (const [address, holders] of emailHolders(database))
|
|
348
416
|
if (holders.length > 1 && touched(holders))
|
|
@@ -350,6 +418,8 @@ export const scanMatches = (context, { full = false } = {}) => {
|
|
|
350
418
|
for (const holders of phoneHolders(database).values())
|
|
351
419
|
if (holders.length > 1 && touched(holders))
|
|
352
420
|
write(database, () => samePhone(pass, holders));
|
|
421
|
+
for (const group of pass.shared)
|
|
422
|
+
write(database, () => proposeShared(pass, group));
|
|
353
423
|
for (const row of guestRows(database))
|
|
354
424
|
if ((changed === undefined || changed.has(row.identity)) && !pass.index.names(row.ref))
|
|
355
425
|
write(database, () => guestEmail(pass, row));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { currentPerson, mergeSql, SEPARATIONS } from "./merged-persons.js";
|
|
3
|
-
import { move, recordOf, renameAfterLeaving, required } from "./person-links.js";
|
|
3
|
+
import { heldBy, move, recordOf, renameAfterLeaving, required } from "./person-links.js";
|
|
4
4
|
import { persons } from "./schema.js";
|
|
5
5
|
export const mergeId = (to, from) => `merge:${to}-${from}`;
|
|
6
6
|
/** The two uids a `merge:<to>-<from>` id names. */
|
|
@@ -116,12 +116,8 @@ export const split = (context, uid, refs, by) => {
|
|
|
116
116
|
const chosen = [...new Map(refs.map((ref) => [`${ref.provider}:${ref.id}`, ref])).values()];
|
|
117
117
|
if (chosen.length === 0)
|
|
118
118
|
throw new CliError("validation_error", "name at least one identity to split off");
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (row.personPk !== person)
|
|
122
|
-
throw new CliError("validation_error", `${ref.provider}:${ref.id} is not an identity of person:${person}`);
|
|
123
|
-
return row;
|
|
124
|
-
});
|
|
119
|
+
heldBy(context, uid, chosen);
|
|
120
|
+
const found = chosen.map((ref) => required(context, ref));
|
|
125
121
|
if (found.length === recordOf(context, person).identities.length)
|
|
126
122
|
throw new CliError("validation_error", "a split leaves at least one identity with the person");
|
|
127
123
|
const at = context.now();
|
|
@@ -6,7 +6,18 @@ export declare const placeholderTitleOf: (row: Row) => string;
|
|
|
6
6
|
export declare const PLACEHOLDER_TITLE_SQL = "title = type || ' \u2014 ' || coalesce(source_locator, '')";
|
|
7
7
|
/**
|
|
8
8
|
* What to show as a task's title: the first line of its source message while the stored title is still the
|
|
9
|
-
* placeholder, the stored title otherwise.
|
|
9
|
+
* placeholder, the stored title otherwise. A found task stores it when it is found, and store version 65 stored it for
|
|
10
|
+
* the tasks found before; read time covers a task found before its message was saved.
|
|
10
11
|
*/
|
|
11
12
|
export declare const displayTitleOf: (database: CacheDatabase, row: Row) => string;
|
|
13
|
+
/** Set by store version 65 and deleted once every found task's title is stored. */
|
|
14
|
+
export declare const FOUND_TASK_TITLES_TO_FILL = "found_task_titles_to_fill";
|
|
15
|
+
/**
|
|
16
|
+
* Stores the title `displayTitleOf` shows for each live found task still titled `<kind> — <source>`, so it stays
|
|
17
|
+
* when the message is deleted. One short write per batch; a task whose message is missing, deleted or empty keeps
|
|
18
|
+
* its title. A failure keeps the key for the next open and only warns.
|
|
19
|
+
*/
|
|
20
|
+
export declare const fillFoundTaskTitles: (database: CacheDatabase, warn: (line: string) => void, { batch }?: {
|
|
21
|
+
batch?: number;
|
|
22
|
+
}) => number;
|
|
12
23
|
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { isLocator } from "../../domain/locator.js";
|
|
2
|
+
import { folded } from "./folded.js";
|
|
2
3
|
import { thingOf } from "./things.js";
|
|
4
|
+
import { writeBatch } from "./transaction.js";
|
|
3
5
|
const MAX_TITLE = 120;
|
|
4
6
|
/** The title a rule gives a task it finds in a message: no message text is stored, so it is only a reference. */
|
|
5
7
|
export const placeholderTitleOf = (row) => `${String(row.type)} — ${String(row.source_locator ?? "")}`;
|
|
@@ -20,7 +22,8 @@ const firstLine = (text) => {
|
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* What to show as a task's title: the first line of its source message while the stored title is still the
|
|
23
|
-
* placeholder, the stored title otherwise.
|
|
25
|
+
* placeholder, the stored title otherwise. A found task stores it when it is found, and store version 65 stored it for
|
|
26
|
+
* the tasks found before; read time covers a task found before its message was saved.
|
|
24
27
|
*/
|
|
25
28
|
export const displayTitleOf = (database, row) => {
|
|
26
29
|
const stored = String(row.title);
|
|
@@ -40,3 +43,41 @@ export const displayTitleOf = (database, row) => {
|
|
|
40
43
|
return stored;
|
|
41
44
|
}
|
|
42
45
|
};
|
|
46
|
+
/** Set by store version 65 and deleted once every found task's title is stored. */
|
|
47
|
+
export const FOUND_TASK_TITLES_TO_FILL = "found_task_titles_to_fill";
|
|
48
|
+
/**
|
|
49
|
+
* Stores the title `displayTitleOf` shows for each live found task still titled `<kind> — <source>`, so it stays
|
|
50
|
+
* when the message is deleted. One short write per batch; a task whose message is missing, deleted or empty keeps
|
|
51
|
+
* its title. A failure keeps the key for the next open and only warns.
|
|
52
|
+
*/
|
|
53
|
+
export const fillFoundTaskTitles = (database, warn, { batch = 500 } = {}) => {
|
|
54
|
+
if (!database.prepare("SELECT 1 AS found FROM store_settings WHERE key = ?").get(FOUND_TASK_TITLES_TO_FILL))
|
|
55
|
+
return 0;
|
|
56
|
+
const next = database.prepare("SELECT id, type, title, source_locator FROM tasks WHERE id > ? AND package_id IS NOT NULL AND deleted_at IS NULL " +
|
|
57
|
+
`AND source_locator LIKE 'msg:%' AND ${PLACEHOLDER_TITLE_SQL} ORDER BY id LIMIT ?`);
|
|
58
|
+
const store = database.prepare(`UPDATE tasks SET title = ?, title_folded = ? WHERE id = ? AND ${PLACEHOLDER_TITLE_SQL}`);
|
|
59
|
+
let filled = 0;
|
|
60
|
+
let after = 0;
|
|
61
|
+
try {
|
|
62
|
+
for (;;) {
|
|
63
|
+
const rows = writeBatch(database, () => {
|
|
64
|
+
const page = next.all(after, batch);
|
|
65
|
+
for (const row of page) {
|
|
66
|
+
const title = displayTitleOf(database, row);
|
|
67
|
+
if (title !== String(row.title))
|
|
68
|
+
filled += store.run(title, folded(title), Number(row.id)).changes;
|
|
69
|
+
}
|
|
70
|
+
if (page.length < batch)
|
|
71
|
+
database.prepare("DELETE FROM store_settings WHERE key = ?").run(FOUND_TASK_TITLES_TO_FILL);
|
|
72
|
+
return page;
|
|
73
|
+
});
|
|
74
|
+
if (rows.length < batch)
|
|
75
|
+
return filled;
|
|
76
|
+
after = Number(rows.at(-1)?.id);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
warn(`could not store the titles of found tasks; the next open tries again: ${String(error)}`);
|
|
81
|
+
return filled;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
@@ -161,12 +161,17 @@ export const taskStoreOver = (context) => {
|
|
|
161
161
|
const key = typedKey(database, task.kind);
|
|
162
162
|
const author = actorOfOrigin(database, task.origin);
|
|
163
163
|
const closedBy = task.closedBy ? actorOfOrigin(database, task.closedBy) : undefined;
|
|
164
|
+
const title = displayTitleOf(database, {
|
|
165
|
+
type: task.kind,
|
|
166
|
+
title: `${task.kind} — ${task.source}`,
|
|
167
|
+
source_locator: task.source,
|
|
168
|
+
});
|
|
164
169
|
const made = database
|
|
165
170
|
.prepare("INSERT INTO tasks (project_id, number, key, title, type, status, due_at, closed_at, closed_by_type, closed_by_id, " +
|
|
166
171
|
"close_reason, author_type, author_id, source, package_id, source_locator, source_kind, source_group, created_at, updated_at, " +
|
|
167
172
|
"title_folded, close_reason_folded, category) " +
|
|
168
173
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id")
|
|
169
|
-
.get(project, number, key,
|
|
174
|
+
.get(project, number, key, title, task.kind, task.state, time(task.dueAt), time(task.closedAt), closedBy?.type ?? null, closedBy?.id ?? null, task.reason ?? null, author.type, author.id, task.origin, task.id, task.source, task.sourceKind, task.group, task.createdAt.getTime(), now(), folded(title), folded(task.reason), task.category ?? null);
|
|
170
175
|
recordTaskEvent(database, Number(made?.id), author, "created", null, task.createdAt.getTime());
|
|
171
176
|
});
|
|
172
177
|
},
|
package/dist/store/types.d.ts
CHANGED
|
@@ -47,6 +47,10 @@ export interface LinkOptions {
|
|
|
47
47
|
method: string;
|
|
48
48
|
by: string;
|
|
49
49
|
}
|
|
50
|
+
export interface UnlinkOptions extends LinkOptions {
|
|
51
|
+
/** The uid of the person the identity is taken from; refused when it sits on someone else. */
|
|
52
|
+
from?: string;
|
|
53
|
+
}
|
|
50
54
|
export interface LinkedIdentity extends IdentityRef {
|
|
51
55
|
name: string | null;
|
|
52
56
|
username: string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.635.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",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"wirecat": {
|
|
17
17
|
"store": {
|
|
18
|
-
"speaks":
|
|
18
|
+
"speaks": 65,
|
|
19
19
|
"minCompatible": 56
|
|
20
20
|
}
|
|
21
21
|
},
|