@cpajs/cpa 0.1.0-rc.6 → 0.1.0-rc.8
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/README.md +29 -138
- package/dist/client/errors.d.ts +0 -50
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +0 -63
- package/dist/client/errors.js.map +1 -1
- package/dist/client/index.d.ts +4 -5
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/resources/config.d.ts +0 -38
- package/dist/client/resources/config.d.ts.map +1 -1
- package/dist/client/resources/config.js +0 -149
- package/dist/client/resources/config.js.map +1 -1
- package/dist/client/resources/credentials.d.ts +5 -170
- package/dist/client/resources/credentials.d.ts.map +1 -1
- package/dist/client/resources/credentials.js +9 -796
- package/dist/client/resources/credentials.js.map +1 -1
- package/dist/client/resources/requests.d.ts +0 -13
- package/dist/client/resources/requests.d.ts.map +1 -1
- package/dist/client/resources/requests.js +0 -40
- package/dist/client/resources/requests.js.map +1 -1
- package/dist/client/transport.d.ts +1 -11
- package/dist/client/transport.d.ts.map +1 -1
- package/dist/client/transport.js +14 -35
- package/dist/client/transport.js.map +1 -1
- package/dist/server/config.d.ts +0 -5
- package/dist/server/config.d.ts.map +1 -1
- package/dist/server/config.js +0 -9
- package/dist/server/config.js.map +1 -1
- package/dist/server/errors.d.ts +0 -2
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js.map +1 -1
- package/dist/server/index.d.ts +1 -33
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +211 -600
- package/dist/server/index.js.map +1 -1
- package/dist/server/logs.d.ts +1 -7
- package/dist/server/logs.d.ts.map +1 -1
- package/dist/server/logs.js +2 -17
- package/dist/server/logs.js.map +1 -1
- package/dist/server/process.d.ts +1 -3
- package/dist/server/process.d.ts.map +1 -1
- package/dist/server/process.js +2 -5
- package/dist/server/process.js.map +1 -1
- package/dist/server/types.d.ts +16 -157
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +27 -39
- package/src/client/errors.ts +0 -74
- package/src/client/index.ts +3 -25
- package/src/client/resources/config.ts +0 -176
- package/src/client/resources/credentials.ts +9 -972
- package/src/client/resources/requests.ts +0 -49
- package/src/client/transport.ts +15 -47
- package/src/server/config.ts +0 -10
- package/src/server/errors.ts +0 -2
- package/src/server/index.ts +226 -692
- package/src/server/logs.ts +3 -18
- package/src/server/process.ts +3 -7
- package/src/server/types.ts +16 -173
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ Bundled CLIProxyAPI: **v8.0.43**.
|
|
|
15
15
|
- Upgrading: [CHANGELOG.md](CHANGELOG.md) and [docs/migration.md](docs/migration.md).
|
|
16
16
|
- Platforms, versions and the versioning policy: [docs/compatibility.md](docs/compatibility.md).
|
|
17
17
|
- Every management API route: [docs/api-coverage.md](docs/api-coverage.md).
|
|
18
|
+
- What cpajs does and does not do: [docs/scope.md](docs/scope.md).
|
|
18
19
|
|
|
19
20
|
```sh
|
|
20
21
|
npm install @cpajs/cpa
|
|
@@ -51,7 +52,7 @@ await server.stop();
|
|
|
51
52
|
`stop()` and `startServer()`. Pass `overwriteConfig: true` to replace it; when a file is kept, `config`, `host`
|
|
52
53
|
and `port` are not applied and a `configReused` warning is emitted. Credentials go to `<stateDir>/auths`
|
|
53
54
|
unless `oauth.auth-dir` is set. The server binds `127.0.0.1` unless you pass `host` or set `server.host`.
|
|
54
|
-
- A function is called before the first start and again before every restart
|
|
55
|
+
- A function is called before the first start and again before every manual `restart()`. It receives
|
|
55
56
|
`{ existing, reason }`: the parsed current `<stateDir>/config.yaml` (or `undefined`) and `'start'` or
|
|
56
57
|
`'restart'`. Its result replaces the file each time, like `overwriteConfig: true`, while cpajs still fills in
|
|
57
58
|
the listener, management secret and panel fields. It cannot be combined with `overwriteConfig`, and a
|
|
@@ -68,11 +69,8 @@ await server.stop();
|
|
|
68
69
|
`tls.enable`. When cpajs writes the file and no port is given, it picks a free port first; a reused file keeps
|
|
69
70
|
the port it already has.
|
|
70
71
|
- `startServer` resolves only once `/healthz` answers. It rejects with `CpaStartError` on early exit, port
|
|
71
|
-
conflict, timeout (`startupTimeoutMs`, default 30 s), `signal` abort, or an
|
|
72
|
-
failure case the process is stopped and the temporary directory removed.
|
|
73
|
-
retryable failures (early exit, timeout, port conflict, a failing `afterStart`, or a config function that
|
|
74
|
-
throws) are retried with `restart.backoffMs`/`restart.maxAttempts` before the last error is thrown; invalid
|
|
75
|
-
options, an aborted signal and a missing binary still reject immediately.
|
|
72
|
+
conflict, timeout (`startupTimeoutMs`, default 30 s), `signal` abort, or an invalid config function. In every
|
|
73
|
+
failure case the process is stopped and the temporary directory removed.
|
|
76
74
|
- `stop()` is idempotent: on POSIX it sends SIGTERM and then SIGKILL after `stopTimeoutMs` (default 10 s). On
|
|
77
75
|
Windows Node cannot deliver a graceful shutdown signal, so `stop()` terminates the process forcefully (equivalent
|
|
78
76
|
to SIGKILL), `stopTimeoutMs` has no effect, and CPA gets no chance to flush state or update auth files. The same
|
|
@@ -81,51 +79,18 @@ await server.stop();
|
|
|
81
79
|
(`timeoutMs` defaults to `stopTimeoutMs`) and starts it again with the original options. The handle keeps
|
|
82
80
|
`origin`, `baseUrl`, `host`, `port`, `stateDir` and `configPath`; `pid`, `process` and `recentLogs` point at the
|
|
83
81
|
new process. With an object `config`, the existing `config.yaml` is reused and never rewritten, so changes made
|
|
84
|
-
through the management API survive. A function `config` is evaluated again before
|
|
85
|
-
replaces the file.
|
|
86
|
-
`CpaStartError` code `port-in-use` instead of changing `origin
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
crash loop escalates instead of restarting every 500 ms. `maxAttempts` consecutive restarts without a stable
|
|
97
|
-
run stop the server and settle `exited` (default `Infinity`); a manual `restart()` resets the count.
|
|
98
|
-
`onStartFailure` applies the same backoff/attempt policy to failures of the first start. `stop()` cancels a
|
|
99
|
-
pending wait, and `restart()` during one tries immediately. A port taken by another process makes that attempt
|
|
100
|
-
fail and retries after the next backoff, unless `allowNewPort` moves a dynamic port as described above.
|
|
101
|
-
- `singleton: true` reuses one server per process for the same resolved `stateDir` (or absolute `configPath`),
|
|
102
|
-
so a dev server that evaluates a module more than once cannot start CPA twice. Concurrent calls share the
|
|
103
|
-
in-flight start and its promise; a handle that has not stopped yet is returned as-is, including while it is
|
|
104
|
-
backing off or restarting. Once the handle stops, the next call starts a new process. It requires an explicit
|
|
105
|
-
`stateDir` or `configPath`, and the options of the first call win: options on later calls are not compared.
|
|
106
|
-
The registry lives on `globalThis` (keyed by `Symbol.for('cpajs.servers')`), so duplicate module instances
|
|
107
|
-
in the same process share it.
|
|
108
|
-
- Lifecycle events: `server.on('exit' | 'restart' | 'restarted' | 'restart-failed', listener)` returns an
|
|
109
|
-
unsubscribe function. An `exit` payload has `code`, `signal`, `recentLogs`, `willRestart` and `reason`:
|
|
110
|
-
`'stop'` when `stop()` stopped the process, `'restart'` when a manual or automatic restart replaced it, and
|
|
111
|
-
`'unexpected'` when the process exited by itself. `restart` and `restarted` carry `reason`
|
|
112
|
-
(`'unexpected-exit' | 'manual'`) and `attempt`, and `restarted` also has `originChanged` (`true` when
|
|
113
|
-
`allowNewPort` moved the server); `restart-failed` has `error`, `attempt` and `willRetry`. A failed first
|
|
114
|
-
start retried by `onStartFailure` is also reported as `restart-failed`, with `attempt` counting failed start
|
|
115
|
-
attempts. A listener that throws is reported through `process.emitWarning` and never disturbs the server. Pass
|
|
116
|
-
`on` to `startServer` to subscribe before the first process is watched; with `singleton: true` only the first
|
|
117
|
-
call's listeners are registered.
|
|
118
|
-
- `hooks.afterStart({ server, client, reason, requireClient })` runs after each process is ready: the first
|
|
119
|
-
start and every restart, manual or automatic. `reason` is `'start'` or `'restart'`; `client` is
|
|
120
|
-
`server.client()` when cpajs knows the plaintext management key and `undefined` otherwise. `startServer`
|
|
121
|
-
narrows `client` to `CpaClient` only when the key is provably known: no `management: false` or `configPath`,
|
|
122
|
-
and `config` omitted, a function, or an object whose type has no `management['secret-key']`. A wide
|
|
123
|
-
`CpaConfig` variable stays `CpaClient | undefined`; `requireClient()` returns the client or throws with the
|
|
124
|
-
reason it is unavailable. The hook may return a cleanup function (or a promise of one), which cpajs calls once
|
|
125
|
-
when that process exits: before the replacement starts on a restart, or after the final stop. A cleanup that
|
|
126
|
-
throws is reported through `process.emitWarning` and does not change the lifecycle. If the hook throws, the
|
|
127
|
-
first start rejects with `CpaStartError` code `hook-failed` after stopping the process, while a restart fails
|
|
128
|
-
like any other (`restart-failed`, then backoff or a rejected `restart()`).
|
|
82
|
+
through the management API survive. A function `config` is evaluated again before the restart and its result
|
|
83
|
+
replaces the file. The original port is reused; if another process took it meanwhile, restart fails with
|
|
84
|
+
`CpaStartError` code `port-in-use` instead of changing `origin`. Concurrent `restart()` calls share one
|
|
85
|
+
operation, `stop()` during a restart aborts it, and `restart()` after the handle stopped (including after an
|
|
86
|
+
unexpected exit) rejects with code `stopped`. A failed restart leaves the handle stopped and cleans up a
|
|
87
|
+
temporary state directory like `startServer` does.
|
|
88
|
+
- There is no automatic restart. Use `server.exited` to observe an unexpected exit and call `startServer()`
|
|
89
|
+
again, or call `restart()` from your own supervisor.
|
|
90
|
+
- Lifecycle events: `server.on('exit', listener)` returns an unsubscribe function. An `exit` payload has
|
|
91
|
+
`code`, `signal`, `recentLogs`, `willRestart` and `reason`: `'stop'` when `stop()` stopped the process,
|
|
92
|
+
`'restart'` when a manual `restart()` replaced it, and `'unexpected'` when the process exited by itself. A
|
|
93
|
+
listener that throws is reported through `process.emitWarning` and never disturbs the server.
|
|
129
94
|
- Shutdown: CPA does not outlive your process, even if it is killed with SIGKILL, crashes, or is restarted by
|
|
130
95
|
`tsx watch` / `nodemon`. Each platform package ships a small `cpa-launcher` (pure Go, in `launcher/`) that
|
|
131
96
|
relies only on operating-system facilities:
|
|
@@ -156,16 +121,8 @@ await server.stop();
|
|
|
156
121
|
for CPA's `--------` placeholder) and `message` (the text after CPA's timestamp, request-id, level and caller
|
|
157
122
|
prefixes). Output that does not match the format still arrives, with only `stream` and `line`.
|
|
158
123
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
unknown output is never hidden; `logs: { minLevel: 'warn', unleveled: 'stderr' }` keeps only those on stderr
|
|
162
|
-
(such as a Go panic) and drops CPA's stdout banner, and `unleveled: 'none'` drops them all.
|
|
163
|
-
|
|
164
|
-
```ts
|
|
165
|
-
await startServer({ config, logs: { minLevel: 'warn' }, onLog: ({ level, message, line }) => {
|
|
166
|
-
console.log(`[${level ?? 'raw'}] ${message ?? line}`);
|
|
167
|
-
} });
|
|
168
|
-
```
|
|
124
|
+
`onLog` receives every redacted line. Filter on `level` yourself when you only want some severities;
|
|
125
|
+
`recentLogs` always keeps everything.
|
|
169
126
|
- Management key: you usually don't need one. Without `management`, cpajs generates a random key for each start,
|
|
170
127
|
writes only its bcrypt hash into the managed config (remote management off), keeps the plaintext in memory,
|
|
171
128
|
and gives you `server.client()`: a management client bound to this server. The key is never exposed, and
|
|
@@ -266,33 +223,14 @@ const { data: config, etag } = await client.config.get();
|
|
|
266
223
|
await client.config.patch({ routing: { strategy: 'round-robin' } }, { ifMatch: etag });
|
|
267
224
|
await client.config.set('routing/retry/request-retry', 2); // value typed by path: number
|
|
268
225
|
|
|
269
|
-
// Read
|
|
270
|
-
|
|
271
|
-
await client.config.
|
|
272
|
-
|
|
273
|
-
// Deep-compares each top-level section and replaces only the ones that differ.
|
|
274
|
-
// A listed section is written wholesale, so nested keys absent from it are removed;
|
|
275
|
-
// sections not listed are untouched.
|
|
276
|
-
await client.config.reconcile({ routing: { strategy: 'fill-first' } });
|
|
226
|
+
// Read one node with its ETag, then write it back conditionally.
|
|
227
|
+
const read = await client.config.getPath('routing/strategy');
|
|
228
|
+
await client.config.set('routing/strategy', 'fill-first', { ifMatch: read.etag });
|
|
277
229
|
|
|
278
230
|
const { files } = await client.credentials.list();
|
|
231
|
+
// Upload a credential file. CPA returns the credential list, models and downloads as-is.
|
|
279
232
|
await client.credentials.upload({ name: 'codex-me.json', content: credentialJson });
|
|
280
233
|
|
|
281
|
-
// Files and config `api-keys` entries in one list, with the runtime auth_index.
|
|
282
|
-
const all = await client.credentials.listAll();
|
|
283
|
-
const models = await client.credentials.modelsFor(all[0]!, { details: true });
|
|
284
|
-
|
|
285
|
-
const desired = [{ name: 'chat-a.json', content: credentialJson, revision: '2026-10-27' }];
|
|
286
|
-
const synced = await client.credentials.reconcile({
|
|
287
|
-
owner: 'chat',
|
|
288
|
-
files: desired,
|
|
289
|
-
// A legacy file without `x-cpajs` is claimed in place. Returning its desired
|
|
290
|
-
// revision keeps the tokens CPA already rotated; a different one uploads `desired`.
|
|
291
|
-
adopt: (name, body) =>
|
|
292
|
-
body.chat_seed === undefined ? undefined : desired.find((file) => file.name === name)?.revision,
|
|
293
|
-
});
|
|
294
|
-
console.log(synced); // { uploaded: ['chat-a.json'], deleted: [], unchanged: [], adopted: [] }
|
|
295
|
-
|
|
296
234
|
const login = await client.oauth.start({ provider: 'claude' });
|
|
297
235
|
console.log('open', login.url);
|
|
298
236
|
await client.oauth.waitForCompletion(login.state);
|
|
@@ -304,73 +242,26 @@ try {
|
|
|
304
242
|
}
|
|
305
243
|
```
|
|
306
244
|
|
|
307
|
-
`credentials.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
in `files` are deleted; files owned by anyone else are never touched. The caller's content objects are not
|
|
311
|
-
mutated.
|
|
312
|
-
|
|
313
|
-
A same-name file without the marker is never overwritten. Reconcile throws `CpaReconcileError` with code
|
|
314
|
-
`unmarked` (also for files owned by another caller, code `owned-by-other`) unless `adopt(name, body)` returns
|
|
315
|
-
a revision. Adoption keeps the stored content, including tokens, writes only the marker, and then compares the
|
|
316
|
-
returned revision with the desired one: equal leaves the file alone, different uploads the desired content.
|
|
317
|
-
Returning `undefined` leaves the file unmanaged; a same-name unmarked file then still throws. `adopt` is also
|
|
318
|
-
called for unmarked files in the prune range, so a recognized legacy file can be claimed and deleted.
|
|
319
|
-
`files[].content` accepts an object, JSON text, bytes, or a `Blob`; strings and bytes are parsed and must
|
|
320
|
-
resolve to a JSON object, which is checked before any request.
|
|
321
|
-
|
|
322
|
-
`credentials.listAll` merges credential files with the config's `api-keys` entries, which `/credentials` only
|
|
323
|
-
exposes as a runtime view. It returns a discriminated union: a file entry has `raw: AuthFileEntry` and its
|
|
324
|
-
`name`, while a config entry has the provider key as `raw` and its group (without `keys`) as `group`. A config
|
|
325
|
-
key is `disabled` when its own or its group's effective `excluded-models` contains `*`, which is what
|
|
326
|
-
`PATCH /credentials/status` writes upstream.
|
|
327
|
-
|
|
328
|
-
`credentials.setStatus` takes a file `name` or a config key's `auth_index`, and `credentials.delete` takes file
|
|
329
|
-
names or one `{ auth_index }`. Upstream's status route can toggle native `api-keys` entries but requires the
|
|
330
|
-
runtime auth ID as `name`, which `GET /credentials` does not expose for config keys; its delete route only
|
|
331
|
-
handles files. For config keys cpajs therefore edits the config through `config.update` (ETag / 412 retry,
|
|
332
|
-
`auth_index` stripped): disable adds `*` to the key's `excluded-models`, enable removes it (other patterns and
|
|
333
|
-
the group are untouched, so a group-level `excluded-models: ["*"]` still disables it), and delete removes the
|
|
334
|
-
key from its group, keeping an empty native-provider group. The last key of an `openai-compatibility` group
|
|
335
|
-
removes the group, because a keyless compat group is itself a credential. OpenAI-compatible entries have no
|
|
336
|
-
per-key switch (and disabling a keyless group clears its `auth_index`), so `setStatus` throws for them; use
|
|
337
|
-
`delete({ auth_index })` instead.
|
|
338
|
-
|
|
339
|
-
`credentials.modelsFor` accepts either a selector (file `name` or `auth_index`) or a `listAll` entry; passing
|
|
340
|
-
the entry skips the extra list/config requests. Config-key models follow CPA's own resolution (model aliases,
|
|
341
|
-
`excluded-models` with `*` wildcards, and per-key overrides); `details: true` adds the channel's static model
|
|
342
|
-
definitions, which are cached for the client's lifetime. Pass `refreshDefinitions: true` or call
|
|
343
|
-
`clearModelDefinitionsCache()` after the CPA binary changes. Runtime state such as cooldowns is only available
|
|
344
|
-
for files.
|
|
245
|
+
`credentials.list`, `upload`, `uploadMany`, `download`, `delete`, `setStatus` and the other methods pass
|
|
246
|
+
through the matching upstream routes. `setStatus` and `delete` take file names (and arrays of names) only; config
|
|
247
|
+
`api-keys` entries are managed through `client.config` like any other config node.
|
|
345
248
|
|
|
346
249
|
| Group | Routes |
|
|
347
250
|
| --- | --- |
|
|
348
|
-
| `config` | `/config`, `/config.yaml`, `/config/*path`, with ETag / `If-Match
|
|
349
|
-
| `credentials` | list
|
|
251
|
+
| `config` | `/config`, `/config.yaml`, `/config/*path`, with ETag / `If-Match` |
|
|
252
|
+
| `credentials` | list, models, upload (raw or multipart), delete, status, download, fields, refresh, SIWC status |
|
|
350
253
|
| `oauth` | auth URL, status / wait, cancel, callback, Vertex import, SIWC bind |
|
|
351
254
|
| `logs` | main log with cursor, clear, error logs, request logs |
|
|
352
255
|
| `usage` | API-key counters, usage queue (destructive pop) |
|
|
353
256
|
| `routing` | cooldown reset, model definitions |
|
|
354
|
-
| `requests` | server-side `api-call` (`apiCall
|
|
257
|
+
| `requests` | server-side `api-call` (`apiCall`) |
|
|
355
258
|
| `plugins` | list, delete, store, install, quota |
|
|
356
259
|
| `server` | `/healthz`, version headers, latest release |
|
|
357
260
|
|
|
358
|
-
|
|
359
|
-
a non-2xx upstream status throws `CpaUpstreamError`, a 2xx body that is not JSON throws `CpaResponseError`, and
|
|
360
|
-
an unresolvable `$TOKEN$` throws `CpaCredentialTokenError`.
|
|
361
|
-
|
|
362
|
-
Every method takes `{ signal, timeoutMs, headers }`. GET requests retry CPA's transient
|
|
363
|
-
`500 invalid_config` (a read landing while `config.yaml` is rewritten) up to three times after
|
|
364
|
-
100/200/400 ms; writes never retry. Pass `retryInvalidConfig: false` to `createClient` to disable it. Errors:
|
|
261
|
+
Every method takes `{ signal, timeoutMs, headers }`. Errors:
|
|
365
262
|
|
|
366
263
|
- `CpaHttpError` for a non-2xx response. It carries `status`, the raw `body`, parsed `data`, and `errorCode` /
|
|
367
264
|
`errorMessage`.
|
|
368
|
-
- `CpaUpstreamError` when `requests.apiCallJson` gets a non-2xx upstream status. It carries the upstream
|
|
369
|
-
`status`, `headers`, and `body` (parsed when JSON).
|
|
370
|
-
- `CpaCredentialTokenError` when `requests.apiCallJson` cannot resolve `$TOKEN$`. It carries `status` and
|
|
371
|
-
`errorCode`.
|
|
372
|
-
- `CpaReconcileError` when `credentials.reconcile` will not overwrite a file. It carries `code` (`unmarked` or
|
|
373
|
-
`owned-by-other`) and `file`.
|
|
374
265
|
- `CpaNetworkError` when the request fails.
|
|
375
266
|
- `CpaTimeoutError` when the request times out.
|
|
376
267
|
- `CpaAbortError` when your `signal` aborts the request.
|
package/dist/client/errors.d.ts
CHANGED
|
@@ -36,54 +36,6 @@ export declare class CpaHttpError extends CpaClientError {
|
|
|
36
36
|
/** The `message` field of a CPA error body, when present. */
|
|
37
37
|
get errorMessage(): string | undefined;
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
* The upstream call made through `requests.apiCallJson` returned a non-2xx status.
|
|
41
|
-
*
|
|
42
|
-
* `headers` and `body` are the upstream response's; `body` is parsed when it is
|
|
43
|
-
* JSON, the raw text when it is not, and `undefined` when it is empty.
|
|
44
|
-
*/
|
|
45
|
-
export declare class CpaUpstreamError extends CpaClientError {
|
|
46
|
-
readonly name = "CpaUpstreamError";
|
|
47
|
-
readonly status: number;
|
|
48
|
-
readonly headers: Record<string, string[]>;
|
|
49
|
-
readonly body: unknown;
|
|
50
|
-
constructor(request: {
|
|
51
|
-
method: string;
|
|
52
|
-
url: string;
|
|
53
|
-
}, response: {
|
|
54
|
-
status: number;
|
|
55
|
-
headers: Record<string, string[]>;
|
|
56
|
-
body: string;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* CPA answered 400 because it could not resolve the credential token behind
|
|
61
|
-
* `$TOKEN$`. `errorCode` is CPA's error, e.g. `"auth token not found"`;
|
|
62
|
-
* `cause` is the original `CpaHttpError`.
|
|
63
|
-
*/
|
|
64
|
-
export declare class CpaCredentialTokenError extends CpaClientError {
|
|
65
|
-
readonly name = "CpaCredentialTokenError";
|
|
66
|
-
readonly status: number;
|
|
67
|
-
readonly errorCode: string;
|
|
68
|
-
constructor(error: CpaHttpError);
|
|
69
|
-
}
|
|
70
|
-
export type CpaReconcileErrorCode =
|
|
71
|
-
/** The file has no `x-cpajs` marker, so it may belong to someone else. */
|
|
72
|
-
'unmarked'
|
|
73
|
-
/** The file carries another caller's `x-cpajs` marker. */
|
|
74
|
-
| 'owned-by-other';
|
|
75
|
-
/**
|
|
76
|
-
* `credentials.reconcile` found an existing file it must not overwrite.
|
|
77
|
-
*
|
|
78
|
-
* `unmarked` files can be claimed by passing `adopt`; `owned-by-other` files
|
|
79
|
-
* are never overwritten. `file` is the auth directory file name.
|
|
80
|
-
*/
|
|
81
|
-
export declare class CpaReconcileError extends Error {
|
|
82
|
-
readonly name = "CpaReconcileError";
|
|
83
|
-
readonly code: CpaReconcileErrorCode;
|
|
84
|
-
readonly file: string;
|
|
85
|
-
constructor(code: CpaReconcileErrorCode, file: string, message: string);
|
|
86
|
-
}
|
|
87
39
|
/** The request could not be sent or the response could not be read. */
|
|
88
40
|
export declare class CpaNetworkError extends CpaClientError {
|
|
89
41
|
readonly name = "CpaNetworkError";
|
|
@@ -115,6 +67,4 @@ export declare class CpaResponseError extends CpaClientError {
|
|
|
115
67
|
cause?: unknown;
|
|
116
68
|
});
|
|
117
69
|
}
|
|
118
|
-
/** Parses an `api-call` body: JSON when possible, raw text otherwise, `undefined` when empty. */
|
|
119
|
-
export declare function parseApiCallBody(text: string): unknown;
|
|
120
70
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,uDAAuD;A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E,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAGrG;CACF;AAED,4EAA4E;AAC5E,qBAAa,aAAc,SAAQ,cAAc;IAC/C,SAAkB,IAAI,mBAAmB;CAC1C;AAED,iFAAiF;AACjF,qBAAa,gBAAiB,SAAQ,cAAc;IAClD,SAAkB,IAAI,sBAAsB;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAIjI;CACF"}
|
package/dist/client/errors.js
CHANGED
|
@@ -43,58 +43,6 @@ export class CpaHttpError extends CpaClientError {
|
|
|
43
43
|
return typeof value === 'string' ? value : undefined;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
/**
|
|
47
|
-
* The upstream call made through `requests.apiCallJson` returned a non-2xx status.
|
|
48
|
-
*
|
|
49
|
-
* `headers` and `body` are the upstream response's; `body` is parsed when it is
|
|
50
|
-
* JSON, the raw text when it is not, and `undefined` when it is empty.
|
|
51
|
-
*/
|
|
52
|
-
export class CpaUpstreamError extends CpaClientError {
|
|
53
|
-
name = 'CpaUpstreamError';
|
|
54
|
-
status;
|
|
55
|
-
headers;
|
|
56
|
-
body;
|
|
57
|
-
constructor(request, response) {
|
|
58
|
-
const body = parseApiCallBody(response.body);
|
|
59
|
-
const detail = describeErrorBody(body);
|
|
60
|
-
super(`${request.method} ${request.url} failed with upstream ${response.status}${detail ? `: ${detail}` : ''}`, request);
|
|
61
|
-
this.status = response.status;
|
|
62
|
-
this.headers = response.headers;
|
|
63
|
-
this.body = body;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* CPA answered 400 because it could not resolve the credential token behind
|
|
68
|
-
* `$TOKEN$`. `errorCode` is CPA's error, e.g. `"auth token not found"`;
|
|
69
|
-
* `cause` is the original `CpaHttpError`.
|
|
70
|
-
*/
|
|
71
|
-
export class CpaCredentialTokenError extends CpaClientError {
|
|
72
|
-
name = 'CpaCredentialTokenError';
|
|
73
|
-
status;
|
|
74
|
-
errorCode;
|
|
75
|
-
constructor(error) {
|
|
76
|
-
const code = error.errorCode ?? 'unknown error';
|
|
77
|
-
super(`${error.method} ${error.url} could not resolve a credential token: ${code}`, error, { cause: error });
|
|
78
|
-
this.status = error.status;
|
|
79
|
-
this.errorCode = code;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* `credentials.reconcile` found an existing file it must not overwrite.
|
|
84
|
-
*
|
|
85
|
-
* `unmarked` files can be claimed by passing `adopt`; `owned-by-other` files
|
|
86
|
-
* are never overwritten. `file` is the auth directory file name.
|
|
87
|
-
*/
|
|
88
|
-
export class CpaReconcileError extends Error {
|
|
89
|
-
name = 'CpaReconcileError';
|
|
90
|
-
code;
|
|
91
|
-
file;
|
|
92
|
-
constructor(code, file, message) {
|
|
93
|
-
super(message);
|
|
94
|
-
this.code = code;
|
|
95
|
-
this.file = file;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
46
|
/** The request could not be sent or the response could not be read. */
|
|
99
47
|
export class CpaNetworkError extends CpaClientError {
|
|
100
48
|
name = 'CpaNetworkError';
|
|
@@ -133,17 +81,6 @@ function parseJsonOrUndefined(text) {
|
|
|
133
81
|
return undefined;
|
|
134
82
|
}
|
|
135
83
|
}
|
|
136
|
-
/** Parses an `api-call` body: JSON when possible, raw text otherwise, `undefined` when empty. */
|
|
137
|
-
export function parseApiCallBody(text) {
|
|
138
|
-
if (text === '')
|
|
139
|
-
return undefined;
|
|
140
|
-
try {
|
|
141
|
-
return JSON.parse(text);
|
|
142
|
-
}
|
|
143
|
-
catch {
|
|
144
|
-
return text;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
84
|
function describeErrorBody(data) {
|
|
148
85
|
if (typeof data !== 'object' || data === null)
|
|
149
86
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,OAAO,cAAe,SAAQ,KAAK;IACrB,IAAI,GAAW,gBAAgB,CAAC;IACzC,MAAM,CAAS;IACf,GAAG,CAAS;IAErB,YAAY,OAAe,EAAE,OAAwC,EAAE,OAA6B;QAClG,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACzB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,cAAc;IAC5B,IAAI,GAAG,cAAc,CAAC;IAC/B,MAAM,CAAS;IACf,UAAU,CAAS;IACnB,OAAO,CAAU;IACjB,IAAI,CAAS;IACb,IAAI,CAAU;IAEvB,YACE,OAAwC,EACxC,QAAkE,EAClE,IAAY;QAEZ,MAAM,IAAI,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;QAC7F,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,gBAAgB,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QAChH,IAAI,CAAC,MAAM,GA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C,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAC7F,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -8,11 +8,10 @@ import { RoutingResource } from './resources/routing.ts';
|
|
|
8
8
|
import { ServerResource } from './resources/server.ts';
|
|
9
9
|
import { UsageResource } from './resources/usage.ts';
|
|
10
10
|
import { type ClientOptions, type RawRequest, type TransportResponse } from './transport.ts';
|
|
11
|
-
export { CpaAbortError, CpaClientError,
|
|
12
|
-
export type {
|
|
13
|
-
export type {
|
|
14
|
-
export type {
|
|
15
|
-
export type { ConfigCredentialGroup, ConfigCredentialRaw, ConfigCredentialSummary, CredentialContent, CredentialDeleteTarget, CredentialFile, CredentialSelector, CredentialSummary, FileCredentialSummary, ModelsForOptions, ReconcileCredentialFile, ReconcileCredentialsInput, ReconcileCredentialsResult, SetCredentialStatusRequest, } from './resources/credentials.ts';
|
|
11
|
+
export { CpaAbortError, CpaClientError, CpaHttpError, CpaNetworkError, CpaResponseError, CpaTimeoutError, } from './errors.ts';
|
|
12
|
+
export type { ClientOptions, FetchLike, Query, QueryValue, RawRequest, RequestOptions, ResponseType, TransportResponse } from './transport.ts';
|
|
13
|
+
export type { ConfigPath, ConfigPathValue, ConfigWriteOptions, ConfigWriteResult, JsonInput, Versioned, } from './resources/config.ts';
|
|
14
|
+
export type { CredentialContent, CredentialFile, CredentialSelector } from './resources/credentials.ts';
|
|
16
15
|
export type { DownloadedFile } from './resources/download.ts';
|
|
17
16
|
export type { WaitForOAuthOptions } from './resources/oauth.ts';
|
|
18
17
|
export { ConfigResource, CredentialsResource, LogsResource, OAuthResource, PluginsResource, RequestsResource, RoutingResource, ServerResource, UsageResource, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAa,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExG,OAAO,EACL,aAAa,EACb,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAa,KAAK,a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Aa,EAWjC;IAED,4CAA4C;IAC5C,IAAI,OAAO,IAAI,GAAG,CAEjB;IAED;;;;OAIG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,8FAA8F;IAC9F,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAEvE;CACF;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,CAE9D;AAED,+CAA+C;AAC/C,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAM7D"}
|
package/dist/client/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { RoutingResource } from './resources/routing.js';
|
|
|
8
8
|
import { ServerResource } from './resources/server.js';
|
|
9
9
|
import { UsageResource } from './resources/usage.js';
|
|
10
10
|
import { Transport } from './transport.js';
|
|
11
|
-
export { CpaAbortError, CpaClientError,
|
|
11
|
+
export { CpaAbortError, CpaClientError, CpaHttpError, CpaNetworkError, CpaResponseError, CpaTimeoutError, } from './errors.js';
|
|
12
12
|
export { ConfigResource, CredentialsResource, LogsResource, OAuthResource, PluginsResource, RequestsResource, RoutingResource, ServerResource, UsageResource, };
|
|
13
13
|
/** Typed client for the CLIProxyAPI v8 management API (`/v8/management`). */
|
|
14
14
|
export class CpaClient {
|
|
@@ -25,7 +25,7 @@ export class CpaClient {
|
|
|
25
25
|
constructor(options) {
|
|
26
26
|
this.#transport = new Transport(options);
|
|
27
27
|
this.config = new ConfigResource(this.#transport);
|
|
28
|
-
this.credentials = new CredentialsResource(this.#transport
|
|
28
|
+
this.credentials = new CredentialsResource(this.#transport);
|
|
29
29
|
this.oauth = new OAuthResource(this.#transport);
|
|
30
30
|
this.logs = new LogsResource(this.#transport);
|
|
31
31
|
this.usage = new UsageResource(this.#transport);
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,SAAS,EAA+D,MAAM,gBAAgB,CAAC;AAExG,OAAO,EACL,aAAa,EACb,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,SAAS,EAA+D,MAAM,gBAAgB,CAAC;AAExG,OAAO,EACL,aAAa,EACb,cAAc,EACd,YAAY,EAC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ED,4CAA4C;IAC5C,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,IAAI,YAAY;QACd,OAAO,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,8FAA8F;IAC9F,OAAO,CAAc,OAAmB;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAI,OAAO,CAAC,CAAC;IAC7C,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,OAAsB;IACjD,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,eAAe,CAAC,OAAqB;IACnD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,GAAG,CAAC,QAAQ,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC;IACxD,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;IAChB,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;IACd,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -22,23 +22,6 @@ export interface ConfigWriteResult {
|
|
|
22
22
|
status: 'ok';
|
|
23
23
|
'config-version': 8;
|
|
24
24
|
}
|
|
25
|
-
export interface ConfigMutationOptions extends RequestOptions {
|
|
26
|
-
/**
|
|
27
|
-
* Read/write attempts before an optimistic-concurrency conflict is thrown.
|
|
28
|
-
* A 412 re-reads the node and calls the update function again. Defaults to 5.
|
|
29
|
-
*/
|
|
30
|
-
maxAttempts?: number | undefined;
|
|
31
|
-
}
|
|
32
|
-
export interface ConfigUpdateResult {
|
|
33
|
-
/** `false` when the update function returned `undefined`, so nothing was written. */
|
|
34
|
-
written: boolean;
|
|
35
|
-
/** ETag of the write, or of the read when nothing was written. */
|
|
36
|
-
etag: string | undefined;
|
|
37
|
-
}
|
|
38
|
-
export interface ConfigReconcileResult extends ConfigUpdateResult {
|
|
39
|
-
/** Top-level keys whose stored value differed and were written. */
|
|
40
|
-
changed: string[];
|
|
41
|
-
}
|
|
42
25
|
/**
|
|
43
26
|
* A config path: `'routing/retry'` or `['routing', 'retry']`. Segments are
|
|
44
27
|
* dash-case YAML keys; list indices are not addressable (lists are replaced whole).
|
|
@@ -82,27 +65,6 @@ export declare class ConfigResource {
|
|
|
82
65
|
replaceYaml(yaml: string, options?: ConfigWriteOptions): Promise<Versioned<ConfigWriteResult>>;
|
|
83
66
|
/** Reads one node, e.g. `getPath('server/port')`. A missing node is a 404 `CpaHttpError`. */
|
|
84
67
|
getPath<T = JsonValue>(path: ConfigPath, options?: RequestOptions): Promise<Versioned<T>>;
|
|
85
|
-
/**
|
|
86
|
-
* Reads a node, passes it to `fn`, and writes the result back with `If-Match`.
|
|
87
|
-
* A missing node (404) passes `undefined`. Returning `undefined` writes
|
|
88
|
-
* nothing. A 412 re-reads and calls `fn` again, up to `maxAttempts` times.
|
|
89
|
-
*
|
|
90
|
-
* The value handed to `fn` has the read-only `auth_index` fields removed
|
|
91
|
-
* (GET injects them into API keys), so it is safe to write back.
|
|
92
|
-
* Calls for the same path on one client instance run one at a time.
|
|
93
|
-
*/
|
|
94
|
-
update<const P extends ConfigPath>(path: P, fn: (current: ConfigPathValue<P> | undefined) => ConfigPathValue<P> | undefined | Promise<ConfigPathValue<P> | undefined>, options?: ConfigMutationOptions): Promise<ConfigUpdateResult>;
|
|
95
|
-
/**
|
|
96
|
-
* Replaces each top-level section in `partial` whose stored value differs,
|
|
97
|
-
* after a deep comparison that ignores the injected `auth_index` fields.
|
|
98
|
-
* Each changed section is written wholesale with PUT `/config/<key>`, so
|
|
99
|
-
* nested keys absent from the target are removed. Sections not listed are
|
|
100
|
-
* left untouched, and a target value of `undefined` is skipped.
|
|
101
|
-
*
|
|
102
|
-
* The first write uses the read's ETag; each later write uses the previous
|
|
103
|
-
* write's ETag. A 412 at any point re-reads and recomputes from scratch.
|
|
104
|
-
*/
|
|
105
|
-
reconcile(partial: CpaConfig, options?: ConfigMutationOptions): Promise<ConfigReconcileResult>;
|
|
106
68
|
/** Replaces or creates one node. Missing parent objects are created. */
|
|
107
69
|
set<const P extends ConfigPath>(path: P, value: ConfigPathValue<P>, options?: ConfigWriteOptions): Promise<Versioned<ConfigWriteResult>>;
|
|
108
70
|
/** Deep-merges into one node (see {@link patch}). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/client/resources/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/client/resources/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAc,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAElF,wFAAwF;AACxF,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,CAAC;IACR,wFAAwF;IACxF,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAmB,SAAQ,cAAc;IACxD;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,IAAI,CAAC;IACb,gBAAgB,EAAE,CAAC,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;AAEpD,6EAA6E;AAC7E,KAAK,cAAc,CAAC,CAAC,SAAS,SAAS,MAAM,EAAE,IAAI,CAAC,SAAS,SAAS,CAAC,MAA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