@wirecat/cli-core 1.0.0-rc.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +186 -0
  2. package/THIRD_PARTY_NOTICES +47 -0
  3. package/dist/cli/account-rename.js +1 -1
  4. package/dist/cli/bot/api-input.d.ts +5 -0
  5. package/dist/cli/bot/api-input.js +6 -1
  6. package/dist/cli/bot/api.js +7 -1
  7. package/dist/cli/domain-lists-command.d.ts +16 -0
  8. package/dist/cli/domain-lists-command.js +88 -0
  9. package/dist/cli/index.d.ts +4 -3
  10. package/dist/cli/index.js +3 -2
  11. package/dist/cli/model-catalogue-command.d.ts +6 -0
  12. package/dist/cli/model-catalogue-command.js +1 -1
  13. package/dist/cli/oauth-session.d.ts +38 -4
  14. package/dist/cli/oauth-session.js +66 -22
  15. package/dist/cli/service-api.js +3 -1
  16. package/dist/cli/shared-command-exports.d.ts +2 -0
  17. package/dist/cli/shared-command-exports.js +3 -0
  18. package/dist/cli/token-session.d.ts +9 -0
  19. package/dist/cli/token-session.js +29 -2
  20. package/dist/crm/manifest/map.d.ts +5 -2
  21. package/dist/crm/manifest/map.js +14 -2
  22. package/dist/domain/domain-lists.d.ts +86 -0
  23. package/dist/domain/domain-lists.js +110 -0
  24. package/dist/domain/free-mail-domains.generated.d.ts +1 -0
  25. package/dist/domain/free-mail-domains.generated.js +4 -0
  26. package/dist/domain/organization-sectors.d.ts +16 -0
  27. package/dist/domain/organization-sectors.generated.d.ts +12 -0
  28. package/dist/domain/organization-sectors.generated.js +15 -0
  29. package/dist/domain/organization-sectors.js +22 -0
  30. package/dist/domain/person-kinds.d.ts +5 -0
  31. package/dist/domain/person-kinds.js +5 -0
  32. package/dist/entities/domain-list.d.ts +27 -0
  33. package/dist/entities/domain-list.js +28 -0
  34. package/dist/entities/index.d.ts +20 -1
  35. package/dist/entities/index.js +3 -1
  36. package/dist/entities/knowledge-lists.d.ts +1 -0
  37. package/dist/entities/knowledge-lists.js +2 -0
  38. package/dist/errors/reasons.js +14 -3
  39. package/dist/mail/mail-types.d.ts +48 -0
  40. package/dist/mail/mail-types.js +218 -0
  41. package/dist/mail/score.d.ts +2 -0
  42. package/dist/mail/score.js +9 -2
  43. package/dist/oauth/index.d.ts +1 -1
  44. package/dist/oauth/storage.d.ts +10 -2
  45. package/dist/oauth/storage.js +23 -9
  46. package/dist/services/domain-lists-download.d.ts +26 -0
  47. package/dist/services/domain-lists-download.js +155 -0
  48. package/dist/services/search-all-rank.d.ts +44 -0
  49. package/dist/services/search-all-rank.js +112 -0
  50. package/dist/services/search-all-tracker.d.ts +58 -0
  51. package/dist/services/search-all-tracker.js +155 -0
  52. package/dist/services/search-all.d.ts +1 -8
  53. package/dist/services/search-all.js +18 -199
  54. package/dist/services/tracker-meaning.js +1 -1
  55. package/dist/store/areas.d.ts +1 -0
  56. package/dist/store/index.d.ts +2 -1
  57. package/dist/store/index.js +1 -1
  58. package/dist/store/people.d.ts +30 -0
  59. package/dist/store/people.js +16 -1
  60. package/dist/store/sqlite/accounts.js +3 -1
  61. package/dist/store/sqlite/domain-organizations.d.ts +36 -0
  62. package/dist/store/sqlite/domain-organizations.js +288 -0
  63. package/dist/store/sqlite/email-types.d.ts +79 -0
  64. package/dist/store/sqlite/email-types.js +261 -0
  65. package/dist/store/sqlite/emails.d.ts +11 -2
  66. package/dist/store/sqlite/emails.js +18 -7
  67. package/dist/store/sqlite/identities.d.ts +4 -1
  68. package/dist/store/sqlite/identities.js +11 -2
  69. package/dist/store/sqlite/identity-rekey.js +2 -0
  70. package/dist/store/sqlite/knowledge.d.ts +2 -9
  71. package/dist/store/sqlite/manifest.js +6 -0
  72. package/dist/store/sqlite/merged-persons.d.ts +3 -2
  73. package/dist/store/sqlite/merged-persons.js +5 -3
  74. package/dist/store/sqlite/migrations.generated.js +77 -0
  75. package/dist/store/sqlite/organizations.d.ts +12 -1
  76. package/dist/store/sqlite/organizations.js +9 -1
  77. package/dist/store/sqlite/people-list.js +69 -11
  78. package/dist/store/sqlite/person-links.js +13 -3
  79. package/dist/store/sqlite/person-match-scan.js +14 -1
  80. package/dist/store/sqlite/schema/sender-bots.d.ts +344 -0
  81. package/dist/store/sqlite/schema/sender-bots.js +30 -0
  82. package/dist/store/sqlite/schema.d.ts +49 -0
  83. package/dist/store/sqlite/schema.js +7 -0
  84. package/dist/store/sqlite/sender-bots.d.ts +108 -0
  85. package/dist/store/sqlite/sender-bots.js +431 -0
  86. package/dist/store/sqlite/sender-signals.d.ts +13 -3
  87. package/dist/store/sqlite/sender-signals.js +17 -13
  88. package/dist/store/sqlite/tracker.d.ts +11 -9
  89. package/dist/store/sqlite/tracker.js +27 -12
  90. package/dist/store/sqlite/work-tasks.js +2 -0
  91. package/dist/tracker/cli/index.d.ts +1 -1
  92. package/dist/tracker/cli/index.js +83 -24
  93. package/dist/tracker/sync.js +43 -20
  94. package/dist/tracker/writes.d.ts +28 -0
  95. package/dist/tracker/writes.js +141 -19
  96. package/package.json +3 -3
