@wirecat/cli-core 0.701.0 → 0.702.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/manifest.d.ts +8 -2
- package/dist/crm/manifest/manifest.js +10 -0
- package/dist/crm/manifest/source.js +78 -17
- 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.702.0 — 18.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **A source manifest's `linked: true` on contacts or companies copies only the ones a deal names**, each read by its
|
|
13
|
+
`get`, as bitrix24-cli's sync does; the rest stay in the service and are read live. Their ids are the deals' links,
|
|
14
|
+
so one no deal names any more leaves the copy at the next full round. Attio's contacts and companies grow from the
|
|
15
|
+
owner's mail, and a full copy held thousands nobody sells to.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- **An optional kind the service answers with 404 is a gap too**, not only a 403. Attio's Deals object is off until an
|
|
20
|
+
admin turns it on, and its records query answers 404: the sync failed instead of naming the gap.
|
|
21
|
+
|
|
8
22
|
## 0.701.0 — 18.11.2026
|
|
9
23
|
|
|
10
24
|
### Added
|
|
@@ -94,13 +94,19 @@ export interface CrmManifestEntity<K extends CrmKind = CrmKind> {
|
|
|
94
94
|
typed?: CrmTypedValues;
|
|
95
95
|
};
|
|
96
96
|
/**
|
|
97
|
-
* A kind the plan or the sign-in may not have (HubSpot's leads
|
|
98
|
-
* scope, and the other kinds still sync.
|
|
97
|
+
* A kind the plan or the sign-in may not have (HubSpot's leads, Attio's Deals object when it is off): the service
|
|
98
|
+
* refusing it, or answering that it is not there, is a gap with this text and scope, and the other kinds still sync.
|
|
99
99
|
*/
|
|
100
100
|
optional?: {
|
|
101
101
|
message: string;
|
|
102
102
|
scope?: string;
|
|
103
103
|
};
|
|
104
|
+
/**
|
|
105
|
+
* Contacts or companies: the sync copies only the ones a deal names, each read by `get`, as Bitrix24's does; the
|
|
106
|
+
* rest stay in the service and are read live. For a service whose own contacts and companies grow from mail
|
|
107
|
+
* (Attio), where a full copy would hold thousands nobody sells to.
|
|
108
|
+
*/
|
|
109
|
+
linked?: true;
|
|
104
110
|
}
|
|
105
111
|
/**
|
|
106
112
|
* Values kept as a list of typed entries, each naming its type (Attio's `values.<slug>`): the entry's type picks where
|
|
@@ -48,6 +48,7 @@ const entity = v.strictObject({
|
|
|
48
48
|
typed: v.optional(v.strictObject({ by: path, current: v.optional(path), paths: v.optional(v.record(v.string(), path)) })),
|
|
49
49
|
})),
|
|
50
50
|
optional: v.optional(v.strictObject({ message: v.pipe(v.string(), v.minLength(1)), scope: v.optional(v.string()) })),
|
|
51
|
+
linked: v.optional(v.literal(true)),
|
|
51
52
|
});
|
|
52
53
|
const pipelines = v.strictObject({
|
|
53
54
|
call,
|
|
@@ -159,6 +160,15 @@ export const parseCrmManifest = (input, api) => {
|
|
|
159
160
|
if (!hasPlaceholder([one.search.path, one.search.query, one.search.body], "{query}"))
|
|
160
161
|
throw invalid(`entities.${kind}.search`, 'no "{query}" in its path, query or body');
|
|
161
162
|
}
|
|
163
|
+
if (one.linked) {
|
|
164
|
+
if (kind !== "person" && kind !== "organization")
|
|
165
|
+
throw invalid(`entities.${kind}.linked`, "only contacts and companies are copied as a deal names them");
|
|
166
|
+
if (!one.get)
|
|
167
|
+
throw invalid(`entities.${kind}.linked`, "each one is read by its get, and this kind has none");
|
|
168
|
+
const link = kind === "person" ? "people" : "organization";
|
|
169
|
+
if (!manifest.kinds.includes("deal") || manifest.entities.deal?.map[link] === undefined)
|
|
170
|
+
throw invalid(`entities.${kind}.linked`, `no deal entity maps ${link}`);
|
|
171
|
+
}
|
|
162
172
|
if (one.map.externalId === undefined)
|
|
163
173
|
throw invalid(`entities.${kind}.map.externalId`, "every kind maps its id");
|
|
164
174
|
const fields = [...Object.keys(FIELDS[kind]), "amount", "currency"];
|
|
@@ -9,6 +9,8 @@ const OVERLAP_MS = 10 * 60_000;
|
|
|
9
9
|
const MOST_LIVE = 100;
|
|
10
10
|
/** How far one read of every page goes: a service that never stops paging must not hold a sync forever. */
|
|
11
11
|
const MOST_PAGES = 500;
|
|
12
|
+
/** Contacts or companies a deal names, read one by one, per page of a sync round. */
|
|
13
|
+
const LINKED_PAGE = 50;
|
|
12
14
|
const DROP = Symbol("drop");
|
|
13
15
|
/** Fills `"{since}"`, `"{select}"`, `"{id}"` and `"{query}"`; an empty select drops the parameter it stands for. */
|
|
14
16
|
const fill = (value, slots) => {
|
|
@@ -189,7 +191,7 @@ export const crmSourceFromManifest = (input, options) => {
|
|
|
189
191
|
/** A refusal of a kind the manifest marks optional is a gap; the other kinds still sync. */
|
|
190
192
|
const optionalRefused = (kind, error, context) => {
|
|
191
193
|
const optional = manifest.entities[kind]?.optional;
|
|
192
|
-
if (!optional || !
|
|
194
|
+
if (!optional || !unseen(error))
|
|
193
195
|
return false;
|
|
194
196
|
gap(context, { kind, message: optional.message, ...(optional.scope ? { scope: optional.scope } : {}) });
|
|
195
197
|
return true;
|
|
@@ -228,6 +230,8 @@ export const crmSourceFromManifest = (input, options) => {
|
|
|
228
230
|
};
|
|
229
231
|
const readChanges = async (kind, cursor, page, context) => {
|
|
230
232
|
const entity = entityOf(kind);
|
|
233
|
+
if (entity.linked && (kind === "person" || kind === "organization"))
|
|
234
|
+
return (await readLinked(kind, page, context));
|
|
231
235
|
const since = cursor === null ? null : Date.parse(cursor);
|
|
232
236
|
if (since !== null && Number.isNaN(since))
|
|
233
237
|
return { reset: true };
|
|
@@ -247,8 +251,80 @@ export const crmSourceFromManifest = (input, options) => {
|
|
|
247
251
|
? { items, hasMore: false, cursor: new Date(started).toISOString() }
|
|
248
252
|
: { items, hasMore: true, nextCursor: `${next}@${started}` };
|
|
249
253
|
};
|
|
254
|
+
const readOne = async (kind, externalId, send, context) => {
|
|
255
|
+
const entity = entityOf(kind);
|
|
256
|
+
if (!entity.get)
|
|
257
|
+
return null;
|
|
258
|
+
const defined = entity.custom ? await fieldsOf(kind, send, context) : [];
|
|
259
|
+
let answer;
|
|
260
|
+
try {
|
|
261
|
+
answer = await send(entity.get.operation, inputOf(entity.get, { id: externalId, select: selectOf(kind, defined, context) }));
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
if (unseen(error))
|
|
265
|
+
return null;
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
const raw = entity.get.items === undefined ? answer : at(answer, entity.get.items);
|
|
269
|
+
return isRaw(raw) ? ((await mapped(kind, [raw], defined, send))[0] ?? null) : null;
|
|
270
|
+
};
|
|
271
|
+
/** The contacts and companies the deals name, from one pass over the deals; deals the service refuses name none. */
|
|
272
|
+
const linkedOf = async (send, context) => {
|
|
273
|
+
const deal = entityOf("deal");
|
|
274
|
+
const found = { person: new Set(), organization: new Set() };
|
|
275
|
+
let rows;
|
|
276
|
+
try {
|
|
277
|
+
rows = await readAll(deal.list, send);
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
if (!optionalRefused("deal", error, context))
|
|
281
|
+
throw error;
|
|
282
|
+
rows = [];
|
|
283
|
+
}
|
|
284
|
+
for (const raw of rows) {
|
|
285
|
+
const record = mapRecord("deal", deal, raw, []);
|
|
286
|
+
if (record?.organization)
|
|
287
|
+
found.organization.add(record.organization);
|
|
288
|
+
for (const one of record?.people ?? [])
|
|
289
|
+
found.person.add(one.externalId);
|
|
290
|
+
}
|
|
291
|
+
return { person: [...found.person].sort(), organization: [...found.organization].sort() };
|
|
292
|
+
};
|
|
293
|
+
/** One pass per round: every page of the round reads the same list, so no id is skipped or read twice. */
|
|
294
|
+
let round;
|
|
295
|
+
const linkedRound = (started, send, context) => {
|
|
296
|
+
if (round?.started !== started) {
|
|
297
|
+
const ids = linkedOf(send, context);
|
|
298
|
+
ids.catch(() => {
|
|
299
|
+
if (round?.ids === ids)
|
|
300
|
+
round = undefined;
|
|
301
|
+
});
|
|
302
|
+
round = { started, ids };
|
|
303
|
+
}
|
|
304
|
+
return round.ids;
|
|
305
|
+
};
|
|
306
|
+
const readLinked = async (kind, page, context) => {
|
|
307
|
+
const { token, started } = pageOf(page, now());
|
|
308
|
+
const from = token === undefined ? 0 : Number(token);
|
|
309
|
+
if (!Number.isSafeInteger(from) || from < 0)
|
|
310
|
+
return { reset: true };
|
|
311
|
+
const send = metered(context);
|
|
312
|
+
const ids = (await linkedRound(started, send, context))[kind];
|
|
313
|
+
const items = [];
|
|
314
|
+
for (const externalId of ids.slice(from, from + LINKED_PAGE)) {
|
|
315
|
+
const one = await readOne(kind, externalId, send, context);
|
|
316
|
+
if (one)
|
|
317
|
+
items.push(one);
|
|
318
|
+
}
|
|
319
|
+
const next = from + LINKED_PAGE;
|
|
320
|
+
return next < ids.length
|
|
321
|
+
? { items, hasMore: true, nextCursor: `${next}@${started}` }
|
|
322
|
+
: { items, hasMore: false, cursor: new Date(started).toISOString() };
|
|
323
|
+
};
|
|
250
324
|
const readIds = async (kind, page, context) => {
|
|
251
325
|
const entity = entityOf(kind);
|
|
326
|
+
if (entity.linked && (kind === "person" || kind === "organization"))
|
|
327
|
+
return { items: (await linkedOf(metered(context), context))[kind], hasMore: false };
|
|
252
328
|
const { rows, next } = await readPage(entity.ids ?? entity.list, {}, page, metered(context));
|
|
253
329
|
const items = rows.flatMap((raw) => {
|
|
254
330
|
const found = evaluate(entity.map.externalId, raw);
|
|
@@ -335,22 +411,7 @@ export const crmSourceFromManifest = (input, options) => {
|
|
|
335
411
|
},
|
|
336
412
|
...(live.length ? { list: readLive } : {}),
|
|
337
413
|
async get(kind, externalId, context) {
|
|
338
|
-
|
|
339
|
-
if (!entity.get)
|
|
340
|
-
return null;
|
|
341
|
-
const send = metered(context);
|
|
342
|
-
const defined = entity.custom ? await fieldsOf(kind, send, context) : [];
|
|
343
|
-
let answer;
|
|
344
|
-
try {
|
|
345
|
-
answer = await send(entity.get.operation, inputOf(entity.get, { id: externalId, select: selectOf(kind, defined, context) }));
|
|
346
|
-
}
|
|
347
|
-
catch (error) {
|
|
348
|
-
if (unseen(error))
|
|
349
|
-
return null;
|
|
350
|
-
throw error;
|
|
351
|
-
}
|
|
352
|
-
const raw = entity.get.items === undefined ? answer : at(answer, entity.get.items);
|
|
353
|
-
return isRaw(raw) ? ((await mapped(kind, [raw], defined, send))[0] ?? null) : null;
|
|
414
|
+
return readOne(kind, externalId, metered(context), context);
|
|
354
415
|
},
|
|
355
416
|
...(manifest.fields
|
|
356
417
|
? { fields: (kind, context) => fieldsOf(kind, metered(context), context) }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.702.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",
|