@wirecat/cli-core 0.725.0 → 0.726.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 +14 -0
- package/dist/crm/manifest/writer.js +10 -6
- package/dist/crm/writes.d.ts +7 -2
- package/dist/crm/writes.js +15 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ 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.726.0 — 23.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `CrmWrites.ownedByDefault`: a new item of these kinds is the sign-in's user's when no `--owner` is given, as Attio
|
|
13
|
+
needs for a deal. With no user known, the create is refused before anything is sent.
|
|
14
|
+
- `CrmWrites.self` may be a function, asked only when a write needs the sign-in's user, so a CLI whose sign-in does
|
|
15
|
+
not name that user still checks `--owner` against it.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- A manifest write that merges a name from its parts sends a cleared part as an empty string beside the given ones,
|
|
20
|
+
as Attio's name needs all three parts: `--name Madonna` and a lone `--first-name` are no longer refused.
|
|
21
|
+
|
|
8
22
|
## 0.725.0 — 23.11.2026
|
|
9
23
|
|
|
10
24
|
### Added
|
|
@@ -59,11 +59,14 @@ const sharedOf = (one) => {
|
|
|
59
59
|
by.set(rule.to, [...(by.get(rule.to) ?? []), field]);
|
|
60
60
|
return [...by.values()].filter((fields) => fields.length > 1);
|
|
61
61
|
};
|
|
62
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* A merge of the entries rules that share a key give: each object's keys beside the others'. A part cleared beside a
|
|
64
|
+
* part given is sent empty, not left out: Attio refuses a name without all three of its parts.
|
|
65
|
+
*/
|
|
63
66
|
const merged = (entries, list) => {
|
|
64
|
-
|
|
65
|
-
if (given.length === 0)
|
|
67
|
+
if (entries.every(({ value }) => value === CLEAR))
|
|
66
68
|
return CLEAR;
|
|
69
|
+
const given = entries.map(({ value, blank }) => (value === CLEAR ? blank : value));
|
|
67
70
|
if (given.length === 1)
|
|
68
71
|
return given[0];
|
|
69
72
|
const first = (one) => (list && Array.isArray(one) ? one[0] : one);
|
|
@@ -175,7 +178,7 @@ export const crmWriterFromManifest = (input, options) => {
|
|
|
175
178
|
const fields = written;
|
|
176
179
|
const given = kind === "person" ? namesOf(one, fields) : fields;
|
|
177
180
|
const parts = new Map();
|
|
178
|
-
const add = (to, list,
|
|
181
|
+
const add = (to, list, value, blank = value) => parts.set(to, { list, entries: [...(parts.get(to)?.entries ?? []), { value, blank }] });
|
|
179
182
|
for (const [field, value] of Object.entries(given)) {
|
|
180
183
|
if (value === undefined || field === "custom")
|
|
181
184
|
continue;
|
|
@@ -194,7 +197,7 @@ export const crmWriterFromManifest = (input, options) => {
|
|
|
194
197
|
throw refused(`${service} keeps a ${kind}'s amount in ${currency}; give that ${field} or none`, field);
|
|
195
198
|
continue;
|
|
196
199
|
}
|
|
197
|
-
add(rule.to, rule.list === true, encode(kind, field, rule, value));
|
|
200
|
+
add(rule.to, rule.list === true, encode(kind, field, rule, value), value === null ? encode(kind, field, rule, "") : undefined);
|
|
198
201
|
}
|
|
199
202
|
const custom = Object.entries(given.custom ?? {});
|
|
200
203
|
if (custom.length && !one.custom)
|
|
@@ -285,13 +288,14 @@ export const crmWriterFromManifest = (input, options) => {
|
|
|
285
288
|
* `api` keys of each operation it sends as `alsoChecks`. The writes' guard asks before each one and journals it.
|
|
286
289
|
*/
|
|
287
290
|
export const crmManifestWrites = (input, options) => {
|
|
288
|
-
const { manifest: api, service, source, app, settings, self, env, warn } = options;
|
|
291
|
+
const { manifest: api, service, source, app, settings, self, ownedByDefault, env, warn } = options;
|
|
289
292
|
return {
|
|
290
293
|
writer: crmWriterFromManifest(input, { api, service, send: serviceApiSend(options), source }),
|
|
291
294
|
alsoChecks: crmManifestWriteKeys(input, api, options.bodyPermissions),
|
|
292
295
|
app,
|
|
293
296
|
settings,
|
|
294
297
|
...(self === undefined ? {} : { self }),
|
|
298
|
+
...(ownedByDefault === undefined ? {} : { ownedByDefault }),
|
|
295
299
|
...(env === undefined ? {} : { env }),
|
|
296
300
|
...(warn === undefined ? {} : { warn }),
|
|
297
301
|
};
|
package/dist/crm/writes.d.ts
CHANGED
|
@@ -12,8 +12,13 @@ import { type CrmVerb, type CrmWriter } from "./writer.js";
|
|
|
12
12
|
/** What a CLI hands the CRM writes for one profile. */
|
|
13
13
|
export interface CrmWrites extends ProfileWrites {
|
|
14
14
|
writer: CrmWriter;
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The CRM user the sign-in acts as, or how to ask the CRM for it when a write needs it. An owner other than it
|
|
17
|
+
* checks `crm.assign-others`; left out, or answered empty, every owner does.
|
|
18
|
+
*/
|
|
19
|
+
self?: string | (() => Promise<string | undefined>);
|
|
20
|
+
/** The kinds a new item of which is the sign-in's user's when no --owner is given: Attio refuses a deal with none. */
|
|
21
|
+
ownedByDefault?: readonly CrmKind[];
|
|
17
22
|
/**
|
|
18
23
|
* The CLI's own keys a write also checks, such as Bitrix24's `api.crm.deal.update`; pass the same function to
|
|
19
24
|
* `crmAlsoChecks` so `--dry-run` names them.
|
package/dist/crm/writes.js
CHANGED
|
@@ -238,13 +238,14 @@ export const crmCustomValues = (fields, pairs) => {
|
|
|
238
238
|
/** `--field` pairs by the field definitions the last sync stored. */
|
|
239
239
|
const customOf = async (context, kind, pairs) => pairs?.length ? crmCustomValues(await context.store.crm.fields(context.account, kind), pairs) : undefined;
|
|
240
240
|
/** Every key the write checks: its own, and each action its fields also take (WC-PERM-22). */
|
|
241
|
-
const
|
|
241
|
+
const selfOf = async ({ writes: { self } }) => (typeof self === "function" ? await self() : self) || undefined;
|
|
242
|
+
const keysOf = async (context, kind, verb, { stage, owner }) => {
|
|
242
243
|
const extra = [];
|
|
243
244
|
if (stage && verb !== "move")
|
|
244
245
|
extra.push(keyOf(kind, "move"));
|
|
245
246
|
if (stage && stage.outcome !== "open")
|
|
246
247
|
extra.push(keyOf(kind, "close"));
|
|
247
|
-
if (owner != null && owner !== context
|
|
248
|
+
if (owner != null && owner !== (await selfOf(context)))
|
|
248
249
|
extra.push(CRM_ASSIGN_OTHERS_KEY);
|
|
249
250
|
return { key: keyOf(kind, verb), extra: [...extra, ...(context.writes.alsoChecks?.(kind, verb) ?? [])] };
|
|
250
251
|
};
|
|
@@ -314,8 +315,14 @@ export const createCrmItem = async (context, kind, input, options = {}) => {
|
|
|
314
315
|
const custom = await customOf(context, kind, input.custom);
|
|
315
316
|
if (custom)
|
|
316
317
|
fields.custom = custom;
|
|
318
|
+
if (fields.owner === undefined && context.writes.ownedByDefault?.includes(kind)) {
|
|
319
|
+
const self = await selfOf(context);
|
|
320
|
+
if (self === undefined)
|
|
321
|
+
throw invalid(`a new ${kind} needs --owner: the sign-in names no CRM user`, "--owner");
|
|
322
|
+
fields.owner = self;
|
|
323
|
+
}
|
|
317
324
|
const operationId = operationOf(context, options.operationId);
|
|
318
|
-
const item = await written(context, keysOf(context, kind, "create", { stage, owner: fields.owner }), operationId, () => writer.create(kind, fields, { operationId }));
|
|
325
|
+
const item = await written(context, await keysOf(context, kind, "create", { stage, owner: fields.owner }), operationId, () => writer.create(kind, fields, { operationId }));
|
|
319
326
|
return { operationId, item: await kept(context, kind, item, operationId) };
|
|
320
327
|
};
|
|
321
328
|
export const updateCrmItem = async (context, kind, reference, input, options = {}) => {
|
|
@@ -334,7 +341,7 @@ export const updateCrmItem = async (context, kind, reference, input, options = {
|
|
|
334
341
|
if (Object.keys(fields).length === 0)
|
|
335
342
|
throw invalid("nothing to change: name a field");
|
|
336
343
|
const operationId = operationOf(context, options.operationId);
|
|
337
|
-
const item = await written(context, keysOf(context, kind, "update", { stage, owner: fields.owner }), operationId, () => writer.update(kind, copy.externalId, fields, { operationId }));
|
|
344
|
+
const item = await written(context, await keysOf(context, kind, "update", { stage, owner: fields.owner }), operationId, () => writer.update(kind, copy.externalId, fields, { operationId }));
|
|
338
345
|
return { operationId, item: await kept(context, kind, item, operationId) };
|
|
339
346
|
};
|
|
340
347
|
export const moveCrmItem = async (context, kind, reference, stageName, options = {}) => {
|
|
@@ -343,7 +350,7 @@ export const moveCrmItem = async (context, kind, reference, stageName, options =
|
|
|
343
350
|
const copy = await copyOf(context, kind, reference);
|
|
344
351
|
const stage = stageOf(await pipelineOf(context, kind, copy.pipeline), stageName);
|
|
345
352
|
const operationId = operationOf(context, options.operationId);
|
|
346
|
-
const item = await written(context, keysOf(context, kind, "move", { stage }), operationId, () => writer.move(kind, copy.externalId, stage.externalId, { operationId }));
|
|
353
|
+
const item = await written(context, await keysOf(context, kind, "move", { stage }), operationId, () => writer.move(kind, copy.externalId, stage.externalId, { operationId }));
|
|
347
354
|
return { operationId, item: await kept(context, kind, item, operationId) };
|
|
348
355
|
};
|
|
349
356
|
export const closeCrmItem = async (context, kind, reference, outcome, options = {}) => {
|
|
@@ -356,7 +363,7 @@ export const closeCrmItem = async (context, kind, reference, outcome, options =
|
|
|
356
363
|
if (reason !== undefined && (reason === "" || reason.length > 2000))
|
|
357
364
|
throw invalid("--reason is 1 to 2000 characters", "--reason");
|
|
358
365
|
const operationId = operationOf(context, options.operationId);
|
|
359
|
-
const item = await written(context, keysOf(context, kind, "close", {}), operationId, () => writer.close(kind, copy.externalId, outcome, { operationId, ...(reason ? { reason } : {}) }));
|
|
366
|
+
const item = await written(context, await keysOf(context, kind, "close", {}), operationId, () => writer.close(kind, copy.externalId, outcome, { operationId, ...(reason ? { reason } : {}) }));
|
|
360
367
|
return { operationId, item: await kept(context, kind, item, operationId) };
|
|
361
368
|
};
|
|
362
369
|
export const removeCrmItem = async (context, kind, reference, options = {}) => {
|
|
@@ -364,7 +371,7 @@ export const removeCrmItem = async (context, kind, reference, options = {}) => {
|
|
|
364
371
|
supported(writer, kind, "remove");
|
|
365
372
|
const copy = await copyOf(context, kind, reference);
|
|
366
373
|
const operationId = operationOf(context, options.operationId);
|
|
367
|
-
await written(context, keysOf(context, kind, "remove", {}), operationId, () => writer.remove(kind, copy.externalId, { operationId }));
|
|
374
|
+
await written(context, await keysOf(context, kind, "remove", {}), operationId, () => writer.remove(kind, copy.externalId, { operationId }));
|
|
368
375
|
const removed = await context.store.crm.remove(context.account, kind, [copy.externalId]);
|
|
369
376
|
return { operationId, ref: copy.ref, removed };
|
|
370
377
|
};
|
|
@@ -450,7 +457,7 @@ const writeRecord = async (context, kind, verb, fields, operationId, act) => {
|
|
|
450
457
|
if (!context.source)
|
|
451
458
|
throw new CliError("configuration_error", "a contact or company write needs the CRM source to tell your clients");
|
|
452
459
|
const rule = foreignContacts(context.source(), undefined);
|
|
453
|
-
const record = await written(context, keysOf(context, kind, verb, { owner: fields.owner }), operationId, act);
|
|
460
|
+
const record = await written(context, await keysOf(context, kind, verb, { owner: fields.owner }), operationId, act);
|
|
454
461
|
const stored = await rule.own(kind, record);
|
|
455
462
|
let removed;
|
|
456
463
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.726.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|