@wirecat/cli-core 0.647.0 → 0.648.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 (63) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/cli/account-remove.d.ts +5 -0
  3. package/dist/cli/account-remove.js +6 -1
  4. package/dist/cli/app-doctor-command.js +15 -57
  5. package/dist/cli/app-store.d.ts +12 -0
  6. package/dist/cli/app-store.js +25 -0
  7. package/dist/cli/commands-command.js +10 -3
  8. package/dist/cli/doctor-reports-command.d.ts +22 -0
  9. package/dist/cli/doctor-reports-command.js +82 -0
  10. package/dist/cli/help/command-help.d.ts +1 -0
  11. package/dist/cli/help/command-help.js +7 -8
  12. package/dist/cli/index.d.ts +3 -1
  13. package/dist/cli/index.js +3 -1
  14. package/dist/cli/messenger/doctor-command.js +21 -64
  15. package/dist/cli/messenger/stats-command.js +1 -1
  16. package/dist/cli/messenger/store-maintenance-command.js +3 -3
  17. package/dist/cli/messenger/tasks-command.js +1 -3
  18. package/dist/cli/permission-keys.js +4 -2
  19. package/dist/cli/program.js +26 -10
  20. package/dist/cli/settings.d.ts +2 -0
  21. package/dist/cli/settings.js +3 -2
  22. package/dist/cli/store-recover.js +2 -2
  23. package/dist/cli/unknown-profile.d.ts +9 -0
  24. package/dist/cli/unknown-profile.js +23 -0
  25. package/dist/crm/cli/search-all.js +4 -4
  26. package/dist/errors/failures.d.ts +2 -0
  27. package/dist/errors/failures.js +6 -0
  28. package/dist/errors/reasons.js +17 -1
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.js +1 -0
  31. package/dist/kit/index.d.ts +1 -0
  32. package/dist/kit/index.js +1 -0
  33. package/dist/kit/own-catalogue.d.ts +7 -0
  34. package/dist/kit/own-catalogue.js +21 -0
  35. package/dist/oauth/index.d.ts +2 -2
  36. package/dist/oauth/index.js +2 -1
  37. package/dist/oauth/provider.d.ts +4 -0
  38. package/dist/oauth/provider.js +16 -1
  39. package/dist/oauth/storage.d.ts +5 -0
  40. package/dist/oauth/storage.js +20 -0
  41. package/dist/runs/error-detail.d.ts +1 -1
  42. package/dist/runs/error-detail.js +5 -2
  43. package/dist/runs/events.d.ts +1 -1
  44. package/dist/runs/secrets.d.ts +5 -4
  45. package/dist/runs/secrets.js +8 -4
  46. package/dist/sends/permissions.d.ts +2 -0
  47. package/dist/sends/permissions.js +4 -1
  48. package/dist/services/search-all.js +1 -1
  49. package/dist/sftp/index.d.ts +1 -0
  50. package/dist/sftp/index.js +1 -0
  51. package/dist/sftp/session.d.ts +61 -0
  52. package/dist/sftp/session.js +230 -0
  53. package/dist/sftp/ssh2.d.ts +38 -0
  54. package/dist/sftp/ssh2.js +306 -0
  55. package/dist/store/index.d.ts +1 -0
  56. package/dist/store/index.js +1 -0
  57. package/dist/store/sqlite/crm-activities.d.ts +2 -0
  58. package/dist/store/sqlite/crm-activities.js +17 -0
  59. package/dist/store/sqlite/deals.d.ts +4 -3
  60. package/dist/store/sqlite/deals.js +8 -2
  61. package/dist/store/sqlite/open-store.js +14 -1
  62. package/package.json +14 -4
  63. package/parity.json +2 -11
@@ -16,6 +16,8 @@ export interface StoredActivity {
16
16
  createdAt: number;
17
17
  updatedAt: number;
18
18
  }
