@wirecat/cli-core 0.604.0 → 0.606.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 +159 -0
- package/dist/calendar/prepare.d.ts +4 -2
- package/dist/calendar/prepare.js +8 -8
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +2 -1
- package/dist/cli/messenger/contacts-command.js +3 -2
- package/dist/cli/messenger/doctor-command.js +14 -7
- package/dist/cli/messenger/store-maintenance-command.d.ts +34 -2
- package/dist/cli/messenger/store-maintenance-command.js +31 -4
- package/dist/cli/program.js +11 -2
- package/dist/cli/steps.js +9 -1
- package/dist/cli/store-recover.d.ts +10 -2
- package/dist/cli/store-recover.js +18 -4
- package/dist/cli/store-settings.js +38 -4
- package/dist/crm/cli/index.js +3 -1
- package/dist/crm/index.d.ts +2 -2
- package/dist/crm/index.js +1 -1
- package/dist/crm/source.d.ts +35 -5
- package/dist/crm/sync.d.ts +15 -7
- package/dist/crm/sync.js +169 -11
- package/dist/domain/crm.d.ts +41 -2
- package/dist/domain/deals.d.ts +5 -2
- package/dist/domain/deals.js +5 -2
- package/dist/domain/record-types.d.ts +61 -0
- package/dist/domain/record-types.js +26 -0
- package/dist/domain/records.d.ts +3 -5
- package/dist/domain/records.js +10 -13
- package/dist/domain/relations.d.ts +125 -0
- package/dist/domain/relations.js +107 -0
- package/dist/entities/contact-activity.d.ts +4 -0
- package/dist/entities/contact-activity.js +1 -0
- package/dist/entities/contact-context.d.ts +20 -0
- package/dist/entities/contact-context.js +2 -0
- package/dist/entities/deal.d.ts +2 -2
- package/dist/entities/deal.js +2 -1
- package/dist/entities/index.d.ts +39 -13
- package/dist/entities/relationship.d.ts +8 -2
- package/dist/entities/relationship.js +8 -2
- package/dist/entities/task-results.d.ts +10 -10
- package/dist/errors/failures.d.ts +17 -1
- package/dist/errors/failures.js +57 -1
- package/dist/errors/reasons.js +28 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/mail/cli/review.js +20 -6
- package/dist/mail/index.d.ts +1 -1
- package/dist/mail/marks.d.ts +10 -5
- package/dist/mail/marks.js +16 -8
- package/dist/mail/review.d.ts +5 -0
- package/dist/mcp/tool.js +2 -1
- package/dist/runs/recording.js +13 -4
- package/dist/services/deps.js +4 -6
- package/dist/services/index.d.ts +1 -1
- package/dist/services/link-scorers/chat-senders.d.ts +3 -2
- package/dist/services/link-scorers/chat-senders.js +7 -4
- package/dist/services/link-scorers/mail-thread.js +1 -0
- package/dist/services/link-scorers/member-chats.js +1 -0
- package/dist/services/link-scorers/member-dialog.d.ts +1 -1
- package/dist/services/link-scorers/member-dialog.js +4 -3
- package/dist/services/link-scorers/scan.d.ts +5 -2
- package/dist/services/link-scorers/scan.js +100 -54
- package/dist/services/link-scorers/shared.d.ts +2 -2
- package/dist/services/link-scorers/shared.js +8 -4
- package/dist/services/link-scorers/types.d.ts +3 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/person-context.d.ts +24 -7
- package/dist/services/person-context.js +45 -11
- package/dist/services/person-preparation.js +4 -5
- package/dist/services/project-status/index.js +2 -1
- package/dist/services/stored-project-gathering.js +4 -3
- package/dist/store/damage.d.ts +3 -1
- package/dist/store/damage.js +19 -12
- package/dist/store/document-transfer/index.js +7 -0
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/index.d.ts +7 -1
- package/dist/store/index.js +2 -0
- package/dist/store/marks.d.ts +57 -0
- package/dist/store/marks.js +121 -0
- package/dist/store/project-transfer/preview.js +12 -7
- package/dist/store/project-transfer/request.d.ts +4 -1
- package/dist/store/project-transfer/schema.d.ts +9 -2
- package/dist/store/project-transfer/schema.js +4 -0
- package/dist/store/project-transfer/snapshot-model.d.ts +8 -2
- package/dist/store/recover.js +16 -1
- package/dist/store/sqlite/crm-settings.d.ts +28 -0
- package/dist/store/sqlite/crm-settings.js +80 -0
- package/dist/store/sqlite/crm.d.ts +42 -2
- package/dist/store/sqlite/crm.js +397 -36
- package/dist/store/sqlite/deals.js +3 -2
- package/dist/store/sqlite/finance.d.ts +8 -1
- package/dist/store/sqlite/finance.js +10 -3
- package/dist/store/sqlite/involvement-queue.js +4 -3
- package/dist/store/sqlite/knowledge.d.ts +7 -3
- package/dist/store/sqlite/knowledge.js +43 -31
- package/dist/store/sqlite/link-kinds.d.ts +2 -3
- package/dist/store/sqlite/link-kinds.js +4 -2
- package/dist/store/sqlite/manifest.js +5 -0
- package/dist/store/sqlite/memories.d.ts +1 -1
- package/dist/store/sqlite/memories.js +33 -7
- package/dist/store/sqlite/migrations.generated.js +31 -0
- package/dist/store/sqlite/notes.d.ts +3 -2
- package/dist/store/sqlite/notes.js +23 -6
- package/dist/store/sqlite/open-store.js +4 -1
- package/dist/store/sqlite/organizations.d.ts +8 -0
- package/dist/store/sqlite/organizations.js +14 -0
- package/dist/store/sqlite/own-identities.d.ts +1 -1
- package/dist/store/sqlite/own-identities.js +7 -5
- package/dist/store/sqlite/person-links.d.ts +5 -2
- package/dist/store/sqlite/person-links.js +24 -18
- package/dist/store/sqlite/person-preparation.d.ts +1 -1
- package/dist/store/sqlite/person-preparation.js +3 -2
- package/dist/store/sqlite/person-separation.d.ts +5 -0
- package/dist/store/sqlite/person-separation.js +26 -0
- package/dist/store/sqlite/project-transfer/records.js +14 -3
- package/dist/store/sqlite/project-transfer/snapshot.d.ts +4 -1
- package/dist/store/sqlite/project-transfer/snapshot.js +6 -0
- package/dist/store/sqlite/record-projectors.d.ts +44 -0
- package/dist/store/sqlite/record-projectors.js +72 -0
- package/dist/store/sqlite/records.js +12 -70
- package/dist/store/sqlite/relation-list.d.ts +43 -0
- package/dist/store/sqlite/relation-list.js +133 -0
- package/dist/store/sqlite/relation-proposals.d.ts +28 -6
- package/dist/store/sqlite/relation-proposals.js +134 -10
- package/dist/store/sqlite/relation-reads.d.ts +8 -0
- package/dist/store/sqlite/relation-reads.js +7 -0
- package/dist/store/sqlite/relation-roles.d.ts +26 -0
- package/dist/store/sqlite/relation-roles.js +91 -0
- package/dist/store/sqlite/reported-relations.d.ts +63 -0
- package/dist/store/sqlite/reported-relations.js +132 -0
- package/dist/store/sqlite/schema/link-revisions.d.ts +136 -0
- package/dist/store/sqlite/schema/link-revisions.js +11 -0
- package/dist/store/sqlite/schema/links.d.ts +360 -0
- package/dist/store/sqlite/schema/links.js +32 -0
- package/dist/store/sqlite/schema.d.ts +2 -296
- package/dist/store/sqlite/schema.js +2 -24
- package/dist/store/sqlite/transaction.js +2 -5
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/dist/store/types.d.ts +5 -0
- package/package.json +5 -5
|
@@ -22,7 +22,7 @@ export declare const projectAnnotationRequest: (request: ProjectAnnotationTarget
|
|
|
22
22
|
ref: string;
|
|
23
23
|
from: string;
|
|
24
24
|
to: string | null;
|
|
25
|
-
kind: "about" | "answered-by" | "assigned-to" | "attached" | "blocked-by" | "created-from" | "duplicate-of" | "evidence" | "follow-up-of" | "labelled" | "links-to" | "member-of" | "related-to";
|
|
25
|
+
kind: "about" | "answered-by" | "assigned-to" | "attached" | "blocked-by" | "created-from" | "customer-of" | "duplicate-of" | "evidence" | "follow-up-of" | "labelled" | "links-to" | "member-of" | "partner-of" | "related-to" | "reports-to";
|
|
26
26
|
origin: "file" | "message" | "owner" | "suggested";
|
|
27
27
|
anchor: string | null;
|
|
28
28
|
target_text: string | null;
|
|
@@ -33,6 +33,9 @@ export declare const projectAnnotationRequest: (request: ProjectAnnotationTarget
|
|
|
33
33
|
created_at: number;
|
|
34
34
|
updated_at: number;
|
|
35
35
|
author: string | null;
|
|
36
|
+
starts_at?: number | undefined;
|
|
37
|
+
ends_at?: number | undefined;
|
|
38
|
+
deleted_at?: number | undefined;
|
|
36
39
|
}[];
|
|
37
40
|
external: {
|
|
38
41
|
ref: string;
|
|
@@ -56,7 +56,7 @@ export declare const projectAnnotationsSchema: v.StrictObjectSchema<{
|
|
|
56
56
|
readonly ref: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
57
57
|
readonly from: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
58
58
|
readonly to: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
59
|
-
readonly kind: v.PicklistSchema<readonly ["links-to", "blocked-by", "follow-up-of", "about", "member-of", "labelled", "answered-by", "evidence", "created-from", "duplicate-of", "related-to", "assigned-to", "attached"], undefined>;
|
|
59
|
+
readonly kind: v.PicklistSchema<readonly ["links-to", "blocked-by", "follow-up-of", "about", "member-of", "labelled", "answered-by", "evidence", "created-from", "duplicate-of", "related-to", "reports-to", "customer-of", "partner-of", "assigned-to", "attached"], undefined>;
|
|
60
60
|
readonly origin: v.PicklistSchema<readonly ["file", "owner", "suggested", "message"], undefined>;
|
|
61
61
|
readonly anchor: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
62
62
|
readonly target_text: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
@@ -67,11 +67,15 @@ export declare const projectAnnotationsSchema: v.StrictObjectSchema<{
|
|
|
67
67
|
readonly created_at: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
68
68
|
readonly updated_at: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
69
69
|
readonly author: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
70
|
+
/** When a relationship held, if known; left out otherwise, so an older reader still reads the snapshot. */
|
|
71
|
+
readonly starts_at: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
72
|
+
readonly ends_at: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
73
|
+
readonly deleted_at: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
70
74
|
}, undefined>, undefined>, v.MaxLengthAction<{
|
|
71
75
|
ref: string;
|
|
72
76
|
from: string;
|
|
73
77
|
to: string | null;
|
|
74
|
-
kind: "about" | "answered-by" | "assigned-to" | "attached" | "blocked-by" | "created-from" | "duplicate-of" | "evidence" | "follow-up-of" | "labelled" | "links-to" | "member-of" | "related-to";
|
|
78
|
+
kind: "about" | "answered-by" | "assigned-to" | "attached" | "blocked-by" | "created-from" | "customer-of" | "duplicate-of" | "evidence" | "follow-up-of" | "labelled" | "links-to" | "member-of" | "partner-of" | "related-to" | "reports-to";
|
|
75
79
|
origin: "file" | "message" | "owner" | "suggested";
|
|
76
80
|
anchor: string | null;
|
|
77
81
|
target_text: string | null;
|
|
@@ -82,6 +86,9 @@ export declare const projectAnnotationsSchema: v.StrictObjectSchema<{
|
|
|
82
86
|
created_at: number;
|
|
83
87
|
updated_at: number;
|
|
84
88
|
author: string | null;
|
|
89
|
+
starts_at?: number | undefined;
|
|
90
|
+
ends_at?: number | undefined;
|
|
91
|
+
deleted_at?: number | undefined;
|
|
85
92
|
}[], 1000, undefined>]>;
|
|
86
93
|
readonly external: v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{
|
|
87
94
|
readonly ref: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
@@ -60,6 +60,10 @@ export const projectAnnotationsSchema = v.strictObject({
|
|
|
60
60
|
created_at: timestamp,
|
|
61
61
|
updated_at: timestamp,
|
|
62
62
|
author: v.nullable(text(200)),
|
|
63
|
+
/** When a relationship held, if known; left out otherwise, so an older reader still reads the snapshot. */
|
|
64
|
+
starts_at: v.optional(timestamp),
|
|
65
|
+
ends_at: v.optional(timestamp),
|
|
66
|
+
deleted_at: v.optional(timestamp),
|
|
63
67
|
})),
|
|
64
68
|
external: bounded(v.strictObject({
|
|
65
69
|
ref,
|
|
@@ -37,7 +37,7 @@ export declare const projectAnnotationSnapshotSchema: v.StrictObjectSchema<{
|
|
|
37
37
|
readonly ref: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
38
38
|
readonly from: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
|
39
39
|
readonly to: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
40
|
-
readonly kind: v.PicklistSchema<readonly ["links-to", "blocked-by", "follow-up-of", "about", "member-of", "labelled", "answered-by", "evidence", "created-from", "duplicate-of", "related-to", "assigned-to", "attached"], undefined>;
|
|
40
|
+
readonly kind: v.PicklistSchema<readonly ["links-to", "blocked-by", "follow-up-of", "about", "member-of", "labelled", "answered-by", "evidence", "created-from", "duplicate-of", "related-to", "reports-to", "customer-of", "partner-of", "assigned-to", "attached"], undefined>;
|
|
41
41
|
readonly origin: v.PicklistSchema<readonly ["file", "owner", "suggested", "message"], undefined>;
|
|
42
42
|
readonly anchor: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
43
43
|
readonly target_text: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
@@ -48,11 +48,14 @@ export declare const projectAnnotationSnapshotSchema: v.StrictObjectSchema<{
|
|
|
48
48
|
readonly created_at: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
49
49
|
readonly updated_at: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
50
50
|
readonly author: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>, undefined>;
|
|
51
|
+
readonly starts_at: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
52
|
+
readonly ends_at: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
53
|
+
readonly deleted_at: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.SafeIntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
51
54
|
}, undefined>, undefined>, v.MaxLengthAction<{
|
|
52
55
|
ref: string;
|
|
53
56
|
from: string;
|
|
54
57
|
to: string | null;
|
|
55
|
-
kind: "about" | "answered-by" | "assigned-to" | "attached" | "blocked-by" | "created-from" | "duplicate-of" | "evidence" | "follow-up-of" | "labelled" | "links-to" | "member-of" | "related-to";
|
|
58
|
+
kind: "about" | "answered-by" | "assigned-to" | "attached" | "blocked-by" | "created-from" | "customer-of" | "duplicate-of" | "evidence" | "follow-up-of" | "labelled" | "links-to" | "member-of" | "partner-of" | "related-to" | "reports-to";
|
|
56
59
|
origin: "file" | "message" | "owner" | "suggested";
|
|
57
60
|
anchor: string | null;
|
|
58
61
|
target_text: string | null;
|
|
@@ -63,6 +66,9 @@ export declare const projectAnnotationSnapshotSchema: v.StrictObjectSchema<{
|
|
|
63
66
|
created_at: number;
|
|
64
67
|
updated_at: number;
|
|
65
68
|
author: string | null;
|
|
69
|
+
starts_at?: number | undefined;
|
|
70
|
+
ends_at?: number | undefined;
|
|
71
|
+
deleted_at?: number | undefined;
|
|
66
72
|
}[], 1000, undefined>]>;
|
|
67
73
|
readonly external: v.SchemaWithPipe<readonly [v.ArraySchema<v.StrictObjectSchema<{
|
|
68
74
|
readonly ref: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, number, undefined>]>;
|
package/dist/store/recover.js
CHANGED
|
@@ -4,7 +4,10 @@ import { basename, dirname, join } from "node:path";
|
|
|
4
4
|
import { Transform } from "node:stream";
|
|
5
5
|
import { CliError } from "@wirecat/cli-base";
|
|
6
6
|
import { holdersOf } from "../background/processes.js";
|
|
7
|
+
import { isStoreDamage } from "../errors/failures.js";
|
|
8
|
+
import { fileSchemaOf } from "./compatibility.js";
|
|
7
9
|
import { fts5Tables, invalidJson, storeHealth } from "./health.js";
|
|
10
|
+
import { recordDeepCheck } from "./marks.js";
|
|
8
11
|
import { migrate } from "./migrations.js";
|
|
9
12
|
import { resetAttachmentWords } from "./sqlite/attachment-texts.js";
|
|
10
13
|
import { involvementStoreOver } from "./sqlite/involvements.js";
|
|
@@ -393,7 +396,16 @@ const recoverLocked = async ({ path, command, version, sqlite3, now, note, copy,
|
|
|
393
396
|
};
|
|
394
397
|
try {
|
|
395
398
|
const dataVersion = () => Number(watch.prepare("PRAGMA data_version").get()?.data_version);
|
|
396
|
-
|
|
399
|
+
let rowsBefore;
|
|
400
|
+
try {
|
|
401
|
+
rowsBefore = tableRows(watch);
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
if (!isStoreDamage(error))
|
|
405
|
+
throw error;
|
|
406
|
+
throw new CliError("configuration_error", "the store file's header or schema is damaged, so its tables cannot be listed and it cannot be recovered; " +
|
|
407
|
+
"the file was left as it was", { reason: "store.unreadable" });
|
|
408
|
+
}
|
|
397
409
|
const before = { data: dataVersion(), inode: statSync(path).ino };
|
|
398
410
|
const stamp = new Date(now()).toISOString().replace(/[:.]/g, "-");
|
|
399
411
|
const target = `${path}.recovering-${stamp}`;
|
|
@@ -422,6 +434,7 @@ const recoverLocked = async ({ path, command, version, sqlite3, now, note, copy,
|
|
|
422
434
|
let dangling;
|
|
423
435
|
let json;
|
|
424
436
|
let fetch;
|
|
437
|
+
let schema;
|
|
425
438
|
try {
|
|
426
439
|
kept = tableRows(opened.database);
|
|
427
440
|
migrate(opened.database, { command, ...(version ? { version } : {}) });
|
|
@@ -431,6 +444,7 @@ const recoverLocked = async ({ path, command, version, sqlite3, now, note, copy,
|
|
|
431
444
|
note("looking for rows that point at rows that were lost");
|
|
432
445
|
dangling = danglingRows(opened.database);
|
|
433
446
|
fetch = mailToFetch(opened.database);
|
|
447
|
+
schema = fileSchemaOf(opened.database).version;
|
|
434
448
|
opened.database.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
435
449
|
}
|
|
436
450
|
catch (error) {
|
|
@@ -459,6 +473,7 @@ const recoverLocked = async ({ path, command, version, sqlite3, now, note, copy,
|
|
|
459
473
|
for (const suffix of STORE_PARTS)
|
|
460
474
|
if (existsSync(`${target}${suffix}`))
|
|
461
475
|
renameSync(`${target}${suffix}`, `${path}${suffix}`);
|
|
476
|
+
recordDeepCheck(path, health, { cli: command, ...(version ? { version } : {}), schema, now });
|
|
462
477
|
const lost = Object.entries(rowsBefore)
|
|
463
478
|
.map(([table, before]) => ({ table, before, read: read[table] ?? 0, kept: kept[table] ?? 0 }))
|
|
464
479
|
.filter(({ before, read, kept }) => before === null || before > kept || read > kept);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CacheDatabase } from "../driver.js";
|
|
2
|
+
import type { AccountKey } from "../types.js";
|
|
3
|
+
/** `reported`: what a CRM account says is a relationship nobody confirmed; `review`: it waits as a proposal. */
|
|
4
|
+
export declare const CRM_LINK_MODES: readonly ["reported", "review"];
|
|
5
|
+
export type CrmLinkMode = (typeof CRM_LINK_MODES)[number];
|
|
6
|
+
/** What a CRM company type may mean: the company buys from the own company, sells to it, or partners with it. */
|
|
7
|
+
export declare const COMPANY_TYPE_MEANINGS: readonly ["customer-of", "supplier", "partner-of"];
|
|
8
|
+
export type CompanyTypeMeaning = (typeof COMPANY_TYPE_MEANINGS)[number];
|
|
9
|
+
declare const NAMES: readonly ["links", "company-types"];
|
|
10
|
+
type CrmSettingName = (typeof NAMES)[number];
|
|
11
|
+
export declare const crmSettingKey: (key: AccountKey, name: CrmSettingName) => string;
|
|
12
|
+
/** The account and the setting a key names; a portal's account may hold dots, so it is read from both ends. */
|
|
13
|
+
export declare const parseCrmSetting: (setting: string) => {
|
|
14
|
+
key: AccountKey;
|
|
15
|
+
name: CrmSettingName;
|
|
16
|
+
} | undefined;
|
|
17
|
+
/** A value this build cannot read is the default: the CRM's relationships stay reported. */
|
|
18
|
+
export declare const crmLinkMode: (database: CacheDatabase, key: AccountKey) => CrmLinkMode;
|
|
19
|
+
/** Only the owner's mapping gives a company type a meaning; none by default. */
|
|
20
|
+
export declare const crmCompanyTypes: (database: CacheDatabase, key: AccountKey) => Record<string, CompanyTypeMeaning>;
|
|
21
|
+
/** `links`: reported or review; `company-types`: `TYPE=meaning` pairs, comma-separated. */
|
|
22
|
+
export declare const parseCrmSettingValue: (name: CrmSettingName, value: string) => unknown;
|
|
23
|
+
export declare const saveCrmSetting: (database: CacheDatabase, setting: string, value: unknown, now: number) => void;
|
|
24
|
+
export declare const crmSettingsOf: (database: CacheDatabase) => {
|
|
25
|
+
setting: string;
|
|
26
|
+
value: unknown;
|
|
27
|
+
}[];
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
/** `reported`: what a CRM account says is a relationship nobody confirmed; `review`: it waits as a proposal. */
|
|
3
|
+
export const CRM_LINK_MODES = ["reported", "review"];
|
|
4
|
+
/** What a CRM company type may mean: the company buys from the own company, sells to it, or partners with it. */
|
|
5
|
+
export const COMPANY_TYPE_MEANINGS = ["customer-of", "supplier", "partner-of"];
|
|
6
|
+
const NAMES = ["links", "company-types"];
|
|
7
|
+
export const crmSettingKey = (key, name) => `crm.${key.provider}:${key.account}.${name}`;
|
|
8
|
+
/** The account and the setting a key names; a portal's account may hold dots, so it is read from both ends. */
|
|
9
|
+
export const parseCrmSetting = (setting) => {
|
|
10
|
+
const match = /^crm\.([a-z0-9-]+):(.+)\.(links|company-types)$/.exec(setting);
|
|
11
|
+
return match
|
|
12
|
+
? { key: { provider: match[1], account: match[2] }, name: match[3] }
|
|
13
|
+
: undefined;
|
|
14
|
+
};
|
|
15
|
+
const stored = (database, setting) => {
|
|
16
|
+
const row = database.prepare("SELECT value FROM store_settings WHERE key = ?").get(setting);
|
|
17
|
+
if (!row)
|
|
18
|
+
return undefined;
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(String(row.value));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/** A value this build cannot read is the default: the CRM's relationships stay reported. */
|
|
27
|
+
export const crmLinkMode = (database, key) => {
|
|
28
|
+
const value = stored(database, crmSettingKey(key, "links"));
|
|
29
|
+
return value === "review" ? "review" : "reported";
|
|
30
|
+
};
|
|
31
|
+
/** Only the owner's mapping gives a company type a meaning; none by default. */
|
|
32
|
+
export const crmCompanyTypes = (database, key) => {
|
|
33
|
+
const value = stored(database, crmSettingKey(key, "company-types"));
|
|
34
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
35
|
+
return {};
|
|
36
|
+
return Object.fromEntries(Object.entries(value).filter((entry) => COMPANY_TYPE_MEANINGS.includes(entry[1])));
|
|
37
|
+
};
|
|
38
|
+
/** `links`: reported or review; `company-types`: `TYPE=meaning` pairs, comma-separated. */
|
|
39
|
+
export const parseCrmSettingValue = (name, value) => {
|
|
40
|
+
const text = value.trim();
|
|
41
|
+
if (name === "links") {
|
|
42
|
+
if (!CRM_LINK_MODES.includes(text))
|
|
43
|
+
throw new CliError("validation_error", `a CRM account's links setting is ${CRM_LINK_MODES.join(" or ")}`);
|
|
44
|
+
return text;
|
|
45
|
+
}
|
|
46
|
+
const pairs = text
|
|
47
|
+
.split(",")
|
|
48
|
+
.map((pair) => pair.trim())
|
|
49
|
+
.filter(Boolean);
|
|
50
|
+
const map = {};
|
|
51
|
+
for (const pair of pairs) {
|
|
52
|
+
const [type, meaning] = pair.split("=").map((part) => part.trim());
|
|
53
|
+
if (!type || !COMPANY_TYPE_MEANINGS.includes(meaning ?? ""))
|
|
54
|
+
throw new CliError("validation_error", `company-types takes TYPE=meaning pairs, the meaning ${COMPANY_TYPE_MEANINGS.join(", ")}: not "${pair}"`);
|
|
55
|
+
map[type] = meaning;
|
|
56
|
+
}
|
|
57
|
+
return map;
|
|
58
|
+
};
|
|
59
|
+
export const saveCrmSetting = (database, setting, value, now) => {
|
|
60
|
+
if (value === undefined)
|
|
61
|
+
database.prepare("DELETE FROM store_settings WHERE key = ?").run(setting);
|
|
62
|
+
else
|
|
63
|
+
database
|
|
64
|
+
.prepare("INSERT OR REPLACE INTO store_settings (key, value, at) VALUES (?, ?, ?)")
|
|
65
|
+
.run(setting, JSON.stringify(value), now);
|
|
66
|
+
};
|
|
67
|
+
export const crmSettingsOf = (database) => database
|
|
68
|
+
.prepare("SELECT key, value FROM store_settings WHERE key LIKE 'crm.%' ORDER BY key")
|
|
69
|
+
.all()
|
|
70
|
+
.flatMap((row) => {
|
|
71
|
+
const parsed = parseCrmSetting(String(row.key));
|
|
72
|
+
if (!parsed)
|
|
73
|
+
return [];
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
setting: String(row.key),
|
|
77
|
+
value: parsed.name === "links" ? crmLinkMode(database, parsed.key) : crmCompanyTypes(database, parsed.key),
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CrmDepartment, type CrmField, type CrmItem, type CrmKind, type CrmOrganization, type CrmPerson, type CrmPipeline, 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";
|
|
@@ -9,9 +9,28 @@ export interface CrmSkipped {
|
|
|
9
9
|
reason: "crm.stage-unknown" | "crm.item-invalid";
|
|
10
10
|
message: string;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* A relationship the CRM reported that the store did not write: a contact, company or user not synced yet (tried
|
|
14
|
+
* again on the next sync), ends the registry refuses, an own company it does not know yet, or an email two people
|
|
15
|
+
* share.
|
|
16
|
+
*/
|
|
17
|
+
export interface CrmRelationIssue {
|
|
18
|
+
/** The CRM row it came from; absent for the account as a whole. */
|
|
19
|
+
externalId?: string;
|
|
20
|
+
reason: "crm.reference-unknown" | "crm.own-unknown" | "crm.email-ambiguous" | "relationship.reference-unknown" | "relationship.invalid";
|
|
21
|
+
message: string;
|
|
22
|
+
}
|
|
12
23
|
export interface CrmSaved {
|
|
13
24
|
saved: number;
|
|
14
25
|
skipped: CrmSkipped[];
|
|
26
|
+
/** Relationships left out; the rows themselves were kept. */
|
|
27
|
+
issues?: CrmRelationIssue[];
|
|
28
|
+
/** Relationships left out because the owner removed or rejected that very one. */
|
|
29
|
+
skippedOwnerRejected?: number;
|
|
30
|
+
/** Deal owners the CRM names among users it cannot list: nothing waits for them. */
|
|
31
|
+
unlistedUsers?: number;
|
|
32
|
+
/** Relationships that waited too long, or were too many, for an end that never came. */
|
|
33
|
+
droppedPending?: number;
|
|
15
34
|
}
|
|
16
35
|
/**
|
|
17
36
|
* A CRM account's copies in the store, written as the CRM has them: nothing waits for review (NEED-2271 A), and
|
|
@@ -22,11 +41,32 @@ export interface CrmCopies {
|
|
|
22
41
|
/** One kind's pipelines and their stages, by the CRM's ids. A stage the CRM dropped stays: deals may stand in it. */
|
|
23
42
|
savePipelines(key: AccountKey, kind: DealKind, pipelines: CrmPipeline[]): Promise<CrmSaved>;
|
|
24
43
|
/** Deals or leads; one whose stage is not stored, or whose fields the store refuses, is skipped and named. */
|
|
25
|
-
|
|
44
|
+
/** `users: false`: the source lists no users, so a deal owner not stored yet is counted, never waited for. */
|
|
45
|
+
saveItems(key: AccountKey, kind: DealKind, items: CrmItem[], options?: {
|
|
46
|
+
users?: boolean;
|
|
47
|
+
}): Promise<CrmSaved>;
|
|
26
48
|
/** Contacts, as identities of the account's provider; a contact joins a person only by its exact email. */
|
|
27
49
|
savePeople(key: AccountKey, people: CrmPerson[]): Promise<CrmSaved>;
|
|
28
50
|
/** Companies, each an organization of its own made on first sight, kept apart from any of the same name. */
|
|
29
51
|
saveOrganizations(key: AccountKey, organizations: CrmOrganization[]): Promise<CrmSaved>;
|
|
52
|
+
/**
|
|
53
|
+
* The account's whole list of users: identities `<account>/user/<id>`, joined by exact email; each active one
|
|
54
|
+
* `member-of` every own company as an `employee`; with `departments`, `reports-to` the head of its department, a head
|
|
55
|
+
* the head of the parent one (`metadata.derived = "department-head"`). An inactive user's relationships are
|
|
56
|
+
* withdrawn; one missing from the list keeps them, since a sign-in that lost its rights lists no user at all.
|
|
57
|
+
* Without `departments` no reporting line is touched.
|
|
58
|
+
*/
|
|
59
|
+
saveUsers(key: AccountKey, users: CrmUser[], departments?: CrmDepartment[]): Promise<CrmSaved>;
|
|
60
|
+
/**
|
|
61
|
+
* Writes the relationships earlier syncs held back for an end not stored then, and drops those that waited past
|
|
62
|
+
* their time; answers how many of each.
|
|
63
|
+
*/
|
|
64
|
+
retryPending(key: AccountKey): Promise<{
|
|
65
|
+
written: number;
|
|
66
|
+
dropped: number;
|
|
67
|
+
}>;
|
|
68
|
+
/** Every stored company of the account against its company-types setting; run after a sync read the companies. */
|
|
69
|
+
saveCompanyTypes(key: AccountKey): Promise<CrmSaved>;
|
|
30
70
|
/** One kind's whole list of the CRM's own fields: one it lacks is marked deleted, one listed again comes back. */
|
|
31
71
|
saveFields(key: AccountKey, kind: CrmKind, fields: CrmField[]): Promise<CrmSaved>;
|
|
32
72
|
/** The kind's fields as last synced, in the CRM's order; none before the first sync. */
|