@wirecat/cli-core 0.605.0 → 0.607.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 +284 -1
- package/dist/calendar/index.d.ts +1 -0
- package/dist/calendar/index.js +1 -0
- package/dist/calendar/reads.js +5 -0
- package/dist/cli/app-mcp-command.d.ts +6 -2
- package/dist/cli/app-mcp-command.js +11 -2
- package/dist/cli/csv.d.ts +10 -0
- package/dist/cli/csv.js +22 -0
- package/dist/cli/early-refusal.d.ts +10 -0
- package/dist/cli/early-refusal.js +19 -0
- package/dist/cli/index.d.ts +4 -1
- package/dist/cli/index.js +4 -0
- package/dist/cli/profile-token.d.ts +29 -0
- package/dist/cli/profile-token.js +65 -0
- package/dist/cli/program.js +4 -2
- package/dist/cli/store-settings.js +38 -4
- package/dist/crm/cli/csv.d.ts +23 -0
- package/dist/crm/cli/csv.js +135 -0
- package/dist/crm/cli/index.d.ts +1 -1
- package/dist/crm/cli/index.js +36 -22
- package/dist/crm/cli/pipeline-view.d.ts +3 -0
- package/dist/crm/cli/pipeline-view.js +36 -0
- 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/crm/writes.d.ts +6 -4
- package/dist/crm/writes.js +17 -13
- package/dist/documents.d.ts +2 -0
- package/dist/documents.js +2 -0
- package/dist/domain/business.d.ts +79 -0
- package/dist/domain/business.js +42 -0
- 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/finance.d.ts +2 -0
- package/dist/domain/finance.js +2 -2
- package/dist/domain/google-documents.d.ts +2 -0
- package/dist/domain/google-documents.js +3 -1
- package/dist/domain/money.d.ts +2 -0
- package/dist/domain/money.js +11 -3
- package/dist/domain/providers.d.ts +36 -1
- package/dist/domain/providers.js +69 -7
- package/dist/domain/record-fields.d.ts +42 -0
- package/dist/domain/record-fields.js +122 -0
- package/dist/domain/record-types.d.ts +489 -16
- package/dist/domain/record-types.js +374 -7
- package/dist/domain/records.d.ts +96 -5
- package/dist/domain/records.js +178 -32
- package/dist/domain/ref-summaries.js +5 -0
- package/dist/domain/references.d.ts +1 -1
- package/dist/domain/references.js +5 -0
- package/dist/domain/relations.d.ts +125 -0
- package/dist/domain/relations.js +107 -0
- package/dist/domain/vcard.d.ts +25 -0
- package/dist/domain/vcard.js +267 -0
- package/dist/entities/deal.d.ts +16 -2
- package/dist/entities/deal.js +5 -1
- package/dist/entities/index.d.ts +29 -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/reasons.js +73 -2
- package/dist/fetch/addresses.d.ts +5 -0
- package/dist/fetch/addresses.js +76 -0
- package/dist/fetch/page.d.ts +64 -0
- package/dist/fetch/page.js +256 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -3
- 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/meetings/calendar-text.d.ts +1 -1
- package/dist/meetings/calendar-text.js +4 -0
- package/dist/meetings/event-store.d.ts +2 -2
- package/dist/search/account-list.d.ts +4 -0
- package/dist/search/account-list.js +19 -8
- package/dist/search/query.js +2 -2
- package/dist/services/events-search.js +2 -2
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/ingest.d.ts +56 -8
- package/dist/services/ingest.js +95 -61
- package/dist/services/link-scorers/scan.js +2 -1
- package/dist/services/link-scorers/shared.js +2 -1
- package/dist/services/messages-search.js +3 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/notes-search.js +1 -0
- package/dist/services/project-status/index.js +2 -1
- package/dist/services/proposals/kinds/contracts.d.ts +4 -0
- package/dist/services/proposals/kinds/contracts.js +9 -0
- package/dist/services/proposals/kinds/finance.d.ts +4 -0
- package/dist/services/proposals/kinds/finance.js +14 -35
- package/dist/services/proposals/kinds/orders.js +7 -30
- package/dist/services/proposals/kinds/shared.d.ts +27 -1
- package/dist/services/proposals/kinds/shared.js +34 -0
- package/dist/services/proposals/kinds/source-review.d.ts +4 -0
- package/dist/services/proposals/kinds/source-review.js +45 -0
- package/dist/services/proposals/kinds/subscriptions.d.ts +9 -0
- package/dist/services/proposals/kinds/subscriptions.js +24 -0
- package/dist/services/proposals/kinds/transactions.d.ts +4 -0
- package/dist/services/proposals/kinds/transactions.js +10 -0
- package/dist/services/proposals/registry.js +9 -0
- package/dist/services/search-all-meetings.js +2 -2
- package/dist/services/search-all.js +4 -3
- package/dist/services/search-kind.js +3 -3
- package/dist/services/stored-project-gathering.js +4 -3
- package/dist/store/decisions.js +5 -1
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/index.d.ts +20 -4
- package/dist/store/index.js +4 -0
- package/dist/store/people.js +1 -1
- 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/source-review.d.ts +64 -0
- package/dist/store/source-review.js +7 -0
- package/dist/store/sqlite/accounts.d.ts +1 -1
- package/dist/store/sqlite/accounts.js +24 -1
- package/dist/store/sqlite/added-sources.d.ts +82 -0
- package/dist/store/sqlite/added-sources.js +237 -0
- package/dist/store/sqlite/business-contracts.d.ts +90 -0
- package/dist/store/sqlite/business-contracts.js +182 -0
- package/dist/store/sqlite/calendar-events.js +7 -3
- package/dist/store/sqlite/calendar-forget.js +3 -0
- package/dist/store/sqlite/calendar.d.ts +21 -1
- package/dist/store/sqlite/calendar.js +27 -7
- package/dist/store/sqlite/chat-rekey.js +7 -0
- package/dist/store/sqlite/chats.d.ts +3 -1
- package/dist/store/sqlite/chats.js +15 -1
- package/dist/store/sqlite/crm-rows.d.ts +44 -0
- package/dist/store/sqlite/crm-rows.js +195 -0
- 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 -11
- package/dist/store/sqlite/crm.js +402 -196
- package/dist/store/sqlite/deals.d.ts +4 -8
- package/dist/store/sqlite/deals.js +8 -5
- package/dist/store/sqlite/document-transfer/snapshot.js +2 -2
- package/dist/store/sqlite/emails.js +2 -0
- package/dist/store/sqlite/entity-types.d.ts +14 -9
- package/dist/store/sqlite/entity-types.js +4 -10
- package/dist/store/sqlite/evidence-signature.d.ts +114 -0
- package/dist/store/sqlite/evidence-signature.js +349 -0
- package/dist/store/sqlite/evidence-sources.d.ts +2 -1
- package/dist/store/sqlite/evidence-sources.js +7 -3
- package/dist/store/sqlite/facts.d.ts +7 -2
- package/dist/store/sqlite/facts.js +21 -5
- package/dist/store/sqlite/finance.d.ts +18 -105
- package/dist/store/sqlite/finance.js +100 -219
- package/dist/store/sqlite/involvement-queue.js +4 -3
- package/dist/store/sqlite/knowledge.d.ts +14 -4
- package/dist/store/sqlite/knowledge.js +108 -102
- package/dist/store/sqlite/labelled.d.ts +3 -0
- package/dist/store/sqlite/labelled.js +11 -0
- package/dist/store/sqlite/link-kinds.d.ts +4 -3
- package/dist/store/sqlite/link-kinds.js +6 -2
- package/dist/store/sqlite/manifest.js +7 -0
- package/dist/store/sqlite/memories.d.ts +24 -10
- package/dist/store/sqlite/memories.js +73 -19
- package/dist/store/sqlite/messages.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +134 -0
- package/dist/store/sqlite/money-lines.d.ts +48 -0
- package/dist/store/sqlite/money-lines.js +76 -0
- package/dist/store/sqlite/money-transactions.d.ts +132 -0
- package/dist/store/sqlite/money-transactions.js +295 -0
- package/dist/store/sqlite/notes.d.ts +14 -4
- package/dist/store/sqlite/notes.js +43 -31
- package/dist/store/sqlite/orders.d.ts +36 -6
- package/dist/store/sqlite/orders.js +126 -46
- package/dist/store/sqlite/organizations.d.ts +8 -0
- package/dist/store/sqlite/organizations.js +14 -0
- package/dist/store/sqlite/payment-facts.js +1 -1
- package/dist/store/sqlite/person-preparation.d.ts +1 -1
- package/dist/store/sqlite/person-preparation.js +3 -2
- package/dist/store/sqlite/private-people.js +2 -0
- package/dist/store/sqlite/products.d.ts +78 -0
- package/dist/store/sqlite/products.js +131 -0
- package/dist/store/sqlite/project-transfer/records.js +39 -3
- package/dist/store/sqlite/project-transfer/snapshot.d.ts +4 -1
- package/dist/store/sqlite/project-transfer/snapshot.js +11 -3
- package/dist/store/sqlite/proposed-actions.d.ts +1 -1
- package/dist/store/sqlite/proposed-actions.js +24 -7
- package/dist/store/sqlite/providers.d.ts +0 -4
- package/dist/store/sqlite/providers.js +20 -2
- package/dist/store/sqlite/record-matching.d.ts +80 -0
- package/dist/store/sqlite/record-matching.js +264 -0
- package/dist/store/sqlite/record-projection.d.ts +89 -0
- package/dist/store/sqlite/record-projection.js +50 -0
- package/dist/store/sqlite/record-projectors-direct.d.ts +17 -0
- package/dist/store/sqlite/record-projectors-direct.js +125 -0
- package/dist/store/sqlite/record-projectors-money.d.ts +26 -0
- package/dist/store/sqlite/record-projectors-money.js +214 -0
- package/dist/store/sqlite/record-projectors-phone.d.ts +28 -0
- package/dist/store/sqlite/record-projectors-phone.js +212 -0
- package/dist/store/sqlite/record-projectors.d.ts +3 -44
- package/dist/store/sqlite/record-projectors.js +7 -67
- package/dist/store/sqlite/record-relations.d.ts +24 -0
- package/dist/store/sqlite/record-relations.js +92 -0
- package/dist/store/sqlite/record-remap.d.ts +12 -0
- package/dist/store/sqlite/record-remap.js +92 -0
- package/dist/store/sqlite/record-run.d.ts +71 -0
- package/dist/store/sqlite/record-run.js +179 -0
- package/dist/store/sqlite/record-settling.d.ts +9 -0
- package/dist/store/sqlite/record-settling.js +74 -0
- package/dist/store/sqlite/record-stamps.d.ts +13 -0
- package/dist/store/sqlite/record-stamps.js +30 -0
- package/dist/store/sqlite/record-writes.d.ts +43 -0
- package/dist/store/sqlite/record-writes.js +307 -0
- package/dist/store/sqlite/records.d.ts +52 -42
- package/dist/store/sqlite/records.js +123 -353
- package/dist/store/sqlite/ref-summaries.d.ts +6 -5
- package/dist/store/sqlite/ref-summaries.js +60 -8
- package/dist/store/sqlite/refunds.d.ts +31 -0
- package/dist/store/sqlite/refunds.js +112 -0
- 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/reviewed.d.ts +109 -0
- package/dist/store/sqlite/reviewed.js +173 -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 +2769 -306
- package/dist/store/sqlite/schema.js +258 -25
- package/dist/store/sqlite/source-review-marks.d.ts +54 -0
- package/dist/store/sqlite/source-review-marks.js +143 -0
- package/dist/store/sqlite/source-review.d.ts +54 -0
- package/dist/store/sqlite/source-review.js +221 -0
- package/dist/store/sqlite/stage-amounts.d.ts +14 -0
- package/dist/store/sqlite/stage-amounts.js +23 -0
- package/dist/store/sqlite/subscriptions.d.ts +135 -0
- package/dist/store/sqlite/subscriptions.js +294 -0
- package/dist/store/sqlite/text-input.d.ts +3 -0
- package/dist/store/sqlite/text-input.js +13 -0
- package/dist/store/sqlite/things.js +2 -9
- package/dist/store/sqlite/transaction.d.ts +15 -0
- package/dist/store/sqlite/transaction.js +57 -0
- package/dist/store/sqlite/wallets.d.ts +88 -0
- package/dist/store/sqlite/wallets.js +143 -0
- package/dist/store/store-errors.d.ts +1 -0
- package/dist/store/store-errors.js +45 -0
- package/dist/store/store.d.ts +19 -1
- package/dist/store/store.js +35 -6
- package/package.json +6 -3
- package/schemas/examples/records-business.jsonl +11 -0
- package/schemas/records-envelope.v1.schema.json +1160 -5
package/dist/cli/program.js
CHANGED
|
@@ -20,7 +20,7 @@ import { commandAvailability } from "./command-availability.js";
|
|
|
20
20
|
import { commandPathOf } from "./command-contract.js";
|
|
21
21
|
import { entityRows } from "./compact.js";
|
|
22
22
|
import { outputFor, provide } from "./context.js";
|
|
23
|
-
import { refuseByCommandPermissions, refuseWriteBeforeConnecting } from "./early-refusal.js";
|
|
23
|
+
import { refuseByCommandPermissions, refuseOfflineCommand, refuseWriteBeforeConnecting } from "./early-refusal.js";
|
|
24
24
|
import { admittedUnderLock, changesAuthorityAt, changesAuthorityNow, isLogin, isStoreChange, judgedEffects, judgedTargets, storeChangeRefusal, } from "./effects.js";
|
|
25
25
|
import { itemOf, renderAnswer, snakeKeys } from "./envelope.js";
|
|
26
26
|
import { byteCount, DEFAULT_AGENT_COOPERATIVE_MS, DEFAULT_COMMAND_MS, DEFAULT_COOPERATIVE_MS, DEFAULT_OUTPUT_BYTES, DEFAULT_SYNC_MS, execution, } from "./execution.js";
|
|
@@ -287,7 +287,8 @@ const runOnce = async (argv, definition, options) => {
|
|
|
287
287
|
const headless = machine || flags.input === false || Boolean(commandEnv.CI) || (options.tty ?? process.stdout.isTTY) !== true;
|
|
288
288
|
checkJson(action, requested, !flags.jsonl && (options.tty ?? process.stdout.isTTY) === true);
|
|
289
289
|
control.configure({
|
|
290
|
-
|
|
290
|
+
// Beside `--format csv`, `--json=a,b` names the table's columns: a CSV is no JSON to pick fields from.
|
|
291
|
+
...(flags.fields === undefined || action.getOptionValue("format") === "csv" ? {} : { fields: flags.fields }),
|
|
291
292
|
maxOutputBytes: flags.maxOutputBytes === undefined
|
|
292
293
|
? machine || (options.tty ?? process.stdout.isTTY) !== true
|
|
293
294
|
? DEFAULT_OUTPUT_BYTES
|
|
@@ -304,6 +305,7 @@ const runOnce = async (argv, definition, options) => {
|
|
|
304
305
|
const localPreview = action.options.some((option) => option.long === "--dry-run");
|
|
305
306
|
if (flags.dryRun && localPreview)
|
|
306
307
|
action.setOptionValue("dryRun", true);
|
|
308
|
+
refuseOfflineCommand(action, definition.app, flags.offline === true, flags.dryRun === true && localPreview);
|
|
307
309
|
const path = commandPathOf(action);
|
|
308
310
|
const lock = readOnlyLockOf(definition.app, commandEnv);
|
|
309
311
|
const input = options.stdin ?? process.stdin;
|
|
@@ -8,7 +8,7 @@ import { DEFAULT_STEMMERS, parseStemmers } from "../search/stem.js";
|
|
|
8
8
|
import { openCache } from "../store/open.js";
|
|
9
9
|
import { storePath } from "../store/path.js";
|
|
10
10
|
import { applyTaskCategoryEdits, editsFrom, readTaskCategoryEdits, sharedConfigPath, writeTaskCategoryEdits, } from "../store/shared-config.js";
|
|
11
|
-
import { accountGroupsOf, DEFAULT_AGENT_CLOSE, DEFAULT_FIRST_PASS_PER_CHAT, firstPassPerChatOf, openStore, savedAgentClose, savedFirstPassPerChat, savedPhoneCountries, savedStemmers, savedTaskCategories, saveStorePhoneCountries, stemmersOrigin, } from "../store/store.js";
|
|
11
|
+
import { accountGroupsOf, crmSettingsOf, DEFAULT_AGENT_CLOSE, DEFAULT_FIRST_PASS_PER_CHAT, firstPassPerChatOf, openStore, parseCrmSetting, parseCrmSettingValue, saveCrmSetting, savedAgentClose, savedFirstPassPerChat, savedPhoneCountries, savedStemmers, savedTaskCategories, saveStorePhoneCountries, stemmersOrigin, } from "../store/store.js";
|
|
12
12
|
const SCRIPTS = {
|
|
13
13
|
"search_stemmers.cyrillic": "cyrillic",
|
|
14
14
|
"search_stemmers.latin": "latin",
|
|
@@ -29,12 +29,16 @@ export const STORE_SETTINGS = [
|
|
|
29
29
|
FIRST_PASS,
|
|
30
30
|
];
|
|
31
31
|
const GROUP_PREFIX = `${ACCOUNT_GROUPS_SETTING}.`;
|
|
32
|
+
/** A CRM account's: whether what it reports is a relationship or waits for review, and what its company types mean. */
|
|
33
|
+
const CRM_SETTINGS = ["crm.<provider>:<account>.links", "crm.<provider>:<account>.company-types"];
|
|
32
34
|
/**
|
|
33
35
|
* The store settings a CLI offers. Phone countries, task rules and account groups belong to messages; a CLI that is
|
|
34
36
|
* not a messenger would change them for tg and MAX without reading them itself.
|
|
35
37
|
*/
|
|
36
|
-
export const storeSettingsOf = (app) => app.messenger === false
|
|
37
|
-
|
|
38
|
+
export const storeSettingsOf = (app) => app.messenger === false
|
|
39
|
+
? [...Object.keys(SCRIPTS), ...CRM_SETTINGS]
|
|
40
|
+
: [...STORE_SETTINGS, `${GROUP_PREFIX}<name>`, ...CRM_SETTINGS];
|
|
41
|
+
export const offersStoreSetting = (app, setting) => app.messenger !== false || setting in SCRIPTS || parseCrmSetting(setting) !== undefined;
|
|
38
42
|
export const isStoreSetting = (setting) => setting in SCRIPTS ||
|
|
39
43
|
setting === PHONE_COUNTRIES ||
|
|
40
44
|
setting === TASK_CATEGORIES ||
|
|
@@ -42,10 +46,13 @@ export const isStoreSetting = (setting) => setting in SCRIPTS ||
|
|
|
42
46
|
setting === AGENT_CLOSE ||
|
|
43
47
|
setting === AGENT_CLOSE_MIN ||
|
|
44
48
|
setting === FIRST_PASS ||
|
|
45
|
-
setting.startsWith(GROUP_PREFIX)
|
|
49
|
+
setting.startsWith(GROUP_PREFIX) ||
|
|
50
|
+
parseCrmSetting(setting) !== undefined;
|
|
46
51
|
export const changeStoreSetting = async (app, env, setting, value) => {
|
|
47
52
|
if (setting.startsWith(GROUP_PREFIX))
|
|
48
53
|
return changeGroup(app, env, setting, value);
|
|
54
|
+
if (parseCrmSetting(setting))
|
|
55
|
+
return changeCrm(env, setting, value);
|
|
49
56
|
if (setting === PHONE_COUNTRIES)
|
|
50
57
|
return changePhoneCountries(app, env, value);
|
|
51
58
|
if (setting === TASK_CATEGORIES || setting.startsWith(CATEGORY_PREFIX))
|
|
@@ -213,6 +220,30 @@ const changeGroup = async (app, env, setting, value) => {
|
|
|
213
220
|
await store.close();
|
|
214
221
|
}
|
|
215
222
|
};
|
|
223
|
+
const crmValueText = (value) => typeof value === "string"
|
|
224
|
+
? value
|
|
225
|
+
: Object.entries(value)
|
|
226
|
+
.map(([type, meaning]) => `${type}=${meaning}`)
|
|
227
|
+
.join(",");
|
|
228
|
+
const changeCrm = async (env, setting, value) => {
|
|
229
|
+
const { name } = parseCrmSetting(setting);
|
|
230
|
+
const parsed = value === undefined ? undefined : parseCrmSettingValue(name, value);
|
|
231
|
+
await (await openStore({ env })).close();
|
|
232
|
+
const database = await openCache(storePath(env));
|
|
233
|
+
try {
|
|
234
|
+
saveCrmSetting(database, setting, parsed, Date.now());
|
|
235
|
+
}
|
|
236
|
+
finally {
|
|
237
|
+
database.close();
|
|
238
|
+
}
|
|
239
|
+
const now = parsed ?? (name === "links" ? "reported" : {});
|
|
240
|
+
return {
|
|
241
|
+
result: { store: storePath(env), scope: "store", setting, value: crmValueText(now) },
|
|
242
|
+
note: name === "links"
|
|
243
|
+
? `store-wide — the next sync of that account writes what it reports as ${now === "review" ? "proposals for the owner to review" : "reported relationships"}; relationships already stored stay`
|
|
244
|
+
: "store-wide — a company of a mapped type becomes a customer, supplier or partner of the own company",
|
|
245
|
+
};
|
|
246
|
+
};
|
|
216
247
|
/** Each category as `config show` lists it, and where it comes from: the shared file, an older store's list, the default. */
|
|
217
248
|
const categoryRows = (saved, file) => {
|
|
218
249
|
let edits;
|
|
@@ -249,6 +280,7 @@ export const storeSettings = async (env) => {
|
|
|
249
280
|
let categories;
|
|
250
281
|
let agentClose = {};
|
|
251
282
|
let firstPass;
|
|
283
|
+
let crm = [];
|
|
252
284
|
if (existsSync(path)) {
|
|
253
285
|
try {
|
|
254
286
|
const database = await openCache(path);
|
|
@@ -261,6 +293,7 @@ export const storeSettings = async (env) => {
|
|
|
261
293
|
categories = table ? savedTaskCategories(database) : undefined;
|
|
262
294
|
agentClose = table ? savedAgentClose(database) : {};
|
|
263
295
|
firstPass = table ? savedFirstPassPerChat(database) : undefined;
|
|
296
|
+
crm = table ? crmSettingsOf(database) : [];
|
|
264
297
|
}
|
|
265
298
|
finally {
|
|
266
299
|
database.close();
|
|
@@ -316,6 +349,7 @@ export const storeSettings = async (env) => {
|
|
|
316
349
|
scope: "store",
|
|
317
350
|
},
|
|
318
351
|
]),
|
|
352
|
+
...crm.map(({ setting, value }) => ({ setting, value: crmValueText(value), from: "store", scope: "store" })),
|
|
319
353
|
...Object.entries(groups).map(([name, members]) => ({
|
|
320
354
|
setting: `${GROUP_PREFIX}${name}`,
|
|
321
355
|
value: members.join(","),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Command, Option } from "commander";
|
|
2
|
+
import type { CrmField } from "../../domain/crm.js";
|
|
3
|
+
/**
|
|
4
|
+
* `--format csv`: `--format` is the vocabulary's output choice, so no CLI's command lint needs a new word. Off MCP: a
|
|
5
|
+
* table carries no `untrusted` marker for an agent.
|
|
6
|
+
*/
|
|
7
|
+
export declare const csvFormatOption: () => Option;
|
|
8
|
+
/** What a page of deals or leads gives the table: its rows as `--json` answers them, and the CRM's own fields. */
|
|
9
|
+
export interface CsvPage {
|
|
10
|
+
items: Record<string, unknown>[];
|
|
11
|
+
fields: CrmField[];
|
|
12
|
+
page: number;
|
|
13
|
+
hasMore: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Reads a page in the profile's run, closes it, then prints the table: stdout carries the CSV and nothing else, and
|
|
17
|
+
* the way to the next page goes to stderr.
|
|
18
|
+
*/
|
|
19
|
+
export declare const renderCsv: <R extends {
|
|
20
|
+
close?: () => Promise<void>;
|
|
21
|
+
}>(command: Command, open: (command: Command, access: {
|
|
22
|
+
readOnly: boolean;
|
|
23
|
+
}) => Promise<R>, read: (run: R) => Promise<CsvPage>) => Promise<void>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotateOption } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { Option } from "commander";
|
|
4
|
+
import { compactOf, environmentOf, inCommandRun, outputFor } from "../../cli/context.js";
|
|
5
|
+
import { writeCsv } from "../../cli/csv.js";
|
|
6
|
+
import { fieldsOf } from "../../cli/result-fields.js";
|
|
7
|
+
/**
|
|
8
|
+
* `--format csv`: `--format` is the vocabulary's output choice, so no CLI's command lint needs a new word. Off MCP: a
|
|
9
|
+
* table carries no `untrusted` marker for an agent.
|
|
10
|
+
*/
|
|
11
|
+
export const csvFormatOption = () => annotateOption(new Option("--format <format>", "csv: this page as a table for a spreadsheet; --json=a,b picks its columns").choices(["csv"]), { mcp: false });
|
|
12
|
+
const DEFAULT_COLUMNS = [
|
|
13
|
+
"ref",
|
|
14
|
+
"title",
|
|
15
|
+
"status",
|
|
16
|
+
"pipeline",
|
|
17
|
+
"pipeline_name",
|
|
18
|
+
"stage",
|
|
19
|
+
"amount",
|
|
20
|
+
"currency",
|
|
21
|
+
"organization",
|
|
22
|
+
"people",
|
|
23
|
+
"close_date",
|
|
24
|
+
"closed_date",
|
|
25
|
+
"closed_reason",
|
|
26
|
+
"assignee",
|
|
27
|
+
"external_id",
|
|
28
|
+
"created_at",
|
|
29
|
+
"updated_at",
|
|
30
|
+
"provider_metadata",
|
|
31
|
+
];
|
|
32
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
const at = (item, path) => path.reduce((value, key) => (isRecord(value) ? value[key] : undefined), item);
|
|
34
|
+
/** One cell's text: a party by its name, a list joined, so no cell holds JSON a spreadsheet cannot read. */
|
|
35
|
+
const flat = (value) => {
|
|
36
|
+
if (Array.isArray(value))
|
|
37
|
+
return value.map(flat).join("; ");
|
|
38
|
+
if (isRecord(value))
|
|
39
|
+
return value.name ?? value.ref ?? JSON.stringify(value);
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
const MONEY = /^(-?\d+(?:\.\d+)?)\|([A-Za-z]{3})$/;
|
|
43
|
+
/** A CRM's own field: headed by its label as `fields list` shows it; money as an amount and a currency column. */
|
|
44
|
+
const customColumns = (field, header) => {
|
|
45
|
+
const value = (item) => at(item, ["provider_metadata", field.code, "value"]);
|
|
46
|
+
if (field.type !== "money")
|
|
47
|
+
return [{ header, cell: (item) => flat(value(item)) }];
|
|
48
|
+
const part = (index) => (item) => {
|
|
49
|
+
const raw = value(item);
|
|
50
|
+
const money = typeof raw === "string" ? MONEY.exec(raw) : null;
|
|
51
|
+
return money ? money[index] : index === 1 ? flat(raw) : null;
|
|
52
|
+
};
|
|
53
|
+
return [
|
|
54
|
+
{ header: `${header} amount`, cell: part(1) },
|
|
55
|
+
{ header: `${header} currency`, cell: part(2) },
|
|
56
|
+
];
|
|
57
|
+
};
|
|
58
|
+
/** Every custom field the CRM lists, then any a row holds that the list does not, each header told apart by code. */
|
|
59
|
+
const customFieldsOf = (page) => {
|
|
60
|
+
const listed = new Set(page.fields.map((field) => field.code));
|
|
61
|
+
const extra = new Map();
|
|
62
|
+
for (const item of page.items) {
|
|
63
|
+
const metadata = item.provider_metadata;
|
|
64
|
+
if (!isRecord(metadata))
|
|
65
|
+
continue;
|
|
66
|
+
for (const [code, value] of Object.entries(metadata))
|
|
67
|
+
if (!listed.has(code) && !extra.has(code)) {
|
|
68
|
+
const label = isRecord(value) && typeof value.label === "string" ? value.label : null;
|
|
69
|
+
extra.set(code, { code, label, type: "string", multiple: false, filterable: false });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return [...page.fields, ...extra.values()];
|
|
73
|
+
};
|
|
74
|
+
const columnsOf = (page, paths) => {
|
|
75
|
+
const custom = customFieldsOf(page);
|
|
76
|
+
const taken = new Set(paths.filter((path) => !path.startsWith("provider_metadata")));
|
|
77
|
+
const labels = new Map();
|
|
78
|
+
for (const field of custom)
|
|
79
|
+
labels.set(field.label ?? field.code, (labels.get(field.label ?? field.code) ?? 0) + 1);
|
|
80
|
+
const headerOf = (field) => {
|
|
81
|
+
const label = field.label ?? field.code;
|
|
82
|
+
return (labels.get(label) ?? 0) > 1 || taken.has(label) ? `${label} (${field.code})` : label;
|
|
83
|
+
};
|
|
84
|
+
return paths.flatMap((path) => {
|
|
85
|
+
const parts = path.split(".");
|
|
86
|
+
if (parts[0] !== "provider_metadata")
|
|
87
|
+
return [{ header: path, cell: (item) => flat(at(item, parts)) }];
|
|
88
|
+
const chosen = parts[1] === undefined ? custom : custom.filter((field) => field.code === parts[1]);
|
|
89
|
+
return chosen.flatMap((field) => customColumns(field, headerOf(field)));
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
/** `--json=a,b` beside `--format csv` names its columns, `items.` or not, as `--json` would keep them. */
|
|
93
|
+
const pathsOf = (command) => {
|
|
94
|
+
const fields = command.optsWithGlobals().fields;
|
|
95
|
+
if (fields === undefined)
|
|
96
|
+
return DEFAULT_COLUMNS;
|
|
97
|
+
return fieldsOf(fields).map((path) => (path.startsWith("items.") ? path.slice("items.".length) : path));
|
|
98
|
+
};
|
|
99
|
+
const refuse = (message) => {
|
|
100
|
+
throw new CliError("validation_error", message, { reason: "output.conflict", param: "--format" });
|
|
101
|
+
};
|
|
102
|
+
/** A table is for a person's spreadsheet: JSON, JSON lines, compact rows and an agent's run each ask for another. */
|
|
103
|
+
const refuseOtherOutput = (command) => {
|
|
104
|
+
const globals = command.optsWithGlobals();
|
|
105
|
+
if (environmentOf(command).agent)
|
|
106
|
+
refuse("--format csv is a table for a spreadsheet; an agent reads the JSON answer");
|
|
107
|
+
if (globals.jsonl)
|
|
108
|
+
refuse("--format csv and --jsonl ask for different output — pick one");
|
|
109
|
+
if (compactOf(command))
|
|
110
|
+
refuse("--format csv and --compact ask for different output — pick one");
|
|
111
|
+
if (globals.json && globals.fields === undefined)
|
|
112
|
+
refuse("--format csv and --json ask for different output — --json=a,b picks the table's columns");
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Reads a page in the profile's run, closes it, then prints the table: stdout carries the CSV and nothing else, and
|
|
116
|
+
* the way to the next page goes to stderr.
|
|
117
|
+
*/
|
|
118
|
+
export const renderCsv = (command, open, read) => {
|
|
119
|
+
refuseOtherOutput(command);
|
|
120
|
+
return inCommandRun(command, async () => {
|
|
121
|
+
const run = await open(command, { readOnly: true });
|
|
122
|
+
let page;
|
|
123
|
+
try {
|
|
124
|
+
page = await read(run);
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
await run.close?.();
|
|
128
|
+
}
|
|
129
|
+
const columns = columnsOf(page, pathsOf(command));
|
|
130
|
+
const { streams, renderer } = outputFor(command);
|
|
131
|
+
writeCsv(streams, columns.map((column) => column.header), page.items.map((item) => columns.map((column) => column.cell(item))));
|
|
132
|
+
if (page.hasMore)
|
|
133
|
+
renderer.note(`→ more rows: run it again with --page ${page.page + 1}`);
|
|
134
|
+
});
|
|
135
|
+
};
|
package/dist/crm/cli/index.d.ts
CHANGED
|
@@ -59,5 +59,5 @@ export declare const STAGES_QUERY: {
|
|
|
59
59
|
readonly backend: "native";
|
|
60
60
|
readonly fields: readonly [import("@wirecat/cli-base/query").FieldSpec, import("@wirecat/cli-base/query").FieldSpec];
|
|
61
61
|
};
|
|
62
|
-
export type CrmWithin = (command: Command, work: (run: CrmRun) => Promise<Body
|
|
62
|
+
export type CrmWithin = (command: Command, work: (run: CrmRun) => Promise<Body>, view?: (body: Body) => string) => Promise<void>;
|
|
63
63
|
export declare const addCrmCommands: (program: Command, options: CrmCommandOptions) => void;
|
package/dist/crm/cli/index.js
CHANGED
|
@@ -15,7 +15,9 @@ import { DEAL_KINDS, DEAL_STATUSES } from "../../domain/deals.js";
|
|
|
15
15
|
import { deal as dealEntity } from "../../entities/deal.js";
|
|
16
16
|
import { count, text } from "../../entities/fields.js";
|
|
17
17
|
import { crmStatus, syncCrm } from "../sync.js";
|
|
18
|
-
import { closeCrmItem, createCrmItem, fieldPairsOf, moveCrmItem, removeCrmItem, updateCrmItem, } from "../writes.js";
|
|
18
|
+
import { closeCrmItem, createCrmItem, fieldPairsOf, moveCrmItem, pipelineOf, removeCrmItem, updateCrmItem, } from "../writes.js";
|
|
19
|
+
import { csvFormatOption, renderCsv } from "./csv.js";
|
|
20
|
+
import { pipelineView } from "./pipeline-view.js";
|
|
19
21
|
import { addCrmSearchAll } from "./search-all.js";
|
|
20
22
|
const MOST = 500;
|
|
21
23
|
const DEAL_FIELDS = [
|
|
@@ -56,6 +58,8 @@ const crmSync = v.strictObject({
|
|
|
56
58
|
provider: text,
|
|
57
59
|
account: text,
|
|
58
60
|
pipelines: count,
|
|
61
|
+
users: v.optional(count),
|
|
62
|
+
skipped_owner_rejected: count,
|
|
59
63
|
synced: v.array(v.strictObject({
|
|
60
64
|
kind: v.picklist(CRM_KINDS),
|
|
61
65
|
round: v.picklist(["full", "changes"]),
|
|
@@ -68,7 +72,7 @@ const crmSync = v.strictObject({
|
|
|
68
72
|
error: v.optional(text),
|
|
69
73
|
})),
|
|
70
74
|
issues: v.array(v.strictObject({
|
|
71
|
-
kind: v.picklist(CRM_KINDS),
|
|
75
|
+
kind: v.picklist([...CRM_KINDS, "user"]),
|
|
72
76
|
reason: text,
|
|
73
77
|
message: text,
|
|
74
78
|
external_id: v.optional(text),
|
|
@@ -137,7 +141,7 @@ const dealKeys = snakeKeysKeeping(["providerMetadata"]);
|
|
|
137
141
|
const marked = (items, untrusted) => items.map((item) => ({ ...dealKeys(item), untrusted }));
|
|
138
142
|
const addCrmCommandsDefinition = (program, options) => {
|
|
139
143
|
const now = () => options.now?.() ?? Date.now();
|
|
140
|
-
const within = (command, work) => inCommandRun(command, async () => {
|
|
144
|
+
const within = (command, work, view) => inCommandRun(command, async () => {
|
|
141
145
|
const run = await options.open(command, { readOnly: metaOf(command).effects?.local !== "write" });
|
|
142
146
|
let body;
|
|
143
147
|
try {
|
|
@@ -146,7 +150,7 @@ const addCrmCommandsDefinition = (program, options) => {
|
|
|
146
150
|
finally {
|
|
147
151
|
await run.close?.();
|
|
148
152
|
}
|
|
149
|
-
renderAnswer(command, outputFor(command), body);
|
|
153
|
+
renderAnswer(command, outputFor(command), body, view);
|
|
150
154
|
});
|
|
151
155
|
const example = (command, ...lines) => annotate(command, { examples: lines.map((line) => `${options.app.command} work ${line}`) });
|
|
152
156
|
example(answerEntity(annotate(program.command("sync"), { effects: FETCH, offline: false, cooperative: true, partial: true }), "crm_sync", crmSync).description("bring the CRM's copy in the local store up to date: pipelines, companies, contacts, deals and leads that " +
|
|
@@ -230,22 +234,31 @@ const addCrmCommandsDefinition = (program, options) => {
|
|
|
230
234
|
: "the CRM's leads as last synced");
|
|
231
235
|
example(withQuery(annotate(group.command("list"), { effects: LOCAL_READ, output: { entity: kind } }).description(`${plural} copied from the CRM, newest first; run sync to bring them up to date`), query)
|
|
232
236
|
.option("--limit <n>", `${plural} per page, 1–${MOST}`, integer(MOST), 50)
|
|
233
|
-
.option("--page <n>", "which page, starting at 1", integer(1_000_000), 1)
|
|
237
|
+
.option("--page <n>", "which page, starting at 1", integer(1_000_000), 1)
|
|
238
|
+
.addOption(csvFormatOption()), `${plural} list status:open --json`, `${plural} list stage:"Quote sent"`, `${plural} list status:open --format csv > ${plural}.csv`).action(async (words, opts, command) => {
|
|
234
239
|
const terms = queryTerms(words, query, `${plural} list`);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
240
|
+
const read = (run) => run.store.deals.list({
|
|
241
|
+
kind,
|
|
242
|
+
account: run.account,
|
|
243
|
+
...(terms.has("status") ? { status: terms.get("status") } : {}),
|
|
244
|
+
...(terms.has("stage") ? { stage: terms.get("stage") } : {}),
|
|
245
|
+
...(terms.has("pipeline") ? { pipeline: terms.get("pipeline") } : {}),
|
|
246
|
+
...(terms.has("organization") ? { organization: terms.get("organization") } : {}),
|
|
247
|
+
limit: Math.min(opts.limit + 1, MOST),
|
|
248
|
+
offset: (opts.page - 1) * opts.limit,
|
|
249
|
+
});
|
|
250
|
+
if (opts.format === "csv")
|
|
251
|
+
return renderCsv(command, options.open, async (run) => {
|
|
252
|
+
const found = await read(run);
|
|
253
|
+
return {
|
|
254
|
+
items: marked(found.slice(0, opts.limit), DEAL_UNTRUSTED),
|
|
255
|
+
fields: await run.store.crm.fields(run.account, kind),
|
|
256
|
+
page: opts.page,
|
|
257
|
+
hasMore: found.length > opts.limit,
|
|
258
|
+
};
|
|
248
259
|
});
|
|
260
|
+
await within(command, async (run) => {
|
|
261
|
+
const found = await read(run);
|
|
249
262
|
return listOf(pathOf(command).join(" "), {
|
|
250
263
|
items: marked(found.slice(0, opts.limit), DEAL_UNTRUSTED),
|
|
251
264
|
limit: opts.limit,
|
|
@@ -393,12 +406,13 @@ const addCrmCommandsDefinition = (program, options) => {
|
|
|
393
406
|
});
|
|
394
407
|
});
|
|
395
408
|
example(annotate(pipelines.command("show"), { effects: LOCAL_READ, output: { entity: "pipeline" } })
|
|
396
|
-
.description("one pipeline
|
|
397
|
-
|
|
409
|
+
.description("one pipeline as a board and a funnel: how many stand in each stage and their sum per currency, never " +
|
|
410
|
+
"converted, how many reached it and went on, and the win rate; won and lost stages are marked by outcome")
|
|
411
|
+
.argument("[pipeline]", "pipeline:<id>, or a name only one of the CRM's pipelines has; needed unless the CRM has one pipeline in all"), "pipelines show pipeline:3", "pipelines show Sales --json").action(async (reference, _opts, command) => {
|
|
398
412
|
await within(command, async (run) => {
|
|
399
|
-
const report = await run
|
|
413
|
+
const report = await pipelineOf(run, undefined, reference, "pipeline");
|
|
400
414
|
return itemOf({ ...snakeKeys(report), untrusted: PIPELINE_UNTRUSTED });
|
|
401
|
-
});
|
|
415
|
+
}, (body) => pipelineView(body, outputFor(command).color));
|
|
402
416
|
});
|
|
403
417
|
const stages = annotate(program.command("stages"), { effects: NO_EFFECTS }).description("the stages of the CRM's pipelines, as last synced");
|
|
404
418
|
example(withQuery(annotate(stages.command("list"), { effects: LOCAL_READ, output: { entity: "stage" } }).description("every stage of the CRM's pipelines in order, with its outcome and how many are open in it"), STAGES_QUERY), "stages list --json", "stages list kind:lead").action(async (words, _opts, command) => {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { renderPretty } from "@wirecat/cli-base";
|
|
2
|
+
import { formatDecimal, groupDigits, parseDecimal, scaleOf } from "../../domain/money.js";
|
|
3
|
+
const sumOf = (amounts) => amounts.map(({ amount, currency }) => `${groupDigits(amount)} ${currency}`).join(", ") || "—";
|
|
4
|
+
const percent = (share) => (share === null ? "—" : `${Math.round(share * 100)}%`);
|
|
5
|
+
const openStages = (stages) => {
|
|
6
|
+
const sums = new Map();
|
|
7
|
+
let items = 0;
|
|
8
|
+
for (const stage of stages.filter((one) => one.outcome === "open")) {
|
|
9
|
+
items += stage.items;
|
|
10
|
+
for (const { amount, currency } of stage.amounts)
|
|
11
|
+
sums.set(currency, (sums.get(currency) ?? 0n) + (parseDecimal(amount, scaleOf(currency)) ?? 0n));
|
|
12
|
+
}
|
|
13
|
+
const amounts = [...sums].map(([currency, units]) => ({
|
|
14
|
+
amount: formatDecimal(units, scaleOf(currency)),
|
|
15
|
+
currency,
|
|
16
|
+
}));
|
|
17
|
+
return `in open stages: ${items} · ${sumOf(amounts)}`;
|
|
18
|
+
};
|
|
19
|
+
/** `pipelines show` at a terminal: the board as a table, then what the open stages hold and how the closed ended. */
|
|
20
|
+
export const pipelineView = (body, color) => {
|
|
21
|
+
const pipeline = body.item;
|
|
22
|
+
const rows = pipeline.stages.map((stage) => ({
|
|
23
|
+
stage: stage.name,
|
|
24
|
+
outcome: stage.outcome,
|
|
25
|
+
[`${pipeline.kind}s`]: stage.items,
|
|
26
|
+
sum: sumOf(stage.amounts),
|
|
27
|
+
reached: stage.reached,
|
|
28
|
+
"went on": percent(stage.conversion),
|
|
29
|
+
}));
|
|
30
|
+
const { won, lost, win_rate } = pipeline.totals;
|
|
31
|
+
return [
|
|
32
|
+
`${pipeline.name} (${pipeline.ref})`,
|
|
33
|
+
renderPretty(rows, { color }),
|
|
34
|
+
`${openStages(pipeline.stages)}\nwon: ${won} · lost: ${lost} · win rate ${percent(win_rate)}`,
|
|
35
|
+
].join("\n\n");
|
|
36
|
+
};
|
package/dist/crm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { CrmChanges, CrmIdPage, CrmPage, CrmSource, CrmSourceTraits } from "./source.js";
|
|
2
|
-
export { type CrmCursor, type CrmSyncIssue, type CrmSyncOptions, type CrmSyncReport, type CrmSyncResult, crmStatus, cursorName, parseCrmCursor, syncCrm, } from "./sync.js";
|
|
1
|
+
export type { CrmCallContext, CrmChanges, CrmGap, CrmIdPage, CrmPage, CrmSource, CrmSourceTraits, } from "./source.js";
|
|
2
|
+
export { type CrmCursor, type CrmSyncIssue, type CrmSyncOptions, type CrmSyncReport, type CrmSyncResult, crmGapsOf, crmStatus, cursorName, parseCrmCursor, syncCrm, } from "./sync.js";
|
|
3
3
|
export { CRM_ASSIGN_OTHERS_KEY, CRM_VERBS, CRM_WRITE_DEFAULTS, CRM_WRITE_KEYS, type CrmDraft, type CrmFields, type CrmVerb, type CrmWriteCapabilities, type CrmWriteOptions, type CrmWriter, crmAlsoChecks, } from "./writer.js";
|
|
4
4
|
export { type CrmFieldsInput, type CrmWriteContext, type CrmWrites, type CrmWritten, closeCrmItem, createCrmItem, fieldNamed, fieldPairsOf, foldFieldName, moveCrmItem, type NamedField, optionOf, removeCrmItem, unknownField, updateCrmItem, } from "./writes.js";
|
package/dist/crm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { crmStatus, cursorName, parseCrmCursor, syncCrm, } from "./sync.js";
|
|
1
|
+
export { crmGapsOf, crmStatus, cursorName, parseCrmCursor, syncCrm, } from "./sync.js";
|
|
2
2
|
export { CRM_ASSIGN_OTHERS_KEY, CRM_VERBS, CRM_WRITE_DEFAULTS, CRM_WRITE_KEYS, crmAlsoChecks, } from "./writer.js";
|
|
3
3
|
export { closeCrmItem, createCrmItem, fieldNamed, fieldPairsOf, foldFieldName, moveCrmItem, optionOf, removeCrmItem, unknownField, updateCrmItem, } from "./writes.js";
|
package/dist/crm/source.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CrmField, CrmKind, CrmPipeline, CrmRecords } from "../domain/crm.js";
|
|
1
|
+
import type { CrmDepartment, CrmField, CrmKind, CrmPipeline, CrmRecords, CrmUser } from "../domain/crm.js";
|
|
2
2
|
import type { DealKind } from "../domain/deals.js";
|
|
3
3
|
export interface CrmSourceTraits {
|
|
4
4
|
/** What this CRM has: one without leads leaves `lead` out. Contacts and companies come before the items on them. */
|
|
@@ -26,23 +26,53 @@ export interface CrmIdPage {
|
|
|
26
26
|
ids: string[];
|
|
27
27
|
nextPage?: string;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* What a CRM account did not report in the last sync, so an answer can name it: a kind it has not, users or departments
|
|
31
|
+
* it does not list, a list the sign-in's scope refused (`code`, and the `scope` the adapter named), or a part a source
|
|
32
|
+
* said it could not read.
|
|
33
|
+
*/
|
|
34
|
+
export interface CrmGap {
|
|
35
|
+
kind: CrmKind | "users" | "departments";
|
|
36
|
+
reason: "not-listed" | "refused" | "partial";
|
|
37
|
+
code?: string;
|
|
38
|
+
scope?: string;
|
|
39
|
+
message: string;
|
|
40
|
+
}
|
|
41
|
+
/** What the engine hands every source call; a source that ignores it works as before. */
|
|
42
|
+
export interface CrmCallContext {
|
|
43
|
+
/**
|
|
44
|
+
* Takes one request from the run's budget, for each request beyond the one the engine takes before the call (a
|
|
45
|
+
* source that pages internally). Throws once the budget is spent: the run stops there as `partial`.
|
|
46
|
+
*/
|
|
47
|
+
spend(): void;
|
|
48
|
+
/** Says what the call could not read without failing it, such as e-mails a missing scope hides. */
|
|
49
|
+
gap(gap: {
|
|
50
|
+
kind: CrmGap["kind"];
|
|
51
|
+
message: string;
|
|
52
|
+
scope?: string;
|
|
53
|
+
}): void;
|
|
54
|
+
}
|
|
29
55
|
/** One CRM account, as an adapter reads it. The engine never sees a provider word. */
|
|
30
56
|
export interface CrmSource {
|
|
31
57
|
/** The registry name: `bitrix24`, `pipedrive`, `hubspot`, `amocrm`. */
|
|
32
58
|
readonly provider: string;
|
|
33
59
|
readonly traits: CrmSourceTraits;
|
|
34
60
|
/** One kind's pipelines with their stages; a CRM whose leads have no pipelines answers one of its own making. */
|
|
35
|
-
pipelines(kind: DealKind): Promise<CrmPipeline[]>;
|
|
61
|
+
pipelines(kind: DealKind, context?: CrmCallContext): Promise<CrmPipeline[]>;
|
|
36
62
|
/**
|
|
37
63
|
* What changed since `cursor`, a page at a time; `cursor: null` lists everything. A CRM without a change feed
|
|
38
64
|
* reads by its own modified time, with an overlap, and gives that time back as the cursor.
|
|
39
65
|
*/
|
|
40
|
-
changes<K extends CrmKind>(kind: K, cursor: string | null, page?: string): Promise<CrmChanges<CrmRecords[K]>>;
|
|
66
|
+
changes<K extends CrmKind>(kind: K, cursor: string | null, page?: string, context?: CrmCallContext): Promise<CrmChanges<CrmRecords[K]>>;
|
|
41
67
|
/**
|
|
42
68
|
* The CRM's own fields on one kind, in its order: what the codes in a row's `metadata` mean. Read every sync; a CRM
|
|
43
69
|
* without custom fields leaves it out, and one that has none on a kind answers `[]`.
|
|
44
70
|
*/
|
|
45
|
-
fields?(kind: CrmKind): Promise<CrmField[]>;
|
|
71
|
+
fields?(kind: CrmKind, context?: CrmCallContext): Promise<CrmField[]>;
|
|
46
72
|
/** Every id the CRM holds of the kind, a page at a time: how deletions are found when `removedInChanges` is false. */
|
|
47
|
-
ids?(kind: CrmKind, page?: string): Promise<CrmIdPage>;
|
|
73
|
+
ids?(kind: CrmKind, page?: string, context?: CrmCallContext): Promise<CrmIdPage>;
|
|
74
|
+
/** Every user of the account, active or not; a CRM that cannot list them leaves it out, and its users stay. */
|
|
75
|
+
users?(context?: CrmCallContext): Promise<CrmUser[]>;
|
|
76
|
+
/** Every department; left out, reporting lines are unknown and none stored is withdrawn. */
|
|
77
|
+
departments?(context?: CrmCallContext): Promise<CrmDepartment[]>;
|
|
48
78
|
}
|
package/dist/crm/sync.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type BudgetStop, type RunBudget } from "../background/budget.js";
|
|
2
2
|
import { type CrmKind } from "../domain/crm.js";
|
|
3
|
-
import type { CrmSkipped } from "../store/sqlite/crm.js";
|
|
3
|
+
import type { CrmRelationIssue, CrmSkipped } from "../store/sqlite/crm.js";
|
|
4
4
|
import type { MessageStore } from "../store/store.js";
|
|
5
5
|
import type { AccountKey } from "../store/types.js";
|
|
6
|
-
import type { CrmSource } from "./source.js";
|
|
6
|
+
import type { CrmGap, CrmSource } from "./source.js";
|
|
7
7
|
/** A round of changes that stopped before its last page: the next run goes on from its page with the same cursor. */
|
|
8
8
|
interface PendingRound {
|
|
9
9
|
from: string | null;
|
|
@@ -44,8 +44,9 @@ export interface CrmSyncOptions {
|
|
|
44
44
|
}
|
|
45
45
|
/** Something a run could not do that the owner should know: an item not kept, or a deletion held back. */
|
|
46
46
|
export interface CrmSyncIssue {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
/** `user`: the account's users and departments. */
|
|
48
|
+
kind: CrmKind | "user";
|
|
49
|
+
reason: CrmSkipped["reason"] | CrmRelationIssue["reason"] | "crm.unlisted-held" | "crm.not-reported" | "crm.pending-dropped";
|
|
49
50
|
message: string;
|
|
50
51
|
externalId?: string;
|
|
51
52
|
}
|
|
@@ -71,6 +72,10 @@ export interface CrmSyncReport {
|
|
|
71
72
|
account: string;
|
|
72
73
|
/** Pipelines read this run, both kinds. */
|
|
73
74
|
pipelines: number;
|
|
75
|
+
/** Users read this run; absent when the CRM cannot list them. */
|
|
76
|
+
users?: number;
|
|
77
|
+
/** Relationships left out because the owner removed or rejected that very one, role included. */
|
|
78
|
+
skippedOwnerRejected: number;
|
|
74
79
|
synced: CrmSyncResult[];
|
|
75
80
|
issues: CrmSyncIssue[];
|
|
76
81
|
/** Every kind finished its round and none failed. */
|
|
@@ -86,10 +91,13 @@ export interface CrmSyncReport {
|
|
|
86
91
|
};
|
|
87
92
|
hint?: string;
|
|
88
93
|
}
|
|
94
|
+
/** The gaps the account's last sync recorded; none before its first. */
|
|
95
|
+
export declare const crmGapsOf: (store: MessageStore, account: AccountKey) => Promise<CrmGap[]>;
|
|
89
96
|
/**
|
|
90
|
-
* Brings one CRM account's copy up to date: both kinds' pipelines and each kind's fields, then
|
|
91
|
-
* deals and leads, each from its cursor or listed in full, a page at a time,
|
|
92
|
-
* the cursor, so a run the budget stops, or one that fails, goes on from
|
|
97
|
+
* Brings one CRM account's copy up to date: both kinds' pipelines and each kind's fields, then companies, contacts,
|
|
98
|
+
* the account's users and departments, deals and leads, each from its cursor or listed in full, a page at a time,
|
|
99
|
+
* each page saved with the round's place in the cursor, so a run the budget stops, or one that fails, goes on from
|
|
100
|
+
* there. Relationships held back for an end not stored yet are written at the end of the run. Deletions come from `changes()`, or
|
|
93
101
|
* from a list of every id that marks only after its last page arrived, and never more than half of a kind without
|
|
94
102
|
* `--rescan`.
|
|
95
103
|
*/
|