19
+ /** The subjects and texts of the activities on each deal or lead of a kind, by `<account id>\u0000<external id>`. */
20
+ export declare const activityTexts: (database: StoreContext["database"], kind: DealKind) => Map<string, string[]>;
19
21
  export interface CrmActivitiesSaved {
20
22
  saved: number;
21
23
  /** On no deal or lead this copy keeps, so not stored. */
@@ -6,6 +6,23 @@ export const ACTIVITY_RECORD = "crm.activity";
6
6
  /** A CRM's text field holds what people typed or pasted, a whole e-mail thread too. */
7
7
  const MOST_BODY = 20_000;
8
8
  const MOST_SUBJECT = 500;
9
+ /** The subjects and texts of the activities on each deal or lead of a kind, by `<account id>\u0000<external id>`. */
10
+ export const activityTexts = (database, kind) => {
11
+ const found = new Map();
12
+ for (const row of database
13
+ .prepare("SELECT r.account_id, rr.target_external_id, json_extract(r.fields, '$.subject') AS subject, " +
14
+ "json_extract(r.fields, '$.body') AS body FROM records r JOIN record_relations rr ON rr.record_id = r.id " +
15
+ "WHERE r.type = ? AND r.deleted_at IS NULL AND rr.role = 'on' AND rr.target_type = ?")
16
+ .all(ACTIVITY_RECORD, kind)) {
17
+ const key = `${row.account_id}\u0000${row.target_external_id}`;
18
+ const texts = found.get(key) ?? [];
19
+ found.set(key, texts);
20
+ for (const text of [row.subject, row.body])
21
+ if (typeof text === "string" && text)
22
+ texts.push(text);
23
+ }
24
+ return found;
25
+ };
9
26
  export const crmActivitiesOver = (context) => {
10
27
  const { database, now } = context;
11
28
  const kept = (accountId, kind, externalId) => database
@@ -182,8 +182,8 @@ export interface DealSearch {
182
182
  limit?: number;
183
183
  offset?: number;
184
184
  }
185
- /** Where a deal's or a lead's words are searched: its title, its company, the people on it. */
186
- export type DealPart = "title" | "company" | "contact";
185
+ /** Where a deal's or a lead's words are searched: its title, its company, the people on it, its CRM activities. */
186
+ export type DealPart = "title" | "company" | "contact" | "activity";
187
187
  export interface FoundDeal extends Deal {
188
188
  /** Where the query's words were found, in the order of `DealPart`. */
189
189
  matched: DealPart[];
@@ -228,7 +228,8 @@ export interface DealsStore {
228
228
  stages(reference: string): Promise<StageChange[]>;
229
229
  list(filter?: DealFilter): Promise<ListResult<Deal>>;
230
230
  /**
231
- * Deals and leads together, by the words of their title, company and contacts: a query word matches a stored word
231
+ * Deals and leads together, by the words of their title, company, contacts and the subjects and texts of their CRM
232
+ * activities (calls, e-mails, meetings, tasks): a query word matches a stored word
232
233
  * it begins or one of the same stem. The most words matched first, then the latest changed. When nothing matches,
233
234
  * a misspelt word is corrected to the stored words nearest to it, once.
234
235
  */
@@ -7,6 +7,7 @@ import { createStemmer, DEFAULT_STEMMERS } from "../../search/stem.js";
7
7
  import { fold } from "../normalize.js";
8
8
  import { proposedBySql } from "./actors.js";
9
9
  import { suggestBaseStages } from "./base-suggest.js";
10
+ import { activityTexts } from "./crm-activities.js";
10
11
  import { crmAccountPrefix } from "./crm-rows.js";
11
12
  import { linkKind } from "./link-kinds.js";
12
13
  import { authorActor, authorOf, evidenceOf, linkEvidence, projectId, projectOf } from "./memories.js";
@@ -48,7 +49,7 @@ const providerMetadataOf = (metadata) => {
48
49
  }
49
50
  };
50
51
  const accountOf = (provider, external) => provider == null ? null : { provider: String(provider), account: String(external) };
51
- const DEAL_PARTS = ["title", "company", "contact"];
52
+ const DEAL_PARTS = ["title", "company", "contact", "activity"];
52
53
  const TOKEN = /[\p{L}\p{N}\p{M}]+/gu;
53
54
  /** A query word shorter than this matches only a whole word: «с» or "a" begins half the words of any title. */
54
55
  const SHORTEST_BEGINNING = 4;
@@ -497,8 +498,9 @@ export const dealOperationsOver = (context) => {
497
498
  for (const phone of phones)
498
499
  texts.add(phone.replace(/\D/g, ""));
499
500
  }
501
+ const activities = activityTexts(database, kind);
500
502
  return database
501
- .prepare(`SELECT d.id, d.title, d.updated_at, a.provider, a.external_id AS account, o.name AS company, ` +
503
+ .prepare(`SELECT d.id, d.account_id, d.external_id, d.title, d.updated_at, a.provider, a.external_id AS account, o.name AS company, ` +
502
504
  "CASE WHEN json_valid(d.metadata) THEN json_extract(d.metadata, '$.company_name') END AS own_company, " +
503
505
  "CASE WHEN json_valid(d.metadata) THEN json_extract(d.metadata, '$.contact_name') END AS own_contact " +
504
506
  `FROM ${TABLES[kind]} d LEFT JOIN accounts a ON a.id = d.account_id ` +
@@ -516,6 +518,10 @@ export const dealOperationsOver = (context) => {
516
518
  ...[row.own_contact, ...(contacts.get(Number(row.id)) ?? [])]
517
519
  .filter((text) => typeof text === "string")
518
520
  .map((text) => ({ part: "contact", words: wordsOf(text) })),
521
+ ...(activities.get(`${row.account_id}\u0000${row.external_id}`) ?? []).map((text) => ({
522
+ part: "activity",
523
+ words: wordsOf(text),
524
+ })),
519
525
  ],
520
526
  }));
521
527
  });
@@ -1,6 +1,7 @@
1
1
  import { accessSync, constants, existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
2
2
  import { dirname } from "node:path";
3
3
  import { CliError } from "@wirecat/cli-base";
4
+ import { sqliteCode } from "../../errors/failures.js";
4
5
  import { DEFAULT_DECISION_POLICY } from "../decisions.js";
5
6
  import { noteShmWithoutWal, watchJournal } from "../journal.js";
6
7
  import { refuseDamagedStore } from "../marks.js";
@@ -71,6 +72,16 @@ const openReadable = async (file, options) => {
71
72
  throw error;
72
73
  }
73
74
  };
