@wirecat/cli-base 0.119.0 → 0.120.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 +38 -0
- package/dist/codegen/index.d.ts +3 -2
- package/dist/codegen/index.js +3 -2
- package/dist/codegen/manifest.js +10 -5
- package/dist/codegen/model.d.ts +10 -0
- package/dist/codegen/openapi.d.ts +3 -0
- package/dist/codegen/openapi.js +2 -1
- package/dist/codegen/pipeline.d.ts +10 -0
- package/dist/codegen/pipeline.js +52 -6
- package/dist/codegen/postman.d.ts +24 -0
- package/dist/codegen/postman.js +315 -0
- package/dist/codegen/wp-json.d.ts +6 -0
- package/dist/codegen/wp-json.js +19 -0
- package/dist/http/fetch.d.ts +5 -0
- package/dist/http/fetch.js +20 -1
- package/dist/standards/audit.js +18 -3
- package/docs/standards/kit-surface.md +13 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,44 @@ 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.120.0 — 19.11.2026
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **A Postman collection becomes OpenAPI: `postmanToOpenApi`.** A service that publishes only a Postman collection
|
|
16
|
+
(Braze) is now generated like any other: the converter turns a parsed collection, v2.0 or v2.1, into OpenAPI 3.1 for
|
|
17
|
+
`adaptOpenApi`. Requests become operations named by method and path, folders their tag, `{{x}}`, `:x` and `{x}` path
|
|
18
|
+
parameters, and the collection's auth or the `Authorization` header an existing sign-in kind. A body is an example,
|
|
19
|
+
never a contract. Braze's collection gives 95 operations from 99 requests (four documented twice). See
|
|
20
|
+
[the reference](docs/REFERENCE.md). Watch for: a POST that only reads keeps the write effect its method gives, so
|
|
21
|
+
the CLI corrects it with an override.
|
|
22
|
+
- **A WordPress list pages by its header.** The page style takes `start` (the first page's number) and `pagesHeader`
|
|
23
|
+
(a response header with the number of pages), and `items: ""` when the answer itself is the list.
|
|
24
|
+
`wpJsonToOpenApi` returns `overrides` that give every collection read this style, from 1, by `X-WP-TotalPages`;
|
|
25
|
+
pass them to `generate`. Before, a WordPress read had no paging, so `api … --all` refused it. Watch for: an executor
|
|
26
|
+
that reads `pagination` must handle the two new fields; cli-core does from its next release.
|
|
27
|
+
- **A permanent delete gets its own key: `permissions.forceFlags`.** WordPress's `force=true` deletes for good, while a
|
|
28
|
+
delete without it moves the item to the trash. `forceFlags: ["force"]` gives such a delete `<group>.delete.force`
|
|
29
|
+
besides `<group>.delete`, applying when the flag is `true`, so a CLI can ask before a permanent delete and still
|
|
30
|
+
allow the trash. See [the generator's options](docs/standards/kit-surface.md).
|
|
31
|
+
- **A publish key covers a date change: `valueKeys[].also`.** WordPress publishes a scheduled post whose `date` moves
|
|
32
|
+
into the past, with no `status` in the call. `also: ["date", "date_gmt"]` makes setting either need the key, unless
|
|
33
|
+
the call itself sets `status` to a value outside `values` (`draft`, `pending` or `private`). The manifest carries it
|
|
34
|
+
as the key's `body` fields with `unless`. Watch for: an executor that does not read `unless` asks for the key on a
|
|
35
|
+
draft's date change too, which is safe.
|
|
36
|
+
- **A sign-in stays under its site's path: `hostFetch`'s `credentialScope`.** Sites under a path share a host
|
|
37
|
+
(`host/blog`, a WordPress multisite in subfolders), and the origin check let a redirect carry the sign-in to
|
|
38
|
+
`host/other`. With `credentialScope: "https://host/blog/wp-json"`, a signed request outside it is refused before it
|
|
39
|
+
is sent, and a redirect out of it drops `authorization`, `cookie` and `proxy-authorization`. A path with an encoded
|
|
40
|
+
slash (`%2F`, `%5C`) counts as outside, as a server that decodes it before routing could leave the scope.
|
|
41
|
+
- **attio-cli joins the `shared-roots` and `crm` parity groups**, beside amo-cli and hubspot-cli: its root commands are
|
|
42
|
+
compared with every CLI's, and its CRM commands with bitrix24-cli's.
|
|
43
|
+
|
|
44
|
+
### Changed — may break callers
|
|
45
|
+
|
|
46
|
+
- **`wpJsonToOpenApi` refuses the `batch/v1` namespace.** A batch call carries requests to other routes in its body,
|
|
47
|
+
past the keys those routes need, so a CLI never offers it. A CLI that listed it stops generating.
|
|
48
|
+
|
|
11
49
|
## 0.119.0 — 18.11.2026
|
|
12
50
|
|
|
13
51
|
### Added
|
package/dist/codegen/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
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; `wpJsonToOpenApi` turns WordPress's REST index into OpenAPI; `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 and `postmanToOpenApi` a Postman collection; `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
8
|
* `signInPlace` say which sign-in a call needs and where its token goes (Basic included). An adapter from
|
|
9
|
-
*
|
|
9
|
+
* any other format 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";
|
|
12
12
|
export { type FakeAnswer, type FakeApi, type FakeApiOptions, type FakeCall, fakeApi, sampleOf, schemaProblems, } from "./fake.js";
|
|
@@ -21,6 +21,7 @@ export { adaptOpenApi, OpenApiError } from "./openapi.js";
|
|
|
21
21
|
export { detectPagination } from "./pagination.js";
|
|
22
22
|
export { type PatchedSpec, type PatchSpecOptions, patchSpec, type SpecPatch } from "./patch.js";
|
|
23
23
|
export { type AuthOverride, applyNames, applyOverrides, applyPagination, applyPermissionRule, CodegenError, type CommandNames, type GenerateOptions, generate, type PermissionRule, READING_POST_REASON, validateModel, type WriteOptions, writeArtifacts, } from "./pipeline.js";
|
|
24
|
+
export { type PostmanOptions, type PostmanResult, postmanToOpenApi } from "./postman.js";
|
|
24
25
|
export { type SignInPlace, signInPlace, signInRequirements } from "./sign-in.js";
|
|
25
26
|
export { API_SKILL_GROUPS, API_SKILL_INDEX, type ApiSkillOptions, apiSkillFiles } from "./skill.js";
|
|
26
27
|
export { upgradeToOpenApi3 } from "./swagger.js";
|
package/dist/codegen/index.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
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; `wpJsonToOpenApi` turns WordPress's REST index into OpenAPI; `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 and `postmanToOpenApi` a Postman collection; `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
8
|
* `signInPlace` say which sign-in a call needs and where its token goes (Basic included). An adapter from
|
|
9
|
-
*
|
|
9
|
+
* any other format lives in the consumer.
|
|
10
10
|
*/
|
|
11
11
|
export { adaptDiscovery, readDiscovery, syncDiscovery, } from "./discovery.js";
|
|
12
12
|
export { fakeApi, sampleOf, schemaProblems, } from "./fake.js";
|
|
@@ -20,6 +20,7 @@ export { adaptOpenApi, OpenApiError } from "./openapi.js";
|
|
|
20
20
|
export { detectPagination } from "./pagination.js";
|
|
21
21
|
export { patchSpec } from "./patch.js";
|
|
22
22
|
export { applyNames, applyOverrides, applyPagination, applyPermissionRule, CodegenError, generate, READING_POST_REASON, validateModel, writeArtifacts, } from "./pipeline.js";
|
|
23
|
+
export { postmanToOpenApi } from "./postman.js";
|
|
23
24
|
export { signInPlace, signInRequirements } from "./sign-in.js";
|
|
24
25
|
export { API_SKILL_GROUPS, API_SKILL_INDEX, apiSkillFiles } from "./skill.js";
|
|
25
26
|
export { upgradeToOpenApi3 } from "./swagger.js";
|
package/dist/codegen/manifest.js
CHANGED
|
@@ -127,11 +127,15 @@ 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, values }) =>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
const when = ({ body, query, values, unless }) => {
|
|
131
|
+
const set = [
|
|
132
|
+
...Object.entries(values ?? {}).map(([field, listed]) => `\`${field}\` is ${listed.join(" or ")}`),
|
|
133
|
+
...(body ?? []).map((flag) => `body \`${flag}\` is ${unless ? "set" : "true"}`),
|
|
134
|
+
...(query ?? []).map((flag) => `query \`${flag}\` is ${unless ? "set" : "true"}`),
|
|
135
|
+
].join(" or ");
|
|
136
|
+
const except = Object.entries(unless ?? {}).map(([field, listed]) => `the call sets \`${field}\` to ${listed.join(" or ")}`);
|
|
137
|
+
return except.length > 0 ? `${set}, unless ${except.join(" or ")}` : set;
|
|
138
|
+
};
|
|
135
139
|
const content = [
|
|
136
140
|
`# ${options.title}`,
|
|
137
141
|
"",
|
|
@@ -170,6 +174,7 @@ export const coverageGenerator = (options) => (model) => {
|
|
|
170
174
|
page.items ? `items \`${page.items}\`` : undefined,
|
|
171
175
|
"hasMore" in page && page.hasMore ? `more \`${page.hasMore}\`` : undefined,
|
|
172
176
|
"total" in page && page.total ? `total \`${page.total}\`` : undefined,
|
|
177
|
+
"pagesHeader" in page && page.pagesHeader ? `pages header \`${page.pagesHeader}\`` : undefined,
|
|
173
178
|
].filter(Boolean);
|
|
174
179
|
return `| \`${id}\` | ${page.style} | ${request.join(", ") || "—"} | ${answer.join(", ")} | ${cell(paginationSource)} |`;
|
|
175
180
|
}),
|
package/dist/codegen/model.d.ts
CHANGED
|
@@ -181,8 +181,13 @@ export type Pagination = {
|
|
|
181
181
|
style: "page";
|
|
182
182
|
page: PageParameter;
|
|
183
183
|
limit?: PageParameter;
|
|
184
|
+
/** `""` when the answer itself is the list, as WordPress's. */
|
|
184
185
|
items: string;
|
|
185
186
|
total?: string;
|
|
187
|
+
/** The first page's number, where the source says it (WordPress counts from 1): `--all` then needs none given. */
|
|
188
|
+
start?: number;
|
|
189
|
+
/** A response header holding the number of pages, as WordPress's `X-WP-TotalPages`: that page is the last. */
|
|
190
|
+
pagesHeader?: string;
|
|
186
191
|
}
|
|
187
192
|
/** The answer holds the next page's whole URL. */
|
|
188
193
|
| {
|
|
@@ -205,6 +210,11 @@ export interface OperationPermission {
|
|
|
205
210
|
* Both places count, as a service that merges them (WordPress) publishes from either.
|
|
206
211
|
*/
|
|
207
212
|
values?: Readonly<Record<string, readonly string[]>>;
|
|
213
|
+
/**
|
|
214
|
+
* The key does not apply when the call itself sets a field to one of these: `{ status: ["draft", "pending", "private"] }` keeps
|
|
215
|
+
* a draft's date change free. A call that leaves the field out still needs the key, as the stored value is unknown.
|
|
216
|
+
*/
|
|
217
|
+
unless?: Readonly<Record<string, readonly string[]>>;
|
|
208
218
|
}
|
|
209
219
|
/** The scheme names an operation needs, each with its OAuth scopes; one requirement of the list is enough. */
|
|
210
220
|
export type SecurityRequirement = Readonly<Record<string, readonly string[]>>;
|
|
@@ -12,6 +12,9 @@ export declare class OpenApiError extends Error {
|
|
|
12
12
|
constructor(problems: readonly string[]);
|
|
13
13
|
}
|
|
14
14
|
export declare const isObject: (value: unknown) => value is Json;
|
|
15
|
+
/** A spec without a single operationId (Attio's) still has calls: `get /v2/objects/{object}` → `getV2ObjectsByObject`. */
|
|
16
|
+
/** The id `adaptOpenApi` gives an operation without an `operationId`: `getWpV2PostsById`. */
|
|
17
|
+
export declare const derivedId: (method: string, path: string) => string;
|
|
15
18
|
/** Throws `OpenApiError` with every problem at once, so one run shows all a spec update broke. */
|
|
16
19
|
export declare const adaptOpenApi: (document: unknown, source?: {
|
|
17
20
|
sourceUrl?: string;
|
package/dist/codegen/openapi.js
CHANGED
|
@@ -93,7 +93,8 @@ const jsonContent = (content) => content[JSON_TYPE] ?? Object.entries(content).f
|
|
|
93
93
|
const SCHEME_TYPES = new Set(["apiKey", "http", "oauth2", "openIdConnect", "mutualTLS"]);
|
|
94
94
|
const FLOWS = ["implicit", "password", "clientCredentials", "authorizationCode"];
|
|
95
95
|
/** A spec without a single operationId (Attio's) still has calls: `get /v2/objects/{object}` → `getV2ObjectsByObject`. */
|
|
96
|
-
|
|
96
|
+
/** The id `adaptOpenApi` gives an operation without an `operationId`: `getWpV2PostsById`. */
|
|
97
|
+
export const derivedId = (method, path) => method +
|
|
97
98
|
path
|
|
98
99
|
.split("/")
|
|
99
100
|
.filter(Boolean)
|
|
@@ -43,12 +43,22 @@ export interface PermissionRule {
|
|
|
43
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
44
|
* that filters by the value. Where the field's default is one of `values` (a WordPress template), leaving it out
|
|
45
45
|
* publishes too, and the key always applies.
|
|
46
|
+
*
|
|
47
|
+
* `also` names fields that make the same change through another door: WordPress publishes a scheduled post whose
|
|
48
|
+
* `date` moves into the past. Setting one applies the key too, unless the call itself sets `field` to a value
|
|
49
|
+
* outside `values` (a draft's new date); a call that leaves `field` out cannot say what is stored, so it needs the key.
|
|
46
50
|
*/
|
|
47
51
|
valueKeys?: readonly {
|
|
48
52
|
key: string;
|
|
49
53
|
field: string;
|
|
50
54
|
values: readonly string[];
|
|
55
|
+
also?: readonly string[];
|
|
51
56
|
}[];
|
|
57
|
+
/**
|
|
58
|
+
* Flags that make a delete permanent instead of a move to the trash: WordPress's `force`. A delete that takes one
|
|
59
|
+
* also needs `<group>.delete.force` when the flag is `true`; without it the trash is `<group>.delete` alone.
|
|
60
|
+
*/
|
|
61
|
+
forceFlags?: readonly string[];
|
|
52
62
|
}
|
|
53
63
|
export declare const applyPermissionRule: (model: ApiModel, rule: PermissionRule) => ApiModel;
|
|
54
64
|
/**
|
package/dist/codegen/pipeline.js
CHANGED
|
@@ -95,8 +95,15 @@ export const applyPagination = (model, overrides, detect) => {
|
|
|
95
95
|
problems.push(`${at} on an operation that is not a read`);
|
|
96
96
|
const request = requestParameters(operation, schemas);
|
|
97
97
|
const answer = answerPaths(operation, schemas);
|
|
98
|
-
const { style
|
|
98
|
+
const { style, start, pagesHeader, ...fields } = override.pagination;
|
|
99
|
+
if (start !== undefined && (style !== "page" || !Number.isInteger(start) || start < 0))
|
|
100
|
+
problems.push(`${at}: start must be a whole number from 0, on the page style`);
|
|
101
|
+
if (pagesHeader !== undefined && (style !== "page" || typeof pagesHeader !== "string" || pagesHeader === ""))
|
|
102
|
+
problems.push(`${at}: pagesHeader must name a header, on the page style`);
|
|
99
103
|
for (const [field, value] of Object.entries(fields)) {
|
|
104
|
+
// `items: ""`: the answer itself is the list.
|
|
105
|
+
if (field === "items" && value === "")
|
|
106
|
+
continue;
|
|
100
107
|
if (typeof value === "string") {
|
|
101
108
|
// An answer without a schema has nothing to check the path against.
|
|
102
109
|
if (answer.size > 0 && !answer.has(value))
|
|
@@ -194,24 +201,59 @@ export const applyPermissionRule = (model, rule) => {
|
|
|
194
201
|
};
|
|
195
202
|
const valueKeys = rule.valueKeys ?? [];
|
|
196
203
|
// A field whose default is one of the values publishes when the call leaves it out: the key then always applies.
|
|
204
|
+
const takes = (operation, names) => ({
|
|
205
|
+
body: names.filter((name) => fieldsOf(operation).has(name)),
|
|
206
|
+
query: names.filter((name) => operation.parameters.some((parameter) => parameter.in === "query" && parameter.name === name)),
|
|
207
|
+
});
|
|
208
|
+
const flagged = ({ body, query }) => ({
|
|
209
|
+
...(body.length > 0 ? { body } : {}),
|
|
210
|
+
...(query.length > 0 ? { query } : {}),
|
|
211
|
+
});
|
|
197
212
|
const valued = (operation) => operation.effect === "read"
|
|
198
213
|
? []
|
|
199
|
-
: valueKeys.flatMap(({ key, field, values }) => {
|
|
214
|
+
: valueKeys.flatMap(({ key, field, values, also = [] }) => {
|
|
200
215
|
const { enums, defaults } = valuesOf(operation, field);
|
|
201
216
|
const named = values.filter((value) => enums.includes(value));
|
|
202
217
|
if (named.length === 0)
|
|
203
218
|
return [];
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
219
|
+
if (defaults.some((value) => values.includes(value)))
|
|
220
|
+
return [{ key }];
|
|
221
|
+
const others = takes(operation, also);
|
|
222
|
+
const unless = [...new Set(enums.filter((value) => typeof value === "string"))].filter((value) => !values.includes(value));
|
|
223
|
+
return [
|
|
224
|
+
{
|
|
225
|
+
key,
|
|
226
|
+
values: { [field]: named },
|
|
227
|
+
...flagged(others),
|
|
228
|
+
...(others.body.length + others.query.length > 0 && unless.length > 0
|
|
229
|
+
? { unless: { [field]: unless } }
|
|
230
|
+
: {}),
|
|
231
|
+
},
|
|
232
|
+
];
|
|
207
233
|
});
|
|
208
234
|
const idle = valueKeys.filter(({ key }) => !model.operations.some((operation) => valued(operation).some((one) => one.key === key)));
|
|
209
235
|
if (idle.length > 0)
|
|
210
236
|
throw new CodegenError(idle.map(({ field, values }) => `valueKeys: no write lists ${values.join(" or ")} in the enum of "${field}"`));
|
|
237
|
+
// A misspelt `also` would leave the other door open without a word.
|
|
238
|
+
const idleAlso = valueKeys.flatMap(({ key, also = [] }) => also
|
|
239
|
+
.filter((name) => !model.operations.some((operation) => valued(operation).some((one) => one.key === key && (one.body?.includes(name) || one.query?.includes(name)))))
|
|
240
|
+
.map((name) => `valueKeys: also "${name}" is in no write that "${key}" guards`));
|
|
241
|
+
if (idleAlso.length > 0)
|
|
242
|
+
throw new CodegenError(idleAlso);
|
|
211
243
|
const unused = flags.filter((flag) => !model.operations.some((operation) => fieldsOf(operation).has(flag) ||
|
|
212
244
|
operation.parameters.some((parameter) => parameter.in === "query" && parameter.name === flag)));
|
|
213
245
|
if (unused.length > 0)
|
|
214
246
|
throw new CodegenError(unused.map((flag) => `deletingFlags: "${flag}" is in no request body or query`));
|
|
247
|
+
const forceFlags = rule.forceFlags ?? [];
|
|
248
|
+
const forcing = (operation) => takes(operation, forceFlags);
|
|
249
|
+
const idleForce = forceFlags.filter((flag) => !model.operations.some((operation) => {
|
|
250
|
+
if (operation.effect !== "destructive")
|
|
251
|
+
return false;
|
|
252
|
+
const { body, query } = forcing(operation);
|
|
253
|
+
return body.includes(flag) || query.includes(flag);
|
|
254
|
+
}));
|
|
255
|
+
if (idleForce.length > 0)
|
|
256
|
+
throw new CodegenError(idleForce.map((flag) => `forceFlags: "${flag}" is in no delete's request body or query`));
|
|
215
257
|
return {
|
|
216
258
|
...model,
|
|
217
259
|
operations: model.operations.map((operation) => {
|
|
@@ -219,8 +261,12 @@ export const applyPermissionRule = (model, rule) => {
|
|
|
219
261
|
const permissions = [];
|
|
220
262
|
if (rule.shares?.includes(operation.id))
|
|
221
263
|
permissions.push({ key: `${group}.share` });
|
|
222
|
-
if (operation.effect === "destructive")
|
|
264
|
+
if (operation.effect === "destructive") {
|
|
223
265
|
permissions.push({ key: `${group}.delete` });
|
|
266
|
+
const force = forcing(operation);
|
|
267
|
+
if (force.body.length + force.query.length > 0)
|
|
268
|
+
permissions.push({ key: `${group}.delete.force`, ...flagged(force) });
|
|
269
|
+
}
|
|
224
270
|
else {
|
|
225
271
|
const body = flags.filter((flag) => fieldsOf(operation).has(flag));
|
|
226
272
|
const query = flags.filter((flag) => operation.parameters.some((parameter) => parameter.in === "query" && parameter.name === flag));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type Json = Record<string, unknown>;
|
|
2
|
+
export interface PostmanOptions {
|
|
3
|
+
/** Values for `{{variables}}` the collection leaves empty, as Braze's `instance_url`; they win over its own. */
|
|
4
|
+
variables?: Readonly<Record<string, string>>;
|
|
5
|
+
/** Requests, as `METHOD /path` with `{name}` parameters, left out with the reason. A stale one stops generation. */
|
|
6
|
+
exclude?: Readonly<Record<string, string>>;
|
|
7
|
+
/** The API version the snapshot came from, as `info.version`; the collection's own when left out. */
|
|
8
|
+
version?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PostmanResult {
|
|
11
|
+
/** An OpenAPI 3.1 document for `adaptOpenApi`. */
|
|
12
|
+
document: Json;
|
|
13
|
+
/** What the document leaves out or merges, one line each, for a reviewer. */
|
|
14
|
+
omissions: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts the collection. A request's path is read from its raw URL, as Braze's export leaves `url.query` empty and
|
|
18
|
+
* keeps the query in the string. `{{x}}`, `:x` and `{x}` in the path become path parameters; the URL's host, with its
|
|
19
|
+
* variables, becomes the server. A request with no `auth` of its own or its folders' signs in as its `Authorization`
|
|
20
|
+
* header shows: Bearer or Basic. Two requests on one method and path (Braze documents some once per channel) become
|
|
21
|
+
* one operation, the first, and the second is listed in `omissions`.
|
|
22
|
+
*/
|
|
23
|
+
export declare const postmanToOpenApi: (collection: unknown, options?: PostmanOptions) => PostmanResult;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Postman collection (v2.0 or v2.1), already parsed → an OpenAPI 3.1 document, so `adaptOpenApi` reads it like any
|
|
3
|
+
* other. A service that publishes only a collection (Braze) gives requests with example values, not schemas: each
|
|
4
|
+
* request becomes an operation named by its method and path, its folders its tag, and its body an open schema of the
|
|
5
|
+
* example's JSON kind, so `adaptOpenApi` marks it an example, never a contract.
|
|
6
|
+
*
|
|
7
|
+
* Strict like `adaptOpenApi`: a request without a URL, a host variable without a default, an auth kind with no OpenAPI
|
|
8
|
+
* equivalent or requests on two hosts stop generation unless `exclude` names the request with a reason.
|
|
9
|
+
*/
|
|
10
|
+
import { CodegenError } from "./pipeline.js";
|
|
11
|
+
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
12
|
+
/** These travel as the sign-in and the body's type, never as a flag a user types. */
|
|
13
|
+
const NOT_PARAMETERS = new Set(["authorization", "content-type", "accept"]);
|
|
14
|
+
const text = (value) => typeof value === "string" ? value : object(value) && typeof value.content === "string" ? value.content : undefined;
|
|
15
|
+
/** v2.1 writes an auth's settings as `[{ key, value }]`, v2.0 as `{ key: value }`. */
|
|
16
|
+
const settings = (value) => Array.isArray(value)
|
|
17
|
+
? Object.fromEntries(value.filter(object).map((one) => [String(one.key), String(one.value ?? "")]))
|
|
18
|
+
: object(value)
|
|
19
|
+
? Object.fromEntries(Object.entries(value).map(([key, one]) => [key, String(one ?? "")]))
|
|
20
|
+
: {};
|
|
21
|
+
const pairs = (value) => (Array.isArray(value) ? value.filter(object) : []);
|
|
22
|
+
/** The open schema of an example's JSON kind: the collection shows one body, it does not say which others are valid. */
|
|
23
|
+
const openSchema = (example) => Array.isArray(example)
|
|
24
|
+
? { type: "array", items: {} }
|
|
25
|
+
: object(example)
|
|
26
|
+
? { type: "object", additionalProperties: true }
|
|
27
|
+
: example === null
|
|
28
|
+
? { type: "null" }
|
|
29
|
+
: { type: typeof example === "number" ? "number" : typeof example };
|
|
30
|
+
const FLOWS = {
|
|
31
|
+
authorization_code: "authorizationCode",
|
|
32
|
+
authorization_code_with_pkce: "authorizationCode",
|
|
33
|
+
client_credentials: "clientCredentials",
|
|
34
|
+
password_credentials: "password",
|
|
35
|
+
implicit: "implicit",
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Converts the collection. A request's path is read from its raw URL, as Braze's export leaves `url.query` empty and
|
|
39
|
+
* keeps the query in the string. `{{x}}`, `:x` and `{x}` in the path become path parameters; the URL's host, with its
|
|
40
|
+
* variables, becomes the server. A request with no `auth` of its own or its folders' signs in as its `Authorization`
|
|
41
|
+
* header shows: Bearer or Basic. Two requests on one method and path (Braze documents some once per channel) become
|
|
42
|
+
* one operation, the first, and the second is listed in `omissions`.
|
|
43
|
+
*/
|
|
44
|
+
export const postmanToOpenApi = (collection, options = {}) => {
|
|
45
|
+
if (!object(collection) || !object(collection.info) || !Array.isArray(collection.item))
|
|
46
|
+
throw new CodegenError(["not a Postman collection: no info or items"]);
|
|
47
|
+
const schema = String(collection.info.schema ?? "");
|
|
48
|
+
if (!/schema\.getpostman\.com\/json\/collection\/v2\./.test(schema))
|
|
49
|
+
throw new CodegenError([`not a Postman collection v2.0 or v2.1: info.schema is ${JSON.stringify(schema)}`]);
|
|
50
|
+
const variables = {
|
|
51
|
+
...Object.fromEntries(pairs(collection.variable)
|
|
52
|
+
.filter((one) => typeof one.value === "string" && one.value !== "")
|
|
53
|
+
.map((one) => [String(one.key), String(one.value)])),
|
|
54
|
+
...options.variables,
|
|
55
|
+
};
|
|
56
|
+
const resolve = (value) => value.replace(/\{\{([^}]+)\}\}/g, (all, name) => variables[name] ?? all);
|
|
57
|
+
const exclude = options.exclude ?? {};
|
|
58
|
+
const used = new Set();
|
|
59
|
+
const problems = [];
|
|
60
|
+
const omissions = [];
|
|
61
|
+
const paths = {};
|
|
62
|
+
const names = new Map();
|
|
63
|
+
const schemes = {};
|
|
64
|
+
let host;
|
|
65
|
+
const schemeName = (base, scheme) => {
|
|
66
|
+
let name = base;
|
|
67
|
+
for (let n = 2; schemes[name] && JSON.stringify(schemes[name]) !== JSON.stringify(scheme); n++)
|
|
68
|
+
name = `${base}${n}`;
|
|
69
|
+
schemes[name] = scheme;
|
|
70
|
+
return name;
|
|
71
|
+
};
|
|
72
|
+
/** `undefined` when the request does not say how it signs in; `[]` when it signs in with nothing. */
|
|
73
|
+
const securityOf = (auth, header, where) => {
|
|
74
|
+
if (!object(auth)) {
|
|
75
|
+
if (/^bearer\s/i.test(header ?? ""))
|
|
76
|
+
return [{ [schemeName("bearer", { type: "http", scheme: "bearer" })]: [] }];
|
|
77
|
+
if (/^basic\s/i.test(header ?? ""))
|
|
78
|
+
return [{ [schemeName("basic", { type: "http", scheme: "basic" })]: [] }];
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
const type = String(auth.type);
|
|
82
|
+
const given = settings(auth[type]);
|
|
83
|
+
if (type === "noauth")
|
|
84
|
+
return [];
|
|
85
|
+
if (type === "bearer")
|
|
86
|
+
return [{ [schemeName("bearer", { type: "http", scheme: "bearer" })]: [] }];
|
|
87
|
+
if (type === "basic")
|
|
88
|
+
return [{ [schemeName("basic", { type: "http", scheme: "basic" })]: [] }];
|
|
89
|
+
if (type === "apikey") {
|
|
90
|
+
if (!given.key)
|
|
91
|
+
throw new CodegenError([`${where}: an apikey sign-in without the key's name`]);
|
|
92
|
+
const scheme = { type: "apiKey", name: resolve(given.key), in: given.in === "query" ? "query" : "header" };
|
|
93
|
+
return [{ [schemeName("apiKey", scheme)]: [] }];
|
|
94
|
+
}
|
|
95
|
+
if (type === "oauth2") {
|
|
96
|
+
const flow = FLOWS[given.grant_type ?? "authorization_code"];
|
|
97
|
+
const tokenUrl = resolve(given.accessTokenUrl ?? "");
|
|
98
|
+
const authorizationUrl = resolve(given.authUrl ?? "");
|
|
99
|
+
const needs = flow === "implicit"
|
|
100
|
+
? [authorizationUrl]
|
|
101
|
+
: flow === "authorizationCode"
|
|
102
|
+
? [authorizationUrl, tokenUrl]
|
|
103
|
+
: [tokenUrl];
|
|
104
|
+
if (!flow || needs.some((url) => !/^https?:\/\//.test(url)))
|
|
105
|
+
throw new CodegenError([
|
|
106
|
+
`${where}: an oauth2 sign-in needs its grant type and full URLs; give them as variables`,
|
|
107
|
+
]);
|
|
108
|
+
const scopes = Object.fromEntries((given.scope ?? "")
|
|
109
|
+
.split(/\s+/)
|
|
110
|
+
.filter(Boolean)
|
|
111
|
+
.map((one) => [one, one]));
|
|
112
|
+
const scheme = {
|
|
113
|
+
type: "oauth2",
|
|
114
|
+
flows: {
|
|
115
|
+
[flow]: {
|
|
116
|
+
...(flow === "implicit" || flow === "authorizationCode" ? { authorizationUrl } : {}),
|
|
117
|
+
...(flow === "implicit" ? {} : { tokenUrl }),
|
|
118
|
+
scopes,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
return [{ [schemeName("oauth2", scheme)]: [] }];
|
|
123
|
+
}
|
|
124
|
+
throw new CodegenError([
|
|
125
|
+
`${where}: the ${type} sign-in has no OpenAPI equivalent; exclude the request with a reason`,
|
|
126
|
+
]);
|
|
127
|
+
};
|
|
128
|
+
const request = (item, folders, inherited) => {
|
|
129
|
+
const where = [...folders, String(item.name ?? "")].join(" / ");
|
|
130
|
+
const source = object(item.request) ? item.request : { url: item.request };
|
|
131
|
+
const url = source.url;
|
|
132
|
+
const structured = object(url) ? url : object(source.urlObject) ? source.urlObject : {};
|
|
133
|
+
const raw = (typeof url === "string" ? url : object(url) && typeof url.raw === "string" ? url.raw : "").trim();
|
|
134
|
+
const [address = "", query = ""] = raw.split(/\?(.*)/s);
|
|
135
|
+
const base = /^(?:[a-z]+:\/\/)?[^/]*/i.exec(address)?.[0] ?? "";
|
|
136
|
+
if (!base) {
|
|
137
|
+
problems.push(`${where}: the request has no URL`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const method = String(source.method ?? "GET").toUpperCase();
|
|
141
|
+
const segments = address
|
|
142
|
+
.slice(base.length)
|
|
143
|
+
.split("/")
|
|
144
|
+
.filter(Boolean)
|
|
145
|
+
.map((segment) => segment.replace(/\{\{([^}]+)\}\}/g, "{$1}").replace(/^:(.+)$/, "{$1}"));
|
|
146
|
+
const path = `/${segments.join("/")}`;
|
|
147
|
+
const key = `${method} ${path}`;
|
|
148
|
+
if (exclude[key] !== undefined) {
|
|
149
|
+
used.add(key);
|
|
150
|
+
omissions.push(`${key}: excluded — ${exclude[key]}`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const server = (/^[a-z]+:\/\//i.test(base) || base.startsWith("{{") ? base : `https://${base}`)
|
|
154
|
+
.trim()
|
|
155
|
+
.replace(/\{\{([^}]+)\}\}/g, "{$1}");
|
|
156
|
+
if (host === undefined)
|
|
157
|
+
host = server;
|
|
158
|
+
else if (host !== server) {
|
|
159
|
+
problems.push(`${where}: on ${server}, not ${host}; exclude one with a reason`);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const verb = method.toLowerCase();
|
|
163
|
+
paths[path] ??= {};
|
|
164
|
+
const entry = paths[path];
|
|
165
|
+
if (entry[verb]) {
|
|
166
|
+
omissions.push(`${key}: "${item.name}" (${where}) merged into "${names.get(key)}", same method and path`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
names.set(key, String(item.name));
|
|
170
|
+
const described = (list) => new Map(list.map((one) => [String(one.key), text(one.description)?.trim()]));
|
|
171
|
+
const pathNotes = described(pairs(structured.variable));
|
|
172
|
+
const queryNotes = described(pairs(structured.query));
|
|
173
|
+
const headers = pairs(source.header);
|
|
174
|
+
const parameters = [
|
|
175
|
+
...[...path.matchAll(/\{([^}]+)\}/g)].map(([, name = ""]) => ({
|
|
176
|
+
name,
|
|
177
|
+
in: "path",
|
|
178
|
+
required: true,
|
|
179
|
+
...(pathNotes.get(name) ? { description: pathNotes.get(name) } : {}),
|
|
180
|
+
schema: { type: "string" },
|
|
181
|
+
})),
|
|
182
|
+
...[
|
|
183
|
+
...new Set([
|
|
184
|
+
...pairs(structured.query).map((one) => String(one.key ?? "")),
|
|
185
|
+
...query.split("&").map((pair) => decodeURIComponent(pair.split("=")[0] ?? "")),
|
|
186
|
+
]),
|
|
187
|
+
]
|
|
188
|
+
.filter(Boolean)
|
|
189
|
+
.map((name) => ({
|
|
190
|
+
name,
|
|
191
|
+
in: "query",
|
|
192
|
+
required: false,
|
|
193
|
+
...(queryNotes.get(name) ? { description: queryNotes.get(name) } : {}),
|
|
194
|
+
schema: { type: "string" },
|
|
195
|
+
})),
|
|
196
|
+
...headers
|
|
197
|
+
.filter((one) => !NOT_PARAMETERS.has(String(one.key).toLowerCase()))
|
|
198
|
+
.map((one) => ({
|
|
199
|
+
name: String(one.key),
|
|
200
|
+
in: "header",
|
|
201
|
+
required: one.disabled !== true,
|
|
202
|
+
...(text(one.description) ? { description: text(one.description) } : {}),
|
|
203
|
+
schema: { type: "string" },
|
|
204
|
+
})),
|
|
205
|
+
];
|
|
206
|
+
const header = (name) => headers.find((one) => String(one.key).toLowerCase() === name && one.disabled !== true)?.value;
|
|
207
|
+
const operation = { summary: String(item.name ?? key), parameters };
|
|
208
|
+
const description = text(source.description) ?? text(item.description);
|
|
209
|
+
if (description)
|
|
210
|
+
operation.description = description;
|
|
211
|
+
if (folders.length > 0)
|
|
212
|
+
operation.tags = [folders.join(" / ")];
|
|
213
|
+
try {
|
|
214
|
+
const security = securityOf(object(source.auth) && source.auth.type !== "inherit" ? source.auth : inherited, header("authorization"), where);
|
|
215
|
+
if (security)
|
|
216
|
+
operation.security = security;
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
if (!(error instanceof CodegenError))
|
|
220
|
+
throw error;
|
|
221
|
+
for (const problem of error.problems)
|
|
222
|
+
problems.push(problem);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const body = object(source.body) ? source.body : undefined;
|
|
226
|
+
const mode = body ? String(body.mode) : undefined;
|
|
227
|
+
if (mode === "raw" && typeof body?.raw === "string" && body.raw.trim()) {
|
|
228
|
+
const type = (header("content-type") ?? "application/json").split(";")[0]?.trim() ?? "application/json";
|
|
229
|
+
let example;
|
|
230
|
+
try {
|
|
231
|
+
example = JSON.parse(body.raw);
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
if (/json/i.test(type))
|
|
235
|
+
omissions.push(`${key}: the body's example is not JSON, so the body is an open object; its notes are left out`);
|
|
236
|
+
}
|
|
237
|
+
operation.requestBody = {
|
|
238
|
+
required: true,
|
|
239
|
+
content: {
|
|
240
|
+
[type]: example === undefined
|
|
241
|
+
? {
|
|
242
|
+
schema: /json/i.test(type)
|
|
243
|
+
? { type: "object", additionalProperties: true }
|
|
244
|
+
: { type: "string", format: "binary" },
|
|
245
|
+
}
|
|
246
|
+
: { schema: openSchema(example), example },
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
else if ((mode === "urlencoded" || mode === "formdata") && pairs(body?.[mode]).length > 0) {
|
|
251
|
+
const fields = pairs(body?.[mode]);
|
|
252
|
+
operation.requestBody = {
|
|
253
|
+
required: true,
|
|
254
|
+
content: {
|
|
255
|
+
[mode === "urlencoded" ? "application/x-www-form-urlencoded" : "multipart/form-data"]: {
|
|
256
|
+
schema: {
|
|
257
|
+
type: "object",
|
|
258
|
+
properties: Object.fromEntries(fields.map((one) => [
|
|
259
|
+
String(one.key),
|
|
260
|
+
one.type === "file" ? { type: "string", format: "binary" } : { type: "string" },
|
|
261
|
+
])),
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
else if (mode && mode !== "raw" && mode !== "urlencoded" && mode !== "formdata")
|
|
268
|
+
omissions.push(`${key}: the body in ${mode} mode is left out`);
|
|
269
|
+
operation.responses = { "200": { description: "OK" } };
|
|
270
|
+
entry[verb] = operation;
|
|
271
|
+
};
|
|
272
|
+
const walk = (items, folders, inherited) => {
|
|
273
|
+
for (const item of items.filter(object)) {
|
|
274
|
+
const auth = object(item.auth) && item.auth.type !== "inherit" ? item.auth : inherited;
|
|
275
|
+
if (Array.isArray(item.item))
|
|
276
|
+
walk(item.item, [...folders, String(item.name ?? "")], auth);
|
|
277
|
+
else
|
|
278
|
+
request(item, folders, auth);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
walk(collection.item, [], object(collection.auth) ? collection.auth : undefined);
|
|
282
|
+
const serverVariables = Object.fromEntries([...(host ?? "").matchAll(/\{([^}]+)\}/g)].map(([, name = ""]) => [name, variables[name]]));
|
|
283
|
+
for (const [name, value] of Object.entries(serverVariables))
|
|
284
|
+
if (value === undefined)
|
|
285
|
+
problems.push(`the host variable {{${name}}} has no value; give it in options.variables`);
|
|
286
|
+
const stale = Object.keys(exclude).filter((key) => !used.has(key));
|
|
287
|
+
for (const key of stale)
|
|
288
|
+
problems.push(`exclusion "${key}" matches no request — stale, or the request changed`);
|
|
289
|
+
if (problems.length > 0)
|
|
290
|
+
throw new CodegenError(problems);
|
|
291
|
+
const version = options.version ?? text(collection.info.version) ?? "unknown";
|
|
292
|
+
return {
|
|
293
|
+
document: {
|
|
294
|
+
openapi: "3.1.0",
|
|
295
|
+
info: { title: String(collection.info.name ?? "Postman collection"), version },
|
|
296
|
+
...(host
|
|
297
|
+
? {
|
|
298
|
+
servers: [
|
|
299
|
+
{
|
|
300
|
+
url: host,
|
|
301
|
+
...(Object.keys(serverVariables).length > 0
|
|
302
|
+
? {
|
|
303
|
+
variables: Object.fromEntries(Object.entries(serverVariables).map(([name, value]) => [name, { default: value }])),
|
|
304
|
+
}
|
|
305
|
+
: {}),
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
}
|
|
309
|
+
: {}),
|
|
310
|
+
components: Object.keys(schemes).length > 0 ? { securitySchemes: schemes } : {},
|
|
311
|
+
paths: Object.fromEntries(Object.entries(paths).filter(([, item]) => Object.keys(item).length > 0)),
|
|
312
|
+
},
|
|
313
|
+
omissions,
|
|
314
|
+
};
|
|
315
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Override } from "./model.js";
|
|
1
2
|
type Json = Record<string, unknown>;
|
|
2
3
|
export interface WpJsonOptions {
|
|
3
4
|
/** The namespaces the CLI offers, as `wp/v2`; every other route is left out and listed in `omissions`. */
|
|
@@ -12,6 +13,11 @@ export interface WpJsonOptions {
|
|
|
12
13
|
export interface WpJsonResult {
|
|
13
14
|
/** An OpenAPI 3.1 document for `adaptOpenApi`. */
|
|
14
15
|
document: Json;
|
|
16
|
+
/**
|
|
17
|
+
* For `generate`'s `overrides`: how each collection read pages. WordPress answers the list itself, counts pages from
|
|
18
|
+
* 1 and gives their number in `X-WP-TotalPages`; a page past it is an error, not an empty list.
|
|
19
|
+
*/
|
|
20
|
+
overrides: Record<string, Override>;
|
|
15
21
|
/** What the document leaves out, one line each, for a reviewer. */
|
|
16
22
|
omissions: string[];
|
|
17
23
|
}
|
package/dist/codegen/wp-json.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
12
12
|
import { join } from "node:path";
|
|
13
|
+
import { derivedId } from "./openapi.js";
|
|
13
14
|
import { CodegenError } from "./pipeline.js";
|
|
14
15
|
import { sha256, sortKeys } from "./snapshot.js";
|
|
15
16
|
const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
@@ -125,6 +126,7 @@ const template = (route) => {
|
|
|
125
126
|
return "slash";
|
|
126
127
|
return { path, patterns };
|
|
127
128
|
};
|
|
129
|
+
const BATCH = "batch/v1";
|
|
128
130
|
/** Collection reads page with `page` and `per_page` and answer a list; every other answer is one item. */
|
|
129
131
|
const isList = (args) => "per_page" in args && "page" in args;
|
|
130
132
|
/**
|
|
@@ -136,11 +138,15 @@ const isList = (args) => "per_page" in args && "page" in args;
|
|
|
136
138
|
export const wpJsonToOpenApi = (index, options) => {
|
|
137
139
|
if (!object(index) || !object(index.routes))
|
|
138
140
|
throw new CodegenError(["not a WordPress REST index: no routes"]);
|
|
141
|
+
// One batch call carries requests to other routes in its body, past every key those routes need.
|
|
142
|
+
if (options.namespaces.includes(BATCH))
|
|
143
|
+
throw new CodegenError([`${BATCH} is never offered: a batch call runs other routes' writes past their own keys`]);
|
|
139
144
|
const exclude = options.exclude ?? {};
|
|
140
145
|
const used = new Set();
|
|
141
146
|
const problems = [];
|
|
142
147
|
const omissions = [];
|
|
143
148
|
const paths = {};
|
|
149
|
+
const overrides = {};
|
|
144
150
|
const schemas = {};
|
|
145
151
|
const left = new Map();
|
|
146
152
|
const schemaRef = (route, schema) => {
|
|
@@ -239,6 +245,18 @@ export const wpJsonToOpenApi = (index, options) => {
|
|
|
239
245
|
if (raw.schema !== undefined && method !== "DELETE") {
|
|
240
246
|
const ref = schemaRef(route, raw.schema);
|
|
241
247
|
const answer = method === "GET" && isList(args) ? { type: "array", items: ref } : ref;
|
|
248
|
+
if (method === "GET" && isList(args))
|
|
249
|
+
overrides[derivedId("get", path)] = {
|
|
250
|
+
pagination: {
|
|
251
|
+
style: "page",
|
|
252
|
+
page: { in: "query", name: "page" },
|
|
253
|
+
limit: { in: "query", name: "per_page" },
|
|
254
|
+
items: "",
|
|
255
|
+
start: 1,
|
|
256
|
+
pagesHeader: "x-wp-totalpages",
|
|
257
|
+
},
|
|
258
|
+
reason: "WordPress counts pages from 1 and gives their number in X-WP-TotalPages",
|
|
259
|
+
};
|
|
242
260
|
operation.responses = { "200": { description: "OK", content: { "application/json": { schema: answer } } } };
|
|
243
261
|
}
|
|
244
262
|
else
|
|
@@ -275,6 +293,7 @@ export const wpJsonToOpenApi = (index, options) => {
|
|
|
275
293
|
paths,
|
|
276
294
|
},
|
|
277
295
|
omissions,
|
|
296
|
+
overrides,
|
|
278
297
|
};
|
|
279
298
|
};
|
|
280
299
|
const FILE = "wp-json.json";
|
package/dist/http/fetch.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ export interface HostFetchOptions {
|
|
|
6
6
|
/** For the whole exchange, every redirect and the body. */
|
|
7
7
|
timeoutMs?: number;
|
|
8
8
|
redirects?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Where the sign-in may go, as `https://host/blog/wp-json`: a site under a path shares its host with others. A signed
|
|
11
|
+
* request outside it is refused, and a redirect out of it drops the sign-in. Without it, the origin is the limit.
|
|
12
|
+
*/
|
|
13
|
+
credentialScope?: string;
|
|
9
14
|
}
|
|
10
15
|
export declare const HOST_FETCH_TIMEOUT_MS = 30000;
|
|
11
16
|
/** `fetch` that reaches only the declared hosts, checks every redirect hop, and gives up after `timeoutMs`. */
|
package/dist/http/fetch.js
CHANGED
|
@@ -37,6 +37,20 @@ const checked = (url, hosts) => {
|
|
|
37
37
|
throw undeclared(url);
|
|
38
38
|
return url;
|
|
39
39
|
};
|
|
40
|
+
// A server that decodes `%2F` before it routes would take `/blog/..%2F..%2Fother` out of the scope the prefix saw.
|
|
41
|
+
const ENCODED_SLASH = /%2f|%5c/i;
|
|
42
|
+
const scopeOf = (scope) => {
|
|
43
|
+
if (scope === undefined)
|
|
44
|
+
return undefined;
|
|
45
|
+
if (!URL.canParse(scope))
|
|
46
|
+
throw new CliError("configuration_error", `credentialScope ${scope} is not a URL`);
|
|
47
|
+
const { origin, pathname } = new URL(scope);
|
|
48
|
+
const prefix = pathname.endsWith("/") ? pathname : `${pathname}/`;
|
|
49
|
+
return (url) => url.origin === origin &&
|
|
50
|
+
(url.pathname === pathname || url.pathname.startsWith(prefix)) &&
|
|
51
|
+
!ENCODED_SLASH.test(url.pathname);
|
|
52
|
+
};
|
|
53
|
+
const signedHeaders = (headers) => CREDENTIAL_HEADERS.some((name) => headers.has(name));
|
|
40
54
|
/**
|
|
41
55
|
* A name lookup or a connection the host refused fails before a byte of the request leaves, so even a write may be sent
|
|
42
56
|
* again. Node's fetch puts the system's code on the cause, an AggregateError when it tried several addresses; a
|
|
@@ -57,6 +71,7 @@ export const hostFetch = (options) => {
|
|
|
57
71
|
if (problems.length > 0)
|
|
58
72
|
throw new CliError("configuration_error", problems.join("; "));
|
|
59
73
|
const { hosts, fetch: send = globalThis.fetch, timeoutMs = HOST_FETCH_TIMEOUT_MS, redirects = REDIRECTS } = options;
|
|
74
|
+
const inScope = scopeOf(options.credentialScope);
|
|
60
75
|
return async (input, init = {}) => {
|
|
61
76
|
const request = input instanceof Request ? input : undefined;
|
|
62
77
|
let url = checked(new URL(request?.url ?? String(input)), hosts);
|
|
@@ -67,6 +82,10 @@ export const hostFetch = (options) => {
|
|
|
67
82
|
let method = (init.method ?? request?.method ?? "GET").toUpperCase();
|
|
68
83
|
let body = init.body ?? request?.body ?? undefined;
|
|
69
84
|
const headers = new Headers(init.headers ?? request?.headers);
|
|
85
|
+
if (inScope && signedHeaders(headers) && !inScope(url))
|
|
86
|
+
throw new CliError("configuration_error", `the sign-in goes only under ${options.credentialScope}, not ${url.origin}${url.pathname}`, {
|
|
87
|
+
sent: false,
|
|
88
|
+
});
|
|
70
89
|
// A redirect means the first request arrived: a later hop's failure no longer proves nothing was sent.
|
|
71
90
|
let answered = false;
|
|
72
91
|
try {
|
|
@@ -88,7 +107,7 @@ export const hostFetch = (options) => {
|
|
|
88
107
|
}
|
|
89
108
|
else if (body instanceof ReadableStream)
|
|
90
109
|
throw new CliError("invalid_response", `${url.hostname} redirected a streamed body, which cannot be sent again`);
|
|
91
|
-
if (next.origin !== url.origin)
|
|
110
|
+
if (inScope ? !inScope(next) : next.origin !== url.origin)
|
|
92
111
|
for (const name of CREDENTIAL_HEADERS)
|
|
93
112
|
headers.delete(name);
|
|
94
113
|
url = next;
|
package/dist/standards/audit.js
CHANGED
|
@@ -158,13 +158,28 @@ export const PARITY_GROUPS = defineParityGroups([
|
|
|
158
158
|
},
|
|
159
159
|
// bitrix24-cli's search is cli-core's CRM `search all`, and beeline-cli's and asterisk-cli's meetings take call
|
|
160
160
|
// recordings, not zoom-cli's: they are compared on the root commands every CLI shares, the way gcal and mail are.
|
|
161
|
-
// amo-cli and
|
|
161
|
+
// amo-cli, hubspot-cli and attio-cli share them too, and their CRM commands are compared with b24 in `crm` below.
|
|
162
162
|
// notion-cli joins here until its documents commands ship; then it moves next to drive. ydisk joins here too: in "all"
|
|
163
163
|
// its search and notes differ from the messengers' and memo's as drive's do, and a documents group of drive, notion
|
|
164
164
|
// and ydisk differs in 39 paths (session, folders browse, summaries; measured on the published CLIs 2026-11-17).
|
|
165
165
|
{
|
|
166
166
|
name: "shared-roots",
|
|
167
|
-
members: [
|
|
167
|
+
members: [
|
|
168
|
+
"tg",
|
|
169
|
+
"max",
|
|
170
|
+
"memo",
|
|
171
|
+
"drive",
|
|
172
|
+
"zm",
|
|
173
|
+
"wa",
|
|
174
|
+
"b24",
|
|
175
|
+
"beeline",
|
|
176
|
+
"pbx",
|
|
177
|
+
"notion",
|
|
178
|
+
"amo",
|
|
179
|
+
"hubspot",
|
|
180
|
+
"attio",
|
|
181
|
+
"ydisk",
|
|
182
|
+
],
|
|
168
183
|
covers: ["commands", "doctor", "skill", "mcp", "upgrade"],
|
|
169
184
|
differences: [...MEMO_HAS_NO_PROFILES, ...MEMO_MCP_SUMMARIES, MEMO_DOCTOR_DEEP],
|
|
170
185
|
},
|
|
@@ -177,7 +192,7 @@ export const PARITY_GROUPS = defineParityGroups([
|
|
|
177
192
|
// commands: measured against b24 0.23.0 on 2026-11-16 they differ in options, outputs and summaries.
|
|
178
193
|
{
|
|
179
194
|
name: "crm",
|
|
180
|
-
members: ["b24", "amo", "hubspot"],
|
|
195
|
+
members: ["b24", "amo", "hubspot", "attio"],
|
|
181
196
|
covers: ["deals", "sync", "search", "store", "schedule", "account"],
|
|
182
197
|
differences: [
|
|
183
198
|
{
|
|
@@ -49,6 +49,7 @@ what it cannot do yet.
|
|
|
49
49
|
| Google Discovery | `adaptDiscovery(readDiscovery(dir))`, snapshots written by `syncDiscovery` |
|
|
50
50
|
| GraphQL (Linear) | `adaptGraphql(readGraphql(dir), { url, scalars })`, the introspection result written by `syncGraphql` |
|
|
51
51
|
| WordPress's REST index | `adaptOpenApi(wpJsonToOpenApi(readWpJson(dir), { namespaces: ["wp/v2"] }).document)`, the index written by `syncWpJson` |
|
|
52
|
+
| A Postman collection v2.0 or v2.1 (Braze) | `adaptOpenApi(postmanToOpenApi(collection, { variables }).document)`, the collection committed in `spec/<service>/` with its provenance; a POST that only reads gets an `effect` override |
|
|
52
53
|
|
|
53
54
|
`upgradeToOpenApi3` converts with [swagger-converter](https://github.com/apigee-127/swagger-converter) (1.2 → 2.0) and
|
|
54
55
|
[@scalar/openapi-upgrader](https://github.com/scalar/scalar/tree/main/packages/openapi-upgrader) (2.0 → 3.0). They are
|
|
@@ -107,7 +108,7 @@ From the source the generator reads:
|
|
|
107
108
|
empty or not in kebab case stops generation; map that operation in `commands`. `segments` renames a path segment
|
|
108
109
|
or, with `""`, leaves it out: `{ "0-3": "deals", crm: "", objects: "" }`. Without `names` the command is the operation
|
|
109
110
|
id in kebab case, as before.
|
|
110
|
-
- **`permissions`**: `{ group, deletingFlags, shares, valueKeys }`. `group` is a name (`files`) or a function of the operation, for
|
|
111
|
+
- **`permissions`**: `{ group, deletingFlags, forceFlags, shares, valueKeys }`. `group` is a name (`files`) or a function of the operation, for
|
|
111
112
|
example the first word of its `command` (set only with `names`). Each key lands in the manifest as the operation's `permissions`.
|
|
112
113
|
- `<group>.delete` for every destructive operation (Yandex Disk's `DELETE /trash/resources` empties the whole
|
|
113
114
|
trash), and for every operation that takes a flag in `deletingFlags`, as a top-level body field (Notion's
|
|
@@ -121,7 +122,14 @@ From the source the generator reads:
|
|
|
121
122
|
`posts.publish` and `pages.publish`. The key applies when the call sends one of those values, in the body or the
|
|
122
123
|
query; where the field's default is one of them (a WordPress template), leaving it out publishes too, and the key
|
|
123
124
|
always applies. A read that filters by the value gets no key, nor a field of that name without such an enum (a
|
|
124
|
-
comment's `status`); a rule no write matches stops generation.
|
|
125
|
+
comment's `status`); a rule no write matches stops generation. `also` names fields that make the same change
|
|
126
|
+
another way: WordPress publishes a scheduled post whose `date` moves into the past, so with
|
|
127
|
+
`also: ["date", "date_gmt"]` setting either needs the key too, unless the call itself sets `field` to another value
|
|
128
|
+
its enum lists (for WordPress `draft`, `pending`, `private`). A call that leaves `field` out needs the key: the
|
|
129
|
+
stored value is unknown without a read. An `also` field no guarded write takes stops generation.
|
|
130
|
+
- `<group>.delete.force` beside `<group>.delete` on every delete that takes a flag in `forceFlags`: WordPress's
|
|
131
|
+
`force=true` deletes for good, where a delete without it moves to the trash. The key applies when the flag is
|
|
132
|
+
`true`. A flag no delete takes stops generation.
|
|
125
133
|
|
|
126
134
|
Which flags delete is the CLI's call: read the service's documentation, and count an undocumented flag as a delete.
|
|
127
135
|
A flag counts on every method, a GET included: Yandex Disk's upload link is a GET whose `overwrite` replaces a file.
|
|
@@ -133,7 +141,9 @@ From the source the generator reads:
|
|
|
133
141
|
string, so a `start` date is not taken for an offset. Answer fields are dotted paths. Only reads page: a POST
|
|
134
142
|
search pages once `readingPosts` or an override makes it a read. An override's
|
|
135
143
|
`pagination` sets it where detection misses or misreads, and `pagination: null` says the read does not page; a
|
|
136
|
-
parameter the operation does not take stops generation.
|
|
144
|
+
parameter the operation does not take stops generation. A page style may say where the first page is (`start: 1`)
|
|
145
|
+
and name a response header with the number of pages (`pagesHeader: "x-wp-totalpages"`), with `items: ""` when the
|
|
146
|
+
answer itself is the list: WordPress's, which `wpJsonToOpenApi` gives in its `overrides`.
|
|
137
147
|
- **`auth`**: `{ securitySchemes, security, reason }` replaces the source's sign-in, the operations' own requirements
|
|
138
148
|
included. Yandex Disk's Swagger 1.2 has no scheme, and its header is `Authorization: OAuth <token>`:
|
|
139
149
|
`{ oauth: { type: "http", scheme: "OAuth" } }`. HubSpot's spec has no private app token. An operation keeps its own
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.120.0",
|
|
4
4
|
"description": "The parts every command line tool needs: output modes, terminal rendering, error model, exit codes, credentials, clocks",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|