@wirecat/cli-core 0.704.0 → 0.705.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 +86 -0
- package/dist/cli/bot/api-http.d.ts +8 -2
- package/dist/cli/bot/api-http.js +20 -4
- package/dist/cli/documents/words.d.ts +1 -1
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +3 -3
- package/dist/cli/messenger/store-maintenance-command.js +6 -2
- package/dist/cli/service-api-call.d.ts +13 -3
- package/dist/cli/service-api-call.js +19 -9
- package/dist/cli/service-api-manifest.d.ts +11 -2
- package/dist/cli/service-api-manifest.js +30 -9
- package/dist/cli/service-api.d.ts +14 -6
- package/dist/cli/service-api.js +137 -29
- package/dist/cli/token-session.d.ts +5 -2
- package/dist/cli/token-session.js +13 -4
- package/dist/content/cli/index.d.ts +33 -0
- package/dist/content/cli/index.js +368 -0
- package/dist/content/index.d.ts +8 -0
- package/dist/content/index.js +7 -0
- package/dist/content/manifest/index.d.ts +4 -0
- package/dist/content/manifest/index.js +4 -0
- package/dist/content/manifest/manifest.d.ts +92 -0
- package/dist/content/manifest/manifest.js +137 -0
- package/dist/content/manifest/map.d.ts +25 -0
- package/dist/content/manifest/map.js +94 -0
- package/dist/content/manifest/source.d.ts +41 -0
- package/dist/content/manifest/source.js +288 -0
- package/dist/content/manifest/writer.d.ts +26 -0
- package/dist/content/manifest/writer.js +133 -0
- package/dist/content/source.d.ts +64 -0
- package/dist/content/source.js +2 -0
- package/dist/content/sync.d.ts +61 -0
- package/dist/content/sync.js +387 -0
- package/dist/content/testing/index.d.ts +4 -0
- package/dist/content/testing/index.js +4 -0
- package/dist/content/testing/source-contract.d.ts +38 -0
- package/dist/content/testing/source-contract.js +274 -0
- package/dist/content/testing/source.d.ts +55 -0
- package/dist/content/testing/source.js +276 -0
- package/dist/content/testing/sync-contract.d.ts +10 -0
- package/dist/content/testing/sync-contract.js +172 -0
- package/dist/content/testing/write-contract.d.ts +14 -0
- package/dist/content/testing/write-contract.js +102 -0
- package/dist/content/writer.d.ts +64 -0
- package/dist/content/writer.js +38 -0
- package/dist/content/writes.d.ts +58 -0
- package/dist/content/writes.js +129 -0
- package/dist/documents/file-mirror-model.d.ts +3 -1
- package/dist/documents/index.d.ts +3 -3
- package/dist/documents/index.js +1 -1
- package/dist/domain/content.d.ts +102 -0
- package/dist/domain/content.js +11 -0
- package/dist/errors/reasons.js +14 -0
- package/dist/manifest/index.d.ts +21 -7
- package/dist/manifest/index.js +7 -4
- package/dist/services/documents/mirrors.d.ts +13 -1
- package/dist/services/documents/mirrors.js +12 -3
- package/dist/services/files/mirror.d.ts +20 -8
- package/dist/services/files/mirror.js +84 -27
- package/dist/services/files/versions.d.ts +17 -7
- package/dist/services/files/versions.js +56 -21
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/recover.js +2 -0
- package/dist/store/sqlite/account-purge.js +7 -0
- package/dist/store/sqlite/content.d.ts +100 -0
- package/dist/store/sqlite/content.js +375 -0
- package/dist/store/sqlite/entity-types.d.ts +1 -0
- package/dist/store/sqlite/entity-types.js +1 -0
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +26 -0
- package/dist/store/sqlite/schema.d.ts +1140 -0
- package/dist/store/sqlite/schema.js +100 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/package.json +12 -4
package/dist/cli/service-api.js
CHANGED
|
@@ -8,14 +8,14 @@ import { levelFor } from "../sends/permissions.js";
|
|
|
8
8
|
import { newOperationId } from "../sends/send-id.js";
|
|
9
9
|
import { refusedPlace } from "../sends/upload.js";
|
|
10
10
|
import { generatedApiCommand } from "./bot/api.js";
|
|
11
|
-
import {
|
|
12
|
-
import { checkApiBody, checkApiParameter, parseApiJson, readApiBody, readApiBytes } from "./bot/api-input.js";
|
|
11
|
+
import { httpApiExchange, httpApiRequest, unsendableBody } from "./bot/api-http.js";
|
|
12
|
+
import { apiJson, checkApiBody, checkApiParameter, graphqlVariables, parseApiJson, readApiBody, readApiBytes, sendsBytes, } from "./bot/api-input.js";
|
|
13
13
|
import { baseContext, outputFor } from "./context.js";
|
|
14
14
|
import { NO_EFFECTS } from "./effects.js";
|
|
15
15
|
import { itemOf, listOf, renderAnswer } from "./envelope.js";
|
|
16
16
|
import { queryTerms, termField, withQuery } from "./list-query.js";
|
|
17
17
|
import { terminalAsker } from "./messenger/ask.js";
|
|
18
|
-
import { manifestBaseUrl, nextPage, parameterValue, signRequest, } from "./service-api-manifest.js";
|
|
18
|
+
import { manifestBaseUrl, nextPage, parameterValue, signRequest, underBase, } from "./service-api-manifest.js";
|
|
19
19
|
/**
|
|
20
20
|
* The operations the `api` group offers, and why it leaves out the rest: one that answers with a credential needs a
|
|
21
21
|
* bot's `--store-token`, as a service CLI signs in through `session`; a body other than JSON or an upload's bytes (a
|
|
@@ -40,23 +40,36 @@ const permissionsOf = (operation) => operation.permissions ?? [];
|
|
|
40
40
|
const destructive = (operation) => operation.effect === "destructive" || (operation.binding.kind === "http" && operation.binding.method === "DELETE");
|
|
41
41
|
const flagsOf = ({ body = [], query = [] }) => [...body, ...query];
|
|
42
42
|
const valuesOf = ({ values = {} }) => Object.entries(values);
|
|
43
|
-
|
|
43
|
+
const unlessOf = ({ unless = {} }) => Object.entries(unless);
|
|
44
|
+
/**
|
|
45
|
+
* Always, unless its flags or values name when; `with status publish or future`, `with archived set`, `with status
|
|
46
|
+
* publish or future or date set, unless status draft or pending`.
|
|
47
|
+
*/
|
|
44
48
|
const whenOf = (permission) => {
|
|
45
49
|
const flags = flagsOf(permission);
|
|
46
50
|
const values = valuesOf(permission).map(([field, listed]) => `${field} ${listed.join(" or ")}`);
|
|
47
51
|
if (flags.length === 0 && values.length === 0)
|
|
48
52
|
return undefined;
|
|
49
|
-
|
|
53
|
+
const unless = unlessOf(permission).map(([field, listed]) => `${field} ${listed.join(" or ")}`);
|
|
54
|
+
return `with ${[...values, ...(flags.length > 0 ? [`${flags.join(" or ")} set`] : [])].join(" or ")}${unless.length > 0 && flags.length > 0 ? `, unless ${unless.join(" or ")}` : ""}`;
|
|
50
55
|
};
|
|
51
56
|
/** A body field or query parameter holding one of the values: WordPress publishes from either. */
|
|
52
57
|
const holds = (value, listed) => typeof value === "string" && listed.includes(value);
|
|
53
58
|
/** A flag counts unless it is absent or plainly false: a service may read `1` or `True` as true. */
|
|
54
59
|
const set = (value) => value !== undefined && value !== null && value !== false && value !== "false";
|
|
55
60
|
/** Whether a manifest key applies to this call: always, or when one of its flags is set or a field holds a value. */
|
|
56
|
-
const applies = (permission, body, input) =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
const applies = (permission, body, input) => {
|
|
62
|
+
const sends = ([field, listed]) => (isObject(body) && holds(body[field], listed)) || holds(input.query[field], listed);
|
|
63
|
+
// Beside a value, a field is another door to the same change and counts once sent at all: WordPress resets a `date`
|
|
64
|
+
// sent as null to now, which publishes a scheduled post. Either place, as WordPress merges the query with the body.
|
|
65
|
+
const sent = permission.values === undefined ? set : (value) => value !== undefined;
|
|
66
|
+
const flagged = flagsOf(permission).some((name) => (isObject(body) && sent(body[name])) || sent(input.query[name]));
|
|
67
|
+
// `unless` lifts only the flags: WordPress keeps a draft a draft whatever its date, and a call that names no status
|
|
68
|
+
// may move a scheduled post's date into the past, which publishes it.
|
|
69
|
+
return (whenOf(permission) === undefined ||
|
|
70
|
+
valuesOf(permission).some(sends) ||
|
|
71
|
+
(flagged && !unlessOf(permission).some(sends)));
|
|
72
|
+
};
|
|
60
73
|
/** The keys one call checks beside `api.<operation>`: the manifest's that apply, and the CLI's from the body. */
|
|
61
74
|
export const serviceApiKeys = (input, operation, call) => {
|
|
62
75
|
const body = call.body?.trim() ? parseApiJson(call.body) : undefined;
|
|
@@ -120,7 +133,11 @@ const API_QUERY = {
|
|
|
120
133
|
* when `permanently` is true); the journal records that it ran, never its body. A read that pages takes `--all`. There
|
|
121
134
|
* is no free-form `api call`: a request is always one operation of the spec, with its own key (SEC-196).
|
|
122
135
|
*/
|
|
123
|
-
|
|
136
|
+
/**
|
|
137
|
+
* What the `api` group and `serviceApiWriter` share, so a write from code passes the very guard a command's does: the
|
|
138
|
+
* offered operations, the server, the sign-in, the levels, and the guarded send.
|
|
139
|
+
*/
|
|
140
|
+
const serviceApiCore = (options) => {
|
|
124
141
|
const { app, configuration, manifest } = options;
|
|
125
142
|
const { offered: operations, left } = serviceApiOperations(manifest);
|
|
126
143
|
// Without variables the server is known now, and a CLI built against a manifest it cannot reach fails at once.
|
|
@@ -139,13 +156,7 @@ export const serviceApiCommand = (options) => {
|
|
|
139
156
|
.filter(({ key }) => !named.has(key));
|
|
140
157
|
if (unnamed.length > 0)
|
|
141
158
|
throw new CliError("configuration_error", `bodyPermissions name ${unnamed.map(({ key }) => key).join(", ")}, which the manifest does not: the keys come from \`permissions\``);
|
|
142
|
-
|
|
143
|
-
const loaded = () => {
|
|
144
|
-
if (!schemas)
|
|
145
|
-
throw new CliError("configuration_error", "the api schemas were not loaded before the command ran");
|
|
146
|
-
return schemas;
|
|
147
|
-
};
|
|
148
|
-
const send = httpApiSend({
|
|
159
|
+
const exchange = httpApiExchange({
|
|
149
160
|
service: options.service,
|
|
150
161
|
fetch: options.fetch,
|
|
151
162
|
...(options.failure ? { failure: options.failure } : {}),
|
|
@@ -162,19 +173,53 @@ export const serviceApiCommand = (options) => {
|
|
|
162
173
|
};
|
|
163
174
|
const signed = async (command, operation, request) => {
|
|
164
175
|
const { token } = options;
|
|
176
|
+
const baseUrl = baseUrlOf(command);
|
|
177
|
+
if (!underBase(request.url, baseUrl))
|
|
178
|
+
throw new CliError("validation_error", `${operation.command} would leave ${baseUrl}`, { sent: false });
|
|
165
179
|
await signRequest(manifest, operation, request, token && (() => token(command)));
|
|
180
|
+
// A site's sign-in follows no redirect: the host is shared with other sites, and only its path tells them apart.
|
|
181
|
+
if (options.serverVariables)
|
|
182
|
+
request.redirect = "manual";
|
|
166
183
|
for (const [name, value] of Object.entries(options.headers?.(command, operation) ?? {}))
|
|
167
184
|
request.headers.set(name, value);
|
|
168
185
|
return request;
|
|
169
186
|
};
|
|
170
|
-
|
|
171
|
-
|
|
187
|
+
// `own` is the call's own key (`api.<operation>`), asked with the others when the caller confirmed some.
|
|
188
|
+
const guardOf = (command, extra, confirmed = [], own) => {
|
|
189
|
+
const { settings, env, renderer } = baseContext(command, configuration.resolveSettings);
|
|
190
|
+
const levelOf = (key) => levelFor(settings.permissions, key, defaults).level;
|
|
191
|
+
const asker = terminalAsker(command);
|
|
192
|
+
return keyedGuard((ask) => guardFor(app, { ...settings, sendsPerHour: Number.MAX_SAFE_INTEGER, permissionDefaults: defaults }, renderer.warn, env, ask), confirmed.length === 0
|
|
193
|
+
? asker
|
|
194
|
+
: async (_key, asked) => {
|
|
195
|
+
// A caller that already asked about a key in this run is not asked again; `deny` and `readonly` still
|
|
196
|
+
// stop it.
|
|
197
|
+
const asking = [...(own ? [own] : []), ...extra].filter((key) => levelOf(key) === "ask" && !confirmed.includes(key));
|
|
198
|
+
if (asking.length > 0)
|
|
199
|
+
await asker(asking.join(" and "), asked);
|
|
200
|
+
}, levelOf, extra);
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* A read whose keys all allow it is sent as a read, `--all` included; `deny` refuses it here, and `ask` makes it ask
|
|
204
|
+
* as a write does. So a CLI can put its CRM command's read key (`people.list`) on the raw read.
|
|
205
|
+
*/
|
|
206
|
+
const readsFreely = (command, operation, extra) => {
|
|
207
|
+
if (operation.effect !== "read")
|
|
208
|
+
return false;
|
|
209
|
+
if (extra.length === 0)
|
|
210
|
+
return true;
|
|
211
|
+
guardOf(command, extra).refuse({ chatId: null, kind: "edit", key: keyOf(operation), operationId: newOperationId() });
|
|
212
|
+
const { settings } = baseContext(command, configuration.resolveSettings);
|
|
213
|
+
return extra.every((key) => levelFor(settings.permissions, key, defaults).level !== "ask");
|
|
214
|
+
};
|
|
215
|
+
const write = async (command, operation, extra, request, confirmed = []) => {
|
|
216
|
+
const { run } = baseContext(command, configuration.resolveSettings);
|
|
172
217
|
const operationId = newOperationId();
|
|
173
|
-
const guard =
|
|
218
|
+
const guard = guardOf(command, extra, confirmed, keyOf(operation));
|
|
174
219
|
const guarded = { chatId: null, kind: "edit", key: keyOf(operation), operationId };
|
|
175
220
|
guard.refuse(guarded);
|
|
176
221
|
try {
|
|
177
|
-
const result = await guardedWrite(guard, guarded, () => run(() =>
|
|
222
|
+
const result = await guardedWrite(guard, guarded, () => run(async () => (await exchange(command, operation, request)).answer));
|
|
178
223
|
return { operation_id: operationId, result };
|
|
179
224
|
}
|
|
180
225
|
catch (error) {
|
|
@@ -183,11 +228,25 @@ export const serviceApiCommand = (options) => {
|
|
|
183
228
|
throw error;
|
|
184
229
|
}
|
|
185
230
|
};
|
|
186
|
-
|
|
231
|
+
return { operations, left, baseUrlOf, defaults, exchange, operationOf, readsFreely, signed, write };
|
|
232
|
+
};
|
|
233
|
+
export const serviceApiCommand = (options) => {
|
|
234
|
+
const { app, configuration } = options;
|
|
235
|
+
const { operations, baseUrlOf, exchange, operationOf, readsFreely, signed, write } = serviceApiCore(options);
|
|
236
|
+
const send = async (command, operation, request) => (await exchange(command, operation, request)).answer;
|
|
237
|
+
let schemas;
|
|
238
|
+
const loaded = () => {
|
|
239
|
+
if (!schemas)
|
|
240
|
+
throw new CliError("configuration_error", "the api schemas were not loaded before the command ran");
|
|
241
|
+
return schemas;
|
|
242
|
+
};
|
|
243
|
+
/** Every page, in one run; a next page outside the server's address is never sent the sign-in. */
|
|
187
244
|
const allPages = async (command, operation, input) => {
|
|
188
245
|
const pagination = operation.pagination;
|
|
189
|
-
// Services number pages from 0 or from 1, and the manifest
|
|
190
|
-
if (pagination.style === "page" &&
|
|
246
|
+
// Services number pages from 0 or from 1, and the manifest says which only where the source did.
|
|
247
|
+
if (pagination.style === "page" &&
|
|
248
|
+
pagination.start === undefined &&
|
|
249
|
+
parameterValue(input, pagination.page) === undefined)
|
|
191
250
|
throw new CliError("validation_error", `--all on ${operation.command} needs the first page: give --${pagination.page.name} 0 or 1, as ${options.service} counts`);
|
|
192
251
|
const items = [];
|
|
193
252
|
const asked = new Set();
|
|
@@ -207,15 +266,16 @@ export const serviceApiCommand = (options) => {
|
|
|
207
266
|
if (asked.has(key))
|
|
208
267
|
throw new CliError("invalid_response", `${options.service} gave the same next page twice; nothing more read`);
|
|
209
268
|
asked.add(key);
|
|
210
|
-
const
|
|
269
|
+
const { answer, headers } = await exchange(command, operation, request);
|
|
270
|
+
const step = nextPage(pagination, call, answer, headers);
|
|
211
271
|
for (const item of step.items)
|
|
212
272
|
items.push(item);
|
|
213
273
|
if (!step.next)
|
|
214
274
|
return;
|
|
215
275
|
if ("url" in step.next) {
|
|
216
276
|
url = new URL(step.next.url, request.url);
|
|
217
|
-
if (url
|
|
218
|
-
throw new CliError("invalid_response", `${options.service} pointed the next page
|
|
277
|
+
if (!underBase(url, baseUrl))
|
|
278
|
+
throw new CliError("invalid_response", `${options.service} pointed the next page outside ${baseUrl}`);
|
|
219
279
|
}
|
|
220
280
|
else
|
|
221
281
|
call = step.next.input;
|
|
@@ -245,13 +305,14 @@ export const serviceApiCommand = (options) => {
|
|
|
245
305
|
},
|
|
246
306
|
execute: async (command, operation, input) => {
|
|
247
307
|
const extra = serviceApiKeys(options, operation, input);
|
|
308
|
+
const read = readsFreely(command, operation, extra);
|
|
248
309
|
if (operation.pagination && command.opts().all === true) {
|
|
249
|
-
if (
|
|
310
|
+
if (!read)
|
|
250
311
|
throw new CliError("validation_error", `--all reads only; this call of ${operation.command} is guarded by ${extra.join(", ") || "its write"}`);
|
|
251
312
|
return allPages(command, operation, input);
|
|
252
313
|
}
|
|
253
314
|
const request = await signed(command, operation, httpApiRequest(operation, input, baseUrlOf(command)));
|
|
254
|
-
const answer =
|
|
315
|
+
const answer = read
|
|
255
316
|
? await baseContext(command, configuration.resolveSettings).run(() => send(command, operation, request))
|
|
256
317
|
: await write(command, operation, extra, request);
|
|
257
318
|
renderAnswer(command, outputFor(command), itemOf(answer));
|
|
@@ -296,3 +357,50 @@ export const serviceApiCommand = (options) => {
|
|
|
296
357
|
}
|
|
297
358
|
return group;
|
|
298
359
|
};
|
|
360
|
+
// Code may pass a number, a boolean or a list where a person types text; the check reads the text it stands for.
|
|
361
|
+
const flagText = (raw) => (Array.isArray(raw) ? raw.join(",") : String(raw));
|
|
362
|
+
/** The body as the command checks it: an upload and an rpc call as given, GraphQL's flags joined to its variables. */
|
|
363
|
+
const writerBody = (operation, input, schemas) => {
|
|
364
|
+
if (sendsBytes(operation) || operation.binding.kind === "rpc")
|
|
365
|
+
return input;
|
|
366
|
+
const graphql = operation.binding.kind === "graphql";
|
|
367
|
+
const given = graphql ? apiJson(graphqlVariables(operation, input.body, input.fields ?? {})) : input.body;
|
|
368
|
+
const body = checkApiBody(operation, given, schemas);
|
|
369
|
+
return { ...input, ...(graphql ? { fields: {} } : {}), ...(body === undefined ? {} : { body }) };
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* The `api` group's write path for code that is not one of its commands: the same keys (`api.<operation>` and each
|
|
373
|
+
* manifest key the call sets off, as `posts.publish`), levels, question and journal line, so a writer is never a
|
|
374
|
+
* looser door than the command. `command` is the one running, which carries the profile and says whether a terminal
|
|
375
|
+
* can be asked. A read that no key guards goes through `serviceApiCall`.
|
|
376
|
+
*/
|
|
377
|
+
export const serviceApiWriter = (options) => {
|
|
378
|
+
const { baseUrlOf, operationOf, signed, write } = serviceApiCore(options);
|
|
379
|
+
return async (command, name, input, { confirmed } = {}) => {
|
|
380
|
+
const operation = operationOf(name);
|
|
381
|
+
// The api group offers only declared parameters; code must not reach further, as WordPress's `_method` turns a
|
|
382
|
+
// write into a delete that no delete key guards.
|
|
383
|
+
const undeclared = Object.keys(input.query).filter((one) => !operation.parameters.some((parameter) => parameter.in === "query" && parameter.name === one));
|
|
384
|
+
const overriding = Object.keys(input.headers ?? {}).filter((one) => !operation.parameters.some((parameter) => parameter.in === "header" && parameter.name.toLowerCase() === one.toLowerCase()));
|
|
385
|
+
if (undeclared.length > 0 || overriding.length > 0)
|
|
386
|
+
throw new CliError("configuration_error", `${operation.command} does not take ${[...undeclared, ...overriding].join(", ")}`, { sent: false });
|
|
387
|
+
const extra = serviceApiKeys(options, operation, input);
|
|
388
|
+
if (operation.effect === "read" && extra.length === 0)
|
|
389
|
+
throw new CliError("configuration_error", `${operation.command} is a read; send it with serviceApiCall`);
|
|
390
|
+
// The checks the command runs on what a person typed, so code sends nothing a person could not.
|
|
391
|
+
const schemas = await options.schemas();
|
|
392
|
+
const headers = Object.entries(input.headers ?? {});
|
|
393
|
+
for (const parameter of operation.parameters) {
|
|
394
|
+
const raw = parameter.in === "header"
|
|
395
|
+
? headers.find(([one]) => one.toLowerCase() === parameter.name.toLowerCase())?.[1]
|
|
396
|
+
: parameter.in === "query" || parameter.in === "path"
|
|
397
|
+
? input[parameter.in][parameter.name]
|
|
398
|
+
: undefined;
|
|
399
|
+
const problem = raw === undefined ? undefined : checkApiParameter(parameter.name, parameter.schema, flagText(raw), schemas);
|
|
400
|
+
if (problem)
|
|
401
|
+
throw new CliError("validation_error", problem);
|
|
402
|
+
}
|
|
403
|
+
const request = await signed(command, operation, httpApiRequest(operation, writerBody(operation, input, schemas), baseUrlOf(command)));
|
|
404
|
+
return write(command, operation, extra, request, confirmed);
|
|
405
|
+
};
|
|
406
|
+
};
|
|
@@ -52,8 +52,11 @@ export interface ManifestVerifyOptions {
|
|
|
52
52
|
service: string;
|
|
53
53
|
/** The config's `auth.verify`: the operation, where its answer holds the id and a name, and whether it is live. */
|
|
54
54
|
verify: CliVerify;
|
|
55
|
-
/**
|
|
56
|
-
|
|
55
|
+
/**
|
|
56
|
+
* The command's host-checked fetch, such as `hostsFetch(hosts, environment.fetch)`. `site` is the one `session start
|
|
57
|
+
* --site` names, for a service on the owner's own site: its host is not among the CLI's own.
|
|
58
|
+
*/
|
|
59
|
+
fetch: (command: Command, site: string | undefined) => FetchLike;
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
62
|
* `verify` for `tokenSessionCommand` from a config's `auth.verify`: the one operation is sent with the token, a token the
|
|
@@ -16,8 +16,14 @@ import { siteValue } from "./service-api-manifest.js";
|
|
|
16
16
|
* `verify` for `tokenSessionCommand` from a config's `auth.verify`: the one operation is sent with the token, a token the
|
|
17
17
|
* answer does not call active is refused, and the account is the id and name the answer holds.
|
|
18
18
|
*/
|
|
19
|
-
export const manifestVerify = ({ manifest, service, verify, fetch }) => async (command, token) => {
|
|
20
|
-
const call = serviceApiCall({
|
|
19
|
+
export const manifestVerify = ({ manifest, service, verify, fetch }) => async (command, token, _events, site) => {
|
|
20
|
+
const call = serviceApiCall({
|
|
21
|
+
manifest,
|
|
22
|
+
service,
|
|
23
|
+
fetch: fetch(command, site),
|
|
24
|
+
token: () => token,
|
|
25
|
+
...(site === undefined ? {} : { serverVariables: { site } }),
|
|
26
|
+
});
|
|
21
27
|
const answer = await call(verify.operation, { path: {}, query: {}, headers: {}, fields: {} });
|
|
22
28
|
// A service such as Attio answers a revoked key with 200 and `active: false`, not with 401.
|
|
23
29
|
if (verify.active !== undefined && valueAt(answer, verify.active) !== true)
|
|
@@ -86,7 +92,9 @@ export const tokenSessionCommand = (options) => {
|
|
|
86
92
|
throw new CliError("validation_error", "a user name with a colon cannot sign in");
|
|
87
93
|
refuseOffline(this, service);
|
|
88
94
|
const page = options.login?.page?.(site);
|
|
89
|
-
|
|
95
|
+
const input = secretInputOf(this).input ?? process.stdin;
|
|
96
|
+
// Only a person at a terminal pastes it; piped in, the note would stand before the answer on stderr.
|
|
97
|
+
if (page && input.isTTY)
|
|
90
98
|
renderer.note(`the ${word} of ${login}: make one at ${page}, then paste it here`);
|
|
91
99
|
// A secret is never an argument: it would land in shell history and in the run record (WC-SECR-5).
|
|
92
100
|
const secret = (await readSecret(`${service} ${word}: `, secretInputOf(this))).trim();
|
|
@@ -175,6 +183,7 @@ export const signedInSite = (app, resolveSettings) => {
|
|
|
175
183
|
const site = tokens.readWith(settings.profile, SITE)?.secret;
|
|
176
184
|
if (site === undefined)
|
|
177
185
|
throw noSite(app, settings.profile);
|
|
178
|
-
|
|
186
|
+
// <PREFIX>_TOKEN_SITE skips session start's cleaning, and `host/blog/..` would be the root site.
|
|
187
|
+
return { site: siteValue(site) };
|
|
179
188
|
};
|
|
180
189
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Command } from "commander";
|
|
2
|
+
import type { AppIdentity } from "../../ports/app.js";
|
|
3
|
+
import type { MessageStore } from "../../store/store.js";
|
|
4
|
+
import type { AccountKey } from "../../store/types.js";
|
|
5
|
+
import type { ContentSource } from "../source.js";
|
|
6
|
+
import { type ContentWrites } from "../writes.js";
|
|
7
|
+
/** The selected profile's content account, opened for one command and closed before its answer is printed. */
|
|
8
|
+
export interface ContentRun {
|
|
9
|
+
account: AccountKey;
|
|
10
|
+
store: MessageStore;
|
|
11
|
+
/** The source, built on first use: a command that only reads the store never reads the sign-in. */
|
|
12
|
+
source: () => ContentSource;
|
|
13
|
+
/** The writer and the profile's levels, built on first use; absent, the profile cannot write. */
|
|
14
|
+
/** The writes of the invoking command: a manifest writer sends through `serviceApiWriter` bound to it. */
|
|
15
|
+
writes?: (command: Command) => ContentWrites;
|
|
16
|
+
env?: NodeJS.ProcessEnv;
|
|
17
|
+
close?: () => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export interface ContentCommandOptions {
|
|
20
|
+
app: AppIdentity;
|
|
21
|
+
/** Opens the selected profile for one command; `readOnly` when the command only reads the store. */
|
|
22
|
+
open: (command: Command, access: {
|
|
23
|
+
readOnly: boolean;
|
|
24
|
+
}) => Promise<ContentRun>;
|
|
25
|
+
/** Mounts `posts create|update|publish|schedule|unpublish|delete`. */
|
|
26
|
+
writes?: boolean;
|
|
27
|
+
now?: () => number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The content commands: `sync`, `channels list`, `posts list|show|search`, `authors list`, `terms list`,
|
|
31
|
+
* `metrics show`, and with `writes` `posts create|update|publish|schedule|unpublish|delete`.
|
|
32
|
+
*/
|
|
33
|
+
export declare const addContentCommands: (program: Command, options: ContentCommandOptions) => void;
|