@wirecat/cli-core 0.709.0 → 0.710.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 CHANGED
@@ -5,6 +5,29 @@ 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.710.0 — 19.11.2026
9
+
10
+ ### Added
11
+
12
+ - **A refusal keeps the status its details name, as `inner_status`.** A read refused with an answer that names
13
+ another status under `details` (WordPress's 400 with 403 inside) keeps that number in the error's details; the
14
+ service's text stays out.
15
+ - **`contentManifestFake` takes `lacks` and `denied`:** the rights a sign-in lacks (its rights reads answer false,
16
+ and a call whose `needs` is lacked is refused as WordPress refuses it) and the operations refused with 403.
17
+
18
+ ### Fixed
19
+
20
+ - **A content kind read by several calls syncs for a role refused one of them.** A WordPress author or
21
+ contributor may not list pages with a private status: WordPress answers HTTP 400 with 403 in its details, and the
22
+ whole `post` kind failed, so even their own posts stopped syncing. A call's `optional.needs` names a rights read
23
+ and a `check`; unless it is true the call is never sent, and the sync reports a gap with its own text. The kind's
24
+ other calls sync as before, and the gap holds deletions, so no stored row is marked deleted for a skipped call.
25
+ Each rights read is sent once per source, whatever it checks. A content source takes a 400 with 403 inside as a
26
+ refusal, so `optional` reports a gap for it.
27
+ - **A scheduled post the sign-in may not read is a gap, not a failed sync.** Past its time, such a post (a page an
28
+ editor's sign-in stored, read later by an author) is read again; a refusal failed the whole `post` kind on every
29
+ run. It now stays as it was, and the gap holds deletions.
30
+
8
31
  ## 0.709.0 — 19.11.2026
9
32
 
10
33
  ### Added
@@ -171,7 +171,8 @@ export const httpApiExchange = (options) => async (command, operation, request)
171
171
  if (!response.ok) {
172
172
  const failed = status >= 500 && writes
173
173
  ? refusal(options.service, operation, response, writes)
174
- : (options.failure?.(status, answer, operation) ?? refusal(options.service, operation, response, writes));
174
+ : (options.failure?.(status, answer, operation) ??
175
+ refusal(options.service, operation, response, writes, innerStatus(answer)));
175
176
  end({ status, error: failed });
176
177
  throw failed;
177
178
  }
@@ -224,7 +225,26 @@ const unreadable = (service, writes, status) => writes
224
225
  retryable: false,
225
226
  })
226
227
  : new CliError("invalid_response", `${service} sent an answer that could not be read`, { status, retryable: true });
