@wirecat/cli-core 0.669.0 → 0.671.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 +87 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/cli/documents/sync.js +4 -1
- package/dist/cli/documents/words.d.ts +1 -1
- package/dist/cli/store-settings.js +5 -3
- package/dist/crm/cli/csv.d.ts +1 -1
- package/dist/crm/cli/csv.js +2 -2
- package/dist/crm/cli/index.d.ts +11 -1
- package/dist/crm/cli/index.js +11 -5
- package/dist/crm/cli/records.d.ts +94 -0
- package/dist/crm/cli/records.js +412 -0
- package/dist/crm/foreign-contacts.d.ts +34 -0
- package/dist/crm/foreign-contacts.js +104 -0
- package/dist/crm/index.d.ts +9 -3
- package/dist/crm/index.js +7 -1
- package/dist/crm/provider-call.d.ts +23 -0
- package/dist/crm/provider-call.js +49 -0
- package/dist/crm/query.d.ts +32 -0
- package/dist/crm/query.js +122 -0
- package/dist/crm/source.d.ts +41 -4
- package/dist/crm/sync.d.ts +1 -1
- package/dist/crm/sync.js +13 -7
- package/dist/crm/testing/source-contract.d.ts +5 -0
- package/dist/crm/testing/source-contract.js +39 -0
- package/dist/crm/testing/source.d.ts +9 -3
- package/dist/crm/testing/source.js +109 -10
- package/dist/crm/testing/write-contract.d.ts +2 -2
- package/dist/crm/testing/write-contract.js +41 -2
- package/dist/crm/values.d.ts +33 -0
- package/dist/crm/values.js +75 -0
- package/dist/crm/walk.d.ts +18 -0
- package/dist/crm/walk.js +23 -0
- package/dist/crm/writer.d.ts +41 -6
- package/dist/crm/writer.js +16 -10
- package/dist/crm/writes.d.ts +38 -2
- package/dist/crm/writes.js +163 -9
- package/dist/domain/crm.d.ts +41 -5
- package/dist/entities/deal.d.ts +8 -2
- package/dist/entities/deal.js +4 -1
- package/dist/errors/reasons.js +23 -2
- package/dist/oauth/index.d.ts +1 -1
- package/dist/oauth/index.js +1 -1
- package/dist/oauth/keeper.js +4 -0
- package/dist/oauth/storage.d.ts +21 -0
- package/dist/oauth/storage.js +32 -1
- package/dist/services/documents/plan.js +6 -1
- package/dist/store/sqlite/crm-contacts.d.ts +5 -4
- package/dist/store/sqlite/crm-contacts.js +8 -4
- package/dist/store/sqlite/crm-rows.d.ts +1 -0
- package/dist/store/sqlite/crm-rows.js +37 -7
- package/dist/store/sqlite/crm-settings.d.ts +2 -2
- package/dist/store/sqlite/crm-settings.js +4 -3
- package/dist/store/sqlite/crm.d.ts +5 -3
- package/dist/store/sqlite/crm.js +20 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,93 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.671.0 — 15.11.2026
|
|
9
|
+
|
|
10
|
+
### Changed — may break callers
|
|
11
|
+
|
|
12
|
+
- **The shared documents `sync` is cooperative.** It declared `partial` but not `cooperative`, so it got a one-shot's
|
|
13
|
+
30 s deadline and a budget of about 12 requests per call: a first Notion sync of 5 000 pages took some 830 calls.
|
|
14
|
+
It now gets a sync's deadline, 15 min in a terminal and 45 s over MCP, unless `--timeout` sets one. A cancel no
|
|
15
|
+
longer cuts the command from outside: the walk stops at the next folder on the run's `signal` (with or without a
|
|
16
|
+
budget) and saves where it is, and the batch stops before the next file, as before. See
|
|
17
|
+
[Walks over several syncs](docs/dev/DOCUMENTS.md#walks-over-several-syncs).
|
|
18
|
+
|
|
19
|
+
## 0.670.0 — 15.11.2026
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- **`addCrmCommands` mounts `people`, `organizations` and `users` list and show, read live from the CRM.** A CLI passes
|
|
24
|
+
`live: ["person", "organization", "user"]` for what its source reads: `CrmSource.list(kind, query)` and
|
|
25
|
+
`get(kind, id)` for contacts and companies, the existing `users()` for users. `--offline` is refused. Lists take the
|
|
26
|
+
same query language as `deals list` (`name:anna*`, `assigned_to:7`, `created_at>=7d`, a custom field by its code or
|
|
27
|
+
label), `--limit`, `--page`, `--format csv`, and `--json=provider_metadata.<code>`. The answers are the shared
|
|
28
|
+
entities `crm_person`, `crm_organization` and `crm_user` (`crmPersonOf`, `crmOrganizationOf`, `crmUserOf`).
|
|
29
|
+
See [CRM](docs/dev/CRM.md).
|
|
30
|
+
- **`people create|update` and `organizations create|update`** go through the guarded write path of `deals create`:
|
|
31
|
+
the read-only lock, the keys `people.create`, `people.update`, `organizations.create`, `organizations.update`, and
|
|
32
|
+
`crm.assign-others` for another owner, the journal and `operation_id`. The CRM's answer is stored as a sync stores it
|
|
33
|
+
(`createCrmRecord`, `updateCrmRecord`).
|
|
34
|
+
- **The daily limit on foreign contacts is shared.** With `CrmSource.isAdmin()`, anyone but the CRM's administrator
|
|
35
|
+
sees phones and e-mails only of their own clients (`assignee` is the sign-in's user, or `CrmSource.ownClients()`
|
|
36
|
+
names them) and at most `DAILY_FOREIGN_CONTACTS` (100) other contacts or companies a UTC day in `show`, by id or
|
|
37
|
+
exact name. The count is kept per CRM user under a file lock, so two runs never both take the last slot
|
|
38
|
+
(`foreignContacts`). A write of a foreign contact answers it stripped and does not store it (`stored: false`); an
|
|
39
|
+
update that gives a company to someone else removes it from the copy. A foreign record's custom values go where the
|
|
40
|
+
field definition says it holds a phone or an e-mail (new `CrmField.holds`), or all of them when the CRM gives none.
|
|
41
|
+
- **Helpers every CRM adapter needs**, from `@wirecat/cli-core/crm`: `providerCall` (paced calls, reads retried, writes
|
|
42
|
+
retried only on `rate_limited`, a write with no answer `outcome_unknown`, one token refresh on `oauth.expired`),
|
|
43
|
+
`walk` and `crmWindowOf` (the CRM's pages into one answer page with `hasMore`), `conditionsOf` and the custom-field
|
|
44
|
+
query helpers, `crmCustomValues` (`--field` pairs), `crmValues` (JSON coercions and `crmValuesOf`, custom values
|
|
45
|
+
with labels), and `refuseForeignClientReads` for an `api call` that reads clients.
|
|
46
|
+
- **`accountTokenCodec(provider)`** in `@wirecat/cli-core/oauth`: a sign-in entry bound to one CRM account through
|
|
47
|
+
the owner's own app, which keeps the app's secret, the account's `host` and `userId` beside the tokens and saves a
|
|
48
|
+
rotated refresh token. It is `rotating` (new `TokenCodec.rotating`, `TokenStorage.rotating`): a run with moved
|
|
49
|
+
folders refuses to refresh it (`oauth.moved-rotating`).
|
|
50
|
+
- **Money is checked before a deal write is sent:** a currency or a precision the store cannot keep is refused
|
|
51
|
+
(`money.currency`, `money.amount`). A list option label two options share is refused with both
|
|
52
|
+
(`field.ambiguous-option`).
|
|
53
|
+
- **`@wirecat/cli-core/crm/testing`:** `fakeCrmSource` has `list`, `get`, contact and company writes, and `admin` and
|
|
54
|
+
`ownClients` options; `crmSourceContract` checks live pages and `get`, and `crmWriteContract` contact and company
|
|
55
|
+
writes.
|
|
56
|
+
|
|
57
|
+
### Changed — may break callers
|
|
58
|
+
|
|
59
|
+
- **`CrmWriter.create` and `update` take every CRM kind** (`CrmDrafts[K]`, `CrmWriteFields[K]`) and answer
|
|
60
|
+
`CrmRecords[K]`; `CrmWriteCapabilities.kinds` and the `alsoChecks` hooks take `CrmKind`. A writer that writes only
|
|
61
|
+
deals and leads casts its answer and leaves `person` and `organization` out of `kinds`.
|
|
62
|
+
- **`CrmPerson` and `CrmOrganization` carry what a live read answers:** `createdAt`, `updatedAt`, a person's
|
|
63
|
+
`firstName`, `lastName`, `url`, `metadata` and `contactTypes`, a company's `assignee`, `phones`, `emails` and
|
|
64
|
+
`people`. Of these the store keeps a contact's `assignee` only.
|
|
65
|
+
- **`fakeCrmSource` writes every kind by default:** `FakeCrmWrite.kind` is any `CrmKind`, and `calls` counts `list`
|
|
66
|
+
and `get`.
|
|
67
|
+
- **`crmSourceContract` asks more of a source:** a source with `list` must list at least one contact and one company,
|
|
68
|
+
give back every id the fixture names in its new `live`, and keep phones and e-mails out of `metadata`.
|
|
69
|
+
`crmWriteContract` runs contact and company cases for a writer whose `kinds` include them.
|
|
70
|
+
- **A `providerCall` write that ends in `cancelled` or `invalid_response` is `outcome_unknown`.**
|
|
71
|
+
- **`CrmOrganization.metadata` is `Record<string, CrmValue>`**, as a person's; `EncodeInput` gains `signIn`.
|
|
72
|
+
- **A chosen `unassigned` list replaces your own user in scope `mine`.** With `unassigned` set, a sync copies only
|
|
73
|
+
those users' deals and leads, and your own user's only when the list names it, as bitrix24-cli already reads them.
|
|
74
|
+
Before, cli-core kept your own deals while bitrix24-cli no longer sent their changes, so they went stale and were
|
|
75
|
+
later counted as deleted on the CRM. Now they leave the copy as out of scope, or, under the default `mine`, the
|
|
76
|
+
narrowing is held until you set `scope`. To keep your own deals as well, add your own user id to `unassigned`.
|
|
77
|
+
`store status` no longer lists your own user under `applied.users` while `unassigned` names anyone. While a
|
|
78
|
+
narrowing is held, the daily id check marks deleted only deals inside the scope.
|
|
79
|
+
- **A CRM deal whose amount the store cannot hold is kept, with no amount, and says why.** Before, a deal in a
|
|
80
|
+
currency the store has no scale for (BRL, MXN, SGD and others), with more decimals than its currency has, below
|
|
81
|
+
zero or too large, was left out of `deals list`, the funnel and the totals, with `crm.item-invalid` in the sync
|
|
82
|
+
answer. Now the deal is stored with `amount` and `currency` empty, and the sync answer names it as
|
|
83
|
+
`crm.amount-unkept`. Its `provider_metadata.amount_note` ("Amount not kept") is WireCat's own note, not a CRM
|
|
84
|
+
field: what the CRM had and why it was not kept.
|
|
85
|
+
|
|
86
|
+
### Fixed
|
|
87
|
+
|
|
88
|
+
- **Under scope `mine`, a contact assigned to a user in scope is no longer removed when it is on no deal.** A source
|
|
89
|
+
that sends the contact's `assignee` keeps such a contact through the cleanup after a narrowing or `sync --rescan`.
|
|
90
|
+
- **A held narrowing on a small copy is no longer undone by the same run's list of ids.** While the narrowing waits
|
|
91
|
+
for you, the id check marks deleted only deals inside the scope, so no deal outside it is marked deleted.
|
|
92
|
+
- **A deal in a new stage, skipped because the run's budget ran out before the pipelines were read again, is read
|
|
93
|
+
again.** The next run reads that page again instead of moving past it.
|
|
94
|
+
|
|
8
95
|
## 0.669.0 — 15.11.2026
|
|
9
96
|
|
|
10
97
|
### Added
|
|
@@ -24,12 +24,12 @@ export interface DailyArchiveTimerInput {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const dailyArchiveTimer: (input: DailyArchiveTimerInput) => DailyArchiveTimer;
|
|
26
26
|
export declare const manageDailyArchiveTimer: (plan: DailyArchiveTimer, action: "install" | "start" | "stop" | "status" | "uninstall", system: Pick<ServerSystem, "platform" | "run">, env: NodeJS.ProcessEnv, signal?: AbortSignal) => Promise<{
|
|
27
|
+
action?: undefined;
|
|
27
28
|
name: string;
|
|
28
29
|
installed: boolean;
|
|
29
30
|
active: boolean;
|
|
30
31
|
servicePath: string;
|
|
31
32
|
timerPath: string;
|
|
32
|
-
action?: undefined;
|
|
33
33
|
} | {
|
|
34
34
|
active?: undefined;
|
|
35
35
|
name: string;
|
|
@@ -10,13 +10,13 @@ export declare const calendarTools: ({
|
|
|
10
10
|
inputSchema: {
|
|
11
11
|
type: string;
|
|
12
12
|
properties: {
|
|
13
|
+
limit?: undefined;
|
|
13
14
|
account_id: {
|
|
14
15
|
type: string;
|
|
15
16
|
minimum: number;
|
|
16
17
|
};
|
|
17
18
|
query?: undefined;
|
|
18
19
|
timezone?: undefined;
|
|
19
|
-
limit?: undefined;
|
|
20
20
|
page?: undefined;
|
|
21
21
|
event?: undefined;
|
|
22
22
|
} | {
|
|
@@ -45,9 +45,9 @@ export declare const calendarTools: ({
|
|
|
45
45
|
};
|
|
46
46
|
event?: undefined;
|
|
47
47
|
} | {
|
|
48
|
+
limit?: undefined;
|
|
48
49
|
query?: undefined;
|
|
49
50
|
timezone?: undefined;
|
|
50
|
-
limit?: undefined;
|
|
51
51
|
page?: undefined;
|
|
52
52
|
event: {
|
|
53
53
|
type: string;
|
|
@@ -58,9 +58,9 @@ export declare const calendarTools: ({
|
|
|
58
58
|
minimum: number;
|
|
59
59
|
};
|
|
60
60
|
} | {
|
|
61
|
+
limit?: undefined;
|
|
61
62
|
query?: undefined;
|
|
62
63
|
timezone?: undefined;
|
|
63
|
-
limit?: undefined;
|
|
64
64
|
page?: undefined;
|
|
65
65
|
event?: undefined;
|
|
66
66
|
account_id?: undefined;
|
|
@@ -80,13 +80,13 @@ export declare const calendarTools: ({
|
|
|
80
80
|
inputSchema: {
|
|
81
81
|
type: string;
|
|
82
82
|
properties: {
|
|
83
|
+
limit?: undefined;
|
|
83
84
|
account_id: {
|
|
84
85
|
type: string;
|
|
85
86
|
minimum: number;
|
|
86
87
|
};
|
|
87
88
|
query?: undefined;
|
|
88
89
|
timezone?: undefined;
|
|
89
|
-
limit?: undefined;
|
|
90
90
|
page?: undefined;
|
|
91
91
|
event?: undefined;
|
|
92
92
|
} | {
|
|
@@ -115,9 +115,9 @@ export declare const calendarTools: ({
|
|
|
115
115
|
};
|
|
116
116
|
event?: undefined;
|
|
117
117
|
} | {
|
|
118
|
+
limit?: undefined;
|
|
118
119
|
query?: undefined;
|
|
119
120
|
timezone?: undefined;
|
|
120
|
-
limit?: undefined;
|
|
121
121
|
page?: undefined;
|
|
122
122
|
event: {
|
|
123
123
|
type: string;
|
|
@@ -128,9 +128,9 @@ export declare const calendarTools: ({
|
|
|
128
128
|
minimum: number;
|
|
129
129
|
};
|
|
130
130
|
} | {
|
|
131
|
+
limit?: undefined;
|
|
131
132
|
query?: undefined;
|
|
132
133
|
timezone?: undefined;
|
|
133
|
-
limit?: undefined;
|
|
134
134
|
page?: undefined;
|
|
135
135
|
event?: undefined;
|
|
136
136
|
account_id?: undefined;
|
|
@@ -150,13 +150,13 @@ export declare const calendarTools: ({
|
|
|
150
150
|
inputSchema: {
|
|
151
151
|
type: string;
|
|
152
152
|
properties: {
|
|
153
|
+
limit?: undefined;
|
|
153
154
|
account_id: {
|
|
154
155
|
type: string;
|
|
155
156
|
minimum: number;
|
|
156
157
|
};
|
|
157
158
|
query?: undefined;
|
|
158
159
|
timezone?: undefined;
|
|
159
|
-
limit?: undefined;
|
|
160
160
|
page?: undefined;
|
|
161
161
|
event?: undefined;
|
|
162
162
|
} | {
|
|
@@ -185,9 +185,9 @@ export declare const calendarTools: ({
|
|
|
185
185
|
};
|
|
186
186
|
event?: undefined;
|
|
187
187
|
} | {
|
|
188
|
+
limit?: undefined;
|
|
188
189
|
query?: undefined;
|
|
189
190
|
timezone?: undefined;
|
|
190
|
-
limit?: undefined;
|
|
191
191
|
page?: undefined;
|
|
192
192
|
event: {
|
|
193
193
|
type: string;
|
|
@@ -198,9 +198,9 @@ export declare const calendarTools: ({
|
|
|
198
198
|
minimum: number;
|
|
199
199
|
};
|
|
200
200
|
} | {
|
|
201
|
+
limit?: undefined;
|
|
201
202
|
query?: undefined;
|
|
202
203
|
timezone?: undefined;
|
|
203
|
-
limit?: undefined;
|
|
204
204
|
page?: undefined;
|
|
205
205
|
event?: undefined;
|
|
206
206
|
account_id?: undefined;
|
|
@@ -220,13 +220,13 @@ export declare const calendarTools: ({
|
|
|
220
220
|
inputSchema: {
|
|
221
221
|
type: string;
|
|
222
222
|
properties: {
|
|
223
|
+
limit?: undefined;
|
|
223
224
|
account_id: {
|
|
224
225
|
type: string;
|
|
225
226
|
minimum: number;
|
|
226
227
|
};
|
|
227
228
|
query?: undefined;
|
|
228
229
|
timezone?: undefined;
|
|
229
|
-
limit?: undefined;
|
|
230
230
|
page?: undefined;
|
|
231
231
|
event?: undefined;
|
|
232
232
|
} | {
|
|
@@ -255,9 +255,9 @@ export declare const calendarTools: ({
|
|
|
255
255
|
};
|
|
256
256
|
event?: undefined;
|
|
257
257
|
} | {
|
|
258
|
+
limit?: undefined;
|
|
258
259
|
query?: undefined;
|
|
259
260
|
timezone?: undefined;
|
|
260
|
-
limit?: undefined;
|
|
261
261
|
page?: undefined;
|
|
262
262
|
event: {
|
|
263
263
|
type: string;
|
|
@@ -268,9 +268,9 @@ export declare const calendarTools: ({
|
|
|
268
268
|
minimum: number;
|
|
269
269
|
};
|
|
270
270
|
} | {
|
|
271
|
+
limit?: undefined;
|
|
271
272
|
query?: undefined;
|
|
272
273
|
timezone?: undefined;
|
|
273
|
-
limit?: undefined;
|
|
274
274
|
page?: undefined;
|
|
275
275
|
event?: undefined;
|
|
276
276
|
account_id?: undefined;
|
|
@@ -9,7 +9,10 @@ const addDocumentSyncCommandsDefinition = (program, helpers) => {
|
|
|
9
9
|
const { output } = helpers;
|
|
10
10
|
const wording = wordsOf(helpers.words);
|
|
11
11
|
const { prefix, text } = wording;
|
|
12
|
-
const sync = examples(
|
|
12
|
+
const sync = examples(
|
|
13
|
+
// Cooperative: it stops on its own at its budget, its deadline or a cancel and keeps its work, so it gets a sync's
|
|
14
|
+
// deadline (15 min in a terminal, 45 s over MCP) instead of a one-shot's 30 s.
|
|
15
|
+
annotate(program.command("sync"), { effects: FETCH, cooperative: true, partial: true })
|
|
13
16
|
.summary("import what changed in the chosen folders, and finish an unfinished sync")
|
|
14
17
|
.description("import what changed in the chosen folders, and finish an unfinished sync; " +
|
|
15
18
|
`one sync walks about ${helpers.maxEntries} entries under the chosen folders, saves where it stopped, and ` +
|
|
@@ -56,9 +56,9 @@ export interface CopyAge {
|
|
|
56
56
|
}
|
|
57
57
|
export declare const ageOf: (lastSync: string | undefined, now?: number) => CopyAge;
|
|
58
58
|
export declare const staleCopy: (provider: string, lastSync: string | undefined, now?: number) => {
|
|
59
|
-
next?: undefined;
|
|
60
59
|
readonly missing?: undefined;
|
|
61
60
|
meta?: undefined;
|
|
61
|
+
next?: undefined;
|
|
62
62
|
} | {
|
|
63
63
|
missing: {
|
|
64
64
|
field: string;
|
|
@@ -286,10 +286,12 @@ const crmNote = (name, now) => {
|
|
|
286
286
|
if (name === "scope")
|
|
287
287
|
return now === "all"
|
|
288
288
|
? "store-wide — the next sync of that account copies every deal and lead, listing them all again"
|
|
289
|
-
: "store-wide — the next sync of that account copies only the deals and leads of the
|
|
290
|
-
"of the
|
|
289
|
+
: "store-wide — the next sync of that account copies only the deals and leads of the unassigned users, or " +
|
|
290
|
+
"of the sign-in's own user while that list is empty, and marks the others deleted here; contacts and " +
|
|
291
|
+
"companies stay whole";
|
|
291
292
|
if (name === "unassigned")
|
|
292
|
-
return "store-wide — with scope mine, the next sync
|
|
293
|
+
return ("store-wide — with scope mine, the next sync copies only these users' deals and leads, in place of the " +
|
|
294
|
+
"sign-in's own user's (add your own id to keep yours), and marks the others deleted here");
|
|
293
295
|
if (name === "activities")
|
|
294
296
|
return now === "on"
|
|
295
297
|
? "store-wide — the next sync also reads the activities and tasks on the deals and leads it keeps, from the " +
|
package/dist/crm/cli/csv.d.ts
CHANGED
|
@@ -33,4 +33,4 @@ export declare const renderCsv: <R extends {
|
|
|
33
33
|
close?: () => Promise<void>;
|
|
34
34
|
}>(command: Command, open: (command: Command, access: {
|
|
35
35
|
readOnly: boolean;
|
|
36
|
-
}) => Promise<R>, read: (run: R) => Promise<CsvPage
|
|
36
|
+
}) => Promise<R>, read: (run: R) => Promise<CsvPage>, defaults?: readonly string[]) => Promise<void>;
|
package/dist/crm/cli/csv.js
CHANGED
|
@@ -132,7 +132,7 @@ export const printCsv = (command, page, paths) => {
|
|
|
132
132
|
renderer.note(`→ more rows: run it again with --page ${page.page + 1}`);
|
|
133
133
|
};
|
|
134
134
|
/** Reads a page in the profile's run and closes it before the table is printed. */
|
|
135
|
-
export const renderCsv = (command, open, read) => {
|
|
135
|
+
export const renderCsv = (command, open, read, defaults = DEAL_CSV_COLUMNS) => {
|
|
136
136
|
refuseCsvConflict(command);
|
|
137
137
|
return inCommandRun(command, async () => {
|
|
138
138
|
const run = await open(command, { readOnly: true });
|
|
@@ -143,6 +143,6 @@ export const renderCsv = (command, open, read) => {
|
|
|
143
143
|
finally {
|
|
144
144
|
await run.close?.();
|
|
145
145
|
}
|
|
146
|
-
printCsv(command, page, csvColumnPaths(command));
|
|
146
|
+
printCsv(command, page, csvColumnPaths(command, defaults));
|
|
147
147
|
});
|
|
148
148
|
};
|
package/dist/crm/cli/index.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ import type { AccountKey } from "../../store/types.js";
|
|
|
6
6
|
import type { CrmSource } from "../source.js";
|
|
7
7
|
import type { CrmWriteCapabilities } from "../writer.js";
|
|
8
8
|
import { type CrmWrites } from "../writes.js";
|
|
9
|
+
import { type CrmLiveRecord } from "./records.js";
|
|
9
10
|
export { type CsvField, type CsvPage, csvColumnPaths, csvFormatOption, DEAL_CSV_COLUMNS, printCsv, refuseCsvConflict, } from "./csv.js";
|
|
11
|
+
export { CRM_ORGANIZATIONS_QUERY, CRM_PEOPLE_QUERY, CRM_USERS_QUERY, type CrmLiveRecord, crmOrganizationOf, crmOrganizationSchema, crmPersonOf, crmPersonSchema, crmUserOf, crmUserSchema, } from "./records.js";
|
|
10
12
|
export { type CrmStoreOptions, openCrmStore } from "./store.js";
|
|
11
13
|
/**
|
|
12
14
|
* The selected profile's CRM account, opened by the app for one command and closed once its answer is built, before
|
|
@@ -36,8 +38,16 @@ export interface CrmCommandOptions {
|
|
|
36
38
|
}) => Promise<CrmRun>;
|
|
37
39
|
/** The CRM has leads: mounts `leads list|show`. True when absent. */
|
|
38
40
|
leads?: boolean;
|
|
39
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The writer's capabilities: mounts `create`, `update`, `move`, `close` and `delete` of each deal kind it writes, and
|
|
43
|
+
* `create` and `update` of `people` and `organizations` when they are mounted too.
|
|
44
|
+
*/
|
|
40
45
|
writes?: CrmWriteCapabilities;
|
|
46
|
+
/**
|
|
47
|
+
* What the source reads live: `person` and `organization` mount `people` and `organizations` list/show over
|
|
48
|
+
* `source.list`/`get`, `user` mounts `users` list/show over `source.users`. None when absent.
|
|
49
|
+
*/
|
|
50
|
+
live?: readonly CrmLiveRecord[];
|
|
41
51
|
now?: () => number;
|
|
42
52
|
}
|
|
43
53
|
/** What `deals list` and `leads list` narrow by, the same in memo and every CRM CLI (WC-OUT-11). */
|
package/dist/crm/cli/index.js
CHANGED
|
@@ -23,8 +23,10 @@ import { crmStatus, syncCrm } from "../sync.js";
|
|
|
23
23
|
import { closeCrmItem, createCrmItem, fieldPairsOf, moveCrmItem, pipelineOf, removeCrmItem, updateCrmItem, } from "../writes.js";
|
|
24
24
|
import { csvFormatOption, renderCsv } from "./csv.js";
|
|
25
25
|
import { pipelineView } from "./pipeline-view.js";
|
|
26
|
+
import { addCrmRecordCommands, integer } from "./records.js";
|
|
26
27
|
import { addCrmSearchAll } from "./search-all.js";
|
|
27
28
|
export { csvColumnPaths, csvFormatOption, DEAL_CSV_COLUMNS, printCsv, refuseCsvConflict, } from "./csv.js";
|
|
29
|
+
export { CRM_ORGANIZATIONS_QUERY, CRM_PEOPLE_QUERY, CRM_USERS_QUERY, crmOrganizationOf, crmOrganizationSchema, crmPersonOf, crmPersonSchema, crmUserOf, crmUserSchema, } from "./records.js";
|
|
28
30
|
export { openCrmStore } from "./store.js";
|
|
29
31
|
const MOST = 500;
|
|
30
32
|
/** A stage by the store's reference, as memo's `stages list` and a deal's `base_stage` name it. */
|
|
@@ -171,11 +173,6 @@ const collect = (value, previous = []) => {
|
|
|
171
173
|
throw new InvalidArgumentError("expected key=value");
|
|
172
174
|
return [...previous, value];
|
|
173
175
|
};
|
|
174
|
-
const integer = (most) => (value) => {
|
|
175
|
-
if (!/^[1-9]\d*$/.test(value) || Number(value) > most)
|
|
176
|
-
throw new InvalidArgumentError(`expected 1 to ${most}`);
|
|
177
|
-
return Number(value);
|
|
178
|
-
};
|
|
179
176
|
/** The words below the program, as `page.next` and `sync`'s next step run it again. */
|
|
180
177
|
const pathOf = (command) => command.parent?.parent ? [...pathOf(command.parent), command.name()] : [command.name()];
|
|
181
178
|
/** A CRM's own field codes are its keys, never ours to rename. */
|
|
@@ -558,6 +555,15 @@ const addCrmCommandsDefinition = (program, options) => {
|
|
|
558
555
|
});
|
|
559
556
|
});
|
|
560
557
|
});
|
|
558
|
+
addCrmRecordCommands(program, {
|
|
559
|
+
within,
|
|
560
|
+
example,
|
|
561
|
+
open: options.open,
|
|
562
|
+
app: options.app,
|
|
563
|
+
live: options.live ?? [],
|
|
564
|
+
...(writes ? { writes } : {}),
|
|
565
|
+
now,
|
|
566
|
+
});
|
|
561
567
|
const fieldKinds = Object.keys(FIELD_KINDS).filter((word) => word !== "leads" || options.leads !== false);
|
|
562
568
|
const fields = annotate(program.command("fields"), { effects: NO_EFFECTS }).description("the CRM's own fields on deals, leads, people and organizations, as last synced");
|
|
563
569
|
example(withQuery(answerEntity(annotate(fields.command("list"), { effects: LOCAL_READ }), "crm_field", crmField)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type QueryRegistry } from "@wirecat/cli-base/query";
|
|
2
|
+
import { type Command } from "commander";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
import type { CrmOrganization, CrmPerson, CrmUser } from "../../domain/crm.js";
|
|
5
|
+
import type { AppIdentity } from "../../ports/app.js";
|
|
6
|
+
import type { CrmLiveKind } from "../source.js";
|
|
7
|
+
import type { CrmWriteCapabilities } from "../writer.js";
|
|
8
|
+
import type { CrmRun, CrmWithin } from "./index.js";
|
|
9
|
+
/** The kinds a CRM CLI reads live: its contacts and companies by `list`/`get`, its users by `users()`. */
|
|
10
|
+
export type CrmLiveRecord = CrmLiveKind | "user";
|
|
11
|
+
/** A CRM contact as the CRM holds it now. `emails` and `phones` are left out where the sign-in may not see them. */
|
|
12
|
+
export declare const crmPersonSchema: v.StrictObjectSchema<{
|
|
13
|
+
readonly id: v.StringSchema<undefined>;
|
|
14
|
+
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
15
|
+
readonly first_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
16
|
+
readonly last_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
17
|
+
readonly position: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
18
|
+
readonly organization_ids: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
19
|
+
readonly emails: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
|
|
20
|
+
readonly value: v.StringSchema<undefined>;
|
|
21
|
+
readonly type: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
22
|
+
}, undefined>, undefined>, undefined>;
|
|
23
|
+
readonly phones: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
|
|
24
|
+
readonly value: v.StringSchema<undefined>;
|
|
25
|
+
readonly type: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
26
|
+
}, undefined>, undefined>, undefined>;
|
|
27
|
+
readonly assigned_to: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
28
|
+
readonly created_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
|
|
29
|
+
readonly updated_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
|
|
30
|
+
readonly url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
31
|
+
readonly provider_metadata: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StrictObjectSchema<{
|
|
32
|
+
readonly label: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
33
|
+
readonly value: v.UnknownSchema;
|
|
34
|
+
readonly option_id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>], undefined>, undefined>;
|
|
35
|
+
}, undefined>, undefined>, undefined>;
|
|
36
|
+
readonly untrusted: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
37
|
+
}, undefined>;
|
|
38
|
+
/** A CRM company as the CRM holds it now. */
|
|
39
|
+
export declare const crmOrganizationSchema: v.StrictObjectSchema<{
|
|
40
|
+
readonly id: v.StringSchema<undefined>;
|
|
41
|
+
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
42
|
+
readonly type: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
43
|
+
readonly own: v.BooleanSchema<undefined>;
|
|
44
|
+
readonly person_ids: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
45
|
+
readonly emails: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
|
|
46
|
+
readonly value: v.StringSchema<undefined>;
|
|
47
|
+
readonly type: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
48
|
+
}, undefined>, undefined>, undefined>;
|
|
49
|
+
readonly phones: v.OptionalSchema<v.ArraySchema<v.StrictObjectSchema<{
|
|
50
|
+
readonly value: v.StringSchema<undefined>;
|
|
51
|
+
readonly type: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
52
|
+
}, undefined>, undefined>, undefined>;
|
|
53
|
+
readonly assigned_to: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
54
|
+
readonly created_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
|
|
55
|
+
readonly updated_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
|
|
56
|
+
readonly url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
57
|
+
readonly provider_metadata: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StrictObjectSchema<{
|
|
58
|
+
readonly label: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
59
|
+
readonly value: v.UnknownSchema;
|
|
60
|
+
readonly option_id: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.ArraySchema<v.StringSchema<undefined>, undefined>], undefined>, undefined>;
|
|
61
|
+
}, undefined>, undefined>, undefined>;
|
|
62
|
+
readonly untrusted: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
63
|
+
}, undefined>;
|
|
64
|
+
/** A user of the CRM account: someone of the owner's own company. */
|
|
65
|
+
export declare const crmUserSchema: v.StrictObjectSchema<{
|
|
66
|
+
readonly id: v.StringSchema<undefined>;
|
|
67
|
+
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
68
|
+
readonly email: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
69
|
+
readonly position: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
70
|
+
readonly active: v.BooleanSchema<undefined>;
|
|
71
|
+
readonly department_ids: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
72
|
+
readonly untrusted: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
73
|
+
}, undefined>;
|
|
74
|
+
export declare const crmPersonOf: (person: CrmPerson) => v.InferOutput<typeof crmPersonSchema>;
|
|
75
|
+
export declare const crmOrganizationOf: (organization: CrmOrganization) => v.InferOutput<typeof crmOrganizationSchema>;
|
|
76
|
+
export declare const crmUserOf: (user: CrmUser) => v.InferOutput<typeof crmUserSchema>;
|
|
77
|
+
export declare const CRM_PEOPLE_QUERY: QueryRegistry;
|
|
78
|
+
export declare const CRM_ORGANIZATIONS_QUERY: QueryRegistry;
|
|
79
|
+
export declare const CRM_USERS_QUERY: QueryRegistry;
|
|
80
|
+
/** A whole number from 1 to `most`, as `--limit` and `--page` take it. */
|
|
81
|
+
export declare const integer: (most: number) => (value: string) => number;
|
|
82
|
+
export interface CrmRecordCommandOptions {
|
|
83
|
+
within: CrmWithin;
|
|
84
|
+
example: (command: Command, ...lines: string[]) => Command;
|
|
85
|
+
open: (command: Command, access: {
|
|
86
|
+
readOnly: boolean;
|
|
87
|
+
}) => Promise<CrmRun>;
|
|
88
|
+
app: AppIdentity;
|
|
89
|
+
live: readonly CrmLiveRecord[];
|
|
90
|
+
writes?: CrmWriteCapabilities;
|
|
91
|
+
now: () => number;
|
|
92
|
+
}
|
|
93
|
+
/** `people`, `organizations` and `users`: read live from the CRM, so `--offline` is refused (NEED-2661). */
|
|
94
|
+
export declare const addCrmRecordCommands: (program: Command, options: CrmRecordCommandOptions) => void;
|