@@ -203,7 +203,7 @@ const join = (pass, sides, signal) => {
203
203
  result.skipped.push({ persons: [String(from), String(into)], signal: method, reason: "identity.separated" });
204
204
  return into;
205
205
  }
206
- if (touchesOwner(pass, from, into, method))
206
+ if (touchesOwner(pass, from, into, method) || touchesBot(pass, from, into, method))
207
207
  return into;
208
208
  if (index.rejected(from, into) !== undefined) {
209
209
  propose(pass, {
@@ -233,10 +233,23 @@ 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 person every identity left for a sender bot is never proposed as the same person; the owner moves it by hand. */
237
+ const touchesBot = ({ context, result }, from, to, signal) => {
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);
242
+ if (held === undefined)
243
+ return false;
244
+ result.skipped.push({ persons: [String(from), String(to)], signal, reason: "identity.not-a-person" });
245
+ return true;
246
+ };
236
247
  const propose = (pass, opening) => {
237
248
  const { context, index, result } = pass;
238
249
  if (touchesOwner(pass, opening.from, opening.to, opening.signal))
239
250
  return;
251
+ if (touchesBot(pass, opening.from, opening.to, opening.signal))
252
+ return;
240
253
  const opened = openIdentityLink(context, { ...opening, by: RULE }, index);
241
254
  const persons = [String(opening.from), String(opening.to)];
242
255
  if (opened.outcome === "skipped") {
@@ -0,0 +1,344 @@
1
+ export declare const senderBots: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
2
+ name: "sender_bots";
3
+ schema: undefined;
4
+ columns: {
5
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6
+ name: string;
7
+ tableName: "sender_bots";
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
+ personId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
22
+ name: string;
23
+ tableName: "sender_bots";
24
+ dataType: "number int53";
25
+ data: number;
26
+ driverParam: number;
27
+ notNull: true;
28
+ hasDefault: false;
29
+ isPrimaryKey: false;
30
+ isAutoincrement: false;
31
+ hasRuntimeDefault: false;
32
+ enumValues: undefined;
33
+ baseColumn: never;
34
+ identity: undefined;
35
+ generated: undefined;
36
+ }, {}>;
37
+ name: import("drizzle-orm/sqlite-core").SQLiteColumn<{
38
+ name: string;
39
+ tableName: "sender_bots";
40
+ dataType: "string";
41
+ data: string;
42
+ driverParam: string;
43
+ notNull: false;
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
+ organizationId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
54
+ name: string;
55
+ tableName: "sender_bots";
56
+ dataType: "number int53";
57
+ data: number;
58
+ driverParam: number;
59
+ notNull: false;
60
+ hasDefault: false;
61
+ isPrimaryKey: false;
62
+ isAutoincrement: false;
63
+ hasRuntimeDefault: false;
64
+ enumValues: undefined;
65
+ baseColumn: never;
66
+ identity: undefined;
67
+ generated: undefined;
68
+ }, {}>;
69
+ author: import("drizzle-orm/sqlite-core").SQLiteColumn<{
70
+ name: string;
71
+ tableName: "sender_bots";
72
+ dataType: "string";
73
+ data: string;
74
+ driverParam: string;
75
+ notNull: true;
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
+ reason: import("drizzle-orm/sqlite-core").SQLiteColumn<{
86
+ name: string;
87
+ tableName: "sender_bots";
88
+ dataType: "string";
89
+ data: string;
90
+ driverParam: string;
91
+ notNull: false;
92
+ hasDefault: false;
93
+ isPrimaryKey: false;
94
+ isAutoincrement: false;
95
+ hasRuntimeDefault: false;
96
+ enumValues: [string, ...string[]];
97
+ baseColumn: never;
98
+ identity: undefined;
99
+ generated: undefined;
100
+ }, {}>;
101
+ createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
102
+ name: string;
103
+ tableName: "sender_bots";
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
+ updatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
118
+ name: string;
119
+ tableName: "sender_bots";
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
+ };
134
+ dialect: 'sqlite';
135
+ isAlias: false;
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
+ }>;
193
+ export declare const senderBotMoves: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
194
+ name: "sender_bot_moves";
195
+ schema: undefined;
196
+ columns: {
197
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
198
+ name: string;
199
+ tableName: "sender_bot_moves";
200
+ dataType: "number int53";
201
+ data: number;
202
+ driverParam: number;
203
+ notNull: true;
204
+ hasDefault: true;
205
+ isPrimaryKey: true;
206
+ isAutoincrement: false;
207
+ hasRuntimeDefault: false;
208
+ enumValues: undefined;
209
+ baseColumn: never;
210
+ identity: undefined;
211
+ generated: undefined;
212
+ }, {}>;
213
+ identityId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
214
+ name: string;
215
+ tableName: "sender_bot_moves";
216
+ dataType: "number int53";
217
+ data: number;
218
+ driverParam: number;
219
+ notNull: true;
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
+ fromPersonId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
230
+ name: string;
231
+ tableName: "sender_bot_moves";
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
+ fromBotId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
246
+ name: string;
247
+ tableName: "sender_bot_moves";
248
+ dataType: "number int53";
249
+ data: number;
250
+ driverParam: number;
251
+ notNull: false;
252
+ hasDefault: false;
253
+ isPrimaryKey: false;
254
+ isAutoincrement: false;
255
+ hasRuntimeDefault: false;
256
+ enumValues: undefined;
257
+ baseColumn: never;
258
+ identity: undefined;
259
+ generated: undefined;
260
+ }, {}>;
261
+ toPersonId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
262
+ name: string;
263
+ tableName: "sender_bot_moves";
264
+ dataType: "number int53";
265
+ data: number;
266
+ driverParam: number;
267
+ notNull: false;
268
+ hasDefault: false;
269
+ isPrimaryKey: false;
270
+ isAutoincrement: false;
271
+ hasRuntimeDefault: false;
272
+ enumValues: undefined;
273
+ baseColumn: never;
274
+ identity: undefined;
275
+ generated: undefined;
276
+ }, {}>;
277
+ toBotId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
278
+ name: string;
279
+ tableName: "sender_bot_moves";
280
+ dataType: "number int53";
281
+ data: number;
282
+ driverParam: number;
283
+ notNull: false;
284
+ hasDefault: false;
285
+ isPrimaryKey: false;
286
+ isAutoincrement: false;
287
+ hasRuntimeDefault: false;
288
+ enumValues: undefined;
289
+ baseColumn: never;
290
+ identity: undefined;
291
+ generated: undefined;
292
+ }, {}>;
293
+ author: import("drizzle-orm/sqlite-core").SQLiteColumn<{
294
+ name: string;
295
+ tableName: "sender_bot_moves";
296
+ dataType: "string";
297
+ data: string;
298
+ driverParam: string;
299
+ notNull: true;
300
+ hasDefault: false;
301
+ isPrimaryKey: false;
302
+ isAutoincrement: false;
303
+ hasRuntimeDefault: false;
304
+ enumValues: [string, ...string[]];
305
+ baseColumn: never;
306
+ identity: undefined;
307
+ generated: undefined;
308
+ }, {}>;
309
+ reason: import("drizzle-orm/sqlite-core").SQLiteColumn<{
310
+ name: string;
311
+ tableName: "sender_bot_moves";
312
+ dataType: "string";
313
+ data: string;
314
+ driverParam: string;
315
+ notNull: false;
316
+ hasDefault: false;
317
+ isPrimaryKey: false;
318
+ isAutoincrement: false;
319
+ hasRuntimeDefault: false;
320
+ enumValues: [string, ...string[]];
321
+ baseColumn: never;
322
+ identity: undefined;
323
+ generated: undefined;
324
+ }, {}>;
325
+ createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
326
+ name: string;
327
+ tableName: "sender_bot_moves";
328
+ dataType: "number int53";
329
+ data: number;
330
+ driverParam: number;
331
+ notNull: true;
332
+ hasDefault: false;
333
+ isPrimaryKey: false;
334
+ isAutoincrement: false;
335
+ hasRuntimeDefault: false;
336
+ enumValues: undefined;
337
+ baseColumn: never;
338
+ identity: undefined;
339
+ generated: undefined;
340
+ }, {}>;
341
+ };
342
+ dialect: 'sqlite';
343
+ isAlias: false;
344
+ }>;
@@ -0,0 +1,30 @@
1
+ import { index, integer, sqliteTable, text } from "../drizzle/core.js";
2
+ export const senderBots = sqliteTable("sender_bots", {
3
+ id: integer("id").primaryKey({ autoIncrement: true }),
4
+ personId: integer("person_id").notNull().unique(),
5
+ name: text("name"),
6
+ organizationId: integer("organization_id"),
7
+ author: text("author").notNull(),
8
+ reason: text("reason"),
9
+ createdAt: integer("created_at").notNull(),
10
+ updatedAt: integer("updated_at").notNull(),
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)]);
17
+ export const senderBotMoves = sqliteTable("sender_bot_moves", {
18
+ id: integer("id").primaryKey({ autoIncrement: true }),
19
+ identityId: integer("identity_id").notNull(),
20
+ fromPersonId: integer("from_person_id"),
21
+ fromBotId: integer("from_bot_id"),
22
+ toPersonId: integer("to_person_id"),
23
+ toBotId: integer("to_bot_id"),
24
+ author: text("author").notNull(),
25
+ reason: text("reason"),
26
+ createdAt: integer("created_at").notNull(),
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,6 +2433,7 @@ export declare const bots: import("drizzle-orm/sqlite-core").SQLiteTableWithColu
2433
2433
  dialect: 'sqlite';
2434
2434
  isAlias: false;
2435
2435
  }>;
2436
+ export { senderBotIdentities, senderBotMoves, senderBots } from "./schema/sender-bots.js";
2436
2437
  export declare const chats: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
2437
2438
  name: "chats";
2438
2439
  schema: undefined;
@@ -5753,6 +5754,54 @@ export declare const emails: import("drizzle-orm/sqlite-core").SQLiteTableWithCo
5753
5754
  identity: undefined;
5754
5755
  generated: undefined;
5755
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
+ }, {}>;
5756
5805
  };
