@wirecat/cli-core 1.0.0 → 1.1.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 +89 -0
- package/THIRD_PARTY_NOTICES +43 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/documents/words.d.ts +1 -1
- package/dist/cli/domain-lists-command.d.ts +16 -0
- package/dist/cli/domain-lists-command.js +88 -0
- package/dist/cli/index.d.ts +4 -3
- package/dist/cli/index.js +3 -2
- package/dist/cli/model-catalogue-command.d.ts +6 -0
- package/dist/cli/model-catalogue-command.js +1 -1
- package/dist/cli/oauth-session.d.ts +38 -4
- package/dist/cli/oauth-session.js +66 -22
- 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 +9 -0
- package/dist/cli/token-session.js +29 -2
- package/dist/domain/domain-lists.d.ts +86 -0
- package/dist/domain/domain-lists.js +110 -0
- package/dist/domain/free-mail-domains.generated.d.ts +1 -0
- package/dist/domain/free-mail-domains.generated.js +4 -0
- package/dist/domain/organization-sectors.d.ts +9 -3
- package/dist/domain/organization-sectors.generated.d.ts +1 -0
- package/dist/domain/organization-sectors.generated.js +1 -0
- package/dist/domain/organization-sectors.js +16 -3
- package/dist/domain/person-kinds.d.ts +6 -1
- package/dist/domain/person-kinds.js +5 -0
- package/dist/entities/domain-list.d.ts +27 -0
- package/dist/entities/domain-list.js +28 -0
- package/dist/entities/index.d.ts +20 -2
- package/dist/entities/index.js +3 -1
- package/dist/entities/knowledge-lists.d.ts +1 -1
- package/dist/errors/reasons.js +4 -2
- package/dist/mail/mail-types.d.ts +48 -0
- package/dist/mail/mail-types.js +218 -0
- package/dist/oauth/index.d.ts +1 -1
- package/dist/oauth/storage.d.ts +10 -2
- package/dist/oauth/storage.js +23 -9
- package/dist/services/domain-lists-download.d.ts +26 -0
- package/dist/services/domain-lists-download.js +155 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/store/areas.d.ts +1 -1
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/people.d.ts +18 -9
- package/dist/store/people.js +8 -7
- package/dist/store/sqlite/accounts.js +3 -1
- package/dist/store/sqlite/domain-organizations.d.ts +7 -4
- package/dist/store/sqlite/domain-organizations.js +94 -36
- package/dist/store/sqlite/email-types.d.ts +79 -0
- package/dist/store/sqlite/email-types.js +261 -0
- package/dist/store/sqlite/emails.d.ts +11 -2
- package/dist/store/sqlite/emails.js +18 -7
- package/dist/store/sqlite/identities.d.ts +4 -1
- package/dist/store/sqlite/identities.js +11 -2
- package/dist/store/sqlite/identity-rekey.js +2 -0
- package/dist/store/sqlite/manifest.js +4 -0
- package/dist/store/sqlite/merged-persons.d.ts +3 -2
- package/dist/store/sqlite/merged-persons.js +5 -3
- package/dist/store/sqlite/migrations.generated.js +56 -0
- package/dist/store/sqlite/people-list.d.ts +1 -6
- package/dist/store/sqlite/people-list.js +38 -32
- package/dist/store/sqlite/person-links.js +13 -3
- package/dist/store/sqlite/person-match-scan.js +5 -2
- package/dist/store/sqlite/schema/sender-bots.d.ts +56 -0
- package/dist/store/sqlite/schema/sender-bots.js +9 -1
- package/dist/store/sqlite/schema.d.ts +49 -1
- package/dist/store/sqlite/schema.js +6 -1
- package/dist/store/sqlite/sender-bots.d.ts +80 -15
- package/dist/store/sqlite/sender-bots.js +378 -136
- package/dist/store/sqlite/sender-signals.d.ts +11 -4
- package/dist/store/sqlite/sender-signals.js +14 -10
- package/package.json +2 -2
|
@@ -8,7 +8,7 @@ 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 { ownerPeopleOf,
|
|
11
|
+
import { hasLegacyBots, ownerPeopleOf, ruleBotsBack, ruleToBot, settleLegacyBots } from "./sender-bots.js";
|
|
12
12
|
import { senderSignalsOf, sentMailOf } from "./sender-signals.js";
|
|
13
13
|
import { mergedAssignees } from "./task-board.js";
|
|
14
14
|
import { hiddenTestPeople } from "./test-people.js";
|
|
@@ -172,7 +172,7 @@ const PROGRAM_SIGNALS = [
|
|
|
172
172
|
"bulk-never-replied",
|
|
173
173
|
];
|
|
174
174
|
/** 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,
|
|
175
|
+
const kindOf = (shown, facts, ties, mail, test, keptByOwner = false) => {
|
|
176
176
|
if (test)
|
|
177
177
|
return { kind: "test", signals: ["test-data"] };
|
|
178
178
|
const emails = facts?.emails ?? [];
|
|
@@ -189,13 +189,11 @@ const kindOf = (shown, facts, ties, mail, test, held) => {
|
|
|
189
189
|
? ["null-return-path"]
|
|
190
190
|
: []),
|
|
191
191
|
];
|
|
192
|
-
if (held === "bot")
|
|
193
|
-
return { kind: "automated", signals: automated.length > 0 ? automated : ["owner-choice"] };
|
|
194
192
|
const always = ties.filter((tie) => ALWAYS_SHOWN.includes(tie));
|
|
195
193
|
if (always.length > 0)
|
|
196
194
|
return { kind: "person", signals: ties };
|
|
197
195
|
// One mailbox's newsletter signal must not hide someone the owner talks to in a private chat.
|
|
198
|
-
if (
|
|
196
|
+
if (!keptByOwner && automated.length > 0 && (facts?.bot || !facts?.twoWay))
|
|
199
197
|
return { kind: "automated", signals: automated };
|
|
200
198
|
const organization = [
|
|
201
199
|
...(facts?.organization ? ["organization"] : []),
|
|
@@ -221,12 +219,10 @@ const isProgram = ({ kind, signals }, facts, ties) => kind === "automated" &&
|
|
|
221
219
|
signals.some((signal) => PROGRAM_SIGNALS.includes(signal)) &&
|
|
222
220
|
(facts.bot || (!facts.twoWay && !ties.includes("mail"))) &&
|
|
223
221
|
(facts.identities === 1 || facts.programIdentities === facts.identities);
|
|
224
|
-
const moveOf = (bot, program) => bot === undefined ? (program ? "bot" : undefined) : bot.author === "rules" && !program ? "person" : undefined;
|
|
225
222
|
/** Each person with their kind, contact and counts; the last contact is added for the page alone. */
|
|
226
223
|
const classified = (database, people, scope, reasons = shownReasons(database, scope === "all" ? undefined : scope)) => {
|
|
227
224
|
const facts = factsOf(database, scope);
|
|
228
225
|
const test = hiddenTestPeople(database);
|
|
229
|
-
const bots = senderBotsOf(database);
|
|
230
226
|
const ownerPeople = ownerPeopleOf(database);
|
|
231
227
|
const tasks = countsOf(database, TASK_COUNTS, mergedAssignees(database));
|
|
232
228
|
const mail = new Map(database
|
|
@@ -241,19 +237,16 @@ const classified = (database, people, scope, reasons = shownReasons(database, sc
|
|
|
241
237
|
const contact = { username: own?.username ?? null, phone: own?.phone ?? null, email: own?.email ?? null };
|
|
242
238
|
const shown = displayName(name, { ...contact, name: own?.name ?? null });
|
|
243
239
|
const ties = reasons.get(id) ?? [];
|
|
244
|
-
const
|
|
245
|
-
const
|
|
246
|
-
const
|
|
247
|
-
const move = held === undefined && !owner && worked.kind !== "test" ? moveOf(bot, isProgram(worked, own, ties)) : undefined;
|
|
248
|
-
const isBot = (bot !== undefined && move !== "person") || move === "bot";
|
|
249
|
-
const named = bot?.name ?? shown;
|
|
240
|
+
const kept = ownerPeople.has(id);
|
|
241
|
+
const worked = kindOf(shown, own, ties, mail.get(id), test.has(id), kept);
|
|
242
|
+
const toBot = !kept && !owner && worked.kind !== "test" && isProgram(worked, own, ties);
|
|
250
243
|
return {
|
|
251
244
|
id,
|
|
252
|
-
...(
|
|
253
|
-
nameOrder: nameOrderOf(
|
|
245
|
+
...(toBot ? { move: "bot" } : {}),
|
|
246
|
+
nameOrder: nameOrderOf(shown),
|
|
254
247
|
person: `person:${id}`,
|
|
255
248
|
name,
|
|
256
|
-
displayName:
|
|
249
|
+
displayName: shown,
|
|
257
250
|
kind: worked.kind,
|
|
258
251
|
kindSignals: worked.signals,
|
|
259
252
|
owner,
|
|
@@ -262,8 +255,7 @@ const classified = (database, people, scope, reasons = shownReasons(database, sc
|
|
|
262
255
|
...contact,
|
|
263
256
|
usernameSource: own?.usernameSource ?? null,
|
|
264
257
|
messagesFrom: (own?.messages ?? 0) + (mail.get(id)?.n ?? 0),
|
|
265
|
-
ties
|
|
266
|
-
bot: bot !== undefined && move !== "person" ? `${SENDER_BOT_PREFIX}${bot.id}` : null,
|
|
258
|
+
ties,
|
|
267
259
|
emails: own?.emails ?? [],
|
|
268
260
|
twoWay: own?.twoWay ?? false,
|
|
269
261
|
};
|
|
@@ -335,21 +327,32 @@ const workOut = (database, all, most) => {
|
|
|
335
327
|
};
|
|
336
328
|
const keep = (database, worked) => {
|
|
337
329
|
const at = Date.now();
|
|
338
|
-
|
|
330
|
+
settleLegacyBots(database, at);
|
|
331
|
+
ruleBotsBack(database, at);
|
|
332
|
+
const bots = [];
|
|
339
333
|
for (const person of worked)
|
|
340
|
-
if (person.move
|
|
341
|
-
|
|
334
|
+
if (person.move === "bot" && person.kind !== MERGED) {
|
|
335
|
+
bots.push({
|
|
336
|
+
id: ruleToBot(database, person.id, person.kindSignals.join(", "), at),
|
|
337
|
+
displayName: person.displayName,
|
|
338
|
+
holds: true,
|
|
339
|
+
bot: true,
|
|
340
|
+
});
|
|
341
|
+
person.kind = MERGED;
|
|
342
|
+
}
|
|
342
343
|
const keptAsPeople = ownerPeopleOf(database);
|
|
343
|
-
groupByDomain(database,
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
344
|
+
groupByDomain(database, [
|
|
345
|
+
...bots,
|
|
346
|
+
...worked
|
|
347
|
+
.filter((person) => !person.owner && person.kind !== MERGED && person.kind !== "test")
|
|
348
|
+
.map((person) => ({
|
|
349
|
+
id: person.id,
|
|
350
|
+
displayName: person.displayName,
|
|
351
|
+
holds: !keptAsPeople.has(person.id) &&
|
|
352
|
+
person.kind === "organization" &&
|
|
353
|
+
person.kindSignals.includes("role-address"),
|
|
354
|
+
})),
|
|
355
|
+
], at);
|
|
353
356
|
const row = database.prepare("UPDATE persons SET kind = ?, name_order = ?, messages_from = ?, task_count = ?, last_contact = ? WHERE id = ?");
|
|
354
357
|
for (const person of worked)
|
|
355
358
|
row.run(person.kind, person.nameOrder, person.messagesFrom, person.tasks, person.lastContact ?? null, person.id);
|
|
@@ -365,6 +368,9 @@ const keep = (database, worked) => {
|
|
|
365
368
|
* Answers whether every stored one is current.
|
|
366
369
|
*/
|
|
367
370
|
export const storeKinds = (database) => {
|
|
371
|
+
// A 1.0 build keeps the kinds of the people it sorts onto a bot, so nothing else would bring their bot here.
|
|
372
|
+
if (!isQueryOnly(database) && hasLegacyBots(database))
|
|
373
|
+
writeBatch(database, () => settleLegacyBots(database, Date.now()));
|
|
368
374
|
if (isQueryOnly(database))
|
|
369
375
|
return (rulesOf(database) === KIND_RULES &&
|
|
370
376
|
database.prepare("SELECT 1 FROM persons WHERE kind IS NULL LIMIT 1").get() === undefined);
|
|
@@ -552,7 +558,7 @@ export const similarPeople = (database, typed, limit) => {
|
|
|
552
558
|
}));
|
|
553
559
|
const byId = new Map(people.map((person) => [person.id, person]));
|
|
554
560
|
const ordered = [...sameName.keys()].flatMap((id) => byId.get(id) ?? []);
|
|
555
|
-
const rows = classified(database, ordered, [...sameName.keys()], ties).filter(({ kind,
|
|
561
|
+
const rows = classified(database, ordered, [...sameName.keys()], ties).filter(({ kind, move }) => kind !== "test" && move === undefined);
|
|
556
562
|
const same = rows.map(({ id }) => sameName.get(id) === true);
|
|
557
563
|
return withLastContact(database, rows).map((person, at) => ({ ...person, sameName: same[at] === true }));
|
|
558
564
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { isEmailAddress, isRoleAddress } from "../../domain/addresses.js";
|
|
3
3
|
import { displayName, noFallbacks, takeFallbacks } from "../../domain/display-names.js";
|
|
4
|
+
import { SENDER_BOT_PREFIX } from "../../domain/person-kinds.js";
|
|
4
5
|
import { and, eq, inArray, isNull, sql } from "./drizzle/core.js";
|
|
5
6
|
import { identityOf } from "./identities.js";
|
|
6
7
|
import { rejectedEvidence, settleLinks } from "./identity-link-rows.js";
|
|
@@ -17,9 +18,18 @@ const identityRow = ({ orm }, { provider, id }) => orm
|
|
|
17
18
|
.get();
|
|
18
19
|
export const required = (context, ref) => {
|
|
19
20
|
const found = identityRow(context, ref);
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
if (found)
|
|
22
|
+
return found;
|
|
23
|
+
const bot = context.database
|
|
24
|
+
.prepare("SELECT s.bot_id FROM sender_bot_identities s JOIN identities i ON i.id = s.identity_id " +
|
|
25
|
+
"WHERE i.provider = ? AND i.external_id = ?")
|
|
26
|
+
.get(ref.provider, ref.id);
|
|
27
|
+
if (bot !== undefined)
|
|
28
|
+
throw new CliError("validation_error", `${ref.provider} ${ref.id} is ${SENDER_BOT_PREFIX}${bot.bot_id}, not a person`, {
|
|
29
|
+
reason: "sender-bot.not-a-person",
|
|
30
|
+
reference: `${SENDER_BOT_PREFIX}${bot.bot_id}`,
|
|
31
|
+
});
|
|
32
|
+
throw new CliError("not_found", `no ${ref.provider} person ${ref.id} in the store`);
|
|
23
33
|
};
|
|
24
34
|
/** Every phone and address an identity holds: the source's lists, else the one `phone` and `email`. */
|
|
25
35
|
const contactListsOf = ({ phone, email }, metadata) => {
|
|
@@ -233,9 +233,12 @@ const touchesOwner = ({ context, result }, from, to, signal) => {
|
|
|
233
233
|
result.skipped.push({ persons: [String(from), String(to)], signal, reason: "identity.owner" });
|
|
234
234
|
return true;
|
|
235
235
|
};
|
|
236
|
-
/** A sender bot is never proposed as the same person
|
|
236
|
+
/** A person every identity left for a sender bot is never proposed as the same person; the owner moves it by hand. */
|
|
237
237
|
const touchesBot = ({ context, result }, from, to, signal) => {
|
|
238
|
-
const held = context.database
|
|
238
|
+
const held = context.database
|
|
239
|
+
.prepare("SELECT 1 FROM sender_bot_moves m WHERE m.from_person_id IN (?, ?) AND m.to_bot_id IS NOT NULL " +
|
|
240
|
+
"AND NOT EXISTS (SELECT 1 FROM identity_links l WHERE l.person_id = m.from_person_id) LIMIT 1")
|
|
241
|
+
.get(from, to);
|
|
239
242
|
if (held === undefined)
|
|
240
243
|
return false;
|
|
241
244
|
result.skipped.push({ persons: [String(from), String(to)], signal, reason: "identity.not-a-person" });
|
|
@@ -134,6 +134,62 @@ export declare const senderBots: import("drizzle-orm/sqlite-core").SQLiteTableWi
|
|
|
134
134
|
dialect: 'sqlite';
|
|
135
135
|
isAlias: false;
|
|
136
136
|
}>;
|
|
137
|
+
export declare const senderBotIdentities: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
138
|
+
name: "sender_bot_identities";
|
|
139
|
+
schema: undefined;
|
|
140
|
+
columns: {
|
|
141
|
+
identityId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
142
|
+
name: string;
|
|
143
|
+
tableName: "sender_bot_identities";
|
|
144
|
+
dataType: "number int53";
|
|
145
|
+
data: number;
|
|
146
|
+
driverParam: number;
|
|
147
|
+
notNull: true;
|
|
148
|
+
hasDefault: true;
|
|
149
|
+
isPrimaryKey: true;
|
|
150
|
+
isAutoincrement: false;
|
|
151
|
+
hasRuntimeDefault: false;
|
|
152
|
+
enumValues: undefined;
|
|
153
|
+
baseColumn: never;
|
|
154
|
+
identity: undefined;
|
|
155
|
+
generated: undefined;
|
|
156
|
+
}, {}>;
|
|
157
|
+
botId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
158
|
+
name: string;
|
|
159
|
+
tableName: "sender_bot_identities";
|
|
160
|
+
dataType: "number int53";
|
|
161
|
+
data: number;
|
|
162
|
+
driverParam: number;
|
|
163
|
+
notNull: true;
|
|
164
|
+
hasDefault: false;
|
|
165
|
+
isPrimaryKey: false;
|
|
166
|
+
isAutoincrement: false;
|
|
167
|
+
hasRuntimeDefault: false;
|
|
168
|
+
enumValues: undefined;
|
|
169
|
+
baseColumn: never;
|
|
170
|
+
identity: undefined;
|
|
171
|
+
generated: undefined;
|
|
172
|
+
}, {}>;
|
|
173
|
+
createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
174
|
+
name: string;
|
|
175
|
+
tableName: "sender_bot_identities";
|
|
176
|
+
dataType: "number int53";
|
|
177
|
+
data: number;
|
|
178
|
+
driverParam: number;
|
|
179
|
+
notNull: true;
|
|
180
|
+
hasDefault: false;
|
|
181
|
+
isPrimaryKey: false;
|
|
182
|
+
isAutoincrement: false;
|
|
183
|
+
hasRuntimeDefault: false;
|
|
184
|
+
enumValues: undefined;
|
|
185
|
+
baseColumn: never;
|
|
186
|
+
identity: undefined;
|
|
187
|
+
generated: undefined;
|
|
188
|
+
}, {}>;
|
|
189
|
+
};
|
|
190
|
+
dialect: 'sqlite';
|
|
191
|
+
isAlias: false;
|
|
192
|
+
}>;
|
|
137
193
|
export declare const senderBotMoves: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
138
194
|
name: "sender_bot_moves";
|
|
139
195
|
schema: undefined;
|
|
@@ -9,6 +9,11 @@ export const senderBots = sqliteTable("sender_bots", {
|
|
|
9
9
|
createdAt: integer("created_at").notNull(),
|
|
10
10
|
updatedAt: integer("updated_at").notNull(),
|
|
11
11
|
});
|
|
12
|
+
export const senderBotIdentities = sqliteTable("sender_bot_identities", {
|
|
13
|
+
identityId: integer("identity_id").primaryKey(),
|
|
14
|
+
botId: integer("bot_id").notNull(),
|
|
15
|
+
createdAt: integer("created_at").notNull(),
|
|
16
|
+
}, (table) => [index("sender_bot_identities_by_bot_id").on(table.botId)]);
|
|
12
17
|
export const senderBotMoves = sqliteTable("sender_bot_moves", {
|
|
13
18
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
14
19
|
identityId: integer("identity_id").notNull(),
|
|
@@ -19,4 +24,7 @@ export const senderBotMoves = sqliteTable("sender_bot_moves", {
|
|
|
19
24
|
author: text("author").notNull(),
|
|
20
25
|
reason: text("reason"),
|
|
21
26
|
createdAt: integer("created_at").notNull(),
|
|
22
|
-
}, (table) => [
|
|
27
|
+
}, (table) => [
|
|
28
|
+
index("sender_bot_moves_by_identity_id").on(table.identityId),
|
|
29
|
+
index("sender_bot_moves_by_from_person_id").on(table.fromPersonId),
|
|
30
|
+
]);
|
|
@@ -2433,7 +2433,7 @@ export declare const bots: import("drizzle-orm/sqlite-core").SQLiteTableWithColu
|
|
|
2433
2433
|
dialect: 'sqlite';
|
|
2434
2434
|
isAlias: false;
|
|
2435
2435
|
}>;
|
|
2436
|
-
export { senderBotMoves, senderBots } from "./schema/sender-bots.js";
|
|
2436
|
+
export { senderBotIdentities, senderBotMoves, senderBots } from "./schema/sender-bots.js";
|
|
2437
2437
|
export declare const chats: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
2438
2438
|
name: "chats";
|
|
2439
2439
|
schema: undefined;
|
|
@@ -5754,6 +5754,54 @@ export declare const emails: import("drizzle-orm/sqlite-core").SQLiteTableWithCo
|
|
|
5754
5754
|
identity: undefined;
|
|
5755
5755
|
generated: undefined;
|
|
5756
5756
|
}, {}>;
|
|
5757
|
+
mailType: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
5758
|
+
name: string;
|
|
5759
|
+
tableName: "emails";
|
|
5760
|
+
dataType: "string";
|
|
5761
|
+
data: string;
|
|
5762
|
+
driverParam: string;
|
|
5763
|
+
notNull: false;
|
|
5764
|
+
hasDefault: false;
|
|
5765
|
+
isPrimaryKey: false;
|
|
5766
|
+
isAutoincrement: false;
|
|
5767
|
+
hasRuntimeDefault: false;
|
|
5768
|
+
enumValues: [string, ...string[]];
|
|
5769
|
+
baseColumn: never;
|
|
5770
|
+
identity: undefined;
|
|
5771
|
+
generated: undefined;
|
|
5772
|
+
}, {}>;
|
|
5773
|
+
reach: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
5774
|
+
name: string;
|
|
5775
|
+
tableName: "emails";
|
|
5776
|
+
dataType: "string";
|
|
5777
|
+
data: string;
|
|
5778
|
+
driverParam: string;
|
|
5779
|
+
notNull: false;
|
|
5780
|
+
hasDefault: false;
|
|
5781
|
+
isPrimaryKey: false;
|
|
5782
|
+
isAutoincrement: false;
|
|
5783
|
+
hasRuntimeDefault: false;
|
|
5784
|
+
enumValues: [string, ...string[]];
|
|
5785
|
+
baseColumn: never;
|
|
5786
|
+
identity: undefined;
|
|
5787
|
+
generated: undefined;
|
|
5788
|
+
}, {}>;
|
|
5789
|
+
typeSignal: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
5790
|
+
name: string;
|
|
5791
|
+
tableName: "emails";
|
|
5792
|
+
dataType: "string";
|
|
5793
|
+
data: string;
|
|
5794
|
+
driverParam: string;
|
|
5795
|
+
notNull: false;
|
|
5796
|
+
hasDefault: false;
|
|
5797
|
+
isPrimaryKey: false;
|
|
5798
|
+
isAutoincrement: false;
|
|
5799
|
+
hasRuntimeDefault: false;
|
|
5800
|
+
enumValues: [string, ...string[]];
|
|
5801
|
+
baseColumn: never;
|
|
5802
|
+
identity: undefined;
|
|
5803
|
+
generated: undefined;
|
|
5804
|
+
}, {}>;
|
|
5757
5805
|
};
|
|
5758
5806
|
dialect: 'sqlite';
|
|
5759
5807
|
isAlias: false;
|
|
@@ -266,7 +266,7 @@ export const bots = sqliteTable("bots", {
|
|
|
266
266
|
index("bots_by_owner_person_id").on(table.ownerPersonId),
|
|
267
267
|
check("bots_metadata_json", sql `"metadata" IS NULL OR json_valid("metadata")`),
|
|
268
268
|
]);
|
|
269
|
-
export { senderBotMoves, senderBots } from "./schema/sender-bots.js";
|
|
269
|
+
export { senderBotIdentities, senderBotMoves, senderBots } from "./schema/sender-bots.js";
|
|
270
270
|
export const chats = sqliteTable("chats", {
|
|
271
271
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
272
272
|
accountId: integer("account_id")
|
|
@@ -666,10 +666,15 @@ export const emails = sqliteTable("emails", {
|
|
|
666
666
|
deletedAt: integer("deleted_at"),
|
|
667
667
|
// No constraint: older stores add the column without a rebuild; removing a rule clears it.
|
|
668
668
|
mailRuleId: integer("mail_rule_id"),
|
|
669
|
+
mailType: text("mail_type"),
|
|
670
|
+
reach: text("reach"),
|
|
671
|
+
typeSignal: text("type_signal"),
|
|
669
672
|
}, (table) => [
|
|
670
673
|
unique().on(table.accountId, table.externalId),
|
|
671
674
|
index("emails_by_time").on(table.accountId, desc(table.sentAt)),
|
|
672
675
|
index("emails_by_mail_rule_id").on(table.mailRuleId).where(sql `mail_rule_id IS NOT NULL`),
|
|
676
|
+
index("emails_by_mail_type").on(table.mailType),
|
|
677
|
+
index("emails_type_to_work_out").on(table.id).where(sql `mail_type IS NULL`),
|
|
673
678
|
index("emails_by_list_id").on(sql `coalesce(json_extract(headers, '$."list-id"'), json_extract(metadata, '$.listId'))`),
|
|
674
679
|
index("emails_by_email_thread_id").on(table.emailThreadId),
|
|
675
680
|
index("emails_by_from_identity_id").on(table.fromIdentityId),
|
|
@@ -1,41 +1,106 @@
|
|
|
1
1
|
import type { CacheDatabase } from "../driver.js";
|
|
2
2
|
import type { IdentityRef, PersonRecord } from "../types.js";
|
|
3
3
|
import type { StoreContext } from "./open.js";
|
|
4
|
-
|
|
4
|
+
import { type Reach, type SenderSignal } from "./sender-signals.js";
|
|
5
5
|
export type BotAuthor = "rules" | "owner";
|
|
6
|
-
/**
|
|
7
|
-
export interface
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/** @experimental */
|
|
7
|
+
export interface BotIdentity {
|
|
8
|
+
provider: string;
|
|
9
|
+
id: string;
|
|
10
10
|
name: string | null;
|
|
11
|
+
username: string | null;
|
|
11
12
|
}
|
|
13
|
+
/** A program that writes to the owner, apart from people: it has no ties, no tasks and no merge review. @experimental */
|
|
12
14
|
export interface SenderBot {
|
|
15
|
+
/** `sender-bot:<id>`. */
|
|
13
16
|
bot: string;
|
|
14
|
-
/** The
|
|
15
|
-
person: string;
|
|
17
|
+
/** The owner's name for it; `displayName` falls back to its identities'. */
|
|
16
18
|
name: string | null;
|
|
19
|
+
displayName: string | null;
|
|
20
|
+
/** The organization it sends for (`organization:<id>`), from its mail domain or the owner. */
|
|
21
|
+
organization: string | null;
|
|
22
|
+
/** `owner` when the owner moved it: no rule gives it back to a person. */
|
|
23
|
+
author: BotAuthor;
|
|
24
|
+
/** The kind signals that sorted it, or the owner's words. */
|
|
25
|
+
reason: string | null;
|
|
26
|
+
identities: BotIdentity[];
|
|
27
|
+
/** Messages and mail it sent, every account together. */
|
|
28
|
+
messagesFrom: number;
|
|
29
|
+
lastContact: string | null;
|
|
30
|
+
reach: Reach | null;
|
|
31
|
+
signals: SenderSignal[];
|
|
32
|
+
}
|
|
33
|
+
/** One move of an identity between a person and a bot. @experimental */
|
|
34
|
+
export interface BotMove {
|
|
35
|
+
identity: IdentityRef;
|
|
36
|
+
/** `person:<uid>` or `sender-bot:<id>`; `null` for none. */
|
|
37
|
+
from: string | null;
|
|
38
|
+
to: string | null;
|
|
17
39
|
author: BotAuthor;
|
|
18
40
|
reason: string | null;
|
|
41
|
+
at: string;
|
|
42
|
+
}
|
|
43
|
+
/** @experimental */
|
|
44
|
+
export interface SenderBotDetails extends SenderBot {
|
|
45
|
+
/** Every move to or from this bot, oldest first. */
|
|
46
|
+
moves: BotMove[];
|
|
47
|
+
}
|
|
48
|
+
/** @experimental */
|
|
49
|
+
export interface BotListOptions {
|
|
50
|
+
/** Part of a name, address or username, at least 3 characters. */
|
|
51
|
+
query?: string;
|
|
52
|
+
/** `organization:<id>`: the bots that send for it. */
|
|
53
|
+
organization?: string;
|
|
54
|
+
limit: number;
|
|
55
|
+
offset?: number;
|
|
56
|
+
}
|
|
57
|
+
/** @experimental */
|
|
58
|
+
export interface BotList {
|
|
59
|
+
items: SenderBot[];
|
|
60
|
+
hasMore: boolean;
|
|
61
|
+
total: number;
|
|
19
62
|
}
|
|
20
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The source re-keyed `from` onto `to`, both stored: a bot holding `from` takes `to` from its person, since one
|
|
65
|
+
* account is one program. The person it leaves is hidden as `intoBot` hides one. The caller holds the write lock.
|
|
66
|
+
*/
|
|
67
|
+
export declare const rekeyIntoBot: (database: CacheDatabase, from: number, to: number, at: number) => void;
|
|
21
68
|
/** People holding an identity the owner last moved to a person, or kept as one: no rule makes them a bot. */
|
|
22
69
|
export declare const ownerPeopleOf: (database: CacheDatabase) => Set<number>;
|
|
70
|
+
/** A person every identity left for a bot is no one's assignee: the bot has no tasks. */
|
|
23
71
|
export declare const refuseBotAssignee: (database: CacheDatabase, person: number) => void;
|
|
24
|
-
/** A rule's move of a whole person to a bot
|
|
25
|
-
export declare const
|
|
72
|
+
/** A rule's move of a whole person to a new bot; answers the bot. The caller holds the write lock. */
|
|
73
|
+
export declare const ruleToBot: (database: CacheDatabase, person: number, reason: string, at: number) => number;
|
|
74
|
+
/**
|
|
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
|
|
76
|
+
* came from; a messenger's own bot flag holds anyway. The caller holds the write lock.
|
|
77
|
+
*/
|
|
78
|
+
export declare const ruleBotsBack: (database: CacheDatabase, at: number) => void;
|
|
79
|
+
/** Whether a build before version 75 sorted a bot onto a person row since the last kept list. */
|
|
80
|
+
export declare const hasLegacyBots: (database: CacheDatabase) => boolean;
|
|
81
|
+
/**
|
|
82
|
+
* A bot a build before version 75 sorted after the upgrade holds its person row's identities there: they move to the
|
|
83
|
+
* bot, as the upgrade moved the others. The caller holds the write lock.
|
|
84
|
+
*/
|
|
85
|
+
export declare const settleLegacyBots: (database: CacheDatabase, at: number) => void;
|
|
86
|
+
/** The sender bots, by name; a bot a build before version 75 sorted shows once a list has settled it. */
|
|
87
|
+
export declare const listBots: (database: CacheDatabase, options: BotListOptions) => BotList;
|
|
88
|
+
/** One sender bot with its identities and every move to or from it. */
|
|
89
|
+
export declare const showBot: (database: CacheDatabase, ref: string) => SenderBotDetails;
|
|
26
90
|
/**
|
|
27
|
-
* The owner's word that a person, or one
|
|
28
|
-
*
|
|
29
|
-
*
|
|
91
|
+
* The owner's word that a person, a bot or one identity is a program, for its whole history: its messages stay where
|
|
92
|
+
* they are, and no rule gives it back. `bot` joins it to a stored bot; else a bot that already holds it keeps it, or a
|
|
93
|
+
* new one takes it. A person every identity left is hidden, and a move back gives their uid back.
|
|
30
94
|
*/
|
|
31
95
|
export declare const moveToBot: (context: StoreContext, subject: string | IdentityRef, options?: {
|
|
32
96
|
bot?: string;
|
|
33
97
|
name?: string;
|
|
34
98
|
reason?: string;
|
|
35
|
-
}) =>
|
|
99
|
+
}) => SenderBotDetails;
|
|
36
100
|
/**
|
|
37
101
|
* The owner's word that a bot, a person or one identity is a person, for its whole history; no rule makes it a bot
|
|
38
|
-
* again. `person`
|
|
102
|
+
* again. `person` takes it; else each identity goes back to the person it came from, or a person of its own. Said of a
|
|
103
|
+
* person, it keeps them one. Answers the person the first identity is on.
|
|
39
104
|
*/
|
|
40
105
|
export declare const moveToPerson: (context: StoreContext, subject: string | IdentityRef, options?: {
|
|
41
106
|
person?: string;
|