@wirecat/cli-core 1.1.0 → 1.3.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 +80 -0
- package/dist/cli/account-remove.d.ts +3 -0
- package/dist/cli/account-remove.js +1 -1
- package/dist/cli/contract-templates.js +3 -0
- package/dist/cli/documents/index.d.ts +2 -1
- package/dist/cli/documents/index.js +4 -1
- package/dist/cli/help/first-screen.js +2 -2
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +3 -3
- package/dist/cli/messenger/account-command.js +0 -10
- package/dist/cli/messenger/accounts.d.ts +1 -1
- package/dist/cli/messenger/accounts.js +1 -1
- package/dist/cli/messenger/context.d.ts +1 -1
- package/dist/cli/messenger/conversation-answers.d.ts +2 -0
- package/dist/cli/messenger/message-answers.d.ts +2 -0
- package/dist/cli/messenger/message-items.js +2 -0
- package/dist/cli/messenger/message-writes.d.ts +4 -0
- package/dist/cli/messenger/search-answers.js +2 -0
- package/dist/cli/messenger/session-commands.d.ts +1 -1
- package/dist/cli/messenger/session-commands.js +1 -1
- package/dist/cli/oauth-session.js +6 -3
- package/dist/cli/program.js +2 -2
- package/dist/cli/settings.d.ts +3 -3
- package/dist/cli/shared-command-exports.d.ts +2 -0
- package/dist/cli/shared-command-exports.js +3 -0
- package/dist/cli/token-session.d.ts +1 -4
- package/dist/cli/token-session.js +5 -1
- package/dist/domain/models.d.ts +5 -0
- package/dist/domain/person-kinds.d.ts +1 -1
- package/dist/entities/contact-context.d.ts +4 -0
- package/dist/entities/conversation-results.d.ts +4 -0
- package/dist/entities/evidence.d.ts +16 -0
- package/dist/entities/index.d.ts +36 -0
- package/dist/entities/listener.d.ts +8 -0
- package/dist/entities/message-change.d.ts +2 -0
- package/dist/entities/message-context.d.ts +6 -0
- package/dist/entities/message-write.d.ts +8 -0
- package/dist/entities/message.d.ts +4 -0
- package/dist/entities/message.js +4 -0
- package/dist/entities/store-maintenance.js +1 -1
- package/dist/entities/store-records.d.ts +2 -0
- package/dist/errors/failures.d.ts +6 -0
- package/dist/errors/failures.js +18 -4
- package/dist/errors/reasons.js +16 -0
- package/dist/errors/store-reasons.js +1 -0
- package/dist/mail/cli/index.js +1 -1
- package/dist/mail/headers.d.ts +2 -0
- package/dist/mail/headers.js +2 -1
- package/dist/mail/read.js +1 -0
- package/dist/mail/sort-rules.d.ts +58 -0
- package/dist/mail/sort-rules.js +79 -0
- package/dist/mcp/tool.js +2 -2
- package/dist/runs/recording.js +2 -2
- package/dist/search/lucene/registry.js +24 -0
- package/dist/services/messages-search.js +1 -1
- package/dist/store/areas.d.ts +2 -0
- package/dist/store/areas.js +2 -0
- package/dist/store/public.d.ts +1 -1
- package/dist/store/public.js +1 -1
- package/dist/store/queries.js +9 -2
- package/dist/store/sqlite/email-types.d.ts +8 -0
- package/dist/store/sqlite/email-types.js +45 -10
- package/dist/store/sqlite/emails.d.ts +3 -0
- package/dist/store/sqlite/emails.js +14 -5
- package/dist/store/sqlite/lucene-fields.d.ts +6 -0
- package/dist/store/sqlite/lucene-fields.js +10 -0
- package/dist/store/sqlite/lucene.js +6 -0
- package/dist/store/sqlite/mail-sorting.d.ts +122 -0
- package/dist/store/sqlite/mail-sorting.js +482 -0
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +20 -0
- package/dist/store/sqlite/people-list.js +65 -16
- package/dist/store/sqlite/schema/mail-sorting.d.ts +384 -0
- package/dist/store/sqlite/schema/mail-sorting.js +31 -0
- package/dist/store/sqlite/schema.d.ts +17 -0
- package/dist/store/sqlite/schema.js +3 -0
- package/dist/store/sqlite/sender-bots.d.ts +10 -1
- package/dist/store/sqlite/sender-bots.js +47 -8
- package/package.json +2 -2
- package/parity.json +9 -3
|
@@ -8,8 +8,8 @@ import { fold } from "../normalize.js";
|
|
|
8
8
|
import { groupByDomain } from "./domain-organizations.js";
|
|
9
9
|
import { mergedAwaySql } from "./merged-persons.js";
|
|
10
10
|
import { ALWAYS_SHOWN, shownReasons } from "./person-ties.js";
|
|
11
|
-
import { hasLegacyBots, ownerPeopleOf, ruleBotsBack, ruleToBot, settleLegacyBots } from "./sender-bots.js";
|
|
12
|
-
import { senderSignalsOf, sentMailOf } from "./sender-signals.js";
|
|
11
|
+
import { hasLegacyBots, NEWSLETTER_ONLY, newsletterBotsMail, ownerPeopleOf, ruleBotsBack, ruleToBot, settleLegacyBots, settleNewsletterBots, } from "./sender-bots.js";
|
|
12
|
+
import { LIST_ID, senderSignalsOf, sentMailOf } from "./sender-signals.js";
|
|
13
13
|
import { mergedAssignees } from "./task-board.js";
|
|
14
14
|
import { hiddenTestPeople } from "./test-people.js";
|
|
15
15
|
import { read, writeBatch } from "./transaction.js";
|
|
@@ -50,12 +50,16 @@ const IDENTITY_MAIL_COUNTS = (scope) => `SELECT from_identity_id AS identity, co
|
|
|
50
50
|
const TWO_WAY = "SELECT DISTINCT s.sender_identity_id AS identity_id FROM messages s WHERE s.outgoing IS NOT 1 " +
|
|
51
51
|
"AND s.sender_identity_id IS NOT NULL AND s.chat_id IN (SELECT c.id FROM chats c WHERE c.kind = 'dialog' " +
|
|
52
52
|
"AND EXISTS (SELECT 1 FROM messages o WHERE o.chat_id = c.id AND o.outgoing = 1))";
|
|
53
|
-
const MAIL_COUNTS = (scope) => "SELECT
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
53
|
+
const MAIL_COUNTS = (scope) => "SELECT person, count(*) AS n, sum(bulk) AS bulk, sum(auto) AS auto, sum(null_return) AS null_return, " +
|
|
54
|
+
"sum(bulk OR listed) AS listed FROM (SELECT l.person_id AS person, EXISTS (SELECT 1 FROM email_mailboxes m " +
|
|
55
|
+
"JOIN mailboxes b ON b.id = m.mailbox_id WHERE m.email_id = e.id AND b.kind = 'bulk') AS bulk, " +
|
|
56
|
+
"json_extract(e.headers, '$.\"auto-submitted\"') IS NOT NULL AS auto, " +
|
|
57
|
+
"json_extract(e.headers, '$.\"null-return-path\"') IS 1 AS null_return, " +
|
|
58
|
+
`${LIST_ID} IS NOT NULL OR json_extract(e.headers, '$."list-unsubscribe"') IS 1 ` +
|
|
59
|
+
"OR json_extract(e.headers, '$.\"list-unsubscribe-post\"') IS 1 OR json_extract(e.headers, '$.\"feedback-id\"') IS 1 " +
|
|
60
|
+
"OR json_extract(e.headers, '$.precedence') IN ('bulk', 'junk') AS listed " +
|
|
57
61
|
"FROM emails e JOIN identity_links l ON l.identity_id = e.from_identity_id " +
|
|
58
|
-
`WHERE e.outgoing IS NOT 1 AND e.deleted_at IS NULL AND ${IN_SCOPE(scope, "l.person_id")} GROUP BY 1`;
|
|
62
|
+
`WHERE e.outgoing IS NOT 1 AND e.deleted_at IS NULL AND ${IN_SCOPE(scope, "l.person_id")}) GROUP BY 1`;
|
|
59
63
|
const IDENTITIES = (scope) => "SELECT l.person_id AS person, i.id, i.provider, i.external_id, i.name, i.username, i.phone, i.email, i.bot " +
|
|
60
64
|
`FROM identity_links l JOIN identities i ON i.id = l.identity_id WHERE ${IN_SCOPE(scope, "l.person_id")} ORDER BY i.id`;
|
|
61
65
|
/** Few identities have these; one pass each beats a lookup per identity. */
|
|
@@ -112,6 +116,7 @@ const factsOf = (database, scope) => {
|
|
|
112
116
|
messages: 0,
|
|
113
117
|
identities: held.length,
|
|
114
118
|
programIdentities: 0,
|
|
119
|
+
notMail: 0,
|
|
115
120
|
};
|
|
116
121
|
const source = (row) => ({
|
|
117
122
|
provider: String(row.provider),
|
|
@@ -133,6 +138,8 @@ const factsOf = (database, scope) => {
|
|
|
133
138
|
one.organization ||= owned.has(identity);
|
|
134
139
|
one.twoWay ||= twoWay.has(identity);
|
|
135
140
|
one.messages += messages.get(identity) ?? 0;
|
|
141
|
+
if (row.provider !== "email")
|
|
142
|
+
one.notMail += 1;
|
|
136
143
|
if (Number(row.bot) === 1 || (email !== null && (isNoReplyAddress(email) || isNotificationAddress(email))))
|
|
137
144
|
one.programIdentities += 1;
|
|
138
145
|
}
|
|
@@ -162,7 +169,10 @@ const lastContacts = (database, scope) => new Map(database
|
|
|
162
169
|
.map((row) => [Number(row.person), Number(row.at)]));
|
|
163
170
|
/** One misfiled letter is no newsletter. */
|
|
164
171
|
const BULK_MIN = 3;
|
|
165
|
-
/**
|
|
172
|
+
/**
|
|
173
|
+
* A program writes: enough to move a sender to a bot. A name or a bulk mailbox alone does not; a sender all of whose
|
|
174
|
+
* mail a list sent becomes a bot by `NEWSLETTER_ONLY` instead, which a 1-to-1 mail gives back.
|
|
175
|
+
*/
|
|
166
176
|
const PROGRAM_SIGNALS = [
|
|
167
177
|
"bot",
|
|
168
178
|
"no-reply",
|
|
@@ -172,11 +182,12 @@ const PROGRAM_SIGNALS = [
|
|
|
172
182
|
"bulk-never-replied",
|
|
173
183
|
];
|
|
174
184
|
/** The first rule that holds; the list's contract in the people-clients-digests plan names the same order. */
|
|
175
|
-
const kindOf = (shown, facts, ties, mail, test, keptByOwner = false) => {
|
|
185
|
+
const kindOf = (shown, facts, ties, mail, test, keptByOwner = false, newsletterOnly = false) => {
|
|
176
186
|
if (test)
|
|
177
187
|
return { kind: "test", signals: ["test-data"] };
|
|
178
188
|
const emails = facts?.emails ?? [];
|
|
179
189
|
const automated = [
|
|
190
|
+
...(newsletterOnly ? [NEWSLETTER_ONLY] : []),
|
|
180
191
|
...(facts?.bot ? ["bot"] : []),
|
|
181
192
|
...(emails.some(isNoReplyAddress) ? ["no-reply"] : []),
|
|
182
193
|
...(emails.some(isNotificationAddress) ? ["notification-address"] : []),
|
|
@@ -219,6 +230,24 @@ const isProgram = ({ kind, signals }, facts, ties) => kind === "automated" &&
|
|
|
219
230
|
signals.some((signal) => PROGRAM_SIGNALS.includes(signal)) &&
|
|
220
231
|
(facts.bot || (!facts.twoWay && !ties.includes("mail"))) &&
|
|
221
232
|
(facts.identities === 1 || facts.programIdentities === facts.identities);
|
|
233
|
+
/**
|
|
234
|
+
* The owner ruled on 2026-11-25 that a sender who only sends a newsletter is a bot, a human author too: all their mail
|
|
235
|
+
* came as a list's, and they and the owner never exchanged a word. Any tie keeps them a person.
|
|
236
|
+
*/
|
|
237
|
+
const mayBeNewsletterOnly = (facts, ties, mail) => facts !== undefined &&
|
|
238
|
+
mail !== undefined &&
|
|
239
|
+
ties.length === 0 &&
|
|
240
|
+
!facts.bot &&
|
|
241
|
+
!facts.twoWay &&
|
|
242
|
+
facts.messages === 0 &&
|
|
243
|
+
facts.notMail === 0 &&
|
|
244
|
+
mail.n > 0 &&
|
|
245
|
+
mail.listed === mail.n;
|
|
246
|
+
/** A candidate whose mail came through a discussion list writes to a group, not to subscribers. */
|
|
247
|
+
const newsletterOnlyOf = (database, candidates) => {
|
|
248
|
+
const sent = sentMailOf(database, candidates);
|
|
249
|
+
return new Set(candidates.filter((id) => (sent.get(id) ?? []).every((one) => !one.discussionList)));
|
|
250
|
+
};
|
|
222
251
|
/** Each person with their kind, contact and counts; the last contact is added for the page alone. */
|
|
223
252
|
const classified = (database, people, scope, reasons = shownReasons(database, scope === "all" ? undefined : scope)) => {
|
|
224
253
|
const facts = factsOf(database, scope);
|
|
@@ -230,19 +259,36 @@ const classified = (database, people, scope, reasons = shownReasons(database, sc
|
|
|
230
259
|
.all(...scopeParams(scope))
|
|
231
260
|
.map((row) => [
|
|
232
261
|
Number(row.person),
|
|
233
|
-
{
|
|
262
|
+
{
|
|
263
|
+
n: Number(row.n),
|
|
264
|
+
bulk: Number(row.bulk),
|
|
265
|
+
auto: Number(row.auto),
|
|
266
|
+
nullReturn: Number(row.null_return),
|
|
267
|
+
listed: Number(row.listed),
|
|
268
|
+
},
|
|
234
269
|
]));
|
|
270
|
+
const newsletters = newsletterOnlyOf(database, people.flatMap(({ id, owner }) => !owner &&
|
|
271
|
+
!ownerPeople.has(id) &&
|
|
272
|
+
!test.has(id) &&
|
|
273
|
+
mayBeNewsletterOnly(facts.get(id), reasons.get(id) ?? [], mail.get(id))
|
|
274
|
+
? [id]
|
|
275
|
+
: []));
|
|
235
276
|
return people.map(({ id, name, owner }) => {
|
|
236
277
|
const own = facts.get(id);
|
|
237
278
|
const contact = { username: own?.username ?? null, phone: own?.phone ?? null, email: own?.email ?? null };
|
|
238
279
|
const shown = displayName(name, { ...contact, name: own?.name ?? null });
|
|
239
280
|
const ties = reasons.get(id) ?? [];
|
|
240
281
|
const kept = ownerPeople.has(id);
|
|
241
|
-
const worked = kindOf(shown, own, ties, mail.get(id), test.has(id), kept);
|
|
242
|
-
const
|
|
282
|
+
const worked = kindOf(shown, own, ties, mail.get(id), test.has(id), kept, newsletters.has(id));
|
|
283
|
+
const program = !kept && !owner && worked.kind !== "test" && isProgram(worked, own, ties);
|
|
284
|
+
const botReason = program
|
|
285
|
+
? worked.signals.filter((signal) => signal !== NEWSLETTER_ONLY).join(", ")
|
|
286
|
+
: newsletters.has(id)
|
|
287
|
+
? NEWSLETTER_ONLY
|
|
288
|
+
: undefined;
|
|
243
289
|
return {
|
|
244
290
|
id,
|
|
245
|
-
...(
|
|
291
|
+
...(botReason === undefined ? {} : { move: "bot", botReason }),
|
|
246
292
|
nameOrder: nameOrderOf(shown),
|
|
247
293
|
person: `person:${id}`,
|
|
248
294
|
name,
|
|
@@ -265,7 +311,7 @@ const withLastContact = (database, people, known) => {
|
|
|
265
311
|
const at = known ??
|
|
266
312
|
lastContacts(database, people.map(({ id }) => id));
|
|
267
313
|
const sent = sentMailOf(database, people.map(({ id }) => id));
|
|
268
|
-
return people.map(({ id, nameOrder: _, emails, twoWay, move: __, ...person }) => {
|
|
314
|
+
return people.map(({ id, nameOrder: _, emails, twoWay, move: __, botReason: ___, ...person }) => {
|
|
269
315
|
const time = at.get(id);
|
|
270
316
|
const { ties } = person;
|
|
271
317
|
return {
|
|
@@ -286,7 +332,7 @@ const byName = (a, b) => a.nameOrder < b.nameOrder ? -1 : a.nameOrder > b.nameOr
|
|
|
286
332
|
* Bump when what decides a kind, a name's order or a count changes in code (the word lists, `BULK_MIN`, the ties):
|
|
287
333
|
* every stored one is worked out again on the next list.
|
|
288
334
|
*/
|
|
289
|
-
const KIND_RULES = "
|
|
335
|
+
const KIND_RULES = "10";
|
|
290
336
|
const RULES_KEY = "people.kind_rules";
|
|
291
337
|
/** Past this many people to work out, one pass over everyone beats a lookup per person. */
|
|
292
338
|
const WHOLE_PASS = 20_000;
|
|
@@ -333,7 +379,7 @@ const keep = (database, worked) => {
|
|
|
333
379
|
for (const person of worked)
|
|
334
380
|
if (person.move === "bot" && person.kind !== MERGED) {
|
|
335
381
|
bots.push({
|
|
336
|
-
id: ruleToBot(database, person.id, person.kindSignals.join(", "), at),
|
|
382
|
+
id: ruleToBot(database, person.id, person.botReason ?? person.kindSignals.join(", "), at),
|
|
337
383
|
displayName: person.displayName,
|
|
338
384
|
holds: true,
|
|
339
385
|
bot: true,
|
|
@@ -371,6 +417,9 @@ export const storeKinds = (database) => {
|
|
|
371
417
|
// A 1.0 build keeps the kinds of the people it sorts onto a bot, so nothing else would bring their bot here.
|
|
372
418
|
if (!isQueryOnly(database) && hasLegacyBots(database))
|
|
373
419
|
writeBatch(database, () => settleLegacyBots(database, Date.now()));
|
|
420
|
+
const newest = isQueryOnly(database) ? undefined : newsletterBotsMail(database);
|
|
421
|
+
if (newest !== undefined)
|
|
422
|
+
writeBatch(database, () => settleNewsletterBots(database, newest, Date.now()));
|
|
374
423
|
if (isQueryOnly(database))
|
|
375
424
|
return (rulesOf(database) === KIND_RULES &&
|
|
376
425
|
database.prepare("SELECT 1 FROM persons WHERE kind IS NULL LIMIT 1").get() === undefined);
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
export declare const mailSortRules: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
2
|
+
name: "mail_sort_rules";
|
|
3
|
+
schema: undefined;
|
|
4
|
+
columns: {
|
|
5
|
+
id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
6
|
+
name: string;
|
|
7
|
+
tableName: "mail_sort_rules";
|
|
8
|
+
dataType: "number int53";
|
|
9
|
+
data: number;
|
|
10
|
+
driverParam: number;
|
|
11
|
+
notNull: true;
|
|
12
|
+
hasDefault: true;
|
|
13
|
+
isPrimaryKey: true;
|
|
14
|
+
isAutoincrement: false;
|
|
15
|
+
hasRuntimeDefault: false;
|
|
16
|
+
enumValues: undefined;
|
|
17
|
+
baseColumn: never;
|
|
18
|
+
identity: undefined;
|
|
19
|
+
generated: undefined;
|
|
20
|
+
}, {}>;
|
|
21
|
+
scope: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
22
|
+
name: string;
|
|
23
|
+
tableName: "mail_sort_rules";
|
|
24
|
+
dataType: "string";
|
|
25
|
+
data: string;
|
|
26
|
+
driverParam: string;
|
|
27
|
+
notNull: true;
|
|
28
|
+
hasDefault: false;
|
|
29
|
+
isPrimaryKey: false;
|
|
30
|
+
isAutoincrement: false;
|
|
31
|
+
hasRuntimeDefault: false;
|
|
32
|
+
enumValues: [string, ...string[]];
|
|
33
|
+
baseColumn: never;
|
|
34
|
+
identity: undefined;
|
|
35
|
+
generated: undefined;
|
|
36
|
+
}, {}>;
|
|
37
|
+
value: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
38
|
+
name: string;
|
|
39
|
+
tableName: "mail_sort_rules";
|
|
40
|
+
dataType: "string";
|
|
41
|
+
data: string;
|
|
42
|
+
driverParam: string;
|
|
43
|
+
notNull: true;
|
|
44
|
+
hasDefault: false;
|
|
45
|
+
isPrimaryKey: false;
|
|
46
|
+
isAutoincrement: false;
|
|
47
|
+
hasRuntimeDefault: false;
|
|
48
|
+
enumValues: [string, ...string[]];
|
|
49
|
+
baseColumn: never;
|
|
50
|
+
identity: undefined;
|
|
51
|
+
generated: undefined;
|
|
52
|
+
}, {}>;
|
|
53
|
+
mailType: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
54
|
+
name: string;
|
|
55
|
+
tableName: "mail_sort_rules";
|
|
56
|
+
dataType: "string";
|
|
57
|
+
data: string;
|
|
58
|
+
driverParam: string;
|
|
59
|
+
notNull: false;
|
|
60
|
+
hasDefault: false;
|
|
61
|
+
isPrimaryKey: false;
|
|
62
|
+
isAutoincrement: false;
|
|
63
|
+
hasRuntimeDefault: false;
|
|
64
|
+
enumValues: [string, ...string[]];
|
|
65
|
+
baseColumn: never;
|
|
66
|
+
identity: undefined;
|
|
67
|
+
generated: undefined;
|
|
68
|
+
}, {}>;
|
|
69
|
+
sender: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
70
|
+
name: string;
|
|
71
|
+
tableName: "mail_sort_rules";
|
|
72
|
+
dataType: "string";
|
|
73
|
+
data: string;
|
|
74
|
+
driverParam: string;
|
|
75
|
+
notNull: false;
|
|
76
|
+
hasDefault: false;
|
|
77
|
+
isPrimaryKey: false;
|
|
78
|
+
isAutoincrement: false;
|
|
79
|
+
hasRuntimeDefault: false;
|
|
80
|
+
enumValues: [string, ...string[]];
|
|
81
|
+
baseColumn: never;
|
|
82
|
+
identity: undefined;
|
|
83
|
+
generated: undefined;
|
|
84
|
+
}, {}>;
|
|
85
|
+
organizationId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
86
|
+
name: string;
|
|
87
|
+
tableName: "mail_sort_rules";
|
|
88
|
+
dataType: "number int53";
|
|
89
|
+
data: number;
|
|
90
|
+
driverParam: number;
|
|
91
|
+
notNull: false;
|
|
92
|
+
hasDefault: false;
|
|
93
|
+
isPrimaryKey: false;
|
|
94
|
+
isAutoincrement: false;
|
|
95
|
+
hasRuntimeDefault: false;
|
|
96
|
+
enumValues: undefined;
|
|
97
|
+
baseColumn: never;
|
|
98
|
+
identity: undefined;
|
|
99
|
+
generated: undefined;
|
|
100
|
+
}, {}>;
|
|
101
|
+
overAddresses: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
102
|
+
name: string;
|
|
103
|
+
tableName: "mail_sort_rules";
|
|
104
|
+
dataType: "number int53";
|
|
105
|
+
data: number;
|
|
106
|
+
driverParam: number;
|
|
107
|
+
notNull: true;
|
|
108
|
+
hasDefault: false;
|
|
109
|
+
isPrimaryKey: false;
|
|
110
|
+
isAutoincrement: false;
|
|
111
|
+
hasRuntimeDefault: false;
|
|
112
|
+
enumValues: undefined;
|
|
113
|
+
baseColumn: never;
|
|
114
|
+
identity: undefined;
|
|
115
|
+
generated: undefined;
|
|
116
|
+
}, {}>;
|
|
117
|
+
past: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
118
|
+
name: string;
|
|
119
|
+
tableName: "mail_sort_rules";
|
|
120
|
+
dataType: "number int53";
|
|
121
|
+
data: number;
|
|
122
|
+
driverParam: number;
|
|
123
|
+
notNull: true;
|
|
124
|
+
hasDefault: false;
|
|
125
|
+
isPrimaryKey: false;
|
|
126
|
+
isAutoincrement: false;
|
|
127
|
+
hasRuntimeDefault: false;
|
|
128
|
+
enumValues: undefined;
|
|
129
|
+
baseColumn: never;
|
|
130
|
+
identity: undefined;
|
|
131
|
+
generated: undefined;
|
|
132
|
+
}, {}>;
|
|
133
|
+
author: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
134
|
+
name: string;
|
|
135
|
+
tableName: "mail_sort_rules";
|
|
136
|
+
dataType: "string";
|
|
137
|
+
data: string;
|
|
138
|
+
driverParam: string;
|
|
139
|
+
notNull: true;
|
|
140
|
+
hasDefault: false;
|
|
141
|
+
isPrimaryKey: false;
|
|
142
|
+
isAutoincrement: false;
|
|
143
|
+
hasRuntimeDefault: false;
|
|
144
|
+
enumValues: [string, ...string[]];
|
|
145
|
+
baseColumn: never;
|
|
146
|
+
identity: undefined;
|
|
147
|
+
generated: undefined;
|
|
148
|
+
}, {}>;
|
|
149
|
+
decidedBy: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
150
|
+
name: string;
|
|
151
|
+
tableName: "mail_sort_rules";
|
|
152
|
+
dataType: "string";
|
|
153
|
+
data: string;
|
|
154
|
+
driverParam: string;
|
|
155
|
+
notNull: false;
|
|
156
|
+
hasDefault: false;
|
|
157
|
+
isPrimaryKey: false;
|
|
158
|
+
isAutoincrement: false;
|
|
159
|
+
hasRuntimeDefault: false;
|
|
160
|
+
enumValues: [string, ...string[]];
|
|
161
|
+
baseColumn: never;
|
|
162
|
+
identity: undefined;
|
|
163
|
+
generated: undefined;
|
|
164
|
+
}, {}>;
|
|
165
|
+
reason: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
166
|
+
name: string;
|
|
167
|
+
tableName: "mail_sort_rules";
|
|
168
|
+
dataType: "string";
|
|
169
|
+
data: string;
|
|
170
|
+
driverParam: string;
|
|
171
|
+
notNull: false;
|
|
172
|
+
hasDefault: false;
|
|
173
|
+
isPrimaryKey: false;
|
|
174
|
+
isAutoincrement: false;
|
|
175
|
+
hasRuntimeDefault: false;
|
|
176
|
+
enumValues: [string, ...string[]];
|
|
177
|
+
baseColumn: never;
|
|
178
|
+
identity: undefined;
|
|
179
|
+
generated: undefined;
|
|
180
|
+
}, {}>;
|
|
181
|
+
createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
182
|
+
name: string;
|
|
183
|
+
tableName: "mail_sort_rules";
|
|
184
|
+
dataType: "number int53";
|
|
185
|
+
data: number;
|
|
186
|
+
driverParam: number;
|
|
187
|
+
notNull: true;
|
|
188
|
+
hasDefault: false;
|
|
189
|
+
isPrimaryKey: false;
|
|
190
|
+
isAutoincrement: false;
|
|
191
|
+
hasRuntimeDefault: false;
|
|
192
|
+
enumValues: undefined;
|
|
193
|
+
baseColumn: never;
|
|
194
|
+
identity: undefined;
|
|
195
|
+
generated: undefined;
|
|
196
|
+
}, {}>;
|
|
197
|
+
updatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
198
|
+
name: string;
|
|
199
|
+
tableName: "mail_sort_rules";
|
|
200
|
+
dataType: "number int53";
|
|
201
|
+
data: number;
|
|
202
|
+
driverParam: number;
|
|
203
|
+
notNull: true;
|
|
204
|
+
hasDefault: false;
|
|
205
|
+
isPrimaryKey: false;
|
|
206
|
+
isAutoincrement: false;
|
|
207
|
+
hasRuntimeDefault: false;
|
|
208
|
+
enumValues: undefined;
|
|
209
|
+
baseColumn: never;
|
|
210
|
+
identity: undefined;
|
|
211
|
+
generated: undefined;
|
|
212
|
+
}, {}>;
|
|
213
|
+
removedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
214
|
+
name: string;
|
|
215
|
+
tableName: "mail_sort_rules";
|
|
216
|
+
dataType: "number int53";
|
|
217
|
+
data: number;
|
|
218
|
+
driverParam: number;
|
|
219
|
+
notNull: false;
|
|
220
|
+
hasDefault: false;
|
|
221
|
+
isPrimaryKey: false;
|
|
222
|
+
isAutoincrement: false;
|
|
223
|
+
hasRuntimeDefault: false;
|
|
224
|
+
enumValues: undefined;
|
|
225
|
+
baseColumn: never;
|
|
226
|
+
identity: undefined;
|
|
227
|
+
generated: undefined;
|
|
228
|
+
}, {}>;
|
|
229
|
+
undoneAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
230
|
+
name: string;
|
|
231
|
+
tableName: "mail_sort_rules";
|
|
232
|
+
dataType: "number int53";
|
|
233
|
+
data: number;
|
|
234
|
+
driverParam: number;
|
|
235
|
+
notNull: false;
|
|
236
|
+
hasDefault: false;
|
|
237
|
+
isPrimaryKey: false;
|
|
238
|
+
isAutoincrement: false;
|
|
239
|
+
hasRuntimeDefault: false;
|
|
240
|
+
enumValues: undefined;
|
|
241
|
+
baseColumn: never;
|
|
242
|
+
identity: undefined;
|
|
243
|
+
generated: undefined;
|
|
244
|
+
}, {}>;
|
|
245
|
+
};
|
|
246
|
+
dialect: 'sqlite';
|
|
247
|
+
isAlias: false;
|
|
248
|
+
}>;
|
|
249
|
+
export declare const mailSortEffects: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
250
|
+
name: "mail_sort_effects";
|
|
251
|
+
schema: undefined;
|
|
252
|
+
columns: {
|
|
253
|
+
id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
254
|
+
name: string;
|
|
255
|
+
tableName: "mail_sort_effects";
|
|
256
|
+
dataType: "number int53";
|
|
257
|
+
data: number;
|
|
258
|
+
driverParam: number;
|
|
259
|
+
notNull: true;
|
|
260
|
+
hasDefault: true;
|
|
261
|
+
isPrimaryKey: true;
|
|
262
|
+
isAutoincrement: false;
|
|
263
|
+
hasRuntimeDefault: false;
|
|
264
|
+
enumValues: undefined;
|
|
265
|
+
baseColumn: never;
|
|
266
|
+
identity: undefined;
|
|
267
|
+
generated: undefined;
|
|
268
|
+
}, {}>;
|
|
269
|
+
ruleId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
270
|
+
name: string;
|
|
271
|
+
tableName: "mail_sort_effects";
|
|
272
|
+
dataType: "number int53";
|
|
273
|
+
data: number;
|
|
274
|
+
driverParam: number;
|
|
275
|
+
notNull: true;
|
|
276
|
+
hasDefault: false;
|
|
277
|
+
isPrimaryKey: false;
|
|
278
|
+
isAutoincrement: false;
|
|
279
|
+
hasRuntimeDefault: false;
|
|
280
|
+
enumValues: undefined;
|
|
281
|
+
baseColumn: never;
|
|
282
|
+
identity: undefined;
|
|
283
|
+
generated: undefined;
|
|
284
|
+
}, {}>;
|
|
285
|
+
identityId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
286
|
+
name: string;
|
|
287
|
+
tableName: "mail_sort_effects";
|
|
288
|
+
dataType: "number int53";
|
|
289
|
+
data: number;
|
|
290
|
+
driverParam: number;
|
|
291
|
+
notNull: true;
|
|
292
|
+
hasDefault: false;
|
|
293
|
+
isPrimaryKey: false;
|
|
294
|
+
isAutoincrement: false;
|
|
295
|
+
hasRuntimeDefault: false;
|
|
296
|
+
enumValues: undefined;
|
|
297
|
+
baseColumn: never;
|
|
298
|
+
identity: undefined;
|
|
299
|
+
generated: undefined;
|
|
300
|
+
}, {}>;
|
|
301
|
+
action: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
302
|
+
name: string;
|
|
303
|
+
tableName: "mail_sort_effects";
|
|
304
|
+
dataType: "string";
|
|
305
|
+
data: string;
|
|
306
|
+
driverParam: string;
|
|
307
|
+
notNull: true;
|
|
308
|
+
hasDefault: false;
|
|
309
|
+
isPrimaryKey: false;
|
|
310
|
+
isAutoincrement: false;
|
|
311
|
+
hasRuntimeDefault: false;
|
|
312
|
+
enumValues: [string, ...string[]];
|
|
313
|
+
baseColumn: never;
|
|
314
|
+
identity: undefined;
|
|
315
|
+
generated: undefined;
|
|
316
|
+
}, {}>;
|
|
317
|
+
before: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
318
|
+
name: string;
|
|
319
|
+
tableName: "mail_sort_effects";
|
|
320
|
+
dataType: "string";
|
|
321
|
+
data: string;
|
|
322
|
+
driverParam: string;
|
|
323
|
+
notNull: false;
|
|
324
|
+
hasDefault: false;
|
|
325
|
+
isPrimaryKey: false;
|
|
326
|
+
isAutoincrement: false;
|
|
327
|
+
hasRuntimeDefault: false;
|
|
328
|
+
enumValues: [string, ...string[]];
|
|
329
|
+
baseColumn: never;
|
|
330
|
+
identity: undefined;
|
|
331
|
+
generated: undefined;
|
|
332
|
+
}, {}>;
|
|
333
|
+
after: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
334
|
+
name: string;
|
|
335
|
+
tableName: "mail_sort_effects";
|
|
336
|
+
dataType: "string";
|
|
337
|
+
data: string;
|
|
338
|
+
driverParam: string;
|
|
339
|
+
notNull: false;
|
|
340
|
+
hasDefault: false;
|
|
341
|
+
isPrimaryKey: false;
|
|
342
|
+
isAutoincrement: false;
|
|
343
|
+
hasRuntimeDefault: false;
|
|
344
|
+
enumValues: [string, ...string[]];
|
|
345
|
+
baseColumn: never;
|
|
346
|
+
identity: undefined;
|
|
347
|
+
generated: undefined;
|
|
348
|
+
}, {}>;
|
|
349
|
+
createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
350
|
+
name: string;
|
|
351
|
+
tableName: "mail_sort_effects";
|
|
352
|
+
dataType: "number int53";
|
|
353
|
+
data: number;
|
|
354
|
+
driverParam: number;
|
|
355
|
+
notNull: true;
|
|
356
|
+
hasDefault: false;
|
|
357
|
+
isPrimaryKey: false;
|
|
358
|
+
isAutoincrement: false;
|
|
359
|
+
hasRuntimeDefault: false;
|
|
360
|
+
enumValues: undefined;
|
|
361
|
+
baseColumn: never;
|
|
362
|
+
identity: undefined;
|
|
363
|
+
generated: undefined;
|
|
364
|
+
}, {}>;
|
|
365
|
+
undoneAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
366
|
+
name: string;
|
|
367
|
+
tableName: "mail_sort_effects";
|
|
368
|
+
dataType: "number int53";
|
|
369
|
+
data: number;
|
|
370
|
+
driverParam: number;
|
|
371
|
+
notNull: false;
|
|
372
|
+
hasDefault: false;
|
|
373
|
+
isPrimaryKey: false;
|
|
374
|
+
isAutoincrement: false;
|
|
375
|
+
hasRuntimeDefault: false;
|
|
376
|
+
enumValues: undefined;
|
|
377
|
+
baseColumn: never;
|
|
378
|
+
identity: undefined;
|
|
379
|
+
generated: undefined;
|
|
380
|
+
}, {}>;
|
|
381
|
+
};
|
|
382
|
+
dialect: 'sqlite';
|
|
383
|
+
isAlias: false;
|
|
384
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { index, integer, sqliteTable, text } from "../drizzle/core.js";
|
|
2
|
+
export const mailSortRules = sqliteTable("mail_sort_rules", {
|
|
3
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
4
|
+
scope: text("scope").notNull(),
|
|
5
|
+
value: text("value").notNull(),
|
|
6
|
+
mailType: text("mail_type"),
|
|
7
|
+
sender: text("sender"),
|
|
8
|
+
organizationId: integer("organization_id"),
|
|
9
|
+
overAddresses: integer("over_addresses").notNull(),
|
|
10
|
+
past: integer("past").notNull(),
|
|
11
|
+
author: text("author").notNull(),
|
|
12
|
+
decidedBy: text("decided_by"),
|
|
13
|
+
reason: text("reason"),
|
|
14
|
+
createdAt: integer("created_at").notNull(),
|
|
15
|
+
updatedAt: integer("updated_at").notNull(),
|
|
16
|
+
removedAt: integer("removed_at"),
|
|
17
|
+
undoneAt: integer("undone_at"),
|
|
18
|
+
}, (table) => [index("mail_sort_rules_by_scope_value").on(table.scope, table.value)]);
|
|
19
|
+
export const mailSortEffects = sqliteTable("mail_sort_effects", {
|
|
20
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
21
|
+
ruleId: integer("rule_id").notNull(),
|
|
22
|
+
identityId: integer("identity_id").notNull(),
|
|
23
|
+
action: text("action").notNull(),
|
|
24
|
+
before: text("before"),
|
|
25
|
+
after: text("after"),
|
|
26
|
+
createdAt: integer("created_at").notNull(),
|
|
27
|
+
undoneAt: integer("undone_at"),
|
|
28
|
+
}, (table) => [
|
|
29
|
+
index("mail_sort_effects_by_rule_id").on(table.ruleId),
|
|
30
|
+
index("mail_sort_effects_by_identity_id").on(table.identityId),
|
|
31
|
+
]);
|
|
@@ -5802,6 +5802,22 @@ export declare const emails: import("drizzle-orm/sqlite-core").SQLiteTableWithCo
|
|
|
5802
5802
|
identity: undefined;
|
|
5803
5803
|
generated: undefined;
|
|
5804
5804
|
}, {}>;
|
|
5805
|
+
sortChecked: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
5806
|
+
name: string;
|
|
5807
|
+
tableName: "emails";
|
|
5808
|
+
dataType: "number int53";
|
|
5809
|
+
data: number;
|
|
5810
|
+
driverParam: number;
|
|
5811
|
+
notNull: false;
|
|
5812
|
+
hasDefault: false;
|
|
5813
|
+
isPrimaryKey: false;
|
|
5814
|
+
isAutoincrement: false;
|
|
5815
|
+
hasRuntimeDefault: false;
|
|
5816
|
+
enumValues: undefined;
|
|
5817
|
+
baseColumn: never;
|
|
5818
|
+
identity: undefined;
|
|
5819
|
+
generated: undefined;
|
|
5820
|
+
}, {}>;
|
|
5805
5821
|
};
|
|
5806
5822
|
dialect: 'sqlite';
|
|
5807
5823
|
isAlias: false;
|
|
@@ -5974,6 +5990,7 @@ export declare const mailRules: import("drizzle-orm/sqlite-core").SQLiteTableWit
|
|
|
5974
5990
|
dialect: 'sqlite';
|
|
5975
5991
|
isAlias: false;
|
|
5976
5992
|
}>;
|
|
5993
|
+
export { mailSortEffects, mailSortRules } from "./schema/mail-sorting.js";
|
|
5977
5994
|
export declare const emailRecipients: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
5978
5995
|
name: "email_recipients";
|
|
5979
5996
|
schema: undefined;
|
|
@@ -669,12 +669,14 @@ export const emails = sqliteTable("emails", {
|
|
|
669
669
|
mailType: text("mail_type"),
|
|
670
670
|
reach: text("reach"),
|
|
671
671
|
typeSignal: text("type_signal"),
|
|
672
|
+
sortChecked: integer("sort_checked"),
|
|
672
673
|
}, (table) => [
|
|
673
674
|
unique().on(table.accountId, table.externalId),
|
|
674
675
|
index("emails_by_time").on(table.accountId, desc(table.sentAt)),
|
|
675
676
|
index("emails_by_mail_rule_id").on(table.mailRuleId).where(sql `mail_rule_id IS NOT NULL`),
|
|
676
677
|
index("emails_by_mail_type").on(table.mailType),
|
|
677
678
|
index("emails_type_to_work_out").on(table.id).where(sql `mail_type IS NULL`),
|
|
679
|
+
index("emails_sort_to_check").on(table.id).where(sql `mail_type IS NOT NULL AND sort_checked IS NULL`),
|
|
678
680
|
index("emails_by_list_id").on(sql `coalesce(json_extract(headers, '$."list-id"'), json_extract(metadata, '$.listId'))`),
|
|
679
681
|
index("emails_by_email_thread_id").on(table.emailThreadId),
|
|
680
682
|
index("emails_by_from_identity_id").on(table.fromIdentityId),
|
|
@@ -700,6 +702,7 @@ export const mailRules = sqliteTable("mail_rules", {
|
|
|
700
702
|
check("mail_rules_conditions_json", sql `"conditions" IS NULL OR json_valid("conditions")`),
|
|
701
703
|
check("mail_rules_actions_json", sql `"actions" IS NULL OR json_valid("actions")`),
|
|
702
704
|
]);
|
|
705
|
+
export { mailSortEffects, mailSortRules } from "./schema/mail-sorting.js";
|
|
703
706
|
export const emailRecipients = sqliteTable("email_recipients", {
|
|
704
707
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
705
708
|
emailId: integer("email_id")
|
|
@@ -71,11 +71,20 @@ export declare const ownerPeopleOf: (database: CacheDatabase) => Set<number>;
|
|
|
71
71
|
export declare const refuseBotAssignee: (database: CacheDatabase, person: number) => void;
|
|
72
72
|
/** A rule's move of a whole person to a new bot; answers the bot. The caller holds the write lock. */
|
|
73
73
|
export declare const ruleToBot: (database: CacheDatabase, person: number, reason: string, at: number) => number;
|
|
74
|
+
/** The reason of a bot that only sent a newsletter: a mail written to the owner alone gives it back to a person. */
|
|
75
|
+
export declare const NEWSLETTER_ONLY = "newsletter-only";
|
|
74
76
|
/**
|
|
75
|
-
* A rule's bot the owner wrote to, by mail or in a private chat both wrote in, goes back to the people its identities
|
|
77
|
+
* A rule's bot the owner wrote to, or a newsletter's that wrote to the owner alone, by mail or in a private chat both wrote in, goes back to the people its identities
|
|
76
78
|
* came from; a messenger's own bot flag holds anyway. The caller holds the write lock.
|
|
77
79
|
*/
|
|
78
80
|
export declare const ruleBotsBack: (database: CacheDatabase, at: number) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Mail a newsletter's bot sent since the last check: no trigger makes a kind stale for it, so a 1-to-1 mail would wait
|
|
83
|
+
* for someone else's change to give the bot back. Answers the newest email id to check up to, or `undefined`.
|
|
84
|
+
*/
|
|
85
|
+
export declare const newsletterBotsMail: (database: CacheDatabase) => number | undefined;
|
|
86
|
+
/** Gives back the newsletter bots a 1-to-1 mail came from, and keeps how far the mail was checked. */
|
|
87
|
+
export declare const settleNewsletterBots: (database: CacheDatabase, newest: number, at: number) => void;
|
|
79
88
|
/** Whether a build before version 75 sorted a bot onto a person row since the last kept list. */
|
|
80
89
|
export declare const hasLegacyBots: (database: CacheDatabase) => boolean;
|
|
81
90
|
/**
|