@cpajs/cpa 0.1.0-rc.4 → 0.1.0-rc.5
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 +152 -13
- package/dist/binary-packages.cjs +84 -0
- package/dist/binary-packages.d.cts +30 -0
- package/dist/binary.d.ts +11 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +10 -0
- package/dist/binary.js.map +1 -0
- package/dist/client/errors.d.ts +33 -0
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +47 -0
- package/dist/client/errors.js.map +1 -1
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/resources/config.d.ts +38 -0
- package/dist/client/resources/config.d.ts.map +1 -1
- package/dist/client/resources/config.js +149 -0
- package/dist/client/resources/config.js.map +1 -1
- package/dist/client/resources/credentials.d.ts +77 -0
- package/dist/client/resources/credentials.d.ts.map +1 -1
- package/dist/client/resources/credentials.js +476 -0
- package/dist/client/resources/credentials.js.map +1 -1
- package/dist/client/resources/requests.d.ts +12 -0
- package/dist/client/resources/requests.d.ts.map +1 -1
- package/dist/client/resources/requests.js +31 -0
- package/dist/client/resources/requests.js.map +1 -1
- package/dist/client/transport.d.ts +6 -0
- package/dist/client/transport.d.ts.map +1 -1
- package/dist/client/transport.js +24 -8
- package/dist/client/transport.js.map +1 -1
- package/dist/server/binary.d.ts.map +1 -1
- package/dist/server/binary.js +7 -15
- package/dist/server/binary.js.map +1 -1
- package/dist/server/config.d.ts +6 -0
- package/dist/server/config.d.ts.map +1 -1
- package/dist/server/config.js +23 -0
- package/dist/server/config.js.map +1 -1
- package/dist/server/errors.d.ts +2 -0
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/errors.js.map +1 -1
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +428 -80
- package/dist/server/index.js.map +1 -1
- package/dist/server/logs.d.ts +7 -0
- package/dist/server/logs.d.ts.map +1 -0
- package/dist/server/logs.js +30 -0
- package/dist/server/logs.js.map +1 -0
- package/dist/server/management.d.ts +12 -5
- package/dist/server/management.d.ts.map +1 -1
- package/dist/server/management.js +8 -1
- package/dist/server/management.js.map +1 -1
- package/dist/server/process.d.ts +3 -1
- package/dist/server/process.d.ts.map +1 -1
- package/dist/server/process.js +7 -2
- package/dist/server/process.js.map +1 -1
- package/dist/server/types.d.ts +143 -11
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +31 -25
- package/src/binary-packages.cjs +84 -0
- package/src/binary-packages.d.cts +30 -0
- package/src/binary.ts +10 -0
- package/src/client/errors.ts +50 -0
- package/src/client/index.ts +23 -2
- package/src/client/resources/config.ts +176 -0
- package/src/client/resources/credentials.ts +550 -0
- package/src/client/resources/requests.ts +35 -0
- package/src/client/transport.ts +28 -7
- package/src/server/binary.ts +5 -14
- package/src/server/config.ts +21 -0
- package/src/server/errors.ts +2 -0
- package/src/server/index.ts +484 -82
- package/src/server/logs.ts +34 -0
- package/src/server/management.ts +13 -5
- package/src/server/process.ts +9 -3
- package/src/server/types.ts +154 -11
package/README.md
CHANGED
|
@@ -45,11 +45,19 @@ await server.stop();
|
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
- `config` and `configPath` are mutually exclusive.
|
|
48
|
-
- `config` is
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
- `config` is either a native config object or a function that returns one.
|
|
49
|
+
- An object is written as YAML to `<stateDir>/config.yaml` only when that file does not exist yet. On later
|
|
50
|
+
starts the existing file is reused, so changes made through the management API (or by CPA itself) survive
|
|
51
|
+
`stop()` and `startServer()`. Pass `overwriteConfig: true` to replace it; when a file is kept, `config`, `host`
|
|
52
|
+
and `port` are not applied and a `configReused` warning is emitted. Credentials go to `<stateDir>/auths`
|
|
53
|
+
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. It receives
|
|
55
|
+
`{ existing, reason }`: the parsed current `<stateDir>/config.yaml` (or `undefined`) and `'start'` or
|
|
56
|
+
`'restart'`. Its result replaces the file each time, like `overwriteConfig: true`, while cpajs still fills in
|
|
57
|
+
the listener, management secret and panel fields. It cannot be combined with `overwriteConfig`, and a
|
|
58
|
+
`configReused` warning is never emitted. The management key is resolved before the function runs, so
|
|
59
|
+
`management['secret-key']` in its result does not choose the key behind `server.client()`; pass
|
|
60
|
+
`management` for that (or keep the generated key).
|
|
53
61
|
- `configPath` hands an existing file to CPA unchanged. CPA may rewrite it on startup: it hashes a plaintext
|
|
54
62
|
`management.secret-key`, removes legacy keys that conflict with their v8 equivalents, and normalizes the
|
|
55
63
|
layout (`internal/config/config_load.go` and `NormalizeConfigLayout`).
|
|
@@ -60,8 +68,8 @@ await server.stop();
|
|
|
60
68
|
`tls.enable`. When cpajs writes the file and no port is given, it picks a free port first; a reused file keeps
|
|
61
69
|
the port it already has.
|
|
62
70
|
- `startServer` resolves only once `/healthz` answers. It rejects with `CpaStartError` on early exit, port
|
|
63
|
-
conflict, timeout (`startupTimeoutMs`, default 30 s)
|
|
64
|
-
stopped and the temporary directory removed.
|
|
71
|
+
conflict, timeout (`startupTimeoutMs`, default 30 s), `signal` abort, or an `afterStart` hook failure. In every
|
|
72
|
+
failure case the process is stopped and the temporary directory removed.
|
|
65
73
|
- `stop()` is idempotent: on POSIX it sends SIGTERM and then SIGKILL after `stopTimeoutMs` (default 10 s). On
|
|
66
74
|
Windows Node cannot deliver a graceful shutdown signal, so `stop()` terminates the process forcefully (equivalent
|
|
67
75
|
to SIGKILL), `stopTimeoutMs` has no effect, and CPA gets no chance to flush state or update auth files. The same
|
|
@@ -69,11 +77,38 @@ await server.stop();
|
|
|
69
77
|
- `restart({ timeoutMs, signal })` stops the old process with the same SIGTERM → SIGKILL sequence
|
|
70
78
|
(`timeoutMs` defaults to `stopTimeoutMs`) and starts it again with the original options. The handle keeps
|
|
71
79
|
`origin`, `baseUrl`, `host`, `port`, `stateDir` and `configPath`; `pid`, `process` and `recentLogs` point at the
|
|
72
|
-
new process.
|
|
73
|
-
API survive. A
|
|
80
|
+
new process. With an object `config`, the existing `config.yaml` is reused and never rewritten, so changes made
|
|
81
|
+
through the management API survive. A function `config` is evaluated again before each restart and its result
|
|
82
|
+
replaces the file. A dynamic port is reused too; if another process took it meanwhile, restart fails with
|
|
74
83
|
`CpaStartError` code `port-in-use` instead of changing `origin`. Concurrent `restart()` calls share one
|
|
75
84
|
operation, `stop()` during a restart aborts it, and `restart()` after `stop()` rejects. A failed restart leaves
|
|
76
85
|
the handle stopped and cleans up a temporary state directory like `startServer` does.
|
|
86
|
+
- `restart: { onUnexpectedExit, backoffMs, stableAfterMs, maxAttempts }` restarts CPA by itself after an
|
|
87
|
+
unexpected exit. It goes through the same path as `restart()`, so `origin`, `port`, the handle, the existing
|
|
88
|
+
config file and already-created `server.client()` instances keep working. `backoffMs` defaults to
|
|
89
|
+
`[500, 1000, 5000, 30_000]` and its last value repeats. A restarted process must stay up for `stableAfterMs`
|
|
90
|
+
(default 60 s) to count as healthy; one that exits before it keeps the backoff position, so a crash loop
|
|
91
|
+
escalates instead of restarting every 500 ms. `maxAttempts` consecutive restarts without a stable run stop the
|
|
92
|
+
server and settle `exited` (default `Infinity`); a manual `restart()` resets the count. `stop()` cancels a
|
|
93
|
+
pending wait, and `restart()` during one tries immediately. A port taken by another process makes that attempt
|
|
94
|
+
fail and retries after the next backoff instead of changing `origin`.
|
|
95
|
+
- `singleton: true` reuses one server per process for the same resolved `stateDir` (or absolute `configPath`),
|
|
96
|
+
so a dev server that evaluates a module more than once cannot start CPA twice. Concurrent calls share the
|
|
97
|
+
in-flight start and its promise; a handle that has not stopped yet is returned as-is, including while it is
|
|
98
|
+
backing off or restarting. Once the handle stops, the next call starts a new process. It requires an explicit
|
|
99
|
+
`stateDir` or `configPath`, and the options of the first call win: options on later calls are not compared.
|
|
100
|
+
The registry lives on `globalThis` (keyed by `Symbol.for('cpajs.servers')`), so duplicate module instances
|
|
101
|
+
in the same process share it.
|
|
102
|
+
- Lifecycle events: `server.on('exit' | 'restart' | 'restarted' | 'restart-failed', listener)` returns an
|
|
103
|
+
unsubscribe function. An `exit` payload has `code`, `signal`, `recentLogs` and `willRestart`; `restart` and
|
|
104
|
+
`restarted` carry `reason` (`'unexpected-exit' | 'manual'`) and `attempt`, and `restarted` also has
|
|
105
|
+
`originChanged` (currently always `false`); `restart-failed` has `error`, `attempt` and `willRetry`. A
|
|
106
|
+
listener that throws is reported through `process.emitWarning` and never disturbs the server.
|
|
107
|
+
- `hooks.afterStart({ server, client, reason })` runs after each process is ready: the first start and every
|
|
108
|
+
restart, manual or automatic. `reason` is `'start'` or `'restart'`; `client` is `server.client()` when cpajs
|
|
109
|
+
knows the plaintext management key and `undefined` otherwise. If it throws, the first start rejects with
|
|
110
|
+
`CpaStartError` code `hook-failed` after stopping the process, while a restart fails like any other
|
|
111
|
+
(`restart-failed`, then backoff or a rejected `restart()`).
|
|
77
112
|
- Shutdown: CPA does not outlive your process, even if it is killed with SIGKILL, crashes, or is restarted by
|
|
78
113
|
`tsx watch` / `nodemon`. Each platform package ships a small `cpa-launcher` (pure Go, in `launcher/`) that
|
|
79
114
|
relies only on operating-system facilities:
|
|
@@ -99,6 +134,20 @@ await server.stop();
|
|
|
99
134
|
```
|
|
100
135
|
|
|
101
136
|
Lines longer than 64 KiB in CPA's output are truncated, with a marker saying how much was dropped.
|
|
137
|
+
- Logs: `onLog` receives every line with `stream` and the redacted `line`. When the line uses CPA's log format,
|
|
138
|
+
it also has `level` (`debug`, `info`, `warn`, `error` or `fatal`), the short 8-character `requestId` (omitted
|
|
139
|
+
for CPA's `--------` placeholder) and `message` (the text after CPA's timestamp, request-id, level and caller
|
|
140
|
+
prefixes). Output that does not match the format still arrives, with only `stream` and `line`.
|
|
141
|
+
|
|
142
|
+
Pass `logs: { minLevel: 'warn' }` to drop lower-severity lines from `onLog`; `recentLogs` keeps everything,
|
|
143
|
+
because error messages often need the surrounding info lines. Lines without a parsed level always pass, so
|
|
144
|
+
unknown output is never hidden.
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
await startServer({ config, logs: { minLevel: 'warn' }, onLog: ({ level, message, line }) => {
|
|
148
|
+
console.log(`[${level ?? 'raw'}] ${message ?? line}`);
|
|
149
|
+
} });
|
|
150
|
+
```
|
|
102
151
|
- Management key: you usually don't need one. Without `management`, cpajs generates a random key for each start,
|
|
103
152
|
writes only its bcrypt hash into the managed config (remote management off), keeps the plaintext in memory,
|
|
104
153
|
and gives you `server.client()`: a management client bound to this server. The key is never exposed, and
|
|
@@ -199,9 +248,28 @@ const { data: config, etag } = await client.config.get();
|
|
|
199
248
|
await client.config.patch({ routing: { strategy: 'round-robin' } }, { ifMatch: etag });
|
|
200
249
|
await client.config.set('routing/retry/request-retry', 2); // value typed by path: number
|
|
201
250
|
|
|
251
|
+
// Read → change → write with If-Match. `auth_index` (injected on reads) is removed,
|
|
252
|
+
// a 412 re-reads and retries, and returning undefined skips the write.
|
|
253
|
+
await client.config.update('routing/strategy', (current) => current ?? 'fill-first');
|
|
254
|
+
|
|
255
|
+
// Deep-compares each top-level section and replaces only the ones that differ.
|
|
256
|
+
// A listed section is written wholesale, so nested keys absent from it are removed;
|
|
257
|
+
// sections not listed are untouched.
|
|
258
|
+
await client.config.reconcile({ routing: { strategy: 'fill-first' } });
|
|
259
|
+
|
|
202
260
|
const { files } = await client.credentials.list();
|
|
203
261
|
await client.credentials.upload({ name: 'codex-me.json', content: credentialJson });
|
|
204
262
|
|
|
263
|
+
// Files and config `api-keys` entries in one list, with the runtime auth_index.
|
|
264
|
+
const all = await client.credentials.listAll();
|
|
265
|
+
const models = await client.credentials.modelsFor({ auth_index: all[0]!.auth_index }, { details: true });
|
|
266
|
+
|
|
267
|
+
const synced = await client.credentials.reconcile({
|
|
268
|
+
owner: 'chat',
|
|
269
|
+
files: [{ name: 'chat-a.json', content: credentialJson, revision: '2026-10-27' }],
|
|
270
|
+
});
|
|
271
|
+
console.log(synced); // { uploaded: ['chat-a.json'], deleted: [], unchanged: [] }
|
|
272
|
+
|
|
205
273
|
const login = await client.oauth.start({ provider: 'claude' });
|
|
206
274
|
console.log('open', login.url);
|
|
207
275
|
await client.oauth.waitForCompletion(login.state);
|
|
@@ -213,22 +281,43 @@ try {
|
|
|
213
281
|
}
|
|
214
282
|
```
|
|
215
283
|
|
|
284
|
+
`credentials.reconcile` keeps a set of files owned by one caller in sync. Uploads carry a reserved
|
|
285
|
+
`x-cpajs: { owner, revision }` field. Only `revision` is compared, so CPA rewriting a file during a token
|
|
286
|
+
refresh does not cause another upload. With `prune` (the default), files owned by `owner` that are no longer
|
|
287
|
+
in `files` are deleted; files owned by anyone else are never touched. The caller's content objects are not
|
|
288
|
+
mutated.
|
|
289
|
+
|
|
290
|
+
`credentials.listAll` merges credential files with the config's `api-keys` entries, which `/credentials` only
|
|
291
|
+
exposes as a runtime view. Select either a file by `name` or any credential by `auth_index` with
|
|
292
|
+
`credentials.modelsFor`. Config-key models follow CPA's own resolution (model aliases, `excluded-models` with
|
|
293
|
+
`*` wildcards, and per-key overrides); `details: true` adds the channel's static model definitions. Runtime
|
|
294
|
+
state such as cooldowns is only available for files.
|
|
295
|
+
|
|
216
296
|
| Group | Routes |
|
|
217
297
|
| --- | --- |
|
|
218
|
-
| `config` | `/config`, `/config.yaml`, `/config/*path`, with ETag / `If-Match` |
|
|
219
|
-
| `credentials` | list, upload (raw or multipart),
|
|
298
|
+
| `config` | `/config`, `/config.yaml`, `/config/*path`, with ETag / `If-Match`, plus `update` / `reconcile` |
|
|
299
|
+
| `credentials` | list all (files + config keys), models per credential (with details), upload (raw or multipart), reconcile by owner/revision, delete, download, status, fields, refresh, SIWC status |
|
|
220
300
|
| `oauth` | auth URL, status / wait, cancel, callback, Vertex import, SIWC bind |
|
|
221
301
|
| `logs` | main log with cursor, clear, error logs, request logs |
|
|
222
302
|
| `usage` | API-key counters, usage queue (destructive pop) |
|
|
223
303
|
| `routing` | cooldown reset, model definitions |
|
|
224
|
-
| `requests` | server-side `api-call` |
|
|
304
|
+
| `requests` | server-side `api-call` (`apiCall`, `apiCallJson`) |
|
|
225
305
|
| `plugins` | list, delete, store, install, quota |
|
|
226
306
|
| `server` | `/healthz`, version headers, latest release |
|
|
227
307
|
|
|
228
|
-
|
|
308
|
+
`requests.apiCallJson()` is the throwing variant of `apiCall`: a JSON string body becomes `data`, a non-2xx
|
|
309
|
+
upstream status throws `CpaUpstreamError`, and an unresolvable `$TOKEN$` throws `CpaCredentialTokenError`.
|
|
310
|
+
|
|
311
|
+
Every method takes `{ signal, timeoutMs, headers }`. GET requests retry CPA's transient
|
|
312
|
+
`500 invalid_config` (a read landing while `config.yaml` is rewritten) up to three times after
|
|
313
|
+
100/200/400 ms; writes never retry. Pass `retryInvalidConfig: false` to `createClient` to disable it. Errors:
|
|
229
314
|
|
|
230
315
|
- `CpaHttpError` for a non-2xx response. It carries `status`, the raw `body`, parsed `data`, and `errorCode` /
|
|
231
316
|
`errorMessage`.
|
|
317
|
+
- `CpaUpstreamError` when `requests.apiCallJson` gets a non-2xx upstream status. It carries the upstream
|
|
318
|
+
`status`, `headers`, and `body` (parsed when JSON).
|
|
319
|
+
- `CpaCredentialTokenError` when `requests.apiCallJson` cannot resolve `$TOKEN$`. It carries `status` and
|
|
320
|
+
`errorCode`.
|
|
232
321
|
- `CpaNetworkError` when the request fails.
|
|
233
322
|
- `CpaTimeoutError` when the request times out.
|
|
234
323
|
- `CpaAbortError` when your `signal` aborts the request.
|
|
@@ -256,6 +345,55 @@ import OpenAI from 'openai';
|
|
|
256
345
|
const openai = new OpenAI({ baseURL: server.baseUrl, apiKey: 'sk-my-model-key' });
|
|
257
346
|
```
|
|
258
347
|
|
|
348
|
+
## Bundling and deploying
|
|
349
|
+
|
|
350
|
+
The platform package is an optional dependency picked at runtime, so a bundler cannot see it in a normal
|
|
351
|
+
`import`. `@cpajs/cpa/binary` is a small entry that contains a literal `require.resolve()` for every target;
|
|
352
|
+
importing it for its side effect puts the installed platform packages in the module graph:
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
import '@cpajs/cpa/binary';
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Trace on the deployment platform (including glibc vs musl). A file tracer such as `@vercel/nft` then copies
|
|
359
|
+
the package that matches the build machine. Keep `@cpajs/cpa` and `@cpajs/<target>` external rather than
|
|
360
|
+
bundling them. nft reports a warning for every platform package that is not installed; those are expected
|
|
361
|
+
and non-fatal.
|
|
362
|
+
|
|
363
|
+
Nitro uses nft. Import the entry from the server code, and full-trace the platform package so its `bin/`
|
|
364
|
+
directory is copied too (`pkg*` copies every file, not only the traced ones):
|
|
365
|
+
|
|
366
|
+
```ts
|
|
367
|
+
export default defineNitroConfig({
|
|
368
|
+
// Replace linux-x64-gnu with the target you deploy to (see src/server/targets.ts).
|
|
369
|
+
traceDeps: ['@cpajs/cpa', '@cpajs/linux-x64-gnu*'],
|
|
370
|
+
});
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Vite SSR leaves packages in `node_modules` external; make that explicit and run nft over the server output (or
|
|
374
|
+
over `@cpajs/cpa/binary`) as part of the deploy step:
|
|
375
|
+
|
|
376
|
+
```ts
|
|
377
|
+
export default defineConfig({
|
|
378
|
+
ssr: { external: ['@cpajs/cpa'] },
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Next.js: keep cpajs outside the server bundle and let output file tracing include it:
|
|
383
|
+
|
|
384
|
+
```js
|
|
385
|
+
module.exports = {
|
|
386
|
+
serverExternalPackages: ['@cpajs/cpa'],
|
|
387
|
+
};
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
In all three setups the side-effect import is what makes the table visible; if a trace still misses the
|
|
391
|
+
binary, copy `node_modules/@cpajs/<target>/` into the deployment or pass `binaryPath` to `startServer`.
|
|
392
|
+
|
|
393
|
+
Bun ignores `libc`, so `bun install` on Linux installs both `@cpajs/linux-*-gnu` and `@cpajs/linux-*-musl`
|
|
394
|
+
(about 72 MB extra). Install with npm or pnpm, or delete the packages for the other libc before packaging;
|
|
395
|
+
cpajs still picks the right target at runtime. `binaryPath` also lets you ship a single binary yourself.
|
|
396
|
+
|
|
259
397
|
## Development
|
|
260
398
|
|
|
261
399
|
```sh
|
|
@@ -276,6 +414,7 @@ Release tooling, all in `scripts/` and run directly with Node's type stripping:
|
|
|
276
414
|
| Script | Purpose |
|
|
277
415
|
| --- | --- |
|
|
278
416
|
| `fetch-source.ts` | Clone the pinned CPA tag and verify the commit. |
|
|
417
|
+
| `generate-binary-table.ts` | Regenerate `src/binary-packages.cjs` and its types from `TARGETS`; `--check` fails on drift. |
|
|
279
418
|
| `build-binary.ts` | Build one or more targets, with the same CGO/plugin split as upstream. |
|
|
280
419
|
| `verify-binary.ts` | Check format, CPU, static linking and the glibc baseline; `--smoke` starts the binary. |
|
|
281
420
|
| `assemble-packages.ts` | Create the `@cpajs/*` platform packages. |
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static platform package table for `@cpajs/cpa/binary`.
|
|
3
|
+
*
|
|
4
|
+
* Generated by scripts/generate-binary-table.ts from TARGETS in
|
|
5
|
+
* src/server/targets.ts; do not edit. Importing the entry (for its side effect)
|
|
6
|
+
* lets bundlers such as @vercel/nft trace the optional platform packages:
|
|
7
|
+
*
|
|
8
|
+
* import '@cpajs/cpa/binary';
|
|
9
|
+
*
|
|
10
|
+
* Every lookup below is a literal require.resolve() call inside try/catch, so a
|
|
11
|
+
* trace does not depend on the runtime target selection in src/server/binary.ts.
|
|
12
|
+
* This file is CommonJS on purpose: @vercel/nft only follows require.resolve()
|
|
13
|
+
* in CommonJS input.
|
|
14
|
+
*/
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
/** Platform package names by target id. */
|
|
18
|
+
const PLATFORM_PACKAGES = {
|
|
19
|
+
'darwin-x64': '@cpajs/darwin-x64',
|
|
20
|
+
'darwin-arm64': '@cpajs/darwin-arm64',
|
|
21
|
+
'win32-x64': '@cpajs/win32-x64',
|
|
22
|
+
'win32-arm64': '@cpajs/win32-arm64',
|
|
23
|
+
'win32-ia32': '@cpajs/win32-ia32',
|
|
24
|
+
'linux-x64-gnu': '@cpajs/linux-x64-gnu',
|
|
25
|
+
'linux-arm64-gnu': '@cpajs/linux-arm64-gnu',
|
|
26
|
+
'linux-x64-musl': '@cpajs/linux-x64-musl',
|
|
27
|
+
'linux-arm64-musl': '@cpajs/linux-arm64-musl',
|
|
28
|
+
'linux-arm': '@cpajs/linux-arm',
|
|
29
|
+
'linux-ia32': '@cpajs/linux-ia32',
|
|
30
|
+
'linux-riscv64': '@cpajs/linux-riscv64',
|
|
31
|
+
'linux-ppc64': '@cpajs/linux-ppc64',
|
|
32
|
+
'linux-s390x': '@cpajs/linux-s390x',
|
|
33
|
+
'linux-loong64': '@cpajs/linux-loong64',
|
|
34
|
+
'linux-mips': '@cpajs/linux-mips',
|
|
35
|
+
'linux-mipsel': '@cpajs/linux-mipsel',
|
|
36
|
+
'freebsd-x64': '@cpajs/freebsd-x64',
|
|
37
|
+
'freebsd-arm64': '@cpajs/freebsd-arm64',
|
|
38
|
+
'freebsd-ia32': '@cpajs/freebsd-ia32',
|
|
39
|
+
'openbsd-x64': '@cpajs/openbsd-x64',
|
|
40
|
+
'openbsd-arm64': '@cpajs/openbsd-arm64',
|
|
41
|
+
'netbsd-x64': '@cpajs/netbsd-x64',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const resolvers = {
|
|
45
|
+
'darwin-x64': () => require.resolve('@cpajs/darwin-x64/package.json'),
|
|
46
|
+
'darwin-arm64': () => require.resolve('@cpajs/darwin-arm64/package.json'),
|
|
47
|
+
'win32-x64': () => require.resolve('@cpajs/win32-x64/package.json'),
|
|
48
|
+
'win32-arm64': () => require.resolve('@cpajs/win32-arm64/package.json'),
|
|
49
|
+
'win32-ia32': () => require.resolve('@cpajs/win32-ia32/package.json'),
|
|
50
|
+
'linux-x64-gnu': () => require.resolve('@cpajs/linux-x64-gnu/package.json'),
|
|
51
|
+
'linux-arm64-gnu': () => require.resolve('@cpajs/linux-arm64-gnu/package.json'),
|
|
52
|
+
'linux-x64-musl': () => require.resolve('@cpajs/linux-x64-musl/package.json'),
|
|
53
|
+
'linux-arm64-musl': () => require.resolve('@cpajs/linux-arm64-musl/package.json'),
|
|
54
|
+
'linux-arm': () => require.resolve('@cpajs/linux-arm/package.json'),
|
|
55
|
+
'linux-ia32': () => require.resolve('@cpajs/linux-ia32/package.json'),
|
|
56
|
+
'linux-riscv64': () => require.resolve('@cpajs/linux-riscv64/package.json'),
|
|
57
|
+
'linux-ppc64': () => require.resolve('@cpajs/linux-ppc64/package.json'),
|
|
58
|
+
'linux-s390x': () => require.resolve('@cpajs/linux-s390x/package.json'),
|
|
59
|
+
'linux-loong64': () => require.resolve('@cpajs/linux-loong64/package.json'),
|
|
60
|
+
'linux-mips': () => require.resolve('@cpajs/linux-mips/package.json'),
|
|
61
|
+
'linux-mipsel': () => require.resolve('@cpajs/linux-mipsel/package.json'),
|
|
62
|
+
'freebsd-x64': () => require.resolve('@cpajs/freebsd-x64/package.json'),
|
|
63
|
+
'freebsd-arm64': () => require.resolve('@cpajs/freebsd-arm64/package.json'),
|
|
64
|
+
'freebsd-ia32': () => require.resolve('@cpajs/freebsd-ia32/package.json'),
|
|
65
|
+
'openbsd-x64': () => require.resolve('@cpajs/openbsd-x64/package.json'),
|
|
66
|
+
'openbsd-arm64': () => require.resolve('@cpajs/openbsd-arm64/package.json'),
|
|
67
|
+
'netbsd-x64': () => require.resolve('@cpajs/netbsd-x64/package.json'),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Resolves an installed platform package's package.json, or returns undefined
|
|
72
|
+
* when the package is not installed for this platform.
|
|
73
|
+
*/
|
|
74
|
+
function resolvePlatformPackage(id) {
|
|
75
|
+
const resolve = resolvers[id];
|
|
76
|
+
if (resolve === undefined) return undefined;
|
|
77
|
+
try {
|
|
78
|
+
return resolve();
|
|
79
|
+
} catch {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = { PLATFORM_PACKAGES, resolvePlatformPackage };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Generated by scripts/generate-binary-table.ts from TARGETS; do not edit. */
|
|
2
|
+
export declare const PLATFORM_PACKAGES: {
|
|
3
|
+
readonly 'darwin-x64': '@cpajs/darwin-x64';
|
|
4
|
+
readonly 'darwin-arm64': '@cpajs/darwin-arm64';
|
|
5
|
+
readonly 'win32-x64': '@cpajs/win32-x64';
|
|
6
|
+
readonly 'win32-arm64': '@cpajs/win32-arm64';
|
|
7
|
+
readonly 'win32-ia32': '@cpajs/win32-ia32';
|
|
8
|
+
readonly 'linux-x64-gnu': '@cpajs/linux-x64-gnu';
|
|
9
|
+
readonly 'linux-arm64-gnu': '@cpajs/linux-arm64-gnu';
|
|
10
|
+
readonly 'linux-x64-musl': '@cpajs/linux-x64-musl';
|
|
11
|
+
readonly 'linux-arm64-musl': '@cpajs/linux-arm64-musl';
|
|
12
|
+
readonly 'linux-arm': '@cpajs/linux-arm';
|
|
13
|
+
readonly 'linux-ia32': '@cpajs/linux-ia32';
|
|
14
|
+
readonly 'linux-riscv64': '@cpajs/linux-riscv64';
|
|
15
|
+
readonly 'linux-ppc64': '@cpajs/linux-ppc64';
|
|
16
|
+
readonly 'linux-s390x': '@cpajs/linux-s390x';
|
|
17
|
+
readonly 'linux-loong64': '@cpajs/linux-loong64';
|
|
18
|
+
readonly 'linux-mips': '@cpajs/linux-mips';
|
|
19
|
+
readonly 'linux-mipsel': '@cpajs/linux-mipsel';
|
|
20
|
+
readonly 'freebsd-x64': '@cpajs/freebsd-x64';
|
|
21
|
+
readonly 'freebsd-arm64': '@cpajs/freebsd-arm64';
|
|
22
|
+
readonly 'freebsd-ia32': '@cpajs/freebsd-ia32';
|
|
23
|
+
readonly 'openbsd-x64': '@cpajs/openbsd-x64';
|
|
24
|
+
readonly 'openbsd-arm64': '@cpajs/openbsd-arm64';
|
|
25
|
+
readonly 'netbsd-x64': '@cpajs/netbsd-x64';
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type PlatformTargetId = keyof typeof PLATFORM_PACKAGES;
|
|
29
|
+
|
|
30
|
+
export declare function resolvePlatformPackage(id: string): string | undefined;
|
package/dist/binary.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point for bundlers: importing `@cpajs/cpa/binary` (for its side effect)
|
|
3
|
+
* puts the installed platform packages in the module graph, so a tracer such as
|
|
4
|
+
* @vercel/nft copies the one that matches the deployment.
|
|
5
|
+
*
|
|
6
|
+
* The table itself is generated into binary-packages.cjs; see
|
|
7
|
+
* scripts/generate-binary-table.ts and src/server/binary.ts.
|
|
8
|
+
*/
|
|
9
|
+
export { PLATFORM_PACKAGES, resolvePlatformPackage } from './binary-packages.cjs';
|
|
10
|
+
export type { PlatformTargetId } from './binary-packages.cjs';
|
|
11
|
+
//# sourceMappingURL=binary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAClF,YAAY,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/binary.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point for bundlers: importing `@cpajs/cpa/binary` (for its side effect)
|
|
3
|
+
* puts the installed platform packages in the module graph, so a tracer such as
|
|
4
|
+
* @vercel/nft copies the one that matches the deployment.
|
|
5
|
+
*
|
|
6
|
+
* The table itself is generated into binary-packages.cjs; see
|
|
7
|
+
* scripts/generate-binary-table.ts and src/server/binary.ts.
|
|
8
|
+
*/
|
|
9
|
+
export { PLATFORM_PACKAGES, resolvePlatformPackage } from './binary-packages.cjs';
|
|
10
|
+
//# sourceMappingURL=binary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary.js","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/client/errors.d.ts
CHANGED
|
@@ -36,6 +36,37 @@ 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
|
+
}
|
|
39
70
|
/** The request could not be sent or the response could not be read. */
|
|
40
71
|
export declare class CpaNetworkError extends CpaClientError {
|
|
41
72
|
readonly name = "CpaNetworkError";
|
|
@@ -67,4 +98,6 @@ export declare class CpaResponseError extends CpaClientError {
|
|
|
67
98
|
cause?: unknown;
|
|
68
99
|
});
|
|
69
100
|
}
|
|
101
|
+
/** Parses an `api-call` body: JSON when possible, raw text otherwise, `undefined` when empty. */
|
|
102
|
+
export declare function parseApiCallBody(text: string): unknown;
|
|
70
103
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/client/errors.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAkB,IAAI,EAAE,MAAM,CAAoB;IAClD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAInG;CACF;AAED;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,cAAc;IAC9C,SAAkB,IAAI,kBAAkB;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB,YACE,OAAO,EAA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,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;AAWD,iGAAiG;AACjG,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOtD"}
|
package/dist/client/errors.js
CHANGED
|
@@ -43,6 +43,42 @@ 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
|
+
}
|
|
46
82
|
/** The request could not be sent or the response could not be read. */
|
|
47
83
|
export class CpaNetworkError extends CpaClientError {
|
|
48
84
|
name = 'CpaNetworkError';
|
|
@@ -81,6 +117,17 @@ function parseJsonOrUndefined(text) {
|
|
|
81
117
|
return undefined;
|
|
82
118
|
}
|
|
83
119
|
}
|
|
120
|
+
/** Parses an `api-call` body: JSON when possible, raw text otherwise, `undefined` when empty. */
|
|
121
|
+
export function parseApiCallBody(text) {
|
|
122
|
+
if (text === '')
|
|
123
|
+
return undefined;
|
|
124
|
+
try {
|
|
125
|
+
return JSON.parse(text);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return text;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
84
131
|
function describeErrorBody(data) {
|
|
85
132
|
if (typeof data !== 'object' || data === null)
|
|
86
133
|
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,SAA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AAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -8,10 +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, CpaHttpError, CpaNetworkError, CpaResponseError, CpaTimeoutError, } from './errors.ts';
|
|
11
|
+
export { CpaAbortError, CpaClientError, CpaCredentialTokenError, CpaHttpError, CpaNetworkError, CpaResponseError, CpaTimeoutError, CpaUpstreamError, } from './errors.ts';
|
|
12
12
|
export type { ClientOptions, FetchLike, Query, QueryValue, RawRequest, RequestOptions, ResponseType, TransportResponse } from './transport.ts';
|
|
13
|
-
export type { ConfigPath, ConfigPathValue,
|
|
14
|
-
export type { CredentialContent, CredentialFile, CredentialSelector } from './resources/credentials.ts';
|
|
13
|
+
export type { ConfigMutationOptions, ConfigPath, ConfigPathValue, ConfigReconcileResult, ConfigUpdateResult, ConfigWriteOptions, ConfigWriteResult, JsonInput, Versioned, } from './resources/config.ts';
|
|
14
|
+
export type { CredentialContent, CredentialFile, CredentialSelector, CredentialSummary, ModelsForOptions, ReconcileCredentialFile, ReconcileCredentialsInput, ReconcileCredentialsResult, } from './resources/credentials.ts';
|
|
15
15
|
export type { DownloadedFile } from './resources/download.ts';
|
|
16
16
|
export type { WaitForOAuthOptions } from './resources/oauth.ts';
|
|
17
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,EA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,eAAe,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAEhC,YAAY,OAAO,EAAE,aAAa,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, CpaHttpError, CpaNetworkError, CpaResponseError, CpaTimeoutError, } from './errors.js';
|
|
11
|
+
export { CpaAbortError, CpaClientError, CpaCredentialTokenError, CpaHttpError, CpaNetworkError, CpaResponseError, CpaTimeoutError, CpaUpstreamError, } 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 {
|
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,4BAA4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,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,6 +22,23 @@ 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
|
+
}
|
|
25
42
|
/**
|
|
26
43
|
* A config path: `'routing/retry'` or `['routing', 'retry']`. Segments are
|
|
27
44
|
* dash-case YAML keys; list indices are not addressable (lists are replaced whole).
|
|
@@ -58,6 +75,27 @@ export declare class ConfigResource {
|
|
|
58
75
|
replaceYaml(yaml: string, options?: ConfigWriteOptions): Promise<Versioned<ConfigWriteResult>>;
|
|
59
76
|
/** Reads one node, e.g. `getPath('server/port')`. A missing node is a 404 `CpaHttpError`. */
|
|
60
77
|
getPath<T = JsonValue>(path: ConfigPath, options?: RequestOptions): Promise<Versioned<T>>;
|
|
78
|
+
/**
|
|
79
|
+
* Reads a node, passes it to `fn`, and writes the result back with `If-Match`.
|
|
80
|
+
* A missing node (404) passes `undefined`. Returning `undefined` writes
|
|
81
|
+
* nothing. A 412 re-reads and calls `fn` again, up to `maxAttempts` times.
|
|
82
|
+
*
|
|
83
|
+
* The value handed to `fn` has the read-only `auth_index` fields removed
|
|
84
|
+
* (GET injects them into API keys), so it is safe to write back.
|
|
85
|
+
* Calls for the same path on one client instance run one at a time.
|
|
86
|
+
*/
|
|
87
|
+
update<P extends ConfigPath>(path: P, fn: (current: ConfigPathValue<P> | undefined) => ConfigPathValue<P> | undefined | Promise<ConfigPathValue<P> | undefined>, options?: ConfigMutationOptions): Promise<ConfigUpdateResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Replaces each top-level section in `partial` whose stored value differs,
|
|
90
|
+
* after a deep comparison that ignores the injected `auth_index` fields.
|
|
91
|
+
* Each changed section is written wholesale with PUT `/config/<key>`, so
|
|
92
|
+
* nested keys absent from the target are removed. Sections not listed are
|
|
93
|
+
* left untouched, and a target value of `undefined` is skipped.
|
|
94
|
+
*
|
|
95
|
+
* The first write uses the read's ETag; each later write uses the previous
|
|
96
|
+
* write's ETag. A 412 at any point re-reads and recomputes from scratch.
|
|
97
|
+
*/
|
|
98
|
+
reconcile(partial: CpaConfig, options?: ConfigMutationOptions): Promise<ConfigReconcileResult>;
|
|
61
99
|
/** Replaces or creates one node. Missing parent objects are created. */
|
|
62
100
|
set<P extends ConfigPath>(path: P, value: ConfigPathValue<P>, options?: ConfigWriteOptions): Promise<Versioned<ConfigWriteResult>>;
|
|
63
101
|
/** Deep-merges into one node (see {@link patch}). */
|