@wirecat/cli-core 0.703.0 → 0.705.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +135 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/bot/api-http.d.ts +8 -2
- package/dist/cli/bot/api-http.js +20 -4
- package/dist/cli/documents/words.d.ts +1 -1
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +3 -3
- package/dist/cli/messenger/store-maintenance-command.js +6 -2
- package/dist/cli/service-api-call.d.ts +13 -3
- package/dist/cli/service-api-call.js +19 -9
- package/dist/cli/service-api-manifest.d.ts +11 -2
- package/dist/cli/service-api-manifest.js +30 -9
- package/dist/cli/service-api.d.ts +14 -6
- package/dist/cli/service-api.js +137 -29
- package/dist/cli/token-session.d.ts +5 -2
- package/dist/cli/token-session.js +13 -4
- package/dist/content/cli/index.d.ts +33 -0
- package/dist/content/cli/index.js +368 -0
- package/dist/content/index.d.ts +8 -0
- package/dist/content/index.js +7 -0
- package/dist/content/manifest/index.d.ts +4 -0
- package/dist/content/manifest/index.js +4 -0
- package/dist/content/manifest/manifest.d.ts +92 -0
- package/dist/content/manifest/manifest.js +137 -0
- package/dist/content/manifest/map.d.ts +25 -0
- package/dist/content/manifest/map.js +94 -0
- package/dist/content/manifest/source.d.ts +41 -0
- package/dist/content/manifest/source.js +288 -0
- package/dist/content/manifest/writer.d.ts +26 -0
- package/dist/content/manifest/writer.js +133 -0
- package/dist/content/source.d.ts +64 -0
- package/dist/content/source.js +2 -0
- package/dist/content/sync.d.ts +61 -0
- package/dist/content/sync.js +387 -0
- package/dist/content/testing/index.d.ts +4 -0
- package/dist/content/testing/index.js +4 -0
- package/dist/content/testing/source-contract.d.ts +38 -0
- package/dist/content/testing/source-contract.js +274 -0
- package/dist/content/testing/source.d.ts +55 -0
- package/dist/content/testing/source.js +276 -0
- package/dist/content/testing/sync-contract.d.ts +10 -0
- package/dist/content/testing/sync-contract.js +172 -0
- package/dist/content/testing/write-contract.d.ts +14 -0
- package/dist/content/testing/write-contract.js +102 -0
- package/dist/content/writer.d.ts +64 -0
- package/dist/content/writer.js +38 -0
- package/dist/content/writes.d.ts +58 -0
- package/dist/content/writes.js +129 -0
- package/dist/documents/file-mirror-model.d.ts +90 -0
- package/dist/documents/file-mirror-model.js +1 -0
- package/dist/documents/index.d.ts +6 -3
- package/dist/documents/index.js +3 -1
- package/dist/documents/push-model.d.ts +3 -0
- package/dist/domain/content.d.ts +102 -0
- package/dist/domain/content.js +11 -0
- package/dist/embeddings/onnx-runtime.d.ts +1 -1
- package/dist/embeddings/onnx-runtime.js +42 -61
- package/dist/errors/reasons.js +22 -0
- package/dist/manifest/index.d.ts +21 -7
- package/dist/manifest/index.js +7 -4
- package/dist/ports/wirecat-tools.js +7 -0
- package/dist/sends/upload.js +0 -1
- package/dist/services/documents/mirror-watch.d.ts +12 -4
- package/dist/services/documents/mirror-watch.js +2 -0
- package/dist/services/documents/mirrors.d.ts +67 -35
- package/dist/services/documents/mirrors.js +72 -66
- package/dist/services/documents/push.d.ts +56 -4
- package/dist/services/documents/push.js +131 -24
- package/dist/services/files/mirror.d.ts +157 -0
- package/dist/services/files/mirror.js +660 -0
- package/dist/services/files/versions.d.ts +60 -0
- package/dist/services/files/versions.js +177 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/recover.js +2 -0
- package/dist/store/sqlite/account-purge.js +7 -0
- package/dist/store/sqlite/content.d.ts +100 -0
- package/dist/store/sqlite/content.js +375 -0
- package/dist/store/sqlite/entity-types.d.ts +1 -0
- package/dist/store/sqlite/entity-types.js +1 -0
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +26 -0
- package/dist/store/sqlite/schema.d.ts +1140 -0
- package/dist/store/sqlite/schema.js +100 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/package.json +12 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,141 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.705.0 — 19.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **The first screen's "Works with" names `amo`** (amoCRM and Kommo, `@wirecat/amo-cli`), now that it is on npm.
|
|
13
|
+
- **The content category: posts and pages of a site such as WordPress, in the store.** Store version 71 adds
|
|
14
|
+
channels, authors, tags and categories, posts with their text as Markdown, the versions a sync or a write replaced,
|
|
15
|
+
metrics readings and a word index. `@wirecat/cli-core/content` has the `ContentSource` and `ContentWriter` ports,
|
|
16
|
+
`syncContent` (a trashed post stays with the status `trashed`, a post deleted for good is marked so only by a
|
|
17
|
+
complete id pass, and a pass is held when the sign-in read only part or the site moved), and `addContentCommands`:
|
|
18
|
+
`sync`, `posts list|show|search`, `authors list`, `terms list`, `channels list`, `metrics show`, and with writes
|
|
19
|
+
`posts create|update|publish|unpublish|schedule|delete`. Publishing asks first (`posts.publish`, the key the `api`
|
|
20
|
+
group checks), and so do an edit of a public post and a deletion past the trash (`posts.delete.force`).
|
|
21
|
+
- **`contentSourceFromManifest` and `contentWriterFromManifest`** build a content CLI's source and writer from
|
|
22
|
+
configuration over its generated `api` group. A WordPress manifest needs no hook. The category `content` joins
|
|
23
|
+
`wirecat.config`. See [Content](docs/dev/CONTENT.md).
|
|
24
|
+
- **`/content/testing`**: `contentSourceContract`, `contentSyncContract`, `contentWriteContract` and
|
|
25
|
+
`fakeContentSource`.
|
|
26
|
+
- **A file mirror keeps the remote content it replaces, too.** Before an upload overwrites a remote file, the old
|
|
27
|
+
content is kept in the mirror's version store, downloaded first when the store does not have it. A remote deletion
|
|
28
|
+
downloads nothing, since the provider's trash holds the file; its log entry says `oldIn: "remote-trash"` when the
|
|
29
|
+
store lacks the content. Each log entry says in `from` which side its `old` content came from. When the store
|
|
30
|
+
cannot keep a content, a full disk during the download included, the file fails with `mirror.version-not-kept`
|
|
31
|
+
and nothing is replaced; a remote file that changed since the listing fails with `mirror.remote-changed`
|
|
32
|
+
([DOCUMENTS.md](docs/dev/DOCUMENTS.md#sync-plain-files-with-a-provider)).
|
|
33
|
+
- **`skippedName` in `@wirecat/cli-core/documents`,** so a target skips `.git`, `node_modules` and editor leftovers
|
|
34
|
+
while it lists. `syncFileMirror` takes `hints` to name the app's own preview, repin and allow-deletions commands in
|
|
35
|
+
its messages.
|
|
36
|
+
- **`syncFileMirrors` and `restoreFileVersion` take the lock `acquireLock` returns.** Its `held()` is checked before
|
|
37
|
+
every write; a caller no longer keeps its own flag. A lock with `assertHeld` works as before.
|
|
38
|
+
- **`serviceApiWriter`: a write from code through the `api` group's own guard.** A content command that publishes or
|
|
39
|
+
deletes through a generated manifest now checks the same keys as `<cli> api <operation>`: `api.<operation>` and
|
|
40
|
+
every manifest key the call sets off (`posts.publish`, `posts.delete.force`), at the profile's levels, with the same
|
|
41
|
+
question and journal line. `confirmed` names keys the command already asked about in this run, so a person is
|
|
42
|
+
asked once; a `deny` or `readonly` on them still stops the write. The writer checks parameters and the body against
|
|
43
|
+
the schemas as the command does, and refuses a query parameter or header the operation does not declare (a
|
|
44
|
+
method override among them), so it reaches no further than the command.
|
|
45
|
+
- **`serviceApiCall(…).withHeaders` gives a read's response headers**, and `nextPage` takes them: a page style with
|
|
46
|
+
`pagesHeader` (WordPress's `X-WP-TotalPages`) stops at the last page instead of asking for one past the end, which
|
|
47
|
+
WordPress refuses. `items: ""` reads the answer itself as the list, and `start` is the first page's number, so
|
|
48
|
+
`api … --all` on such a read needs no `--page`. `nextPage`, `PageStep` and `underBase` are exported.
|
|
49
|
+
- **A manifest key can lift itself with `unless`.** WordPress publishes a scheduled post whose `date` moves into the
|
|
50
|
+
past; the generated key on `date` and `date_gmt` applies unless the call itself sets `status` to draft, pending or
|
|
51
|
+
private. Such a field counts once sent, `null` included, as WordPress resets a null date to now. A flag now counts in
|
|
52
|
+
the body or the query, as WordPress reads both.
|
|
53
|
+
- **`manifestVerify` checks a sign-in on the owner's own site.** For a service on the owner's site (WordPress), the
|
|
54
|
+
check goes to the site `session start --site` names, and its `fetch` gets that site, as its host is not among the
|
|
55
|
+
CLI's own. A `fetch` that takes one argument still works.
|
|
56
|
+
- **`wirecat.config.ts` takes `spec.kind: "wp-json"` (with the `spec.version` the index runs) and `auth.preset: "app-password"`** for a WordPress CLI made with
|
|
57
|
+
`new --from-config`.
|
|
58
|
+
|
|
59
|
+
### Changed — may break callers
|
|
60
|
+
|
|
61
|
+
- **`FileVersions` has `has(sha256)`, and `keep` takes a writer as well as a path.** Code that implements
|
|
62
|
+
`FileVersions` itself adds `has`; `fileVersions()` has both. `FileMirrorOptions.assertHeld` may return a promise.
|
|
63
|
+
- **`--all` refuses a next link outside the server's path.** A service whose links point to another path on the same
|
|
64
|
+
host (a `/v2` link from a `/v1` server) now stops with `invalid_response` instead of following it.
|
|
65
|
+
- **Requires `@wirecat/cli-base` 0.120.0** for the new page style fields and `unless`.
|
|
66
|
+
|
|
67
|
+
### Fixed
|
|
68
|
+
|
|
69
|
+
- **A raw read that names its command's read key is sent as a read.** A CLI can put `people.list` on `api
|
|
70
|
+
contacts-list`, so `people: deny` stops the raw read too (WC-PERM-22). Before, any key beyond `api.*` sent the read
|
|
71
|
+
the way a write goes, with an `operation_id` in the answer, and refused `--all`. Now `deny` refuses it, `allow`
|
|
72
|
+
sends it as a read with `--all`, and only `ask` keeps the write's path. Found by the hubspot-cli review.
|
|
73
|
+
- **A download that replaced a file is never reported as cut off.** Only a new file can be left partial, so only a
|
|
74
|
+
new file's interrupted download makes the path a conflict. A download that fails cleanly clears its pending entry
|
|
75
|
+
(kept while a partial copy could not be removed),
|
|
76
|
+
and a leftover temporary file under a symbolic link is left alone. The error for an empty local folder says what
|
|
77
|
+
to do: mount it, or add a file or remove the mirror's state when the files really were deleted.
|
|
78
|
+
- **A content source from a manifest pages by `nextPage` with the answer's headers.** Its own reader of the page count
|
|
79
|
+
is gone.
|
|
80
|
+
- **`session start --login` names where to make the password only at a terminal.** Piped in, as an agent or a test
|
|
81
|
+
signs in, the note stood before the JSON error on stderr.
|
|
82
|
+
|
|
83
|
+
### Security
|
|
84
|
+
|
|
85
|
+
- **A sign-in never leaves the server's path.** For a site under a path (`host/blog`, a WordPress multisite in
|
|
86
|
+
subfolders), `--all` refuses a next page outside the base URL's path, not only outside its origin, and the `api`
|
|
87
|
+
group, the writer and `serviceApiCall` refuse to sign a request outside it, and a signed request to a site (a server
|
|
88
|
+
with free variables) follows no redirect: its error names the address the site moved to, without its query.
|
|
89
|
+
`hostsFetch` takes a `credentialScope` that refuses a signed request outside it and drops the sign-in on a redirect
|
|
90
|
+
out of it (cli-base `hostFetch`).
|
|
91
|
+
- **`<PREFIX>_TOKEN_SITE` is cleaned as `--site` is.** `host/blog/..` was the root site of the same host, and the
|
|
92
|
+
password went there.
|
|
93
|
+
|
|
94
|
+
## 0.704.0 — 19.11.2026
|
|
95
|
+
|
|
96
|
+
### Added
|
|
97
|
+
|
|
98
|
+
- **`syncFileMirror` and the `FileTarget` port in `@wirecat/cli-core/documents`: two-way sync of plain files.** A CLI
|
|
99
|
+
for a file store (Yandex Disk next) keeps a local folder and a remote folder the same, whole files at a time,
|
|
100
|
+
binary and large files included, streamed both ways. A change on one side is copied, the same content on both is
|
|
101
|
+
adopted, different changes are a conflict that `keep` (`local`, `remote`, `both`) settles; deletions go to the
|
|
102
|
+
remote's trash and to `<mirror>/.wirecat-trash/`, and a run that would delete more than 2 files and also more than
|
|
103
|
+
50 or a quarter of the mirror stops first. Symbolic links are never followed, and a file system without hard links
|
|
104
|
+
(exFAT, FAT, FUSE, SMB) works through exclusive copies. Every write is conditional on the last listing, so a crash at any step is settled by the next
|
|
105
|
+
run. `syncFileMirrors`, `fileSyncState`, `fileMirrorStatus` and `fileRemoteChanges` (the watch lists only when the
|
|
106
|
+
remote's revision moved) complete it ([DOCUMENTS.md](docs/dev/DOCUMENTS.md#sync-plain-files-with-a-provider)).
|
|
107
|
+
- **A file mirror deletes only what it can prove was deleted.** The last sync saw the file, the side's listing is
|
|
108
|
+
complete, and the side's root is the same folder (the remote root's id; the local folder's device and inode, and
|
|
109
|
+
not empty while the state has files, as an unmounted drive is). Anything else is reported as `unknown` and the run
|
|
110
|
+
is partial, with a root problem reported as an error even at a first sync. Files under a symbolic link are
|
|
111
|
+
`unknown` too, as is a file moved remotely to a path the mirror refuses. When the owner confirms a replaced root
|
|
112
|
+
is the right folder, `repin: true` records it again and runs a first sync that deletes nothing and settles no
|
|
113
|
+
conflict; a mirror whose root was not replaced ignores it. A download cut off midway stays a conflict until its
|
|
114
|
+
partial file is moved away.
|
|
115
|
+
- **`fileVersions`: a local version store for mirrors.** Before a sync overwrites or deletes a local file, its content
|
|
116
|
+
is kept by sha256 under the profile's state folder, with an append-only log of every change both ways; versions stay
|
|
117
|
+
30 days, and a deleted file's last version stays for good; a version kept just before a crash stays 30 days too.
|
|
118
|
+
`restoreFileVersion` puts one back under the sync lock.
|
|
119
|
+
- **`watchMirrors` takes `localChanges` instead of `kindOf` and `stateOf`**, for an engine with its own state. A
|
|
120
|
+
document mirror passes `kindOf` and `stateOf` as before.
|
|
121
|
+
- **`scanLocal` reports each file's `size` and `mtimeMs`, and the symbolic links it skipped in `links`,** and takes an optional lookup that reuses a known hash when
|
|
122
|
+
both match, so a sync does not read unchanged files again. `conflictReport` adds `local_size` and `<remote>_size`
|
|
123
|
+
when a conflict has them. A mirror guard's `action` can also be `delete` and `move`.
|
|
124
|
+
|
|
125
|
+
### Changed — may break callers
|
|
126
|
+
|
|
127
|
+
- **`PushConflict.url` is optional, and `MirrorWatchOptions` is a type, not an interface.** A file conflict has no
|
|
128
|
+
URL, so `conflictReport` leaves `url` out when there is none; a document conflict still has one. Code that reads
|
|
129
|
+
`conflict.url` as a string, or extends `MirrorWatchOptions` with `interface … extends`, needs a small change. drive
|
|
130
|
+
needs none.
|
|
131
|
+
|
|
132
|
+
### Fixed
|
|
133
|
+
|
|
134
|
+
- **`models download` takes the native ONNX Runtime from WireCat's own npm packages.** Microsoft's GitHub repository,
|
|
135
|
+
and every release download in it, answers 404 since 17.11.2026, so the download failed on Linux and macOS and the
|
|
136
|
+
models ran through WebAssembly. The library now comes from `@wirecat/onnxruntime-<platform>` on npm (linux-x64,
|
|
137
|
+
linux-arm64, darwin-arm64, win32-x64, win32-arm64), 10–13 MB each, with the same sha256 check of the library. No
|
|
138
|
+
download depends on Microsoft's hosting any more. `bin/publish-onnxruntime` builds the packages once from
|
|
139
|
+
Microsoft's NuGet package `Microsoft.ML.OnnxRuntime` 1.30.0, and on Windows from `onnxruntime-node`'s npm tarball as
|
|
140
|
+
before. The Linux and Windows libraries are byte for byte the ones used so far. The macOS one is NuGet's build of
|
|
141
|
+
the same version, with a new sha256. Windows downloads 11 MB instead of the 113 MB `onnxruntime-node` tarball.
|
|
142
|
+
|
|
8
143
|
## 0.703.0 — 18.11.2026
|
|
9
144
|
|
|
10
145
|
### Added
|
|
@@ -24,12 +24,12 @@ export interface DailyArchiveTimerInput {
|
|
|
24
24
|
}
|
|
25
25
|
export declare const dailyArchiveTimer: (input: DailyArchiveTimerInput) => DailyArchiveTimer;
|
|
26
26
|
export declare const manageDailyArchiveTimer: (plan: DailyArchiveTimer, action: "install" | "start" | "stop" | "status" | "uninstall", system: Pick<ServerSystem, "platform" | "run">, env: NodeJS.ProcessEnv, signal?: AbortSignal) => Promise<{
|
|
27
|
-
action?: undefined;
|
|
28
27
|
name: string;
|
|
29
28
|
installed: boolean;
|
|
30
29
|
active: boolean;
|
|
31
30
|
servicePath: string;
|
|
32
31
|
timerPath: string;
|
|
32
|
+
action?: undefined;
|
|
33
33
|
} | {
|
|
34
34
|
active?: undefined;
|
|
35
35
|
name: string;
|
|
@@ -42,9 +42,15 @@ export declare const httpApiRequest: (operation: ManifestOperation, input: ApiCo
|
|
|
42
42
|
/** What one exchange needs: the service's name, the fetch, its own refusals and the answer's size limit. */
|
|
43
43
|
export type HttpApiSendOptions = Pick<HttpApiExecutorOptions, "service" | "fetch" | "failure" | "maxBytes">;
|
|
44
44
|
/**
|
|
45
|
-
* Sends one request, records it in the run by its path template, never an id, and gives the parsed answer
|
|
46
|
-
*
|
|
45
|
+
* Sends one request, records it in the run by its path template, never an id, and gives the parsed answer with the
|
|
46
|
+
* response's headers, where a service may page (WordPress's `X-WP-TotalPages`). A write that got no answer is
|
|
47
|
+
* `outcome_unknown` (WC-LIFE-9); the service's own error text is never repeated (WC-SECR-6).
|
|
47
48
|
*/
|
|
49
|
+
export declare const httpApiExchange: (options: HttpApiSendOptions) => (command: Command, operation: ManifestOperation, request: HttpApiRequest) => Promise<{
|
|
50
|
+
answer: unknown;
|
|
51
|
+
headers: Headers;
|
|
52
|
+
}>;
|
|
53
|
+
/** `httpApiExchange`'s answer alone. */
|
|
48
54
|
export declare const httpApiSend: (options: HttpApiSendOptions) => (command: Command, operation: ManifestOperation, request: HttpApiRequest) => Promise<unknown>;
|
|
49
55
|
/**
|
|
50
56
|
* The `execute` of `generatedApiCommand` for any OpenAPI CLI: fills the path, adds the query, sends the JSON body
|
package/dist/cli/bot/api-http.js
CHANGED
|
@@ -131,10 +131,11 @@ const answerOf = async (response, maxBytes) => {
|
|
|
131
131
|
return readJsonResponse(response, { maxBytes });
|
|
132
132
|
};
|
|
133
133
|
/**
|
|
134
|
-
* Sends one request, records it in the run by its path template, never an id, and gives the parsed answer
|
|
135
|
-
*
|
|
134
|
+
* Sends one request, records it in the run by its path template, never an id, and gives the parsed answer with the
|
|
135
|
+
* response's headers, where a service may page (WordPress's `X-WP-TotalPages`). A write that got no answer is
|
|
136
|
+
* `outcome_unknown` (WC-LIFE-9); the service's own error text is never repeated (WC-SECR-6).
|
|
136
137
|
*/
|
|
137
|
-
export const
|
|
138
|
+
export const httpApiExchange = (options) => async (command, operation, request) => {
|
|
138
139
|
const writes = operation.effect !== "read";
|
|
139
140
|
const template = endpointOf(operation);
|
|
140
141
|
const end = providerRequest(`${request.method} ${template}`, undefined, {
|
|
@@ -177,13 +178,18 @@ export const httpApiSend = (options) => async (command, operation, request) => {
|
|
|
177
178
|
try {
|
|
178
179
|
const result = graphqlAnswer(options, operation, answer);
|
|
179
180
|
end({ status });
|
|
180
|
-
return result;
|
|
181
|
+
return { answer: result, headers: response.headers };
|
|
181
182
|
}
|
|
182
183
|
catch (error) {
|
|
183
184
|
end({ status, error });
|
|
184
185
|
throw error;
|
|
185
186
|
}
|
|
186
187
|
};
|
|
188
|
+
/** `httpApiExchange`'s answer alone. */
|
|
189
|
+
export const httpApiSend = (options) => {
|
|
190
|
+
const exchange = httpApiExchange(options);
|
|
191
|
+
return async (command, operation, request) => (await exchange(command, operation, request)).answer;
|
|
192
|
+
};
|
|
187
193
|
/**
|
|
188
194
|
* The `execute` of `generatedApiCommand` for any OpenAPI CLI: fills the path, adds the query, sends the JSON body
|
|
189
195
|
* with the caller's headers through the caller's fetch, and prints the answer. Nothing here retries: a write is
|
|
@@ -243,6 +249,16 @@ const refusal = (service, operation, response, writes) => {
|
|
|
243
249
|
reason: "access.denied",
|
|
244
250
|
status,
|
|
245
251
|
});
|
|
252
|
+
const location = status >= 300 && status < 400 ? response.headers.get("location") : null;
|
|
253
|
+
// A signed call follows no redirect, so it might take the sign-in elsewhere; the address shows where the site
|
|
254
|
+
// went. Its query is left out: it may carry a key.
|
|
255
|
+
if (location !== null) {
|
|
256
|
+
const to = URL.canParse(location, response.url || undefined)
|
|
257
|
+
? new URL(location, response.url || undefined)
|
|
258
|
+
: undefined;
|
|
259
|
+
const where = to ? `${to.origin}${to.pathname}` : "another address";
|
|
260
|
+
return new CliError(statusToCode(status), `${service} moved ${operation.command} to ${where} (HTTP ${status}); nothing was sent there`, { status, retryable: false });
|
|
261
|
+
}
|
|
246
262
|
return new CliError(statusToCode(status), `${service} refused ${operation.command} (HTTP ${status})`, {
|
|
247
263
|
status,
|
|
248
264
|
retryable: status >= 500,
|
|
@@ -58,8 +58,8 @@ export interface CopyAge {
|
|
|
58
58
|
}
|
|
59
59
|
export declare const ageOf: (lastSync: string | undefined, now?: number) => CopyAge;
|
|
60
60
|
export declare const staleCopy: (provider: string, lastSync: string | undefined, now?: number) => {
|
|
61
|
-
next?: undefined;
|
|
62
61
|
missing?: undefined;
|
|
62
|
+
next?: undefined;
|
|
63
63
|
meta?: undefined;
|
|
64
64
|
} | {
|
|
65
65
|
missing: {
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -153,9 +153,9 @@ export { fieldsOf, projectFields } from "./result-fields.js";
|
|
|
153
153
|
export { HARNESSES, type Harness, harnessesOn, harnessInfo, harnessOfArgv, isHarness, reportsCost, } from "./schedule/harnesses.js";
|
|
154
154
|
export { type AgentScheduleSpec, agentSchedule, backfillScheduleRun, pauseSchedule, removeSchedule, runScheduleNow, SCHEDULE_SETTINGS, type ScheduleHost, type ScheduleLimits, type ScheduleSite, scheduleLimitsOf, scheduleState, slotsOfAt, writeSchedule, } from "./schedule/schedule-command.js";
|
|
155
155
|
export { deniedKinds, deniedKindsOf, type LeftOut, type SearchedKind } from "./search-left-out.js";
|
|
156
|
-
export { type BodyPermission, type ServiceApiOptions, type ServiceApiPermissionsInput, serviceApiKeys, serviceApiOperations, serviceApiPermissions, } from "./service-api.js";
|
|
157
|
-
export { hostsFetch, type ServiceApiCall, type ServiceApiCallOptions, serviceApiCall } from "./service-api-call.js";
|
|
158
|
-
export { manifestBaseUrl, type ServiceApiManifest, signRequest, siteValue } from "./service-api-manifest.js";
|
|
156
|
+
export { type BodyPermission, type ServiceApiOptions, type ServiceApiPermissionsInput, type ServiceApiWrite, serviceApiKeys, serviceApiOperations, serviceApiPermissions, serviceApiWriter, } from "./service-api.js";
|
|
157
|
+
export { hostsFetch, type ServiceApiCall, type ServiceApiCallOptions, type ServiceApiCallWithHeaders, serviceApiCall, } from "./service-api-call.js";
|
|
158
|
+
export { manifestBaseUrl, nextPage, type PageStep, type ServiceApiManifest, signRequest, siteValue, underBase, } from "./service-api-manifest.js";
|
|
159
159
|
export { type DeclaredSetting, type SettingRow, settingRows, withSettingDefaults } from "./setting-defaults.js";
|
|
160
160
|
export { type Config, type Configuration, count, first, flag, fromFile, type GlobalFlags, NONE_NAMED, namedProfile, type ProfileKind, plain, type ResolveOptions, type Settings, type SettingsExtension, type SettingsExtensionContext, type Source, settingsFor, } from "./settings.js";
|
|
161
161
|
export { type PermissionAnswer, readSetupAnswers, type SetupAnswers, setupPermissionCeiling } from "./setup-answers.js";
|
package/dist/cli/index.js
CHANGED
|
@@ -142,9 +142,9 @@ export { fieldsOf, projectFields } from "./result-fields.js";
|
|
|
142
142
|
export { HARNESSES, harnessesOn, harnessInfo, harnessOfArgv, isHarness, reportsCost, } from "./schedule/harnesses.js";
|
|
143
143
|
export { agentSchedule, backfillScheduleRun, pauseSchedule, removeSchedule, runScheduleNow, SCHEDULE_SETTINGS, scheduleLimitsOf, scheduleState, slotsOfAt, writeSchedule, } from "./schedule/schedule-command.js";
|
|
144
144
|
export { deniedKinds, deniedKindsOf } from "./search-left-out.js";
|
|
145
|
-
export { serviceApiKeys, serviceApiOperations, serviceApiPermissions, } from "./service-api.js";
|
|
146
|
-
export { hostsFetch, serviceApiCall } from "./service-api-call.js";
|
|
147
|
-
export { manifestBaseUrl, signRequest, siteValue } from "./service-api-manifest.js";
|
|
145
|
+
export { serviceApiKeys, serviceApiOperations, serviceApiPermissions, serviceApiWriter, } from "./service-api.js";
|
|
146
|
+
export { hostsFetch, serviceApiCall, } from "./service-api-call.js";
|
|
147
|
+
export { manifestBaseUrl, nextPage, signRequest, siteValue, underBase, } from "./service-api-manifest.js";
|
|
148
148
|
export { settingRows, withSettingDefaults } from "./setting-defaults.js";
|
|
149
149
|
export { count, first, flag, fromFile, NONE_NAMED, namedProfile, plain, settingsFor, } from "./settings.js";
|
|
150
150
|
export { readSetupAnswers, setupPermissionCeiling } from "./setup-answers.js";
|
|
@@ -16,7 +16,7 @@ import { migrate } from "../../store/migrations.js";
|
|
|
16
16
|
import { openCache } from "../../store/open.js";
|
|
17
17
|
import { storePath } from "../../store/path.js";
|
|
18
18
|
import { deleteCopy, repairStore } from "../../store/repair.js";
|
|
19
|
-
import { drainNoteIndex, dropAllUnusedVectors, fillSearchIndex, fillStems, involvementStoreOver, noteIndexState, openSqlite, openStore, orphanPointers, pendingNormalization, resetAttachmentWords, resetCrmFileWords, resetNoteIndex, resetSearchIndex, resetStems, resetTrackerItemWords, rollBack, searchIndexState, stemmerCache, stemsState, vectorIndexCounts, } from "../../store/store.js";
|
|
19
|
+
import { drainNoteIndex, dropAllUnusedVectors, fillSearchIndex, fillStems, involvementStoreOver, noteIndexState, openSqlite, openStore, orphanPointers, pendingNormalization, resetAttachmentWords, resetContentPostWords, resetCrmFileWords, resetNoteIndex, resetSearchIndex, resetStems, resetTrackerItemWords, rollBack, searchIndexState, stemmerCache, stemsState, vectorIndexCounts, } from "../../store/store.js";
|
|
20
20
|
import { environmentOf, outputFor } from "../context.js";
|
|
21
21
|
import { destroysNothing, grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "../effects.js";
|
|
22
22
|
import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
@@ -328,6 +328,7 @@ const inspect = (path) => reading(path, (database) => {
|
|
|
328
328
|
...(schema.version > 0 ? [["attachment_words", indexIntegrity(database, "attachment_words", 0)]] : []),
|
|
329
329
|
...(schema.version >= 68 ? [["crm_file_words", indexIntegrity(database, "crm_file_words", 0)]] : []),
|
|
330
330
|
...(schema.version >= 70 ? [["tracker_item_words", indexIntegrity(database, "tracker_item_words", 0)]] : []),
|
|
331
|
+
...(schema.version >= 71 ? [["content_post_words", indexIntegrity(database, "content_post_words", 0)]] : []),
|
|
331
332
|
]);
|
|
332
333
|
const size = bytesOf(path) + bytesOf(`${path}-wal`);
|
|
333
334
|
const { bavail, bsize } = statfsSync(dirname(path));
|
|
@@ -532,7 +533,10 @@ const reindexCommand = (owner) => destroysNothing(annotate(new Command("rebuild"
|
|
|
532
533
|
throw new CliError("validation_error", `the store is behind this build — \`${lineOf(this, "store migrate")}\` first`);
|
|
533
534
|
}
|
|
534
535
|
resetSearchIndex(database);
|
|
535
|
-
const fileTexts = resetAttachmentWords(database) +
|
|
536
|
+
const fileTexts = resetAttachmentWords(database) +
|
|
537
|
+
resetCrmFileWords(database) +
|
|
538
|
+
resetTrackerItemWords(database) +
|
|
539
|
+
resetContentPostWords(database);
|
|
536
540
|
const words = buildWordIndex(database, (note) => renderer.note(note));
|
|
537
541
|
return {
|
|
538
542
|
path,
|
|
@@ -5,6 +5,11 @@ import { type HttpApiSendOptions } from "./bot/api-http.js";
|
|
|
5
5
|
import { type ServiceApiManifest } from "./service-api-manifest.js";
|
|
6
6
|
/** One operation of the generated manifest, by its id, sent with the sign-in its security scheme names. */
|
|
7
7
|
export type ServiceApiCall = (operation: string, input: ApiCommandInput) => Promise<unknown>;
|
|
8
|
+
/** The same read, with the response's headers, where a service pages (WordPress's `X-WP-TotalPages`, for `nextPage`). */
|
|
9
|
+
export type ServiceApiCallWithHeaders = (operation: string, input: ApiCommandInput) => Promise<{
|
|
10
|
+
body: unknown;
|
|
11
|
+
headers: Headers;
|
|
12
|
+
}>;
|
|
8
13
|
export interface ServiceApiCallOptions {
|
|
9
14
|
manifest: ServiceApiManifest;
|
|
10
15
|
/** The service's name in messages: "HubSpot". */
|
|
@@ -25,10 +30,15 @@ export interface ServiceApiCallOptions {
|
|
|
25
30
|
* A fetch that reaches only `hosts` (WC-CMD-32), over the fetch a test gives in its environment, or the network when
|
|
26
31
|
* none: a CLI passes `environment.fetch` as it is.
|
|
27
32
|
*/
|
|
28
|
-
export declare const hostsFetch: (hosts: readonly string[], fetch: FetchLike | undefined
|
|
33
|
+
export declare const hostsFetch: (hosts: readonly string[], fetch: FetchLike | undefined,
|
|
34
|
+
/** Where the sign-in may go, for a site under a path (`https://host/blog/wp-json`): see cli-base `hostFetch`. */
|
|
35
|
+
credentialScope?: string) => FetchLike;
|
|
29
36
|
/**
|
|
30
37
|
* The `api` group's request path for code that is not a command, such as a source read from a manifest: the same
|
|
31
38
|
* request building, sign-in header, redirect rule, run record and refusals as `serviceApiCommand`, without a guard. It
|
|
32
|
-
* sends reads only; a write goes through the `api` group, where the profile's guard asks.
|
|
39
|
+
* sends reads only; a write goes through `serviceApiWriter` or the `api` group, where the profile's guard asks. A
|
|
40
|
+
* request is sent only under the server's address, path included: a site at `host/blog` never signs `host/other`.
|
|
33
41
|
*/
|
|
34
|
-
export declare const serviceApiCall: (options: ServiceApiCallOptions) => ServiceApiCall
|
|
42
|
+
export declare const serviceApiCall: (options: ServiceApiCallOptions) => ServiceApiCall & {
|
|
43
|
+
withHeaders: ServiceApiCallWithHeaders;
|
|
44
|
+
};
|
|
@@ -1,38 +1,48 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { hostFetch } from "@wirecat/cli-base/http";
|
|
3
3
|
import { Command } from "commander";
|
|
4
|
-
import {
|
|
5
|
-
import { manifestBaseUrl, signRequest } from "./service-api-manifest.js";
|
|
4
|
+
import { httpApiExchange, httpApiRequest } from "./bot/api-http.js";
|
|
5
|
+
import { manifestBaseUrl, signRequest, underBase } from "./service-api-manifest.js";
|
|
6
6
|
/**
|
|
7
7
|
* A fetch that reaches only `hosts` (WC-CMD-32), over the fetch a test gives in its environment, or the network when
|
|
8
8
|
* none: a CLI passes `environment.fetch` as it is.
|
|
9
9
|
*/
|
|
10
|
-
export const hostsFetch = (hosts, fetch
|
|
10
|
+
export const hostsFetch = (hosts, fetch,
|
|
11
|
+
/** Where the sign-in may go, for a site under a path (`https://host/blog/wp-json`): see cli-base `hostFetch`. */
|
|
12
|
+
credentialScope) => hostFetch({ hosts, ...(fetch ? { fetch } : {}), ...(credentialScope ? { credentialScope } : {}) });
|
|
11
13
|
// The run record and the fetch are the only things httpApiSend asks a command for, and a sync has no command of its own.
|
|
12
14
|
const NO_COMMAND = new Command("source");
|
|
13
15
|
/**
|
|
14
16
|
* The `api` group's request path for code that is not a command, such as a source read from a manifest: the same
|
|
15
17
|
* request building, sign-in header, redirect rule, run record and refusals as `serviceApiCommand`, without a guard. It
|
|
16
|
-
* sends reads only; a write goes through the `api` group, where the profile's guard asks.
|
|
18
|
+
* sends reads only; a write goes through `serviceApiWriter` or the `api` group, where the profile's guard asks. A
|
|
19
|
+
* request is sent only under the server's address, path included: a site at `host/blog` never signs `host/other`.
|
|
17
20
|
*/
|
|
18
21
|
export const serviceApiCall = (options) => {
|
|
19
22
|
const baseUrl = manifestBaseUrl(options.manifest, options.baseUrl, options.serverVariables);
|
|
20
23
|
const operations = new Map(options.manifest.operations.map((one) => [one.id, one]));
|
|
21
|
-
const
|
|
22
|
-
|
|
24
|
+
const exchange = httpApiExchange({ service: options.service, fetch: () => options.fetch, failure: options.failure });
|
|
25
|
+
const withHeaders = async (id, input) => {
|
|
23
26
|
const operation = operations.get(id);
|
|
24
27
|
if (!operation)
|
|
25
28
|
throw new CliError("configuration_error", `no ${options.service} API operation ${id}`);
|
|
26
29
|
if (operation.effect !== "read")
|
|
27
30
|
throw new CliError("configuration_error", `${operation.command} is not a read; a source only reads`);
|
|
28
31
|
const request = httpApiRequest(operation, input, baseUrl);
|
|
32
|
+
if (!underBase(request.url, baseUrl))
|
|
33
|
+
throw new CliError("validation_error", `${operation.command} would leave ${baseUrl}`, { sent: false });
|
|
29
34
|
const extra = Object.entries(options.headers?.(operation) ?? {});
|
|
30
35
|
for (const [name, value] of extra)
|
|
31
36
|
request.headers.set(name, value);
|
|
32
37
|
await signRequest(options.manifest, operation, request, options.token);
|
|
33
|
-
// A redirect to another host drops only the standard sign-in headers; a hook's header would go along.
|
|
34
|
-
|
|
38
|
+
// A redirect to another host drops only the standard sign-in headers; a hook's header would go along. A site
|
|
39
|
+
// shares its host with others, and only its path tells them apart, so its sign-in follows no redirect.
|
|
40
|
+
if (extra.length || options.serverVariables)
|
|
35
41
|
request.redirect = "manual";
|
|
36
|
-
|
|
42
|
+
const { answer, headers } = await exchange(NO_COMMAND, operation, request);
|
|
43
|
+
return { body: answer, headers };
|
|
37
44
|
};
|
|
45
|
+
return Object.assign(async (id, input) => (await withHeaders(id, input)).body, {
|
|
46
|
+
withHeaders,
|
|
47
|
+
});
|
|
38
48
|
};
|
|
@@ -29,6 +29,11 @@ export declare const signRequest: (manifest: ServiceApiManifest, operation: Mani
|
|
|
29
29
|
headers: Headers;
|
|
30
30
|
redirect?: "follow" | "manual" | "error";
|
|
31
31
|
}, token: (() => Promise<string> | string) | undefined) => Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* A URL on the server's origin and under its path: a site at `host/blog` shares its host with `host/other`, which
|
|
34
|
+
* must never get its sign-in.
|
|
35
|
+
*/
|
|
36
|
+
export declare const underBase: (url: URL, baseUrl: string) => boolean;
|
|
32
37
|
export declare const parameterValue: (input: ApiCommandInput, parameter: {
|
|
33
38
|
in: "query" | "body";
|
|
34
39
|
name: string;
|
|
@@ -46,5 +51,9 @@ export interface PageStep {
|
|
|
46
51
|
url: string;
|
|
47
52
|
};
|
|
48
53
|
}
|
|
49
|
-
/**
|
|
50
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Reads one answer by the manifest's pagination: where its items are and what the next request is. `headers` are the
|
|
56
|
+
* response's, where a page style's `pagesHeader` gives the number of pages: the page that reaches it is the last, as
|
|
57
|
+
* WordPress refuses a page past the end.
|
|
58
|
+
*/
|
|
59
|
+
export declare const nextPage: (pagination: Pagination, input: ApiCommandInput, answer: unknown, headers?: Headers) => PageStep;
|
|
@@ -121,9 +121,21 @@ export const signRequest = async (manifest, operation, request, token) => {
|
|
|
121
121
|
if (auth.in === "query" || auth.name !== "authorization")
|
|
122
122
|
request.redirect = "manual";
|
|
123
123
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
/**
|
|
125
|
+
* A URL on the server's origin and under its path: a site at `host/blog` shares its host with `host/other`, which
|
|
126
|
+
* must never get its sign-in.
|
|
127
|
+
*/
|
|
128
|
+
export const underBase = (url, baseUrl) => {
|
|
129
|
+
const base = new URL(baseUrl);
|
|
130
|
+
const prefix = base.pathname.endsWith("/") ? base.pathname : `${base.pathname}/`;
|
|
131
|
+
return url.origin === base.origin && (url.pathname === base.pathname || url.pathname.startsWith(prefix));
|
|
132
|
+
};
|
|
133
|
+
/** `""` is the answer itself: WordPress answers the list. */
|
|
134
|
+
const at = (value, path) => path === ""
|
|
135
|
+
? value
|
|
136
|
+
: path
|
|
137
|
+
.split(".")
|
|
138
|
+
.reduce((inner, key) => (inner && typeof inner === "object" ? inner[key] : undefined), value);
|
|
127
139
|
const numberOf = (value) => {
|
|
128
140
|
const number = typeof value === "number" ? value : typeof value === "string" ? Number(value) : Number(String(value));
|
|
129
141
|
return Number.isFinite(number) ? number : undefined;
|
|
@@ -142,8 +154,12 @@ export const withValue = (input, parameter, value) => {
|
|
|
142
154
|
const { [parameter.name]: _, ...fields } = input.fields;
|
|
143
155
|
return { ...input, fields, body: apiJson({ ...body, [parameter.name]: value }) };
|
|
144
156
|
};
|
|
145
|
-
/**
|
|
146
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Reads one answer by the manifest's pagination: where its items are and what the next request is. `headers` are the
|
|
159
|
+
* response's, where a page style's `pagesHeader` gives the number of pages: the page that reaches it is the last, as
|
|
160
|
+
* WordPress refuses a page past the end.
|
|
161
|
+
*/
|
|
162
|
+
export const nextPage = (pagination, input, answer, headers) => {
|
|
147
163
|
const listed = pagination.items === undefined ? [answer] : at(answer, pagination.items);
|
|
148
164
|
const items = Array.isArray(listed) ? listed : [];
|
|
149
165
|
switch (pagination.style) {
|
|
@@ -158,11 +174,16 @@ export const nextPage = (pagination, input, answer) => {
|
|
|
158
174
|
case "page": {
|
|
159
175
|
const parameter = pagination.style === "offset" ? pagination.offset : pagination.page;
|
|
160
176
|
const total = pagination.total === undefined ? undefined : numberOf(at(answer, pagination.total));
|
|
161
|
-
const current = numberOf(parameterValue(input, parameter)) ?? (pagination.style === "offset" ? 0 : 1);
|
|
177
|
+
const current = numberOf(parameterValue(input, parameter)) ?? (pagination.style === "offset" ? 0 : (pagination.start ?? 1));
|
|
162
178
|
const next = pagination.style === "offset" ? current + items.length : current + 1;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
179
|
+
const pages = pagination.style === "page" && pagination.pagesHeader !== undefined
|
|
180
|
+
? numberOf(headers?.get(pagination.pagesHeader) ?? undefined)
|
|
181
|
+
: undefined;
|
|
182
|
+
// A short page is not the last: a service may cap the page below the limit asked for. Only a total, the number
|
|
183
|
+
// of pages or an empty page ends it.
|
|
184
|
+
const last = items.length === 0 ||
|
|
185
|
+
(total !== undefined && pagination.style === "offset" && next >= total) ||
|
|
186
|
+
(pages !== undefined && current >= pages);
|
|
166
187
|
return last ? { items } : { items, next: { input: withValue(input, parameter, next) } };
|
|
167
188
|
}
|
|
168
189
|
case "link": {
|
|
@@ -83,11 +83,19 @@ export declare const serviceApiPermissions: (input: ServiceApiPermissionsInput)
|
|
|
83
83
|
/** The keys, so a profile may name one that no command path spells. */
|
|
84
84
|
extra: readonly PermissionKey[];
|
|
85
85
|
};
|
|
86
|
+
export declare const serviceApiCommand: (options: ServiceApiOptions) => Command;
|
|
87
|
+
/** One write of a manifest's operation from code, such as a content command's publish. */
|
|
88
|
+
export type ServiceApiWrite = (command: Command, operation: string, input: ApiCommandInput, options?: {
|
|
89
|
+
/** Keys the caller already asked about in this run: not asked again, but a `deny` or `readonly` still stops them. */
|
|
90
|
+
confirmed?: readonly PermissionKey[];
|
|
91
|
+
}) => Promise<{
|
|
92
|
+
operation_id: string;
|
|
93
|
+
result: unknown;
|
|
94
|
+
}>;
|
|
86
95
|
/**
|
|
87
|
-
* The
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* is no free-form `api call`: a request is always one operation of the spec, with its own key (SEC-196).
|
|
96
|
+
* The `api` group's write path for code that is not one of its commands: the same keys (`api.<operation>` and each
|
|
97
|
+
* manifest key the call sets off, as `posts.publish`), levels, question and journal line, so a writer is never a
|
|
98
|
+
* looser door than the command. `command` is the one running, which carries the profile and says whether a terminal
|
|
99
|
+
* can be asked. A read that no key guards goes through `serviceApiCall`.
|
|
92
100
|
*/
|
|
93
|
-
export declare const
|
|
101
|
+
export declare const serviceApiWriter: (options: ServiceApiOptions) => ServiceApiWrite;
|