227
- const refusal = (service, operation, response, writes) => {
228
+ /**
229
+ * The status a refusal's `details` name, as WordPress answers a role a status it may not read: HTTP 400 with 403 in
230
+ * `data.details`. Only the number is kept, never the service's text (WC-SECR-6).
231
+ */
232
+ const innerStatus = (answer) => {
233
+ const find = (value, depth, inDetails) => {
234
+ if (depth > 5 || typeof value !== "object" || value === null || Array.isArray(value))
235
+ return undefined;
236
+ for (const [key, one] of Object.entries(value)) {
237
+ if (inDetails && key === "status" && typeof one === "number" && one >= 400 && one < 600)
238
+ return one;
239
+ const found = find(one, depth + 1, inDetails || key === "details");
240
+ if (found !== undefined)
241
+ return found;
242
+ }
243
+ return undefined;
244
+ };
245
+ return find(answer, 0, false);
246
+ };
247
+ const refusal = (service, operation, response, writes, inner) => {
228
248
  const { status } = response;
229
249
  if (status === 429) {
230
250
  const wait = providerWaitMs(response.headers, wallClock);
@@ -262,5 +282,6 @@ const refusal = (service, operation, response, writes) => {
262
282
  return new CliError(statusToCode(status), `${service} refused ${operation.command} (HTTP ${status})`, {
263
283
  status,
264
284
  retryable: status >= 500,
285
+ ...(inner === undefined || inner === status ? {} : { inner_status: inner }),
265
286
  });
266
287
  };
@@ -39,16 +39,23 @@ export interface ContentManifestEntity {
39
39
  /**
40
40
  * The sign-in may be refused this call (a role without the right): a gap with this text, and the rest syncs. A
41
41
  * source that leaves rows out without an error names `requires`: a read whose value at `check` is true when the
42
- * sign-in sees every row; false or missing is the same gap.
42
+ * sign-in sees every row; false or missing is the same gap. A source that refuses the call outright to a role names
43
+ * `needs`: unless its `check` is true the call is never sent, and the gap says its own `message`.
43
44
  */
44
45
  optional?: {
45
46
  message: string;
46
47
  scope?: string;
47
- requires?: CrmOperationCall & {
48
- check: string;
48
+ requires?: ContentRightsCall;
49
+ needs?: ContentRightsCall & {
50
+ message: string;
51
+ scope?: string;
49
52
  };
50
53
  };
51
54
  }
55
+ /** A read of the sign-in's rights, true at `check` when it has the right (WordPress: `users/me`'s capabilities). */
56
+ export type ContentRightsCall = CrmOperationCall & {
57
+ check: string;
58
+ };
52
59
  /** A post's writes, as calls and values over the update call. `"{id}"` and `"{at}"` are filled by the engine. */
53
60
  export interface ContentManifestWrites {
54
61
  create: CrmOperationCall;
@@ -30,6 +30,12 @@ const entity = v.strictObject({
30
30
  message: v.pipe(v.string(), v.minLength(1)),
31
31
  scope: v.optional(v.string()),
32
32
  requires: v.optional(v.strictObject({ ...call.entries, check: path })),
33
+ needs: v.optional(v.strictObject({
34
+ ...call.entries,
35
+ check: path,
36
+ message: v.pipe(v.string(), v.minLength(1)),
37
+ scope: v.optional(v.string()),
38
+ })),
33
39
  })),
34
40
  });
35
41
  const schema = v.strictObject({
@@ -101,6 +107,8 @@ export const parseContentManifest = (input, api) => {
101
107
  checkCall(`${where}.ids`, one.ids, true);
102
108
  if (one.optional?.requires)
103
109
  checkCall(`${where}.optional.requires`, one.optional.requires, true);
110
+ if (one.optional?.needs)
111
+ checkCall(`${where}.optional.needs`, one.optional.needs, true);
104
112
  if (one.get) {
105
113
  checkCall(`${where}.get`, one.get, true);
106
114
  if (!holds([one.get.path, one.get.query], "{id}"))
@@ -3,7 +3,7 @@ import { nextPage, parameterValue, withValue } from "../../cli/service-api-manif
3
3
  import { crmValues } from "../../crm/index.js";
4
4
  import { at, evaluate, MISSING } from "../../crm/manifest/map.js";
5
5
  import { GET_UNSUPPORTED, } from "../source.js";
6
- import { parseContentManifest } from "./manifest.js";
6
+ import { parseContentManifest, } from "./manifest.js";
7
7
  import { mapContentRecord, postBodyOf, utcEpoch } from "./map.js";
8
8
  /**
9
9
  * The one channel's id, the same whatever the site's address: a profile pointed at another address is then a moved
@@ -66,7 +66,9 @@ const pageOf = (page, now) => {
66
66
  return Number.isSafeInteger(call) && call >= 0 ? { call, token, started } : { call: -1, token: undefined, started };
67
67
  };
68
68
  const gone = (error) => isCliError(error) && error.code === "not_found";
69
- const refused = (error) => isCliError(error) && (error.code === "permission_error" || error.code === "not_found");
69
+ // A service may refuse a role with a 400 whose details say 403 (WordPress, for a status the role may not read).
70
+ const refused = (error) => isCliError(error) &&
71
+ (error.code === "permission_error" || error.code === "not_found" || error.details.inner_status === 403);
70
72
  /**
71
73
  * A `ContentSource` read from a manifest: each kind by the calls it names, paged by each operation's own
72
74
  * `pagination`, each row mapped onto the content domain, a post's text turned into Markdown.
@@ -136,23 +138,35 @@ export const contentSourceFromManifest = (input, options) => {
136
138
  return records;
137
139
  };
138
140
  const rights = new Map();
139
- /** Whether the sign-in sees every row of the entity, by its `requires` read; asked once per source. */
141
+ /** Whether the sign-in has the right `check` names; each rights read is sent once per source, whatever it checks. */
142
+ const has = async (read, send) => {
143
+ const request = inputOf(read, {});
144
+ const key = JSON.stringify([read.operation, request]);
145
+ let answer = rights.get(key);
146
+ if (answer === undefined) {
147
+ answer = send(read.operation, request);
148
+ rights.set(key, answer);
149
+ answer.catch(() => rights.delete(key));
150
+ }
151
+ return at(await answer, read.check) === true;
152
+ };
153
+ /**
154
+ * Whether the call may be sent: a role its `needs` read refuses is a gap, and the call is skipped. Else a sign-in
155
+ * its `requires` read says sees only part is a gap, and the call is sent.
156
+ */
140
157
  const checkRights = async (kind, entity, send, context) => {
141
- const requires = entity.optional?.requires;
142
- if (!requires)
143
- return;
144
- const key = JSON.stringify(requires);
145
- let seen = rights.get(key);
146
- if (seen === undefined) {
147
- seen = at(await send(requires.operation, inputOf(requires, {})), requires.check) === true;
148
- rights.set(key, seen);
158
+ const { needs, requires } = entity.optional ?? {};
159
+ if (needs && !(await has(needs, send))) {
160
+ context?.gap({ kind, message: needs.message, ...(needs.scope ? { scope: needs.scope } : {}) });
161
+ return false;
149
162
  }
150
- if (!seen)
163
+ if (requires && !(await has(requires, send)))
151
164
  context?.gap({
152
165
  kind,
153
166
  message: entity.optional?.message ?? "",
154
167
  ...(entity.optional?.scope ? { scope: entity.optional.scope } : {}),
155
168
  });
169
+ return true;
156
170
  };
157
171
  const gapOf = (kind, entity, error, context) => {
158
172
  if (!entity.optional || !refused(error))
@@ -189,9 +203,9 @@ export const contentSourceFromManifest = (input, options) => {
189
203
  const changes = since === null ? undefined : entity.changes;
190
204
  let read;
191
205
  try {
192
- await checkRights(kind, entity, send, context);
193
- read =
194
- changes?.keyset && since !== null
206
+ read = !(await checkRights(kind, entity, send, context))
207
+ ? { rows: [], next: undefined }
208
+ : changes?.keyset && since !== null
195
209
  ? await keysetPage({ ...changes, keyset: changes.keyset }, spot.token === undefined ? since - overlap : Number(spot.token), send)
196
210
  : await readPage(changes ?? entity.list, changes && since !== null ? { since: SINCE[changes.since](since - overlap) } : {}, spot.token, send);
197
211
  }
@@ -218,8 +232,9 @@ export const contentSourceFromManifest = (input, options) => {
218
232
  let read;
219
233
  const send = metered(context);
220
234
  try {
221
- await checkRights(kind, entity, send, context);
222
- read = await readPage(entity.ids ?? entity.list, {}, spot.token, send);
235
+ read = (await checkRights(kind, entity, send, context))
236
+ ? await readPage(entity.ids ?? entity.list, {}, spot.token, send)
237
+ : { rows: [], next: undefined };
223
238
  }
224
239
  catch (error) {
225
240
  // Refused, the ids read so far would mark every unread row deleted: the gap holds the pass.
@@ -8,6 +8,8 @@ const MOST_UNLISTED = 0.5;
8
8
  const GUARDED_FROM = 10;
9
9
  /** Scheduled posts past their time read one by one per run; more wait for the next. */
10
10
  const MOST_DUE = 50;
11
+ /** The sign-in may not read it, which proves nothing about the row; WordPress also refuses with 400 and 403 inside. */
12
+ const refusedRead = (error) => isCliError(error) && (error.code === "permission_error" || error.details.inner_status === 403);
11
13
  const fresh = () => ({ v: 1, token: null, round: null, passAt: 0 });
12
14
  const parsed = (value) => {
13
15
  try {
@@ -170,7 +172,14 @@ const readDue = async (run, result) => {
170
172
  catch (error) {
171
173
  if (isCliError(error) && error.details.reason === GET_UNSUPPORTED)
172
174
  return null;
173
- throw error;
175
+ // An author's scheduled page, stored by an editor's sign-in: a refusal holds it, and the other posts go on.
176
+ if (!refusedRead(error))
177
+ throw error;
178
+ run.context.gap({
179
+ kind: "post",
180
+ message: `${source.provider} would not give this sign-in every post: ${error.message}`,
181
+ });
182
+ continue;
174
183
  }
175
184
  if (post)
176
185
  result.saved += await store.content.save(account, "post", [post], run.now);
@@ -213,7 +222,7 @@ const confirmGone = async (run, kind, missing, result) => {
213
222
  catch (error) {
214
223
  // WordPress leaves others' drafts out of a contributor's list and refuses to read them, and a row of a status we
215
224
  // do not know reads as nothing: neither proves it gone.
216
- if (isCliError(error) && (error.code === "permission_error" || error.code === "invalid_response")) {
225
+ if (refusedRead(error) || (isCliError(error) && error.code === "invalid_response")) {
217
226
  run.context.gap({
218
227
  kind,
219
228
  message: `${source.provider} would not give this sign-in every ${kind}: ${error.message}`,
@@ -12,6 +12,15 @@ export interface ContentManifestFakeOptions {
12
12
  pageSize?: number;
13
13
  /** The service's clock, for the change time a write stamps. */
14
14
  clock?: () => number;
15
+ /**
16
+ * The rights the sign-in lacks, as the `check` paths of the manifest's `requires` and `needs` reads
17
+ * (`capabilities.edit_pages`): they answer false. A call whose `needs` is lacked is refused, as WordPress refuses an
18
+ * author pages with a private status: a list with HTTP 400 and 403 in its details, one row with 403. It lands in
19
+ * `refusals`.
20
+ */
21
+ lacks?: readonly string[];
22
+ /** Operations refused with 403 to this sign-in, as WordPress refuses an author the users list. */
23
+ denied?: readonly string[];
15
24
  }
16
25
  export interface ContentManifestFake {
17
26
  /** Reads as `serviceApiCall` sends them, with the answer's headers through `withHeaders`. */
@@ -169,10 +169,10 @@ export const contentManifestFake = (input, options) => {
169
169
  ...(entity.get ? [{ kind, index, role: "get", call: entity.get }] : []),
170
170
  { kind, index, role: "list", call: entity.list },
171
171
  ...(entity.ids ? [{ kind, index, role: "list", call: entity.ids }] : []),
172
- ...(entity.optional?.requires
173
- ? [{ kind, index, role: "requires", call: entity.optional.requires }]
174
- : []),
172
+ ...[entity.optional?.requires, entity.optional?.needs].flatMap((call) => call ? [{ kind, index, role: "rights", call }] : []),
175
173
  ]));
174
+ const lacks = new Set(options.lacks ?? []);
175
+ const checks = manifest.kinds.flatMap((kind) => entities(kind).flatMap((entity) => [entity.optional?.requires, entity.optional?.needs].flatMap((call) => (call ? [call] : []))));
176
176
  const carries = (route, request) => {
177
177
  const fixed = fixedOf({ path: route.call.path ?? {}, query: route.call.query ?? {} });
178
178
  const own = { path: request.path, query: request.query };
@@ -241,13 +241,28 @@ export const contentManifestFake = (input, options) => {
241
241
  refusals.push(operation);
242
242
  throw new CliError("configuration_error", `the content fake answers no ${operation} call like this`);
243
243
  }
244
+ if (options.denied?.includes(operation))
245
+ throw new CliError("permission_error", `the content fake denies ${operation} to this sign-in`);
244
246
  const entity = entities(route.kind)[route.index];
245
247
  const held = rows[route.kind]?.[route.index] ?? [];
246
- if (route.role === "requires") {
248
+ // One rights read answers every right the manifest checks with it.
249
+ if (route.role === "rights") {
247
250
  const body = {};
248
- put(body, route.call.check, true);
251
+ for (const one of checks)
252
+ if (one.operation === operation && carries({ ...route, call: one }, request))
253
+ put(body, one.check, !lacks.has(one.check));
249
254
  return { body, headers: new Headers() };
250
255
  }
256
+ const needs = entity.optional?.needs;
257
+ if (needs && lacks.has(needs.check)) {
258
+ refusals.push(operation);
259
+ if (route.role === "get")
260
+ throw new CliError("permission_error", `the content fake denies ${operation} to this sign-in`);
261
+ throw new CliError("validation_error", `the content fake refuses ${operation} to this sign-in`, {
262
+ status: 400,
263
+ inner_status: 403,
264
+ });
265
+ }
251
266
  if (route.role === "get") {
252
267
  const place = placeOf(route.call, "{id}");
253
268
  const id = place ? request[place.in][place.name] : undefined;
@@ -375,7 +390,10 @@ export const contentManifestFake = (input, options) => {
375
390
  catch (error) {
376
391
  if (!(error instanceof CliError) || error.code === "outcome_unknown")
377
392
  throw error;
378
- return Response.json({ message: error.message }, { status: statusOf(error) });
393
+ const inner = error.details.inner_status;
394
+ return Response.json(inner === undefined
395
+ ? { message: error.message }
396
+ : { message: error.message, data: { status: 400, details: { status: { data: { status: inner } } } } }, { status: statusOf(error) });
379
397
  }
380
398
  };
381
399
  const call = Object.assign(async (operation, request) => (await read(operation, request)).body, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.709.0",
3
+ "version": "0.710.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",