@wirecat/cli-core 1.0.0 → 1.2.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 (111) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/THIRD_PARTY_NOTICES +43 -0
  3. package/dist/background/daily-archive-timer.d.ts +1 -1
  4. package/dist/cli/account-remove.d.ts +3 -0
  5. package/dist/cli/account-remove.js +1 -1
  6. package/dist/cli/documents/index.d.ts +2 -1
  7. package/dist/cli/documents/index.js +4 -1
  8. package/dist/cli/documents/words.d.ts +1 -1
  9. package/dist/cli/domain-lists-command.d.ts +16 -0
  10. package/dist/cli/domain-lists-command.js +88 -0
  11. package/dist/cli/index.d.ts +4 -3
  12. package/dist/cli/index.js +4 -3
  13. package/dist/cli/messenger/conversation-answers.d.ts +2 -0
  14. package/dist/cli/messenger/message-answers.d.ts +2 -0
  15. package/dist/cli/messenger/message-items.js +2 -0
  16. package/dist/cli/messenger/message-writes.d.ts +4 -0
  17. package/dist/cli/messenger/search-answers.js +2 -0
  18. package/dist/cli/model-catalogue-command.d.ts +6 -0
  19. package/dist/cli/model-catalogue-command.js +1 -1
  20. package/dist/cli/oauth-session.d.ts +38 -4
  21. package/dist/cli/oauth-session.js +72 -25
  22. package/dist/cli/shared-command-exports.d.ts +4 -0
  23. package/dist/cli/shared-command-exports.js +6 -0
  24. package/dist/cli/token-session.d.ts +9 -3
  25. package/dist/cli/token-session.js +34 -3
  26. package/dist/domain/domain-lists.d.ts +86 -0
  27. package/dist/domain/domain-lists.js +110 -0
  28. package/dist/domain/free-mail-domains.generated.d.ts +1 -0
  29. package/dist/domain/free-mail-domains.generated.js +4 -0
  30. package/dist/domain/models.d.ts +5 -0
  31. package/dist/domain/organization-sectors.d.ts +9 -3
  32. package/dist/domain/organization-sectors.generated.d.ts +1 -0
  33. package/dist/domain/organization-sectors.generated.js +1 -0
  34. package/dist/domain/organization-sectors.js +16 -3
  35. package/dist/domain/person-kinds.d.ts +6 -1
  36. package/dist/domain/person-kinds.js +5 -0
  37. package/dist/entities/contact-context.d.ts +4 -0
  38. package/dist/entities/conversation-results.d.ts +4 -0
  39. package/dist/entities/domain-list.d.ts +27 -0
  40. package/dist/entities/domain-list.js +28 -0
  41. package/dist/entities/evidence.d.ts +16 -0
  42. package/dist/entities/index.d.ts +56 -2
  43. package/dist/entities/index.js +3 -1
  44. package/dist/entities/knowledge-lists.d.ts +1 -1
  45. package/dist/entities/listener.d.ts +8 -0
  46. package/dist/entities/message-change.d.ts +2 -0
  47. package/dist/entities/message-context.d.ts +6 -0
  48. package/dist/entities/message-write.d.ts +8 -0
  49. package/dist/entities/message.d.ts +4 -0
  50. package/dist/entities/message.js +4 -0
  51. package/dist/entities/store-records.d.ts +2 -0
  52. package/dist/errors/reasons.js +20 -2
  53. package/dist/mail/cli/index.js +1 -1
  54. package/dist/mail/headers.d.ts +2 -0
  55. package/dist/mail/headers.js +2 -1
  56. package/dist/mail/mail-types.d.ts +48 -0
  57. package/dist/mail/mail-types.js +218 -0
  58. package/dist/mail/read.js +1 -0
  59. package/dist/mail/sort-rules.d.ts +58 -0
  60. package/dist/mail/sort-rules.js +79 -0
  61. package/dist/oauth/index.d.ts +1 -1
  62. package/dist/oauth/storage.d.ts +10 -2
  63. package/dist/oauth/storage.js +23 -9
  64. package/dist/search/lucene/registry.js +24 -0
  65. package/dist/services/domain-lists-download.d.ts +26 -0
  66. package/dist/services/domain-lists-download.js +155 -0
  67. package/dist/services/messages-search.js +1 -1
  68. package/dist/services/metadata.d.ts +1 -1
  69. package/dist/store/areas.d.ts +3 -1
  70. package/dist/store/areas.js +2 -0
  71. package/dist/store/index.d.ts +2 -2
  72. package/dist/store/index.js +1 -1
  73. package/dist/store/people.d.ts +18 -9
  74. package/dist/store/people.js +8 -7
  75. package/dist/store/public.d.ts +1 -1
  76. package/dist/store/public.js +1 -1
  77. package/dist/store/queries.js +9 -2
  78. package/dist/store/sqlite/accounts.js +3 -1
  79. package/dist/store/sqlite/domain-organizations.d.ts +7 -4
  80. package/dist/store/sqlite/domain-organizations.js +94 -36
  81. package/dist/store/sqlite/email-types.d.ts +87 -0
  82. package/dist/store/sqlite/email-types.js +296 -0
  83. package/dist/store/sqlite/emails.d.ts +14 -2
  84. package/dist/store/sqlite/emails.js +32 -12
  85. package/dist/store/sqlite/identities.d.ts +4 -1
  86. package/dist/store/sqlite/identities.js +11 -2
  87. package/dist/store/sqlite/identity-rekey.js +2 -0
  88. package/dist/store/sqlite/lucene-fields.d.ts +6 -0
  89. package/dist/store/sqlite/lucene-fields.js +10 -0
  90. package/dist/store/sqlite/lucene.js +6 -0
  91. package/dist/store/sqlite/mail-sorting.d.ts +122 -0
  92. package/dist/store/sqlite/mail-sorting.js +482 -0
  93. package/dist/store/sqlite/manifest.js +6 -0
  94. package/dist/store/sqlite/merged-persons.d.ts +3 -2
  95. package/dist/store/sqlite/merged-persons.js +5 -3
  96. package/dist/store/sqlite/migrations.generated.js +76 -0
  97. package/dist/store/sqlite/people-list.d.ts +1 -6
  98. package/dist/store/sqlite/people-list.js +97 -42
  99. package/dist/store/sqlite/person-links.js +13 -3
  100. package/dist/store/sqlite/person-match-scan.js +5 -2
  101. package/dist/store/sqlite/schema/mail-sorting.d.ts +384 -0
  102. package/dist/store/sqlite/schema/mail-sorting.js +31 -0
  103. package/dist/store/sqlite/schema/sender-bots.d.ts +56 -0
  104. package/dist/store/sqlite/schema/sender-bots.js +9 -1
  105. package/dist/store/sqlite/schema.d.ts +66 -1
  106. package/dist/store/sqlite/schema.js +9 -1
  107. package/dist/store/sqlite/sender-bots.d.ts +89 -15
  108. package/dist/store/sqlite/sender-bots.js +417 -136
  109. package/dist/store/sqlite/sender-signals.d.ts +11 -4
  110. package/dist/store/sqlite/sender-signals.js +14 -10
  111. package/package.json +2 -2
