@wirecat/cli-base 0.116.0 → 0.118.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 +90 -0
- package/dist/codegen/discovery.js +1 -10
- package/dist/codegen/fake.js +30 -5
- package/dist/codegen/graphql.js +1 -9
- package/dist/codegen/index.d.ts +3 -2
- package/dist/codegen/index.js +3 -2
- package/dist/codegen/manifest.js +6 -2
- package/dist/codegen/model.d.ts +9 -1
- package/dist/codegen/openapi.js +34 -3
- package/dist/codegen/pipeline.d.ts +12 -0
- package/dist/codegen/pipeline.js +53 -5
- package/dist/codegen/sign-in.d.ts +3 -1
- package/dist/codegen/sign-in.js +9 -2
- package/dist/codegen/snapshot.d.ts +4 -0
- package/dist/codegen/snapshot.js +11 -0
- package/dist/codegen/wp-json.d.ts +49 -0
- package/dist/codegen/wp-json.js +333 -0
- package/dist/dev/family.js +1 -0
- package/dist/standards/audit.js +4 -2
- package/dist/standards/vocabulary.js +4 -0
- package/dist/wcat/manifest.d.ts +42 -0
- package/dist/wcat/manifest.js +34 -1
- package/docs/standards/README.md +1 -1
- package/docs/standards/architecture.md +6 -1
- package/docs/standards/ci.md +1 -0
- package/docs/standards/commands.md +9 -4
- package/docs/standards/kit-surface.md +17 -5
- package/docs/standards/mcp.md +20 -1
- package/docs/standards/new-cli.md +16 -5
- package/docs/standards/security.md +42 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,96 @@ Versions before 0.8.0 are in the [git tags](https://github.com/WireCatLabs/cli-b
|
|
|
8
8
|
Every entry says what changed as a caller sees it, why, and what to watch for — the rules are
|
|
9
9
|
[`docs/dev/CONVENTIONS.md`](docs/dev/CONVENTIONS.md#the-changelog).
|
|
10
10
|
|
|
11
|
+
## 0.118.0 — 18.11.2026
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **A WordPress API from the site's own index: `syncWpJson`, `readWpJson` and `wpJsonToOpenApi`.** WordPress has no
|
|
16
|
+
OpenAPI, but `/wp-json/?context=help` lists every route with its arguments and the schema of its answer.
|
|
17
|
+
`syncWpJson` keeps that one answer, without the site's name, address and links, with its provenance;
|
|
18
|
+
`wpJsonToOpenApi` turns the routes of the namespaces a CLI offers into OpenAPI 3.1 for `adaptOpenApi`. WordPress
|
|
19
|
+
6.9.4's `wp/v2` gives 152 operations (`getWpV2Posts`, `postWpV2PostsById`…). A route whose value may hold a slash
|
|
20
|
+
(templates, plugins, fonts) is left out and listed in `omissions`. Watch for: an array argument in the query is
|
|
21
|
+
one comma-separated string, as WordPress splits it and PHP keeps only the last of a repeated name, so it loses
|
|
22
|
+
its `enum`; WordPress's lists
|
|
23
|
+
page by headers, so `pagination: true` finds no paging for them yet.
|
|
24
|
+
- **A permission key from a field's value: `permissions.valueKeys`.** `{ key: "publish", field: "status", values:
|
|
25
|
+
["publish", "future"] }` gives `posts.publish` to a write that sends `status: "publish"`, in the body or the query,
|
|
26
|
+
so a profile that denies publishing also stops the raw `api` group. Where the field defaults to such a value
|
|
27
|
+
(WordPress's templates, template parts and menu items), the key applies on every call, as leaving the field out
|
|
28
|
+
publishes. `OperationPermission.values` carries it in the manifest, and the coverage page's "When" says `` `status` is publish or future ``. Watch for: cli-core checks
|
|
29
|
+
`values` only from the release that reads them; an older cli-core asks for the key on every call of that operation,
|
|
30
|
+
as it does for a key with no flags.
|
|
31
|
+
|
|
32
|
+
## 0.117.0 — 18.11.2026
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
|
|
36
|
+
- **The command vocabulary has a tracker's nouns: `issues`, `teams`, `states` and `labels`.** cli-core's tracker
|
|
37
|
+
commands (`issues list`, `teams list`…) name them, so `cli-dev lint` passes a tracker CLI's command tree. `labels`
|
|
38
|
+
are a tracker's own, shared by its users; `tags` stay the labels the owner puts on things.
|
|
39
|
+
- **A CLI can say how Desktop signs it in, in Desktop's own window.** `ManifestIdentity.signIn` takes an optional
|
|
40
|
+
`methods` list, each `{ id, label, words, stdin? }`, and `cli-dev manifest` writes it to `desktop.signIn.methods`.
|
|
41
|
+
Until now an own tool could only be signed in at a terminal. `words` start with `{profile}` and name a command the
|
|
42
|
+
CLI has; `stdin: true` says the secret the person types is the command's whole stdin. Nothing else (a password
|
|
43
|
+
variable, a client file, OAuth words) is accepted, because Desktop does not take those from a tool it did not build.
|
|
44
|
+
Watch for: a manifest without `methods` is byte-for-byte as before; one with it needs a Desktop that shows a token
|
|
45
|
+
field for a `stdin` method.
|
|
46
|
+
- **ydisk (`@wirecat/yandex-disk-cli`) joins the shared lists.** It is in `PARITY_GROUPS`' `shared-roots` group, beside
|
|
47
|
+
notion, so `cli-dev audit --family` installs its latest release and compares the root commands every CLI shares. Its
|
|
48
|
+
monthly run holds 03:04 UTC in WC-CI-9's table. Watch for: a CLI's `--family` audit now installs one more package.
|
|
49
|
+
- **The handbook has a rule for a provider token the owner pastes, WC-SECR-26.** Yandex Disk, for one, gives the
|
|
50
|
+
owner a token to copy instead of a sign-in a CLI can run. The rule says how `session start` reads it (hidden at a
|
|
51
|
+
terminal or from stdin, never an argument), checks it with the service before keeping it, keeps it in the keyring
|
|
52
|
+
through cli-core's `ProfileTokenStore`, and what `session status --check`, `doctor --online` and `session end` do.
|
|
53
|
+
Watch for: a CLI with such a sign-in checks its `session end` and docs against the "Revoked" line.
|
|
54
|
+
- **WC-MCP-9 covers the MCP Registry entry.** A `server.json` passes `--profiles` as a required argument with a
|
|
55
|
+
placeholder such as `personal`, never a fixed `all`, and leaves its versions to `release.yml`. Watch for: tg, max,
|
|
56
|
+
wa, zm, gcal, drive, notion, mail, pbx, b24, amo, hubspot and cli-template shipped `--profiles all`; each now passes the
|
|
57
|
+
required argument.
|
|
58
|
+
|
|
59
|
+
### Changed — may break callers
|
|
60
|
+
|
|
61
|
+
- **`signInPlace` signs an HTTP `basic` scheme**, as `Authorization: Basic <base64>` of a `<user>:<password>` token,
|
|
62
|
+
and marks the place `basic: true`; it returned `undefined` before. WordPress application passwords are Basic, and a
|
|
63
|
+
CLI's tests need `fakeApi` to take them. Watch for: a caller that told Basic apart by `undefined`, as cli-core's `api`
|
|
64
|
+
group up to 0.695.0 does, must read `place.basic` instead. Until it does, a call that offers Basic and a token may
|
|
65
|
+
be signed with Basic, and a token with no `:` is no longer refused. The caller keeps that check: `value` never throws.
|
|
66
|
+
Digest is still `undefined`.
|
|
67
|
+
- **A sample of a union takes the branch with the most required fields, not the first.** Attio's `GET /v2/self`
|
|
68
|
+
answers `{ active: false }` first, so `fakeApi` answered a sign-in check without the workspace's id. Watch for: a
|
|
69
|
+
test that reads a sampled union, in `fakeApi` or the GraphQL fake, now sees the larger branch. A field typed
|
|
70
|
+
`string | { id }` samples as the object; Notion's description samples 92 of its 609 definitions differently, while
|
|
71
|
+
HubSpot's, ydisk's, Drive's and Calendar's sample as before.
|
|
72
|
+
|
|
73
|
+
### Fixed
|
|
74
|
+
|
|
75
|
+
- **`fakeApi` refuses a token sent to another host in base64 too**, in a header or a query string, as Basic sends it,
|
|
76
|
+
not only as the raw token.
|
|
77
|
+
- **The New CLI page lists every shared list a new WireCat CLI joins, with the file and when.** It left out the family
|
|
78
|
+
audit's package map, `PACKAGES` in `src/dev/family.ts`, so a new CLI's neighbours never installed it for
|
|
79
|
+
`cli-dev audit --family`.
|
|
80
|
+
- **The Kit surface page no longer says that nothing checks the permission keys.** cli-core's `serviceApiCommand`
|
|
81
|
+
checks each operation's keys from 0.684.0; the page now says so, and that `--dry-run` shows them once the CLI merges
|
|
82
|
+
`serviceApiPermissions` into its `commandPermissions`. It also no longer says that cli-core cannot read every page:
|
|
83
|
+
`--all` does.
|
|
84
|
+
- **WC-CMD-29 says what it requires of a CLI's name: the `wcat-<name>` key.** A short name beside it, as every WireCat
|
|
85
|
+
CLI installs, is fine; the lint's warning about it is not a failure, and an override only silences it.
|
|
86
|
+
- **WC-ARCH-5 names a known gap:** drive's and ydisk's live `files` groups are hand-written in each CLI until cli-core
|
|
87
|
+
has a shared files domain.
|
|
88
|
+
- **Publishing no longer tells a CLI to pass `--profiles all` in `server.json`.**
|
|
89
|
+
- **`names: { fromPath: true }` names a PUT on a collection `-upsert` when a PUT on its item exists too.** Attio's
|
|
90
|
+
`PUT /v2/objects/{object}/records` (create or update by a unique value) and `PUT …/records/{record_id}` both became
|
|
91
|
+
`objects-records-replace`, and generation stopped. Watch for: a CLI that named one of such a pair in
|
|
92
|
+
`names.commands` to avoid the clash now gets `-upsert` for the other.
|
|
93
|
+
- **A string with a `pattern` gets a sample the pattern and its length bounds take.** A pattern of groups,
|
|
94
|
+
alternatives or a `.` (Attio's `^https:\/\/.*` and ISO 8601 durations) fell back to `xxxxxx`, which the strict fake
|
|
95
|
+
then refused.
|
|
96
|
+
- **The OpenAPI adapter reads `prefixItems`, an `allOf` of unions of plain values, and skips `minProperties` and
|
|
97
|
+
`maxProperties`.** Each stopped generation for Attio's description. A tuple is read as a list of its places, an
|
|
98
|
+
`allOf` of unions with no object in any branch as its first member; one with an object is still refused. A closed
|
|
99
|
+
tuple (`items: false`) is still refused.
|
|
100
|
+
|
|
11
101
|
## 0.116.0 — 17.11.2026
|
|
12
102
|
|
|
13
103
|
### Changed — may break callers
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* Strict like `adaptOpenApi`: an unknown schema keyword, format or parameter location stops generation.
|
|
7
7
|
* Effects come from the HTTP verb; a method the verb misjudges is corrected with `generate`'s `overrides`.
|
|
8
8
|
*/
|
|
9
|
-
import { createHash } from "node:crypto";
|
|
10
9
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
10
|
import { join } from "node:path";
|
|
12
11
|
import { CodegenError } from "./pipeline.js";
|
|
12
|
+
import { sha256, sortKeys } from "./snapshot.js";
|
|
13
13
|
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
14
14
|
/** Discovery links point at developers.google.com without the host, which breaks them in generated Markdown. */
|
|
15
15
|
const description = (value) => String(value ?? "").replace(/\]\((\/workspace\/[^)]+)\)/g, "](https://developers.google.com$1)");
|
|
@@ -249,15 +249,6 @@ export const adaptDiscovery = (documents, options = {}) => {
|
|
|
249
249
|
services,
|
|
250
250
|
};
|
|
251
251
|
};
|
|
252
|
-
const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
253
|
-
/** Google serves the same revision with its keys in a different order each time; arrays keep theirs. */
|
|
254
|
-
const sortKeys = (value) => Array.isArray(value)
|
|
255
|
-
? value.map(sortKeys)
|
|
256
|
-
: object(value)
|
|
257
|
-
? Object.fromEntries(Object.keys(value)
|
|
258
|
-
.sort()
|
|
259
|
-
.map((key) => [key, sortKeys(value[key])]))
|
|
260
|
-
: value;
|
|
261
252
|
const NORMALIZATION = "object keys sorted, 2-space JSON; values and array order unchanged";
|
|
262
253
|
/**
|
|
263
254
|
* Downloads each Discovery document, sorts its object keys so the same revision always gives the same file, and
|
package/dist/codegen/fake.js
CHANGED
|
@@ -155,8 +155,12 @@ const patternSample = (pattern) => {
|
|
|
155
155
|
return undefined;
|
|
156
156
|
at += 2;
|
|
157
157
|
}
|
|
158
|
-
else if ("()
|
|
158
|
+
else if ("()|".includes(char))
|
|
159
159
|
return undefined;
|
|
160
|
+
else if (char === ".") {
|
|
161
|
+
atom = "x";
|
|
162
|
+
at += 1;
|
|
163
|
+
}
|
|
160
164
|
else {
|
|
161
165
|
atom = char;
|
|
162
166
|
at += 1;
|
|
@@ -170,6 +174,9 @@ const patternSample = (pattern) => {
|
|
|
170
174
|
const sample = atoms.join("");
|
|
171
175
|
return regexOf(pattern)?.test(sample) ? sample : undefined;
|
|
172
176
|
};
|
|
177
|
+
const requiredCount = (node, definitions) => objectParts(node, definitions)?.required.length ?? 0;
|
|
178
|
+
// Strings a pattern made of groups or alternatives often takes: a link, an ISO duration and date, a number, a word.
|
|
179
|
+
const GUESSES = ["https://example.com", "P1D", "2026-01-01", "0", "000000", "x", "example", "a@example.com"];
|
|
173
180
|
/** A value the schema accepts: the first enum value, the minimum, one array item, every object field. */
|
|
174
181
|
export const sampleOf = (node, definitions, seen = new Set()) => {
|
|
175
182
|
switch (node.type) {
|
|
@@ -178,8 +185,11 @@ export const sampleOf = (node, definitions, seen = new Set()) => {
|
|
|
178
185
|
// A schema that contains itself stops at its first repeat.
|
|
179
186
|
return target && !seen.has(node.ref) ? sampleOf(target, definitions, new Set([...seen, node.ref])) : null;
|
|
180
187
|
}
|
|
181
|
-
case "union":
|
|
182
|
-
|
|
188
|
+
case "union": {
|
|
189
|
+
// The branch that asks the most: a first branch such as `{ active: false }` would leave out what a reader needs.
|
|
190
|
+
const [best] = [...node.of].sort((a, b) => requiredCount(b, definitions) - requiredCount(a, definitions));
|
|
191
|
+
return best ? sampleOf(best, definitions, seen) : null;
|
|
192
|
+
}
|
|
183
193
|
case "allOf": {
|
|
184
194
|
const parts = objectParts(node, definitions);
|
|
185
195
|
return parts ? sampleOf({ type: "object", ...parts }, definitions, seen) : null;
|
|
@@ -190,7 +200,14 @@ export const sampleOf = (node, definitions, seen = new Set()) => {
|
|
|
190
200
|
if (node.format === "binary")
|
|
191
201
|
return "attach://xxxxxx";
|
|
192
202
|
const plain = "x".repeat(Math.max(node.minLength ?? 6, 1)).slice(0, node.maxLength ?? 64);
|
|
193
|
-
|
|
203
|
+
if (node.pattern === undefined)
|
|
204
|
+
return plain;
|
|
205
|
+
const pattern = regexOf(node.pattern);
|
|
206
|
+
const fits = (one) => one !== undefined &&
|
|
207
|
+
one.length >= (node.minLength ?? 0) &&
|
|
208
|
+
one.length <= (node.maxLength ?? Number.POSITIVE_INFINITY) &&
|
|
209
|
+
pattern?.test(one) !== false;
|
|
210
|
+
return [patternSample(node.pattern), ...GUESSES, plain].find(fits) ?? plain;
|
|
194
211
|
}
|
|
195
212
|
case "integer":
|
|
196
213
|
case "number":
|
|
@@ -285,7 +302,15 @@ export const fakeApi = (options) => {
|
|
|
285
302
|
return place?.in === "query" ? [place.name] : [];
|
|
286
303
|
}));
|
|
287
304
|
const carries = (request, url, place, token) => (place.in === "header" ? request.headers.get(place.name) : url.searchParams.get(place.name)) === place.value(token);
|
|
288
|
-
|
|
305
|
+
// A Basic header holds the token only in base64, which a query string may also carry URL-encoded.
|
|
306
|
+
const encoded = Object.values(options.securitySchemes ?? {}).some((scheme) => signInPlace(scheme)?.basic);
|
|
307
|
+
const secrets = (token) => {
|
|
308
|
+
if (!encoded)
|
|
309
|
+
return [token];
|
|
310
|
+
const base64 = Buffer.from(token).toString("base64");
|
|
311
|
+
return [token, base64, encodeURIComponent(base64)];
|
|
312
|
+
};
|
|
313
|
+
const leaks = (request, url, token) => secrets(token).some((secret) => [...request.headers.values()].some((value) => value.includes(secret)) || url.search.includes(secret));
|
|
289
314
|
const fetch = async (input, init) => {
|
|
290
315
|
const request = new Request(input, init);
|
|
291
316
|
const url = new URL(request.url);
|
package/dist/codegen/graphql.js
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
* ends in `Delete` or `Archive` deletes. A Relay connection pages as a `cursor`: `after`, `pageInfo.endCursor`.
|
|
9
9
|
* SDL is not read: that needs graphql-js, and codegen adds no runtime dependency.
|
|
10
10
|
*/
|
|
11
|
-
import { createHash } from "node:crypto";
|
|
12
11
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
12
|
import { join } from "node:path";
|
|
14
13
|
import { CodegenError } from "./pipeline.js";
|
|
14
|
+
import { sha256, sortKeys } from "./snapshot.js";
|
|
15
15
|
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
16
16
|
const BUILT_IN = {
|
|
17
17
|
String: { type: "string" },
|
|
@@ -326,14 +326,6 @@ fragment TypeRef on __Type {
|
|
|
326
326
|
ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } }
|
|
327
327
|
}`;
|
|
328
328
|
const FILE = "schema.json";
|
|
329
|
-
const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
330
|
-
const sortKeys = (value) => Array.isArray(value)
|
|
331
|
-
? value.map(sortKeys)
|
|
332
|
-
: object(value)
|
|
333
|
-
? Object.fromEntries(Object.keys(value)
|
|
334
|
-
.sort()
|
|
335
|
-
.map((key) => [key, sortKeys(value[key])]))
|
|
336
|
-
: value;
|
|
337
329
|
const byName = (list) => Array.isArray(list)
|
|
338
330
|
? [...list].sort((a, b) => String(a?.name).localeCompare(String(b?.name)))
|
|
339
331
|
: list;
|
package/dist/codegen/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* manifest and a coverage page. Build-time, apart from the small helpers a CLI reads the generated
|
|
4
4
|
* files with (`identifier`, `requestSchema`), and format-neutral: it parses no file format and
|
|
5
5
|
* adds no runtime dependency. `adaptOpenApi` reads an OpenAPI document and `adaptDiscovery` Google Discovery
|
|
6
|
-
* documents the consumer has parsed, and `adaptGraphql` a GraphQL introspection result; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
|
|
6
|
+
* documents the consumer has parsed, and `adaptGraphql` a GraphQL introspection result; `wpJsonToOpenApi` turns WordPress's REST index into OpenAPI; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
|
|
7
7
|
* peer dependencies. `fakeApi` serves the generated manifest as a strict fake for a CLI's tests, and `signInRequirements` with
|
|
8
|
-
* `signInPlace` say which sign-in a call needs and where its token goes. An adapter from
|
|
8
|
+
* `signInPlace` say which sign-in a call needs and where its token goes (Basic included). An adapter from
|
|
9
9
|
* Postman or anything else lives in the consumer.
|
|
10
10
|
*/
|
|
11
11
|
export { adaptDiscovery, type DiscoveryMetadata, type DiscoveryOptions, type DiscoveryProvenance, type DiscoveryResult, type DiscoveryService, readDiscovery, type SyncDiscoveryOptions, syncDiscovery, } from "./discovery.js";
|
|
@@ -26,3 +26,4 @@ export { API_SKILL_GROUPS, API_SKILL_INDEX, type ApiSkillOptions, apiSkillFiles
|
|
|
26
26
|
export { upgradeToOpenApi3 } from "./swagger.js";
|
|
27
27
|
export { typesGenerator } from "./typescript.js";
|
|
28
28
|
export { type ValibotOptions, valibotGenerator } from "./valibot.js";
|
|
29
|
+
export { readWpJson, syncWpJson, type WpJsonOptions, type WpJsonProvenance, type WpJsonResult, wpJsonToOpenApi, } from "./wp-json.js";
|
package/dist/codegen/index.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* manifest and a coverage page. Build-time, apart from the small helpers a CLI reads the generated
|
|
4
4
|
* files with (`identifier`, `requestSchema`), and format-neutral: it parses no file format and
|
|
5
5
|
* adds no runtime dependency. `adaptOpenApi` reads an OpenAPI document and `adaptDiscovery` Google Discovery
|
|
6
|
-
* documents the consumer has parsed, and `adaptGraphql` a GraphQL introspection result; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
|
|
6
|
+
* documents the consumer has parsed, and `adaptGraphql` a GraphQL introspection result; `wpJsonToOpenApi` turns WordPress's REST index into OpenAPI; `upgradeToOpenApi3` brings Swagger 1.2 and 2.0 to OpenAPI 3 through two optional
|
|
7
7
|
* peer dependencies. `fakeApi` serves the generated manifest as a strict fake for a CLI's tests, and `signInRequirements` with
|
|
8
|
-
* `signInPlace` say which sign-in a call needs and where its token goes. An adapter from
|
|
8
|
+
* `signInPlace` say which sign-in a call needs and where its token goes (Basic included). An adapter from
|
|
9
9
|
* Postman or anything else lives in the consumer.
|
|
10
10
|
*/
|
|
11
11
|
export { adaptDiscovery, readDiscovery, syncDiscovery, } from "./discovery.js";
|
|
@@ -25,3 +25,4 @@ export { API_SKILL_GROUPS, API_SKILL_INDEX, apiSkillFiles } from "./skill.js";
|
|
|
25
25
|
export { upgradeToOpenApi3 } from "./swagger.js";
|
|
26
26
|
export { typesGenerator } from "./typescript.js";
|
|
27
27
|
export { valibotGenerator } from "./valibot.js";
|
|
28
|
+
export { readWpJson, syncWpJson, wpJsonToOpenApi, } from "./wp-json.js";
|
package/dist/codegen/manifest.js
CHANGED
|
@@ -127,7 +127,11 @@ export const coverageGenerator = (options) => (model) => {
|
|
|
127
127
|
const reasoned = model.operations.filter((operation) => operation.effectReason);
|
|
128
128
|
const paged = model.operations.filter((operation) => operation.pagination);
|
|
129
129
|
const guarded = model.operations.flatMap((operation) => (operation.permissions ?? []).map((permission) => ({ id: operation.id, permission })));
|
|
130
|
-
const when = ({ body, query }) => [
|
|
130
|
+
const when = ({ body, query, values }) => [
|
|
131
|
+
...(body ?? []).map((flag) => `body \`${flag}\` is true`),
|
|
132
|
+
...(query ?? []).map((flag) => `query \`${flag}\` is true`),
|
|
133
|
+
...Object.entries(values ?? {}).map(([field, listed]) => `\`${field}\` is ${listed.join(" or ")}`),
|
|
134
|
+
].join(" or ");
|
|
131
135
|
const content = [
|
|
132
136
|
`# ${options.title}`,
|
|
133
137
|
"",
|
|
@@ -181,7 +185,7 @@ export const coverageGenerator = (options) => (model) => {
|
|
|
181
185
|
"|---|---|---|",
|
|
182
186
|
...guarded.map(({ id, permission }) => {
|
|
183
187
|
const flags = when(permission);
|
|
184
|
-
return `| \`${id}\` | \`${permission.key}\` | ${flags
|
|
188
|
+
return `| \`${id}\` | \`${permission.key}\` | ${flags || "always"} |`;
|
|
185
189
|
}),
|
|
186
190
|
]
|
|
187
191
|
: []),
|
package/dist/codegen/model.d.ts
CHANGED
|
@@ -190,13 +190,21 @@ export type Pagination = {
|
|
|
190
190
|
next: string;
|
|
191
191
|
items?: string;
|
|
192
192
|
};
|
|
193
|
-
/**
|
|
193
|
+
/**
|
|
194
|
+
* A key a call must pass: always, or, when `body`, `query` or `values` is given, only when one of those flags is `true`
|
|
195
|
+
* or one of those fields holds one of its values.
|
|
196
|
+
*/
|
|
194
197
|
export interface OperationPermission {
|
|
195
198
|
key: string;
|
|
196
199
|
/** Top-level request body fields. */
|
|
197
200
|
body?: readonly string[];
|
|
198
201
|
/** Query parameters. */
|
|
199
202
|
query?: readonly string[];
|
|
203
|
+
/**
|
|
204
|
+
* A top-level body field or query parameter of this name holding one of these values: `{ status: ["publish"] }`.
|
|
205
|
+
* Both places count, as a service that merges them (WordPress) publishes from either.
|
|
206
|
+
*/
|
|
207
|
+
values?: Readonly<Record<string, readonly string[]>>;
|
|
200
208
|
}
|
|
201
209
|
/** The scheme names an operation needs, each with its OAuth scopes; one requirement of the list is enough. */
|
|
202
210
|
export type SecurityRequirement = Readonly<Record<string, readonly string[]>>;
|
package/dist/codegen/openapi.js
CHANGED
|
@@ -3,7 +3,19 @@ const METHODS = ["get", "post", "put", "patch", "delete", "head"];
|
|
|
3
3
|
* Carried by the model, or harmless to lose. `not` only narrows what a payload may hold; losing it
|
|
4
4
|
* accepts more, never refuses a valid request.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
// minProperties and maxProperties only check a count; the service checks it again, so a looser schema loses nothing.
|
|
7
|
+
const IGNORED = new Set([
|
|
8
|
+
"readOnly",
|
|
9
|
+
"example",
|
|
10
|
+
"examples",
|
|
11
|
+
"externalDocs",
|
|
12
|
+
"title",
|
|
13
|
+
"xml",
|
|
14
|
+
"writeOnly",
|
|
15
|
+
"not",
|
|
16
|
+
"minProperties",
|
|
17
|
+
"maxProperties",
|
|
18
|
+
]);
|
|
7
19
|
const KNOWN = new Set([
|
|
8
20
|
...IGNORED,
|
|
9
21
|
"type",
|
|
@@ -20,6 +32,7 @@ const KNOWN = new Set([
|
|
|
20
32
|
"minimum",
|
|
21
33
|
"maximum",
|
|
22
34
|
"items",
|
|
35
|
+
"prefixItems",
|
|
23
36
|
"minItems",
|
|
24
37
|
"maxItems",
|
|
25
38
|
"uniqueItems",
|
|
@@ -207,7 +220,7 @@ class Adapter {
|
|
|
207
220
|
if (types.size === 1)
|
|
208
221
|
return [...types][0];
|
|
209
222
|
}
|
|
210
|
-
if (source.items !== undefined)
|
|
223
|
+
if (source.items !== undefined || source.prefixItems !== undefined)
|
|
211
224
|
return "array";
|
|
212
225
|
if (source.properties !== undefined || source.required !== undefined || source.additionalProperties !== undefined)
|
|
213
226
|
return "object";
|
|
@@ -303,7 +316,12 @@ class Adapter {
|
|
|
303
316
|
}
|
|
304
317
|
case "array": {
|
|
305
318
|
// JSON Schema reads a missing `items` as "any item".
|
|
306
|
-
const
|
|
319
|
+
const rest = source.items === undefined ? { type: "unknown" } : this.schema(source.items, `${where}[]`);
|
|
320
|
+
// A tuple (`prefixItems`) is read as a list whose every item is one of its places: looser, never wrong.
|
|
321
|
+
const places = Array.isArray(source.prefixItems)
|
|
322
|
+
? source.prefixItems.map((one, index) => this.schema(one, `${where}.prefixItems[${index}]`))
|
|
323
|
+
: [];
|
|
324
|
+
const items = places.length === 0 ? rest : { type: "union", of: [...places, rest] };
|
|
307
325
|
const node = { ...common, type: "array", items };
|
|
308
326
|
if (typeof source.minItems === "number")
|
|
309
327
|
node.minItems = source.minItems;
|
|
@@ -401,6 +419,19 @@ class Adapter {
|
|
|
401
419
|
if (unions.length === 0)
|
|
402
420
|
return undefined;
|
|
403
421
|
const [union] = unions;
|
|
422
|
+
// Every value of an allOf of unions of plain values passes each one, so the first alone is looser and never refuses
|
|
423
|
+
// a right value, as Attio's kanban status_attribute narrows a path union again. With an object in a branch the
|
|
424
|
+
// value may need fields from two unions at once, which the first alone would refuse.
|
|
425
|
+
const plain = (member) => !isObject(member) ||
|
|
426
|
+
(member.type !== "object" &&
|
|
427
|
+
member.properties === undefined &&
|
|
428
|
+
member.allOf === undefined &&
|
|
429
|
+
member.$ref === undefined);
|
|
430
|
+
if (unions.length > 1 &&
|
|
431
|
+
union &&
|
|
432
|
+
unions.length === members.length &&
|
|
433
|
+
unions.every((one) => one.members.every(plain)))
|
|
434
|
+
return { ...this.schema(union.member, `${where}.allOf[0]`), ...common };
|
|
404
435
|
if (unions.length > 1 || !union) {
|
|
405
436
|
this.problems.push(`${where}: an allOf of several unions`);
|
|
406
437
|
return { type: "unknown" };
|
|
@@ -37,6 +37,18 @@ export interface PermissionRule {
|
|
|
37
37
|
deletingFlags?: readonly string[];
|
|
38
38
|
/** Operation ids that make something public, as a share link does: neither a plain write nor a delete. */
|
|
39
39
|
shares?: readonly string[];
|
|
40
|
+
/**
|
|
41
|
+
* A field whose value is the change, not a flag: WordPress publishes by `status: "publish"`. Each gives
|
|
42
|
+
* `<group>.<key>` to every write or delete whose body field or query parameter `field` lists one of `values` in its
|
|
43
|
+
* `enum`, so a field of the same name that means something else (a comment's `status`) gets no key, nor does a read
|
|
44
|
+
* that filters by the value. Where the field's default is one of `values` (a WordPress template), leaving it out
|
|
45
|
+
* publishes too, and the key always applies.
|
|
46
|
+
*/
|
|
47
|
+
valueKeys?: readonly {
|
|
48
|
+
key: string;
|
|
49
|
+
field: string;
|
|
50
|
+
values: readonly string[];
|
|
51
|
+
}[];
|
|
40
52
|
}
|
|
41
53
|
export declare const applyPermissionRule: (model: ApiModel, rule: PermissionRule) => ApiModel;
|
|
42
54
|
/**
|
package/dist/codegen/pipeline.js
CHANGED
|
@@ -43,12 +43,17 @@ const commandFromPath = (operation, all, names) => {
|
|
|
43
43
|
const collection = all.some((other) => other.binding.kind === "http" &&
|
|
44
44
|
((other.binding.method === "GET" && other.binding.path === path) ||
|
|
45
45
|
(other.binding.path.startsWith(`${path}/{`) && !other.binding.path.slice(path.length + 1).includes("/"))));
|
|
46
|
+
// A PUT on the collection beside a PUT on its item is the "create or update by a unique value" (Attio's assert).
|
|
47
|
+
const itemPut = all.some((other) => other.binding.kind === "http" &&
|
|
48
|
+
other.binding.method === "PUT" &&
|
|
49
|
+
other.binding.path.startsWith(`${path}/{`) &&
|
|
50
|
+
!other.binding.path.slice(path.length + 1).includes("/"));
|
|
46
51
|
const verb = {
|
|
47
52
|
GET: onItem || parts.at(-1) === "me" ? "get" : "list",
|
|
48
53
|
HEAD: "head",
|
|
49
54
|
DELETE: "delete",
|
|
50
55
|
PATCH: "update",
|
|
51
|
-
PUT: onItem
|
|
56
|
+
PUT: onItem ? "replace" : collection ? (itemPut ? "upsert" : "replace") : "",
|
|
52
57
|
POST: onItem ? "update" : collection ? "create" : "",
|
|
53
58
|
}[method];
|
|
54
59
|
return [...words, verb].filter(Boolean).join("-");
|
|
@@ -130,7 +135,7 @@ export const applyOverrides = (model, overrides) => {
|
|
|
130
135
|
}),
|
|
131
136
|
};
|
|
132
137
|
};
|
|
133
|
-
/** The top-level
|
|
138
|
+
/** The top-level properties a body may carry, through references, inheritance, unions and subtypes. */
|
|
134
139
|
const bodyFields = (node, schemas, seen = new Set()) => {
|
|
135
140
|
switch (node.type) {
|
|
136
141
|
case "ref": {
|
|
@@ -142,7 +147,7 @@ const bodyFields = (node, schemas, seen = new Set()) => {
|
|
|
142
147
|
return [...bodyFields(target.schema, schemas, inner), ...subtypes];
|
|
143
148
|
}
|
|
144
149
|
case "object":
|
|
145
|
-
return Object.
|
|
150
|
+
return Object.entries(node.properties);
|
|
146
151
|
case "union":
|
|
147
152
|
case "allOf":
|
|
148
153
|
return node.of.flatMap((member) => bodyFields(member, schemas, seen));
|
|
@@ -159,9 +164,50 @@ export const applyPermissionRule = (model, rule) => {
|
|
|
159
164
|
const schemas = new Map(model.schemas.map((schema) => [schema.id, schema]));
|
|
160
165
|
const fields = new Map(model.operations.map((operation) => [
|
|
161
166
|
operation.id,
|
|
162
|
-
new
|
|
167
|
+
new Map(operation.requestBody?.schema ? bodyFields(operation.requestBody.schema, schemas) : []),
|
|
163
168
|
]));
|
|
164
|
-
const fieldsOf = (operation) => fields.get(operation.id) ?? new
|
|
169
|
+
const fieldsOf = (operation) => fields.get(operation.id) ?? new Map();
|
|
170
|
+
/** The enums and defaults of a field, through references and every alternative of a union. */
|
|
171
|
+
const valuesIn = (node, seen = new Set()) => {
|
|
172
|
+
if (!node)
|
|
173
|
+
return { enums: [], defaults: [] };
|
|
174
|
+
const own = {
|
|
175
|
+
enums: "enum" in node && node.enum ? [...node.enum] : [],
|
|
176
|
+
defaults: node.default === undefined ? [] : [node.default],
|
|
177
|
+
};
|
|
178
|
+
const inner = node.type === "ref" && !seen.has(node.ref)
|
|
179
|
+
? [valuesIn(schemas.get(node.ref)?.schema, new Set([...seen, node.ref]))]
|
|
180
|
+
: node.type === "union" || node.type === "allOf"
|
|
181
|
+
? node.of.map((member) => valuesIn(member, seen))
|
|
182
|
+
: [];
|
|
183
|
+
return {
|
|
184
|
+
enums: [...own.enums, ...inner.flatMap((one) => one.enums)],
|
|
185
|
+
defaults: [...own.defaults, ...inner.flatMap((one) => one.defaults)],
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
const valuesOf = (operation, name) => {
|
|
189
|
+
const nodes = [
|
|
190
|
+
fieldsOf(operation).get(name),
|
|
191
|
+
operation.parameters.find((parameter) => parameter.in === "query" && parameter.name === name)?.schema,
|
|
192
|
+
].map((node) => valuesIn(node));
|
|
193
|
+
return { enums: nodes.flatMap((one) => one.enums), defaults: nodes.flatMap((one) => one.defaults) };
|
|
194
|
+
};
|
|
195
|
+
const valueKeys = rule.valueKeys ?? [];
|
|
196
|
+
// A field whose default is one of the values publishes when the call leaves it out: the key then always applies.
|
|
197
|
+
const valued = (operation) => operation.effect === "read"
|
|
198
|
+
? []
|
|
199
|
+
: valueKeys.flatMap(({ key, field, values }) => {
|
|
200
|
+
const { enums, defaults } = valuesOf(operation, field);
|
|
201
|
+
const named = values.filter((value) => enums.includes(value));
|
|
202
|
+
if (named.length === 0)
|
|
203
|
+
return [];
|
|
204
|
+
return defaults.some((value) => values.includes(value))
|
|
205
|
+
? [{ key }]
|
|
206
|
+
: [{ key, values: { [field]: named } }];
|
|
207
|
+
});
|
|
208
|
+
const idle = valueKeys.filter(({ key }) => !model.operations.some((operation) => valued(operation).some((one) => one.key === key)));
|
|
209
|
+
if (idle.length > 0)
|
|
210
|
+
throw new CodegenError(idle.map(({ field, values }) => `valueKeys: no write lists ${values.join(" or ")} in the enum of "${field}"`));
|
|
165
211
|
const unused = flags.filter((flag) => !model.operations.some((operation) => fieldsOf(operation).has(flag) ||
|
|
166
212
|
operation.parameters.some((parameter) => parameter.in === "query" && parameter.name === flag)));
|
|
167
213
|
if (unused.length > 0)
|
|
@@ -185,6 +231,8 @@ export const applyPermissionRule = (model, rule) => {
|
|
|
185
231
|
...(query.length > 0 ? { query } : {}),
|
|
186
232
|
});
|
|
187
233
|
}
|
|
234
|
+
for (const permission of valued(operation))
|
|
235
|
+
permissions.push({ ...permission, key: `${group}.${permission.key}` });
|
|
188
236
|
return permissions.length > 0 ? { ...operation, permissions } : operation;
|
|
189
237
|
}),
|
|
190
238
|
};
|
|
@@ -9,8 +9,10 @@ export interface SignInPlace {
|
|
|
9
9
|
/** A header name in lower case, or a query parameter as the spec spells it. */
|
|
10
10
|
name: string;
|
|
11
11
|
value: (token: string) => string;
|
|
12
|
+
/** Basic: the token is `<user>:<password>`, which a sign-in with a token alone does not keep. */
|
|
13
|
+
basic?: true;
|
|
12
14
|
}
|
|
13
|
-
/** `undefined` for a scheme a token cannot be sent by:
|
|
15
|
+
/** `undefined` for a scheme a token cannot be sent by: digest, a key in a cookie, mutual TLS. */
|
|
14
16
|
export declare const signInPlace: (scheme: SecurityScheme) => SignInPlace | undefined;
|
|
15
17
|
/**
|
|
16
18
|
* The requirements one call signs in by: the operation's own `security`, else the document's. `undefined` when it needs
|
package/dist/codegen/sign-in.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const BEARER = { in: "header", name: "authorization", value: (token) => `Bearer ${token}` };
|
|
2
|
-
/** `undefined` for a scheme a token cannot be sent by:
|
|
2
|
+
/** `undefined` for a scheme a token cannot be sent by: digest, a key in a cookie, mutual TLS. */
|
|
3
3
|
export const signInPlace = (scheme) => {
|
|
4
4
|
if (scheme.type === "apiKey") {
|
|
5
5
|
if (!scheme.name || (scheme.in !== "header" && scheme.in !== "query"))
|
|
@@ -13,7 +13,14 @@ export const signInPlace = (scheme) => {
|
|
|
13
13
|
if (scheme.type === "http") {
|
|
14
14
|
if (!scheme.scheme || /^bearer$/i.test(scheme.scheme))
|
|
15
15
|
return BEARER;
|
|
16
|
-
if (/^
|
|
16
|
+
if (/^basic$/i.test(scheme.scheme))
|
|
17
|
+
return {
|
|
18
|
+
in: "header",
|
|
19
|
+
name: "authorization",
|
|
20
|
+
value: (token) => `Basic ${Buffer.from(token).toString("base64")}`,
|
|
21
|
+
basic: true,
|
|
22
|
+
};
|
|
23
|
+
if (/^digest$/i.test(scheme.scheme))
|
|
17
24
|
return undefined;
|
|
18
25
|
return { in: "header", name: "authorization", value: (token) => `${scheme.scheme} ${token}` };
|
|
19
26
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The hash a snapshot's `provenance.json` keeps, so a hand edit or a changed file stops generation. */
|
|
2
|
+
export declare const sha256: (bytes: string | Buffer) => string;
|
|
3
|
+
/** A service may send the same description with its keys in another order each time; arrays keep theirs. */
|
|
4
|
+
export declare const sortKeys: (value: unknown) => unknown;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
/** The hash a snapshot's `provenance.json` keeps, so a hand edit or a changed file stops generation. */
|
|
3
|
+
export const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
4
|
+
/** A service may send the same description with its keys in another order each time; arrays keep theirs. */
|
|
5
|
+
export const sortKeys = (value) => Array.isArray(value)
|
|
6
|
+
? value.map(sortKeys)
|
|
7
|
+
: value && typeof value === "object"
|
|
8
|
+
? Object.fromEntries(Object.keys(value)
|
|
9
|
+
.sort()
|
|
10
|
+
.map((key) => [key, sortKeys(value[key])]))
|
|
11
|
+
: value;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
type Json = Record<string, unknown>;
|
|
2
|
+
export interface WpJsonOptions {
|
|
3
|
+
/** The namespaces the CLI offers, as `wp/v2`; every other route is left out and listed in `omissions`. */
|
|
4
|
+
namespaces: readonly string[];
|
|
5
|
+
/** Routes, as the index spells them, left out with the reason. One that matches no route stops generation. */
|
|
6
|
+
exclude?: Readonly<Record<string, string>>;
|
|
7
|
+
/** The `site` server variable's default: the host in `https://{site}/wp-json`. */
|
|
8
|
+
site?: string;
|
|
9
|
+
/** The WordPress version the snapshot came from, as `info.version`. */
|
|
10
|
+
version?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface WpJsonResult {
|
|
13
|
+
/** An OpenAPI 3.1 document for `adaptOpenApi`. */
|
|
14
|
+
document: Json;
|
|
15
|
+
/** What the document leaves out, one line each, for a reviewer. */
|
|
16
|
+
omissions: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The OpenAPI document of the routes under `namespaces`. A route offers GET as a read, DELETE as a delete with its
|
|
20
|
+
* arguments in the query (`force=true`), and one write: POST where the route takes it, as WordPress takes the same
|
|
21
|
+
* call by POST, PUT and PATCH. A write's arguments are its JSON body. An array argument in the query travels as one
|
|
22
|
+
* comma-separated value, which WordPress splits, as PHP keeps only the last of a repeated name.
|
|
23
|
+
*/
|
|
24
|
+
export declare const wpJsonToOpenApi: (index: unknown, options: WpJsonOptions) => WpJsonResult;
|
|
25
|
+
/** The snapshot's entry in `provenance.json`. */
|
|
26
|
+
export interface WpJsonProvenance {
|
|
27
|
+
source: string;
|
|
28
|
+
/** The WordPress version it came from; the index does not say it. */
|
|
29
|
+
version: string;
|
|
30
|
+
/** Of the committed file; `readWpJson` refuses a snapshot that no longer matches it. */
|
|
31
|
+
sha256: string;
|
|
32
|
+
retrieved_at: string;
|
|
33
|
+
normalization: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Asks `root` (`https://<site>/wp-json/`) for its index with every schema and writes `wp-json.json` and
|
|
37
|
+
* `provenance.json` to `dir`. Take it from a plain WordPress, as the CLI serves every site: a plugin's routes and
|
|
38
|
+
* fields belong to that site. Run by hand, then review the diff: the build never fetches.
|
|
39
|
+
*/
|
|
40
|
+
export declare const syncWpJson: (options: {
|
|
41
|
+
root: string;
|
|
42
|
+
dir: string;
|
|
43
|
+
version: string;
|
|
44
|
+
fetch?: typeof globalThis.fetch;
|
|
45
|
+
now?: Date;
|
|
46
|
+
}) => Promise<WpJsonProvenance>;
|
|
47
|
+
/** The snapshot `syncWpJson` wrote, parsed. Throws if its hash changed. */
|
|
48
|
+
export declare const readWpJson: (dir: string) => unknown;
|
|
49
|
+
export {};
|