5757
5806
  dialect: 'sqlite';
5758
5807
  isAlias: false;
@@ -266,6 +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 { senderBotIdentities, senderBotMoves, senderBots } from "./schema/sender-bots.js";
269
270
  export const chats = sqliteTable("chats", {
270
271
  id: integer("id").primaryKey({ autoIncrement: true }),
271
272
  accountId: integer("account_id")
@@ -665,10 +666,16 @@ export const emails = sqliteTable("emails", {
665
666
  deletedAt: integer("deleted_at"),
666
667
  // No constraint: older stores add the column without a rebuild; removing a rule clears it.
667
668
  mailRuleId: integer("mail_rule_id"),
669
+ mailType: text("mail_type"),
670
+ reach: text("reach"),
671
+ typeSignal: text("type_signal"),
668
672
  }, (table) => [
669
673
  unique().on(table.accountId, table.externalId),
670
674
  index("emails_by_time").on(table.accountId, desc(table.sentAt)),
671
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`),
678
+ index("emails_by_list_id").on(sql `coalesce(json_extract(headers, '$."list-id"'), json_extract(metadata, '$.listId'))`),
672
679
  index("emails_by_email_thread_id").on(table.emailThreadId),
673
680
  index("emails_by_from_identity_id").on(table.fromIdentityId),
674
681
  check("emails_references_json", sql `"references" IS NULL OR json_valid("references")`),
@@ -0,0 +1,108 @@
1
+ import type { CacheDatabase } from "../driver.js";
2
+ import type { IdentityRef, PersonRecord } from "../types.js";
3
+ import type { StoreContext } from "./open.js";
4
+ import { type Reach, type SenderSignal } from "./sender-signals.js";
5
+ export type BotAuthor = "rules" | "owner";
6
+ /** @experimental */
7
+ export interface BotIdentity {
8
+ provider: string;
9
+ id: string;
10
+ name: string | null;
11
+ username: string | null;
12
+ }
13
+ /** A program that writes to the owner, apart from people: it has no ties, no tasks and no merge review. @experimental */
14
+ export interface SenderBot {
15
+ /** `sender-bot:<id>`. */
16
+ bot: string;
17
+ /** The owner's name for it; `displayName` falls back to its identities'. */
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;
39
+ author: BotAuthor;
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;
62
+ }
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;
68
+ /** People holding an identity the owner last moved to a person, or kept as one: no rule makes them a bot. */
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. */
71
+ export declare const refuseBotAssignee: (database: CacheDatabase, person: number) => void;
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;
90
+ /**
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.
94
+ */
95
+ export declare const moveToBot: (context: StoreContext, subject: string | IdentityRef, options?: {
96
+ bot?: string;
97
+ name?: string;
98
+ reason?: string;
99
+ }) => SenderBotDetails;
100
+ /**
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
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.
104
+ */
105
+ export declare const moveToPerson: (context: StoreContext, subject: string | IdentityRef, options?: {
106
+ person?: string;
107
+ reason?: string;
108
+ }) => PersonRecord;