@@ -22,6 +22,11 @@ export interface SentMail {
22
22
  }
23
23
  /** A list three people write to is a discussion; one sender, even under `+tag` addresses, is a newsletter. */
24
24
  export declare const DISCUSSION_SENDERS = 3;
25
+ /** How one email reached the owner, and the signal that says so. */
26
+ export declare const reachOfOne: (mail: SentMail) => {
27
+ reach: Reach;
28
+ signal?: SenderSignal;
29
+ };
25
30
  /**
26
31
  * A sender's signals and reach, worked out from their mail alone. Reach is the one most of their mail reached the
27
32
  * owner by, the wider on a tie. Mail the owner wrote them, or a private chat both wrote in, makes it `direct`
@@ -35,11 +40,13 @@ export declare const senderSignalsOf: (mail: readonly SentMail[], { addresses, o
35
40
  signals: SenderSignal[];
36
41
  reach: Reach | null;
37
42
  };
38
- /** `bob+news@x` and `bob@x` are one sender. */
43
+ export declare const LIST_ID = "coalesce(json_extract(e.headers, '$.\"list-id\"'), json_extract(e.metadata, '$.listId'))";
39
44
  /** The senders of each of these List-Ids, through `emails_by_list_id`. */
40
45
  export declare const LIST_SENDERS: string;
46
+ /** `bob+news@x` and `bob@x` are one sender. */
47
+ export declare const senderKey: (address: string) => string;
41
48
  /**
42
- * The mail each of these people sent the owner, as `senderSignalsOf` reads it. Asked for a page of people only: the
43
- * senders of their List-Ids tell a discussion list from a newsletter.
49
+ * The mail each of these people, or sender bots, sent the owner, as `senderSignalsOf` reads it. Asked for a page
50
+ * only: the senders of their List-Ids tell a discussion list from a newsletter.
44
51
  */
45
- export declare const sentMailOf: (database: CacheDatabase, people: readonly number[]) => Map<number, SentMail[]>;
52
+ export declare const sentMailOf: (database: CacheDatabase, people: readonly number[], holder?: "person" | "bot") => Map<number, SentMail[]>;
@@ -7,7 +7,8 @@ import { SMALL_GROUP_MEMBERS } from "./person-ties.js";
7
7
  export const REACHES = ["direct", "group", "broadcast"];