75
+ const SQLITE_CANTOPEN = 14;
76
+ /** A store path SQLite cannot open, such as a folder, is the owner's setting to fix, not a bug (BUG-753). */
77
+ const unopenable = (error, file) => {
78
+ const cannot = sqliteCode(error) === SQLITE_CANTOPEN ||
79
+ (error instanceof Error && /unable to open database file/.test(error.message));
80
+ if (!cannot)
81
+ return error;
82
+ const message = `the store at ${file} cannot be opened: it is a folder, or this user may not open it`;
83
+ return new CliError("configuration_error", message, { reason: "store.unopenable", path: file });
84
+ };
74
85
  export const openStoreContext = async (options = {}) => {
75
86
  const { path, env, now = Date.now, command, version, warn = (line) => process.stderr.write(`${line}\n`), readOnly = false, decisions = DEFAULT_DECISION_POLICY, } = options;
76
87
  if (typeof readOnly !== "boolean")
@@ -87,7 +98,9 @@ export const openStoreContext = async (options = {}) => {
87
98
  refuseDamagedStore(file, command);
88
99
  noteShmWithoutWal(file, command ?? "unknown");
89
100
  }
90
- const opened = readOnly ? await openReadable(file, options) : await openSqlite(file, { readOnly });
101
+ const opened = await (readOnly ? openReadable(file, options) : openSqlite(file, { readOnly })).catch((error) => {
102
+ throw unopenable(error, file);
103
+ });
91
104
  const database = opened.database;
92
105
  try {
93
106
  if (!readOnly) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.647.0",
3
+ "version": "0.648.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",
@@ -183,6 +183,10 @@
183
183
  "types": "./dist/update/index.d.ts",
184
184
  "default": "./dist/update/index.js"
185
185
  },
186
+ "./sftp": {
187
+ "types": "./dist/sftp/index.d.ts",
188
+ "default": "./dist/sftp/index.js"
189
+ },
186
190
  "./oauth": {
187
191
  "types": "./dist/oauth/index.d.ts",
188
192
  "default": "./dist/oauth/index.js"
@@ -277,8 +281,9 @@
277
281
  "@types/mdast": "4.0.4",
278
282
  "@types/node": "^22.20.5",
279
283
  "@types/pngjs": "6.0.5",
284
+ "@types/ssh2": "1.15.5",
280
285
  "@vitest/coverage-v8": "^5.0.5",
281
- "@wirecat/cli-base": "0.97.0",
286
+ "@wirecat/cli-base": "0.98.0",
282
287
  "@wirecat/cli-core-legacy-tags": "npm:@wirecat/cli-core@0.414.0",
283
288
  "ajv": "8.17.1",
284
289
  "commander": "15.0.0",
@@ -291,6 +296,7 @@
291
296
  "libphonenumber-js": "1.13.15",
292
297
  "markdownlint-cli2": "0.24.0",
293
298
  "pngjs": "7.0.0",
299
+ "ssh2": "1.17.0",
294
300
  "typescript": "^7.0.2",
295
301
  "vitest": "^5.0.5"
296
302
  },
@@ -299,8 +305,9 @@
299
305
  },
300
306
  "peerDependencies": {
301
307
  "@napi-rs/canvas": ">=0.1.69 <2",
302
- "@wirecat/cli-base": ">=0.80.7 <1.0.0",
303
- "commander": ">=15"
308
+ "@wirecat/cli-base": ">=0.98.0 <1.0.0",
309
+ "commander": ">=15",
310
+ "ssh2": "^1.17.0"
304
311
  },
305
312
  "bin": {
306
313
  "cli-core-parity": "dist/parity/bin.js"
@@ -308,6 +315,9 @@
308
315
  "peerDependenciesMeta": {
309
316
  "@napi-rs/canvas": {
310
317
  "optional": true
318
+ },
319
+ "ssh2": {
320
+ "optional": true
311
321
  }
312
322
  }
313
323
  }
package/parity.json CHANGED
@@ -3199,16 +3199,10 @@
3199
3199
  "in": "all"
3200
3200
  },
3201
3201
  "flood": {
3202
- "in": ["max", "tg"],
3203
- "planned": {
3204
- "wa": "wa backlog: mount the shared flood command"
3205
- }
3202
+ "in": "all"
3206
3203
  },
3207
3204
  "flood clear": {
3208
- "in": ["max", "tg"],
3209
- "planned": {
3210
- "wa": "wa backlog: mount the shared flood command"
3211
- }
3205
+ "in": "all"
3212
3206
  },
3213
3207
  "guide": {
3214
3208
  "in": ["max", "tg"],
@@ -4798,9 +4792,6 @@
4798
4792
  "--by": {
4799
4793
  "in": "all"
4800
4794
  },
4801
- "--chat": {
4802
- "in": "all"
4803
- },
4804
4795
  "--timezone": {
4805
4796
  "in": "all"
4806
4797
  },