@wirecat/cli-core 0.705.0 → 0.707.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 +77 -0
- package/dist/cli/bot/api.d.ts +8 -0
- package/dist/cli/bot/api.js +31 -3
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/list-query.d.ts +3 -1
- package/dist/cli/list-query.js +5 -2
- package/dist/cli/messenger/lacks.js +3 -0
- package/dist/cli/messenger/messages-delete-command.js +30 -25
- package/dist/cli/messenger/messages-edit-command.js +2 -0
- package/dist/cli/messenger/messages-scheduled-command.js +110 -4
- package/dist/cli/service-api.js +65 -27
- package/dist/cli/token-session.d.ts +4 -1
- package/dist/cli/token-session.js +6 -1
- package/dist/content/cli/index.d.ts +2 -2
- package/dist/content/cli/index.js +64 -54
- package/dist/content/manifest/writer.d.ts +4 -1
- package/dist/content/manifest/writer.js +15 -12
- package/dist/content/testing/index.d.ts +1 -0
- package/dist/content/testing/index.js +1 -0
- package/dist/content/testing/manifest-fake.d.ts +54 -0
- package/dist/content/testing/manifest-fake.js +426 -0
- package/dist/content/writer.d.ts +5 -0
- package/dist/content/writer.js +1 -4
- package/dist/content/writes.js +13 -7
- package/dist/entities/index.d.ts +8 -2
- package/dist/entities/index.js +4 -2
- package/dist/entities/message-change.d.ts +240 -0
- package/dist/entities/message-change.js +6 -0
- package/dist/kit/fake.d.ts +2 -2
- package/dist/kit/fake.js +21 -0
- package/dist/mcp/surface.js +6 -3
- package/dist/ports/messenger.d.ts +20 -1
- package/dist/sends/permissions.js +11 -1
- package/dist/services/messages.d.ts +31 -0
- package/dist/services/messages.js +62 -0
- package/package.json +2 -2
|
@@ -102,7 +102,7 @@ export const tokenSessionCommand = (options) => {
|
|
|
102
102
|
throw new CliError("validation_error", `no ${word} was given`);
|
|
103
103
|
const token = login === undefined ? secret : `${login}:${secret}`;
|
|
104
104
|
const { id, account } = await run((events) => options.verify(this, token, events, site));
|
|
105
|
-
(options.claim ?? ((at, name, key) => rememberAccount(app, name, key, at)))(env, profile, id, tokens);
|
|
105
|
+
(options.claim ?? ((at, name, key) => rememberAccount(app, name, key, at)))(env, profile, siteAccount(site, id), tokens);
|
|
106
106
|
const storedIn = tokens.write(profile, token, args.credentialStorage, site === undefined ? {} : { site });
|
|
107
107
|
answer(this, { profile, state: "saved", stored_in: storedIn, verified: true, ...siteOf(site), ...account });
|
|
108
108
|
});
|
|
@@ -170,6 +170,11 @@ export const tokenSessionCommand = (options) => {
|
|
|
170
170
|
.addCommand(list);
|
|
171
171
|
};
|
|
172
172
|
const SITE = "site";
|
|
173
|
+
/**
|
|
174
|
+
* The account a profile keeps: on a service of the owner's own site, `<site>:<id>`, as bitrix24-cli keeps
|
|
175
|
+
* `<portal>:<user id>`. Each site numbers its users from 1, so the id alone would put two sites' records together.
|
|
176
|
+
*/
|
|
177
|
+
const siteAccount = (site, id) => (site === undefined ? id : `${site}:${id}`);
|
|
173
178
|
const noSite = (app, profile) => new CliError("authentication_error", `profile ${profile} is not signed in to a site — run \`${app.command} ${profile} session start --site <address>\``, { reason: "session.missing" });
|
|
174
179
|
/**
|
|
175
180
|
* The site this run's profile signed in to, as the `{ site }` server variable of `serviceApiCommand` (give it as is)
|
|
@@ -27,7 +27,7 @@ export interface ContentCommandOptions {
|
|
|
27
27
|
now?: () => number;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* The content commands: `sync`, `channels list`, `posts list|show|search`, `
|
|
31
|
-
* `
|
|
30
|
+
* The content commands: `sync`, `channels list`, `posts list|show|search|stats`, `users list`, `tags list`, and with
|
|
31
|
+
* `writes` `posts create|update|publish|unpublish|delete`.
|
|
32
32
|
*/
|
|
33
33
|
export declare const addContentCommands: (program: Command, options: ContentCommandOptions) => void;
|
|
@@ -8,7 +8,7 @@ import { environmentOf, inCommandRun, outputFor, runBudgetOf } from "../../cli/c
|
|
|
8
8
|
import { honoursDryRun } from "../../cli/dry-run-guard.js";
|
|
9
9
|
import { FETCH, LOCAL_READ, NO_EFFECTS, REMOTE_WRITE } from "../../cli/effects.js";
|
|
10
10
|
import { itemOf, listOf, renderAnswer } from "../../cli/envelope.js";
|
|
11
|
-
import { listQuery, nativeTermLists, termField, typedQuery, withQuery } from "../../cli/list-query.js";
|
|
11
|
+
import { listQuery, nativeField, nativeTermLists, termField, timeBounds, typedQuery, unfilteredQuery, withQuery, } from "../../cli/list-query.js";
|
|
12
12
|
import { terminalAsker } from "../../cli/messenger/ask.js";
|
|
13
13
|
import { CONTENT_KINDS, POST_STATUSES, POST_TYPES } from "../../domain/content.js";
|
|
14
14
|
import { aheadOf } from "../../domain/moment.js";
|
|
@@ -33,8 +33,15 @@ const POSTS_QUERY = {
|
|
|
33
33
|
}),
|
|
34
34
|
termField("type", "enum", "type:page", { values: [...POST_TYPES] }),
|
|
35
35
|
termField("channel", "kw", "channel:site", { relation: "the channel's id, as channels list shows it" }),
|
|
36
|
-
termField("
|
|
37
|
-
termField("author", "kw", "author:3", { relation: "the author's id, as
|
|
36
|
+
termField("tag", "kw", "tag:12", { relation: "a tag's or category's id, as tags list shows it" }),
|
|
37
|
+
termField("author", "kw", "author:3", { relation: "the author's id, as users list shows it" }),
|
|
38
|
+
nativeField({
|
|
39
|
+
name: "published",
|
|
40
|
+
type: "time",
|
|
41
|
+
operators: ["term", "range"],
|
|
42
|
+
example: "published:>=2026-01-01",
|
|
43
|
+
relation: "published in this time",
|
|
44
|
+
}),
|
|
38
45
|
],
|
|
39
46
|
};
|
|
40
47
|
const TIMES = new Set(["createdAt", "updatedAt", "publishedAt", "scheduledFor"]);
|
|
@@ -58,6 +65,7 @@ const viewOf = (item, extra = {}) => ({
|
|
|
58
65
|
const postBody = (post) => viewOf({ kind: "post", record: post, deletedAt: null, syncedAt: 0 });
|
|
59
66
|
const contentView = v.looseObject({ kind: v.picklist(CONTENT_KINDS), external_id: text, deleted: v.boolean() });
|
|
60
67
|
const channelView = v.looseObject({ external_id: text, kind: text, network: text, name: text });
|
|
68
|
+
const CHANNELS_QUERY = unfilteredQuery("content_channel", channelView);
|
|
61
69
|
const contentWrite = v.looseObject({ operation_id: text, post: v.optional(contentView) });
|
|
62
70
|
const contentSync = v.looseObject({
|
|
63
71
|
provider: text,
|
|
@@ -76,13 +84,6 @@ const contentSync = v.looseObject({
|
|
|
76
84
|
})),
|
|
77
85
|
gaps: v.array(v.looseObject({ kind: v.picklist(CONTENT_KINDS), message: text })),
|
|
78
86
|
});
|
|
79
|
-
const dayOrTime = (flag) => (typed) => {
|
|
80
|
-
const at = Date.parse(typed);
|
|
81
|
-
if (Number.isNaN(at))
|
|
82
|
-
throw new InvalidArgumentError(`${flag} takes a day (YYYY-MM-DD) or an ISO 8601 time`);
|
|
83
|
-
return at;
|
|
84
|
-
};
|
|
85
|
-
const collect = (value, previous) => [...previous, value];
|
|
86
87
|
const addContentCommandsDefinition = (program, options) => {
|
|
87
88
|
const now = () => options.now?.() ?? Date.now();
|
|
88
89
|
const within = (command, readOnly, work) => inCommandRun(command, async () => {
|
|
@@ -152,7 +153,8 @@ const addContentCommandsDefinition = (program, options) => {
|
|
|
152
153
|
});
|
|
153
154
|
});
|
|
154
155
|
const channels = annotate(program.command("channels"), { effects: NO_EFFECTS }).description("the sites and social accounts this profile publishes on");
|
|
155
|
-
example(answerEntity(annotate(channels.command("list"), { effects: LOCAL_READ }), "content_channel", channelView).description("the channels copied by the last sync"), "channels list").action(async (_opts, command) => {
|
|
156
|
+
example(withQuery(answerEntity(annotate(channels.command("list"), { effects: LOCAL_READ }), "content_channel", channelView), CHANNELS_QUERY).description("the channels copied by the last sync"), "channels list").action(async (words, _opts, command) => {
|
|
157
|
+
listQuery(typedQuery(words), CHANNELS_QUERY, "channels list");
|
|
156
158
|
await within(command, true, async (run) => {
|
|
157
159
|
const items = (await run.store.content.channels(run.account)).map((one) => ({
|
|
158
160
|
...Object.fromEntries(Object.entries(one).map(([name, value]) => [snake(name), value])),
|
|
@@ -162,11 +164,10 @@ const addContentCommandsDefinition = (program, options) => {
|
|
|
162
164
|
});
|
|
163
165
|
});
|
|
164
166
|
const posts = annotate(program.command("posts"), { effects: NO_EFFECTS }).description("posts and pages as last synced, with their text as Markdown");
|
|
165
|
-
example(paging(withQuery(answerEntity(annotate(posts.command("list"), { effects: LOCAL_READ }), "content_post", contentView), POSTS_QUERY)
|
|
166
|
-
.description("posts copied from the source, newest change first; run sync to bring them up to date")
|
|
167
|
-
.option("--since <day>", "published on or after this day or time", dayOrTime("--since"))
|
|
168
|
-
.option("--until <day>", "published before this day or time", dayOrTime("--until"))), "posts list status:draft", "posts list type:page --since 2026-01-01").action(async (words, opts, command) => {
|
|
167
|
+
example(paging(withQuery(answerEntity(annotate(posts.command("list"), { effects: LOCAL_READ }), "content_post", contentView), POSTS_QUERY).description("posts copied from the source, newest change first; run sync to bring them up to date")), "posts list status:draft", "posts list type:page published:>=2026-01-01").action(async (words, opts, command) => {
|
|
169
168
|
const lists = nativeTermLists(listQuery(typedQuery(words), POSTS_QUERY, "posts list"), "posts list", ["status"]);
|
|
169
|
+
const published = timeBounds(lists.get("published")?.[0]);
|
|
170
|
+
lists.delete("published");
|
|
170
171
|
if ([...lists.values()].flat().some((one) => one.operator !== "term" && one.operator !== "phrase"))
|
|
171
172
|
throw new InvalidArgumentError("posts list takes field:value terms, each one whole value");
|
|
172
173
|
const statuses = (lists.get("status") ?? []).map((one) => String(one.value).toLowerCase());
|
|
@@ -176,10 +177,11 @@ const addContentCommandsDefinition = (program, options) => {
|
|
|
176
177
|
...(statuses.length ? { statuses } : {}),
|
|
177
178
|
...(terms.has("type") ? { type: terms.get("type") } : {}),
|
|
178
179
|
...(terms.has("channel") ? { channel: terms.get("channel") } : {}),
|
|
179
|
-
...(terms.has("
|
|
180
|
+
...(terms.has("tag") ? { term: terms.get("tag") } : {}),
|
|
180
181
|
...(terms.has("author") ? { author: terms.get("author") } : {}),
|
|
181
|
-
...(
|
|
182
|
-
|
|
182
|
+
...(published.from === undefined ? {} : { since: published.from }),
|
|
183
|
+
// The store reads before `until`; the query's upper bound is the last moment it takes.
|
|
184
|
+
...(published.until === undefined ? {} : { until: published.until + 1 }),
|
|
183
185
|
limit: opts.limit,
|
|
184
186
|
offset: (opts.page - 1) * opts.limit,
|
|
185
187
|
};
|
|
@@ -240,11 +242,13 @@ const addContentCommandsDefinition = (program, options) => {
|
|
|
240
242
|
});
|
|
241
243
|
});
|
|
242
244
|
for (const [kind, plural, what] of [
|
|
243
|
-
["author", "
|
|
244
|
-
["term", "
|
|
245
|
+
["author", "users", "the source's users who write, each with the person the store knows by the same e-mail"],
|
|
246
|
+
["term", "tags", "the source's tags and categories"],
|
|
245
247
|
]) {
|
|
246
248
|
const group = annotate(program.command(plural), { effects: NO_EFFECTS }).description(what);
|
|
247
|
-
|
|
249
|
+
const query = unfilteredQuery(`content_${kind}`, contentView);
|
|
250
|
+
example(paging(withQuery(answerEntity(annotate(group.command("list"), { effects: LOCAL_READ }), `content_${kind}`, contentView), query)).description(`${plural} copied from the source`), `${plural} list`).action(async (words, opts, command) => {
|
|
251
|
+
listQuery(typedQuery(words), query, `${plural} list`);
|
|
248
252
|
await within(command, true, async (run) => {
|
|
249
253
|
const found = await run.store.content.list(run.account, kind, {
|
|
250
254
|
limit: opts.limit,
|
|
@@ -262,16 +266,15 @@ const addContentCommandsDefinition = (program, options) => {
|
|
|
262
266
|
});
|
|
263
267
|
});
|
|
264
268
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
.
|
|
268
|
-
.argument("<post>", "the post's id at the source"), "metrics show 10").action(async (id, _opts, command) => {
|
|
269
|
+
example(answerEntity(annotate(posts.command("stats"), { effects: LOCAL_READ }), "content_metric", v.looseObject({ post: text, at: text }))
|
|
270
|
+
.description("a post's readings of its numbers, one per sync, each kept, the newest first")
|
|
271
|
+
.argument("<post>", "the post's id at the source"), "posts stats 10").action(async (id, _opts, command) => {
|
|
269
272
|
await within(command, true, async (run) => {
|
|
270
273
|
const items = (await run.store.content.metrics(run.account, id)).map((one) => ({
|
|
271
274
|
...one,
|
|
272
275
|
at: new Date(one.at).toISOString(),
|
|
273
276
|
}));
|
|
274
|
-
return listOf("
|
|
277
|
+
return listOf("posts stats", { items, limit: items.length, page: 1, has_more: false });
|
|
275
278
|
});
|
|
276
279
|
});
|
|
277
280
|
if (!options.writes)
|
|
@@ -292,8 +295,8 @@ const addContentCommandsDefinition = (program, options) => {
|
|
|
292
295
|
if (path === undefined)
|
|
293
296
|
return undefined;
|
|
294
297
|
if (path !== "-" && refusedPlace(path, options.app, run.env ?? process.env))
|
|
295
|
-
throw new CliError("validation_error", `--
|
|
296
|
-
param: "--
|
|
298
|
+
throw new CliError("validation_error", `--text-file may not read ${path}: it holds sign-ins or state`, {
|
|
299
|
+
param: "--text-file",
|
|
297
300
|
});
|
|
298
301
|
return readFileSync(path === "-" ? 0 : path, "utf8");
|
|
299
302
|
};
|
|
@@ -301,21 +304,28 @@ const addContentCommandsDefinition = (program, options) => {
|
|
|
301
304
|
const write = (name, description) => answerEntity(annotate(posts.command(name), { effects: REMOTE_WRITE, offline: false }), "content_write", contentWrite).description(description);
|
|
302
305
|
const fields = (command) => command
|
|
303
306
|
.option("--title <title>", "the post's title")
|
|
304
|
-
.option("--
|
|
305
|
-
.option("--
|
|
307
|
+
.option("--text-file <path>", "the text as Markdown, from a file, or - for stdin")
|
|
308
|
+
.option("--description <text>", "the short text lists show, the excerpt")
|
|
306
309
|
.option("--slug <slug>", "the address's last part")
|
|
307
|
-
.option("--
|
|
310
|
+
.option("--tags <ids>", "its tags and categories, by comma-separated ids as tags list shows them; replaces them");
|
|
308
311
|
const fieldsOf = (run, typed) => {
|
|
309
|
-
const body = bodyOf(run, typed.
|
|
312
|
+
const body = bodyOf(run, typed.textFile);
|
|
313
|
+
const tags = typed.tags
|
|
314
|
+
?.split(",")
|
|
315
|
+
.map((one) => one.trim())
|
|
316
|
+
.filter(Boolean);
|
|
317
|
+
// An unset "$TAGS" in a script would otherwise strip every tag from the post.
|
|
318
|
+
if (tags?.length === 0)
|
|
319
|
+
throw new InvalidArgumentError("--tags takes one or more ids");
|
|
310
320
|
return {
|
|
311
321
|
...(typed.title === undefined ? {} : { title: typed.title }),
|
|
312
322
|
...(body === undefined ? {} : { body }),
|
|
313
|
-
...(typed.
|
|
323
|
+
...(typed.description === undefined ? {} : { excerpt: typed.description }),
|
|
314
324
|
...(typed.slug === undefined ? {} : { slug: typed.slug }),
|
|
315
|
-
...(
|
|
325
|
+
...(tags === undefined ? {} : { terms: tags }),
|
|
316
326
|
};
|
|
317
327
|
};
|
|
318
|
-
example(fields(write("create", "write a new draft; publishing is its own step, posts publish")).option("--type <type>", `${POST_TYPES.join(" or ")}; post when left out`), "posts create --title 'Version 3' --
|
|
328
|
+
example(fields(write("create", "write a new draft; publishing is its own step, posts publish")).option("--type <type>", `${POST_TYPES.join(" or ")}; post when left out`), "posts create --title 'Version 3' --text-file notes.md").action(async (typed, command) => {
|
|
319
329
|
if (typed.type !== undefined && !POST_TYPES.includes(typed.type))
|
|
320
330
|
throw new InvalidArgumentError(`--type is ${POST_TYPES.join(" or ")}`);
|
|
321
331
|
await within(command, false, async (run) => {
|
|
@@ -334,35 +344,35 @@ const addContentCommandsDefinition = (program, options) => {
|
|
|
334
344
|
return answered(done.operationId, done.post);
|
|
335
345
|
});
|
|
336
346
|
});
|
|
337
|
-
|
|
338
|
-
["publish", "publish a post now; a published post is answered as it is", publishPost],
|
|
339
|
-
["unpublish", "bring a published or scheduled post back to a draft", unpublishPost],
|
|
340
|
-
])
|
|
341
|
-
example(write(name, description).argument("<post>", "the post's id at the source"), `posts ${name} 11`).action(async (id, _opts, command) => {
|
|
342
|
-
await within(command, false, async (run) => {
|
|
343
|
-
const done = await act(contextOf(run, command), id);
|
|
344
|
-
return answered(done.operationId, done.post, done.unchanged ? { unchanged: true } : {});
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
example(write("schedule", "publish a post at a later time; checks posts.publish too")
|
|
347
|
+
example(write("publish", "publish a post now, or at a later time with --at-time; a published post is answered as it is")
|
|
348
348
|
.argument("<post>", "the post's id at the source")
|
|
349
|
-
.
|
|
349
|
+
.option("--at-time <time>", "when it goes out instead of now: an ISO 8601 time, a day, or 3d from now; it must be ahead", (typed) => aheadOf(typed, "--at-time", Date.now())), "posts publish 11", "posts publish 11 --at-time 2026-12-01T09:00:00Z").action(async (id, opts, command) => {
|
|
350
350
|
await within(command, false, async (run) => {
|
|
351
|
-
|
|
352
|
-
|
|
351
|
+
if (opts.atTime !== undefined) {
|
|
352
|
+
const scheduled = await schedulePost(contextOf(run, command), id, opts.atTime);
|
|
353
|
+
return answered(scheduled.operationId, scheduled.post);
|
|
354
|
+
}
|
|
355
|
+
const done = await publishPost(contextOf(run, command), id);
|
|
356
|
+
return answered(done.operationId, done.post, done.unchanged ? { unchanged: true } : {});
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
example(write("unpublish", "bring a published or scheduled post back to a draft").argument("<post>", "the post's id at the source"), "posts unpublish 11").action(async (id, _opts, command) => {
|
|
360
|
+
await within(command, false, async (run) => {
|
|
361
|
+
const done = await unpublishPost(contextOf(run, command), id);
|
|
362
|
+
return answered(done.operationId, done.post, done.unchanged ? { unchanged: true } : {});
|
|
353
363
|
});
|
|
354
364
|
});
|
|
355
|
-
example(write("delete", "move a post to the source's trash, from which it comes back; --
|
|
365
|
+
example(write("delete", "move a post to the source's trash, from which it comes back; --allow-delete deletes it for good")
|
|
356
366
|
.argument("<post>", "the post's id at the source")
|
|
357
|
-
.option("--
|
|
367
|
+
.option("--allow-delete", "delete it for good, past the trash; checks posts.delete.force"), "posts delete 11").action(async (id, opts, command) => {
|
|
358
368
|
await within(command, false, async (run) => {
|
|
359
|
-
const done = await deletePost(contextOf(run, command), id, opts.
|
|
369
|
+
const done = await deletePost(contextOf(run, command), id, opts.allowDelete ? { force: true } : {});
|
|
360
370
|
return answered(done.operationId, done.post, { deleted: done.deleted });
|
|
361
371
|
});
|
|
362
372
|
});
|
|
363
373
|
};
|
|
364
374
|
/**
|
|
365
|
-
* The content commands: `sync`, `channels list`, `posts list|show|search`, `
|
|
366
|
-
* `
|
|
375
|
+
* The content commands: `sync`, `channels list`, `posts list|show|search|stats`, `users list`, `tags list`, and with
|
|
376
|
+
* `writes` `posts create|update|publish|unpublish|delete`.
|
|
367
377
|
*/
|
|
368
378
|
export const addContentCommands = honoursDryRun(sharedCommand(addContentCommandsDefinition));
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { Command } from "commander";
|
|
2
2
|
import type { ApiCommandInput } from "../../cli/bot/api.js";
|
|
3
3
|
import type { ServiceApiManifest } from "../../cli/service-api-manifest.js";
|
|
4
|
+
import type { PermissionKey } from "../../sends/permissions.js";
|
|
4
5
|
import type { ContentSource } from "../source.js";
|
|
5
6
|
import { type ContentWriter } from "../writer.js";
|
|
6
7
|
/**
|
|
7
8
|
* Sends one write the way the `api` group does: `serviceApiWriter` bound to the invoking command, which checks the
|
|
8
9
|
* profile's keys (the publish value keys, the force-delete key) and asks. Nothing else may write for a CLI.
|
|
9
10
|
*/
|
|
10
|
-
export type ContentWriteCall = (command: Command, operation: string, input: ApiCommandInput
|
|
11
|
+
export type ContentWriteCall = (command: Command, operation: string, input: ApiCommandInput,
|
|
12
|
+
/** The keys the owner was already asked about (level `ask`); with any, the call's own `api.<operation>` too. */
|
|
13
|
+
confirmed: readonly PermissionKey[]) => Promise<{
|
|
11
14
|
operation_id: string;
|
|
12
15
|
result: unknown;
|
|
13
16
|
}>;
|
|
@@ -78,44 +78,47 @@ export const contentWriterFromManifest = (input, options) => {
|
|
|
78
78
|
throw pagesUnwritten();
|
|
79
79
|
return found;
|
|
80
80
|
};
|
|
81
|
-
const send = async (call, slots, body) => {
|
|
81
|
+
const send = async (call, slots, confirmed, body) => {
|
|
82
82
|
const base = call.body === undefined ? {} : fill(call.body, slots);
|
|
83
|
-
|
|
83
|
+
// The owner said yes to this write in the content command, so its one call is not asked about again; a key that
|
|
84
|
+
// command did not ask about, as the publish key for a post that is published at the source now, still is.
|
|
85
|
+
const own = options.api.operations.find((one) => one.id === call.operation)?.command;
|
|
86
|
+
const { result } = await options.write(options.command, call.operation, inputOf(call, slots, body === undefined && call.body === undefined ? undefined : { ...base, ...body }), !confirmed?.length ? [] : [...confirmed, ...(own === undefined ? [] : [`api.${own}`])]);
|
|
84
87
|
return result;
|
|
85
88
|
};
|
|
86
|
-
const updated = async (externalId, body) => {
|
|
87
|
-
const post = await postOf(await send(writes.update, { id: externalId }, body));
|
|
89
|
+
const updated = async (externalId, body, confirmed) => {
|
|
90
|
+
const post = await postOf(await send(writes.update, { id: externalId }, confirmed, body));
|
|
88
91
|
if (!post)
|
|
89
92
|
throw new CliError("invalid_response", `${manifest.provider} answered an update with no post`);
|
|
90
93
|
return post;
|
|
91
94
|
};
|
|
92
95
|
return {
|
|
93
96
|
provider: manifest.provider,
|
|
94
|
-
async createDraft(draft) {
|
|
97
|
+
async createDraft(draft, options_) {
|
|
95
98
|
if (draft.type === "page")
|
|
96
99
|
throw pagesUnwritten();
|
|
97
|
-
const post = await postOf(await send(writes.create, {}, await bodyOf(draft)));
|
|
100
|
+
const post = await postOf(await send(writes.create, {}, options_.confirmed, await bodyOf(draft)));
|
|
98
101
|
if (!post)
|
|
99
102
|
throw new CliError("invalid_response", `${manifest.provider} answered a create with no post`);
|
|
100
103
|
return post;
|
|
101
104
|
},
|
|
102
105
|
async update(externalId, patch, options_) {
|
|
103
106
|
await current(externalId, options_);
|
|
104
|
-
return updated(externalId, await bodyOf(patch));
|
|
107
|
+
return updated(externalId, await bodyOf(patch), options_.confirmed);
|
|
105
108
|
},
|
|
106
109
|
async publish(externalId, options_) {
|
|
107
110
|
const found = await current(externalId, options_);
|
|
108
111
|
if (found.status === "published")
|
|
109
112
|
return found;
|
|
110
|
-
return updated(externalId, { ...writes.publish });
|
|
113
|
+
return updated(externalId, { ...writes.publish }, options_.confirmed);
|
|
111
114
|
},
|
|
112
115
|
async schedule(externalId, when, options_) {
|
|
113
116
|
await current(externalId, options_);
|
|
114
|
-
return updated(externalId, fill(writes.schedule, { at: iso(when) }));
|
|
117
|
+
return updated(externalId, fill(writes.schedule, { at: iso(when) }), options_.confirmed);
|
|
115
118
|
},
|
|
116
119
|
async unpublish(externalId, options_) {
|
|
117
120
|
await current(externalId, options_);
|
|
118
|
-
return updated(externalId, { ...writes.unpublish });
|
|
121
|
+
return updated(externalId, { ...writes.unpublish }, options_.confirmed);
|
|
119
122
|
},
|
|
120
123
|
async trash(externalId, options_) {
|
|
121
124
|
await current(externalId, options_);
|
|
@@ -124,10 +127,10 @@ export const contentWriterFromManifest = (input, options) => {
|
|
|
124
127
|
throw new CliError("validation_error", `${manifest.provider} takes no deletion past the trash`, {
|
|
125
128
|
reason: "content.write-unsupported",
|
|
126
129
|
});
|
|
127
|
-
await send(writes.delete, { id: externalId });
|
|
130
|
+
await send(writes.delete, { id: externalId }, options_.confirmed);
|
|
128
131
|
return null;
|
|
129
132
|
}
|
|
130
|
-
return postOf(await send(writes.trash, { id: externalId }));
|
|
133
|
+
return postOf(await send(writes.trash, { id: externalId }, options_.confirmed));
|
|
131
134
|
},
|
|
132
135
|
};
|
|
133
136
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { type ContentManifestFake, type ContentManifestFakeOptions, contentManifestFake } from "./manifest-fake.js";
|
|
1
2
|
export { exampleContentRows, type FakeContentRows, type FakeContentSource, type FakeContentSourceOptions, fakeContentSource, } from "./source.js";
|
|
2
3
|
export { type ContentSourceFaults, type ContentSourceFixture, contentSourceContract, } from "./source-contract.js";
|
|
3
4
|
export { type ContentSyncFixture, contentSyncContract } from "./sync-contract.js";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ApiCommandInput } from "../../cli/bot/api.js";
|
|
2
|
+
import type { ServiceApiManifest } from "../../cli/service-api-manifest.js";
|
|
3
|
+
import type { ContentKind } from "../../domain/content.js";
|
|
4
|
+
import { type FakeContentRows } from "./source.js";
|
|
5
|
+
type Row = Record<string, unknown>;
|
|
6
|
+
export interface ContentManifestFakeOptions {
|
|
7
|
+
/** The generated API manifest the source manifest names its operations in. */
|
|
8
|
+
api: ServiceApiManifest;
|
|
9
|
+
/** Our records, written into the service's own shape by each entity's map; default `exampleContentRows()`. */
|
|
10
|
+
rows?: FakeContentRows;
|
|
11
|
+
/** Each page holds at most this many rows, whatever limit the call asks: a small page makes every list page. */
|
|
12
|
+
pageSize?: number;
|
|
13
|
+
/** The service's clock, for the change time a write stamps. */
|
|
14
|
+
clock?: () => number;
|
|
15
|
+
}
|
|
16
|
+
export interface ContentManifestFake {
|
|
17
|
+
/** Reads as `serviceApiCall` sends them, with the answer's headers through `withHeaders`. */
|
|
18
|
+
call: ((operation: string, input: ApiCommandInput) => Promise<unknown>) & {
|
|
19
|
+
withHeaders: (operation: string, input: ApiCommandInput) => Promise<{
|
|
20
|
+
body: unknown;
|
|
21
|
+
headers: Headers;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
/** Writes as `serviceApiWriter` sends them: the `write` a manifest writer takes. */
|
|
25
|
+
write: (command: unknown, operation: string, input: ApiCommandInput, confirmed?: readonly string[]) => Promise<{
|
|
26
|
+
operation_id: string;
|
|
27
|
+
result: unknown;
|
|
28
|
+
}>;
|
|
29
|
+
/** The same service over HTTP, for a CLI's own commands: each request matched to its operation by method and path. */
|
|
30
|
+
fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
31
|
+
/** Each kind's rows in the service's shape, by entity, as a test may change them. */
|
|
32
|
+
rows: Partial<Record<ContentKind, Row[][]>>;
|
|
33
|
+
/** The ids of each kind's rows as the service holds them: what a contract's `held` names. */
|
|
34
|
+
ids(kind: ContentKind): string[];
|
|
35
|
+
/** The operations each write reached, in order. */
|
|
36
|
+
writes: string[];
|
|
37
|
+
/** Calls no route of the manifest makes: a source that sends one would fail on the real service. */
|
|
38
|
+
refusals: string[];
|
|
39
|
+
/** Moves a post's change time to now, as an edit elsewhere does. */
|
|
40
|
+
touch(kind: ContentKind, id: string): void;
|
|
41
|
+
/** Moves a post to the trash, as the owner does in the service's own editor. */
|
|
42
|
+
trash(id: string): void;
|
|
43
|
+
remove(kind: ContentKind, id: string): void;
|
|
44
|
+
loseNextAnswer(): void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A content service in memory, built from a source manifest and the generated API it names. Our records are written
|
|
48
|
+
* into each entity's shape by its map (the status by its `map`, a post's text by its body format), read back by the
|
|
49
|
+
* calls the manifest names, paged by each operation's own pagination (the page count in its header where it has one,
|
|
50
|
+
* a page past the end refused), and written by the manifest's writes. Service-neutral: a content CLI's own config
|
|
51
|
+
* drives it, as `crmManifestFake` does a CRM's.
|
|
52
|
+
*/
|
|
53
|
+
export declare const contentManifestFake: (input: unknown, options: ContentManifestFakeOptions) => ContentManifestFake;
|
|
54
|
+
export {};
|