@wirecat/cli-core 0.646.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.
- package/CHANGELOG.md +109 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/account-remove.d.ts +5 -0
- package/dist/cli/account-remove.js +6 -1
- package/dist/cli/app-doctor-command.js +15 -55
- package/dist/cli/app-store.d.ts +12 -0
- package/dist/cli/app-store.js +25 -0
- package/dist/cli/commands-command.js +10 -3
- package/dist/cli/doctor-reports-command.d.ts +22 -0
- package/dist/cli/doctor-reports-command.js +82 -0
- package/dist/cli/help/command-help.d.ts +1 -0
- package/dist/cli/help/command-help.js +7 -6
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/messenger/doctor-command.js +21 -62
- package/dist/cli/messenger/stats-command.js +1 -1
- package/dist/cli/messenger/store-maintenance-command.js +3 -3
- package/dist/cli/messenger/tasks-command.js +1 -3
- package/dist/cli/permission-keys.js +4 -2
- package/dist/cli/program.js +26 -10
- package/dist/cli/settings.d.ts +2 -0
- package/dist/cli/settings.js +3 -2
- package/dist/cli/store-recover.js +2 -2
- package/dist/cli/store-settings.d.ts +2 -2
- package/dist/cli/store-settings.js +11 -5
- package/dist/cli/unknown-profile.d.ts +9 -0
- package/dist/cli/unknown-profile.js +23 -0
- package/dist/crm/cli/index.js +26 -4
- package/dist/crm/cli/search-all.js +4 -4
- package/dist/crm/source.d.ts +8 -2
- package/dist/crm/sync.d.ts +7 -1
- package/dist/crm/sync.js +73 -0
- package/dist/domain/crm.d.ts +27 -0
- package/dist/domain/crm.js +2 -0
- package/dist/entities/deal.d.ts +17 -0
- package/dist/entities/deal.js +16 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/errors/failures.d.ts +2 -0
- package/dist/errors/failures.js +6 -0
- package/dist/errors/reasons.js +18 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/kit/index.d.ts +1 -0
- package/dist/kit/index.js +1 -0
- package/dist/kit/own-catalogue.d.ts +7 -0
- package/dist/kit/own-catalogue.js +21 -0
- package/dist/oauth/index.d.ts +2 -2
- package/dist/oauth/index.js +2 -1
- package/dist/oauth/provider.d.ts +4 -0
- package/dist/oauth/provider.js +16 -1
- package/dist/oauth/storage.d.ts +5 -0
- package/dist/oauth/storage.js +20 -0
- package/dist/runs/error-detail.d.ts +1 -1
- package/dist/runs/error-detail.js +5 -2
- package/dist/runs/events.d.ts +1 -1
- package/dist/runs/secrets.d.ts +5 -4
- package/dist/runs/secrets.js +8 -4
- package/dist/sends/permissions.d.ts +2 -0
- package/dist/sends/permissions.js +4 -1
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/search-all.js +1 -1
- package/dist/sftp/index.d.ts +1 -0
- package/dist/sftp/index.js +1 -0
- package/dist/sftp/session.d.ts +61 -0
- package/dist/sftp/session.js +230 -0
- package/dist/sftp/ssh2.d.ts +38 -0
- package/dist/sftp/ssh2.js +306 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.js +1 -0
- package/dist/store/sqlite/crm-activities.d.ts +29 -0
- package/dist/store/sqlite/crm-activities.js +113 -0
- package/dist/store/sqlite/crm-settings.d.ts +5 -1
- package/dist/store/sqlite/crm-settings.js +9 -1
- package/dist/store/sqlite/crm.d.ts +9 -1
- package/dist/store/sqlite/crm.js +6 -1
- package/dist/store/sqlite/deals.d.ts +4 -3
- package/dist/store/sqlite/deals.js +8 -2
- package/dist/store/sqlite/open-store.js +14 -1
- package/package.json +14 -4
- package/parity.json +2 -11
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { recordFingerprint } from "../../domain/records.js";
|
|
2
|
+
import { accountPk, findAccountPk } from "./accounts.js";
|
|
3
|
+
import { crmIdentityId, SOURCE, TABLES, textOf } from "./crm-rows.js";
|
|
4
|
+
import { write } from "./transaction.js";
|
|
5
|
+
export const ACTIVITY_RECORD = "crm.activity";
|
|
6
|
+
/** A CRM's text field holds what people typed or pasted, a whole e-mail thread too. */
|
|
7
|
+
const MOST_BODY = 20_000;
|
|
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
|
+
};
|
|
26
|
+
export const crmActivitiesOver = (context) => {
|
|
27
|
+
const { database, now } = context;
|
|
28
|
+
const kept = (accountId, kind, externalId) => database
|
|
29
|
+
.prepare(`SELECT 1 FROM ${TABLES[kind]} WHERE account_id = ? AND external_id = ? AND deleted_at IS NULL`)
|
|
30
|
+
.get(accountId, externalId) !== undefined;
|
|
31
|
+
const save = (key, activities) => write(database, () => {
|
|
32
|
+
const accountId = accountPk(context, key);
|
|
33
|
+
const at = now();
|
|
34
|
+
let saved = 0;
|
|
35
|
+
let outOfScope = 0;
|
|
36
|
+
for (const activity of activities) {
|
|
37
|
+
const on = activity.on.filter((one) => kept(accountId, one.kind, one.externalId));
|
|
38
|
+
const held = database
|
|
39
|
+
.prepare("SELECT id FROM records WHERE account_id = ? AND type = ? AND external_id = ?")
|
|
40
|
+
.get(accountId, ACTIVITY_RECORD, activity.externalId);
|
|
41
|
+
if (on.length === 0) {
|
|
42
|
+
// It left every kept deal: one stored before goes with it.
|
|
43
|
+
if (held)
|
|
44
|
+
database.prepare("UPDATE records SET deleted_at = ? WHERE id = ?").run(at, Number(held.id));
|
|
45
|
+
outOfScope += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const fields = {
|
|
49
|
+
kind: activity.kind,
|
|
50
|
+
subject: textOf(activity.subject, MOST_SUBJECT) ?? "",
|
|
51
|
+
body: textOf(activity.body, MOST_BODY),
|
|
52
|
+
due_at: activity.dueAt ?? null,
|
|
53
|
+
done: activity.done,
|
|
54
|
+
assignee: activity.assignee ? crmIdentityId(key, activity.assignee, "user") : null,
|
|
55
|
+
created_at: activity.createdAt,
|
|
56
|
+
updated_at: activity.updatedAt,
|
|
57
|
+
};
|
|
58
|
+
const relations = on.map((one) => ({ role: "on", type: one.kind, external_id: one.externalId }));
|
|
59
|
+
const fingerprint = recordFingerprint(fields, relations);
|
|
60
|
+
let id;
|
|
61
|
+
if (held) {
|
|
62
|
+
id = Number(held.id);
|
|
63
|
+
database
|
|
64
|
+
.prepare("UPDATE records SET fields = ?, fingerprint = ?, batch_id = ?, updated_at = ?, deleted_at = NULL " +
|
|
65
|
+
"WHERE id = ?")
|
|
66
|
+
.run(JSON.stringify(fields), fingerprint, SOURCE, at, id);
|
|
67
|
+
database.prepare("DELETE FROM record_relations WHERE record_id = ?").run(id);
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
id = Number(database
|
|
71
|
+
.prepare("INSERT INTO records (account_id, type, external_id, fields, fingerprint, batch_id, created_at, " +
|
|
72
|
+
"updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING id")
|
|
73
|
+
.get(accountId, ACTIVITY_RECORD, activity.externalId, JSON.stringify(fields), fingerprint, SOURCE, at, at)
|
|
74
|
+
?.id);
|
|
75
|
+
for (const one of on)
|
|
76
|
+
database
|
|
77
|
+
.prepare("INSERT INTO record_relations (record_id, role, target_type, target_external_id, created_at) " +
|
|
78
|
+
"VALUES (?, 'on', ?, ?, ?)")
|
|
79
|
+
.run(id, one.kind, one.externalId, at);
|
|
80
|
+
saved += 1;
|
|
81
|
+
}
|
|
82
|
+
return { saved, outOfScope };
|
|
83
|
+
});
|
|
84
|
+
/** The activities on one deal or lead: open ones first by due time, then the rest, newest first. */
|
|
85
|
+
const of = (key, kind, externalId, limit) => {
|
|
86
|
+
const accountId = findAccountPk(context, key);
|
|
87
|
+
if (accountId === undefined)
|
|
88
|
+
return [];
|
|
89
|
+
return database
|
|
90
|
+
.prepare("SELECT r.external_id, r.fields FROM records r JOIN record_relations rr ON rr.record_id = r.id " +
|
|
91
|
+
"WHERE r.account_id = ? AND r.type = ? AND r.deleted_at IS NULL AND rr.role = 'on' " +
|
|
92
|
+
"AND rr.target_type = ? AND rr.target_external_id = ? " +
|
|
93
|
+
"ORDER BY json_extract(r.fields, '$.done') ASC, " +
|
|
94
|
+
"CASE WHEN json_extract(r.fields, '$.done') THEN NULL ELSE json_extract(r.fields, '$.due_at') END ASC, " +
|
|
95
|
+
"json_extract(r.fields, '$.updated_at') DESC LIMIT ?")
|
|
96
|
+
.all(accountId, ACTIVITY_RECORD, kind, externalId, limit)
|
|
97
|
+
.map((row) => {
|
|
98
|
+
const fields = JSON.parse(String(row.fields));
|
|
99
|
+
return {
|
|
100
|
+
externalId: String(row.external_id),
|
|
101
|
+
kind: fields.kind,
|
|
102
|
+
subject: String(fields.subject ?? ""),
|
|
103
|
+
body: fields.body ?? null,
|
|
104
|
+
dueAt: fields.due_at ?? null,
|
|
105
|
+
done: fields.done === true,
|
|
106
|
+
assignee: fields.assignee ?? null,
|
|
107
|
+
createdAt: Number(fields.created_at),
|
|
108
|
+
updatedAt: Number(fields.updated_at),
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
return { save, of };
|
|
113
|
+
};
|
|
@@ -10,7 +10,9 @@ export declare const COMPANY_TYPE_MEANINGS: readonly ["customer-of", "supplier",
|
|
|
10
10
|
export type CompanyTypeMeaning = (typeof COMPANY_TYPE_MEANINGS)[number];
|
|
11
11
|
/** `mine`: only the deals and leads of the sign-in's own user and of the `unassigned` users; `all`: every one. */
|
|
12
12
|
export declare const CRM_SCOPES: readonly ["mine", "all"];
|
|
13
|
-
|
|
13
|
+
/** `activities`: whether a sync also reads the activities and tasks on the deals and leads it keeps; off by default. */
|
|
14
|
+
export declare const CRM_ACTIVITIES: readonly ["on", "off"];
|
|
15
|
+
declare const NAMES: readonly ["links", "company-types", "scope", "unassigned", "self", "stage-tasks", "activities"];
|
|
14
16
|
type CrmSettingName = (typeof NAMES)[number];
|
|
15
17
|
export declare const crmSettingKey: (key: AccountKey, name: CrmSettingName) => string;
|
|
16
18
|
/** The account and the setting a key names; a portal's account may hold dots, so it is read from both ends. */
|
|
@@ -20,6 +22,8 @@ export declare const parseCrmSetting: (setting: string) => {
|
|
|
20
22
|
} | undefined;
|
|
21
23
|
/** A value this build cannot read is the default: the CRM's relationships stay reported. */
|
|
22
24
|
export declare const crmLinkMode: (database: CacheDatabase, key: AccountKey) => CrmLinkMode;
|
|
25
|
+
/** Activities and tasks hold what clients wrote and said: read only once the owner turns them on. */
|
|
26
|
+
export declare const crmActivitiesOn: (database: CacheDatabase, key: AccountKey) => boolean;
|
|
23
27
|
/** Only the owner's mapping gives a company type a meaning; none by default. */
|
|
24
28
|
export declare const crmCompanyTypes: (database: CacheDatabase, key: AccountKey) => Record<string, CompanyTypeMeaning>;
|
|
25
29
|
/** `mine` unless the owner chose `all`: a sync never copies other people's deals without being asked. */
|
|
@@ -6,7 +6,9 @@ export const CRM_LINK_MODES = ["reported", "review"];
|
|
|
6
6
|
export const COMPANY_TYPE_MEANINGS = ["customer-of", "supplier", "partner-of"];
|
|
7
7
|
/** `mine`: only the deals and leads of the sign-in's own user and of the `unassigned` users; `all`: every one. */
|
|
8
8
|
export const CRM_SCOPES = ["mine", "all"];
|
|
9
|
-
|
|
9
|
+
/** `activities`: whether a sync also reads the activities and tasks on the deals and leads it keeps; off by default. */
|
|
10
|
+
export const CRM_ACTIVITIES = ["on", "off"];
|
|
11
|
+
const NAMES = ["links", "company-types", "scope", "unassigned", "self", "stage-tasks", "activities"];
|
|
10
12
|
const SETTING = new RegExp(`^crm\\.([a-z0-9-]+):(.+)\\.(${NAMES.join("|")})$`);
|
|
11
13
|
export const crmSettingKey = (key, name) => `crm.${key.provider}:${key.account}.${name}`;
|
|
12
14
|
/** The account and the setting a key names; a portal's account may hold dots, so it is read from both ends. */
|
|
@@ -32,6 +34,8 @@ export const crmLinkMode = (database, key) => {
|
|
|
32
34
|
const value = stored(database, crmSettingKey(key, "links"));
|
|
33
35
|
return value === "review" ? "review" : "reported";
|
|
34
36
|
};
|
|
37
|
+
/** Activities and tasks hold what clients wrote and said: read only once the owner turns them on. */
|
|
38
|
+
export const crmActivitiesOn = (database, key) => stored(database, crmSettingKey(key, "activities")) === "on";
|
|
35
39
|
/** Only the owner's mapping gives a company type a meaning; none by default. */
|
|
36
40
|
export const crmCompanyTypes = (database, key) => {
|
|
37
41
|
const value = stored(database, crmSettingKey(key, "company-types"));
|
|
@@ -163,6 +167,8 @@ export const parseCrmSettingValue = (name, value) => {
|
|
|
163
167
|
return picked(name, text, CRM_LINK_MODES);
|
|
164
168
|
if (name === "scope")
|
|
165
169
|
return picked(name, text, CRM_SCOPES);
|
|
170
|
+
if (name === "activities")
|
|
171
|
+
return picked(name, text, CRM_ACTIVITIES);
|
|
166
172
|
if (name === "self") {
|
|
167
173
|
if (!isCrmUserId(text))
|
|
168
174
|
throw new CliError("validation_error", `self takes the CRM's numeric user id: not "${text}"`);
|
|
@@ -218,6 +224,8 @@ const settingValue = (database, key, name) => {
|
|
|
218
224
|
return crmOwnUser(database, key) ?? null;
|
|
219
225
|
if (name === "stage-tasks")
|
|
220
226
|
return stored(database, crmSettingKey(key, name)) ?? {};
|
|
227
|
+
if (name === "activities")
|
|
228
|
+
return crmActivitiesOn(database, key) ? "on" : "off";
|
|
221
229
|
return userIds(stored(database, crmSettingKey(key, name)));
|
|
222
230
|
};
|
|
223
231
|
export const crmSettingsOf = (database) => database
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { type CrmDepartment, type CrmField, type CrmItem, type CrmKind, type CrmOrganization, type CrmPerson, type CrmPipeline, type CrmScopeSetting, type CrmUser } from "../../domain/crm.js";
|
|
1
|
+
import { type CrmActivity, type CrmDepartment, type CrmField, type CrmItem, type CrmKind, type CrmOrganization, type CrmPerson, type CrmPipeline, type CrmScopeSetting, type CrmUser } from "../../domain/crm.js";
|
|
2
2
|
import { type DealKind } from "../../domain/deals.js";
|
|
3
3
|
import type { AccountPeople } from "../people.js";
|
|
4
4
|
import type { AccountKey } from "../types.js";
|
|
5
|
+
import { type CrmActivitiesSaved, type StoredActivity } from "./crm-activities.js";
|
|
5
6
|
import { type CrmContactsRemoved } from "./crm-contacts.js";
|
|
6
7
|
import { type CrmSkipped } from "./crm-rows.js";
|
|
7
8
|
import { type CrmStageMove, type CrmStageTasks } from "./crm-settings.js";
|
|
@@ -94,6 +95,12 @@ export interface CrmCopies {
|
|
|
94
95
|
through: number;
|
|
95
96
|
}>;
|
|
96
97
|
markStageMoves(key: AccountKey, through: number): Promise<void>;
|
|
98
|
+
/** Whether the owner turned on reading activities and tasks (`activities` setting). */
|
|
99
|
+
activitiesOn(key: AccountKey): Promise<boolean>;
|
|
100
|
+
/** Activities and tasks, each on the kept deals and leads it names; one on none of them is not stored. */
|
|
101
|
+
saveActivities(key: AccountKey, activities: readonly CrmActivity[]): Promise<CrmActivitiesSaved>;
|
|
102
|
+
/** One deal's or lead's activities, open ones first. */
|
|
103
|
+
activitiesOf(key: AccountKey, kind: DealKind, externalId: string, limit: number): Promise<StoredActivity[]>;
|
|
97
104
|
/**
|
|
98
105
|
* Marks deleted every stored deal or lead of the kind assigned to a user outside `userIds`; one with no assignee
|
|
99
106
|
* stays. Reads only the store. Answers how many; `dryRun` only counts them.
|
|
@@ -116,6 +123,7 @@ export interface CrmCopies {
|
|
|
116
123
|
/** The stored copy's `deal:<id>` or `lead:<id>`, deleted or not; `null` when the store holds none. */
|
|
117
124
|
refOf(key: AccountKey, kind: DealKind, externalId: string): Promise<string | null>;
|
|
118
125
|
}
|
|
126
|
+
export type { CrmActivitiesSaved, StoredActivity } from "./crm-activities.js";
|
|
119
127
|
export type { CrmContactsRemoved } from "./crm-contacts.js";
|
|
120
128
|
export { type CrmSkipped, crmIdentityId, crmRowsOver, type ItemWriter } from "./crm-rows.js";
|
|
121
129
|
export declare const crmCopiesOver: (context: StoreContext, people: AccountPeople) => CrmCopies;
|
package/dist/store/sqlite/crm.js
CHANGED
|
@@ -4,9 +4,10 @@ import { DEAL_ROLES } from "../../domain/deals.js";
|
|
|
4
4
|
import { recordFingerprint } from "../../domain/records.js";
|
|
5
5
|
import { accountPk, findAccountPk } from "./accounts.js";
|
|
6
6
|
import { suggestBaseStages } from "./base-suggest.js";
|
|
7
|
+
import { crmActivitiesOver } from "./crm-activities.js";
|
|
7
8
|
import { removeCrmContacts } from "./crm-contacts.js";
|
|
8
9
|
import { crmAccountPrefix, crmIdentityId, crmRowsOver, SOURCE, TABLES, textOf } from "./crm-rows.js";
|
|
9
|
-
import { crmCompanyTypes, crmOwnUser, crmScope, crmScopeUsers, crmSettingKey, crmStageMoves, crmStageTasks, saveCrmSetting, saveStageMovesMark, } from "./crm-settings.js";
|
|
10
|
+
import { crmActivitiesOn, crmCompanyTypes, crmOwnUser, crmScope, crmScopeUsers, crmSettingKey, crmStageMoves, crmStageTasks, saveCrmSetting, saveStageMovesMark, } from "./crm-settings.js";
|
|
10
11
|
import { syncReportedIn } from "./reported-relations.js";
|
|
11
12
|
import { clearState, syncStateOf, writeState } from "./sync.js";
|
|
12
13
|
import { write } from "./transaction.js";
|
|
@@ -28,6 +29,7 @@ export const crmCopiesOver = (context, people) => {
|
|
|
28
29
|
const { database, now } = context;
|
|
29
30
|
const { savePipeline, saveItemRow } = crmRowsOver(context);
|
|
30
31
|
const account = (key) => accountPk(context, key);
|
|
32
|
+
const activityStore = crmActivitiesOver(context);
|
|
31
33
|
/**
|
|
32
34
|
* One kind's whole list: a pipeline it lacks is marked deleted, one listed again comes back. An empty list marks
|
|
33
35
|
* nothing: a sign-in that lost its CRM rights lists no pipeline at all.
|
|
@@ -591,6 +593,9 @@ export const crmCopiesOver = (context, people) => {
|
|
|
591
593
|
stageTasks: async (key) => crmStageTasks(database, key),
|
|
592
594
|
stageMoves: async (key) => crmStageMoves(database, key, findAccountPk(context, key)),
|
|
593
595
|
markStageMoves: async (key, through) => saveStageMovesMark(database, key, through, now()),
|
|
596
|
+
activitiesOn: async (key) => crmActivitiesOn(database, key),
|
|
597
|
+
saveActivities: async (key, activities) => activityStore.save(key, activities),
|
|
598
|
+
activitiesOf: async (key, kind, externalId, limit) => activityStore.of(key, kind, externalId, limit),
|
|
594
599
|
removeOutOfScope: async (key, kind, userIds, { dryRun } = {}) => write(database, () => {
|
|
595
600
|
const keep = new Set(userIds.map((id) => crmIdentityId(key, id, "user")));
|
|
596
601
|
const accountId = findAccountPk(context, key);
|
|
@@ -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
|
|
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 ?
|
|
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.
|
|
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.
|
|
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.
|
|
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":
|
|
3203
|
-
"planned": {
|
|
3204
|
-
"wa": "wa backlog: mount the shared flood command"
|
|
3205
|
-
}
|
|
3202
|
+
"in": "all"
|
|
3206
3203
|
},
|
|
3207
3204
|
"flood clear": {
|
|
3208
|
-
"in":
|
|
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
|
},
|