8
8
  /** A list three people write to is a discussion; one sender, even under `+tag` addresses, is a newsletter. */
9
9
  export const DISCUSSION_SENDERS = 3;
10
- const reachOfOne = (mail) => {
10
+ /** How one email reached the owner, and the signal that says so. */
11
+ export const reachOfOne = (mail) => {
11
12
  if (mail.discussionList)
12
13
  return { reach: "group", signal: "discussion-list" };
13
14
  if (mail.oneClick)
@@ -52,22 +53,25 @@ export const senderSignalsOf = (mail, { addresses, ownerWrote, chatted }) => {
52
53
  const reach = ownerWrote ? "direct" : (voted ?? (chatted ? "direct" : null));
53
54
  return { signals: [...signals], reach };
54
55
  };
55
- const LIST_ID = "coalesce(json_extract(e.headers, '$.\"list-id\"'), json_extract(e.metadata, '$.listId'))";
56
- /** `bob+news@x` and `bob@x` are one sender. */
56
+ export const LIST_ID = "coalesce(json_extract(e.headers, '$.\"list-id\"'), json_extract(e.metadata, '$.listId'))";
57
57
  /** The senders of each of these List-Ids, through `emails_by_list_id`. */
58
58
  export const LIST_SENDERS = `SELECT DISTINCT ${LIST_ID} AS list, e.from_address AS address FROM emails e ` +
59
59
  `WHERE e.from_address IS NOT NULL AND ${LIST_ID} IN (SELECT value FROM json_each(?))`;
60
- const senderKey = (address) => address.toLowerCase().replace(/\+[^@]*@/, "@");
60
+ /** `bob+news@x` and `bob@x` are one sender. */
61
+ export const senderKey = (address) => address.toLowerCase().replace(/\+[^@]*@/, "@");
61
62
  /**
62
- * The mail each of these people sent the owner, as `senderSignalsOf` reads it. Asked for a page of people only: the
63
- * senders of their List-Ids tell a discussion list from a newsletter.
63
+ * The mail each of these people, or sender bots, sent the owner, as `senderSignalsOf` reads it. Asked for a page
64
+ * only: the senders of their List-Ids tell a discussion list from a newsletter.
64
65
  */
65
- export const sentMailOf = (database, people) => {
66
+ export const sentMailOf = (database, people, holder = "person") => {
66
67
  const found = new Map();
67
68
  if (people.length === 0)
68
69
  return found;
70
+ const held = holder === "person"
71
+ ? { owner: "l.person_id", join: "identity_links l" }
72
+ : { owner: "l.bot_id", join: "sender_bot_identities l" };
69
73
  const rows = database
70
- .prepare("SELECT l.person_id AS person, " +
74
+ .prepare(`SELECT ${held.owner} AS person, ` +
71
75
  `${LIST_ID} AS list, json_extract(e.headers, '$."auto-submitted"') IS NOT NULL AS auto, ` +
72
76
  "json_extract(e.headers, '$.\"null-return-path\"') IS 1 AS null_return, " +
73
77
  "json_extract(e.headers, '$.\"list-unsubscribe-post\"') IS 1 AS one_click, " +
@@ -76,8 +80,8 @@ export const sentMailOf = (database, people) => {
76
80
  "WHERE m.email_id = e.id AND b.kind = 'bulk') AS bulk, " +
77
81
  "CASE WHEN json_extract(e.metadata, '$.rule') IS NOT NULL THEN NULL ELSE " +
78
82
  "(SELECT count(*) FROM email_recipients r WHERE r.email_id = e.id AND r.role IN ('to', 'cc')) END AS recipients " +
79
- "FROM emails e JOIN identity_links l ON l.identity_id = e.from_identity_id " +
80
- "WHERE e.outgoing IS NOT 1 AND e.deleted_at IS NULL AND l.person_id IN (SELECT value FROM json_each(?))")
83
+ `FROM emails e JOIN ${held.join} ON l.identity_id = e.from_identity_id ` +
84
+ `WHERE e.outgoing IS NOT 1 AND e.deleted_at IS NULL AND ${held.owner} IN (SELECT value FROM json_each(?))`)
81
85
  .all(JSON.stringify(people));
82
86
  const lists = [...new Set(rows.flatMap((row) => (typeof row.list === "string" ? [row.list] : [])))];
83
87
  const senders = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "1.0.0",
3
+ "version": "1.2.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",
@@ -27,7 +27,7 @@
27
27
  "./update"
28
28
  ],
29
29
  "store": {
30
- "speaks": 74,
30
+ "speaks": 77,
31
31
  "minCompatible": 73
32
32
  }
33
33
  },