@toshicloud/sdk 0.4.0 → 0.5.1
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 +102 -19
- package/dist/client.d.ts +40 -4
- package/dist/client.js +35 -4
- package/dist/errors.d.ts +99 -0
- package/dist/errors.js +208 -0
- package/dist/gen/toshi/permission_pb.d.ts +244 -0
- package/dist/gen/toshi/permission_pb.js +94 -0
- package/dist/gen/toshi/workspace/v1/account_pb.d.ts +590 -0
- package/dist/gen/toshi/workspace/v1/account_pb.js +75 -0
- package/dist/gen/toshi/workspace/v1/artifacts_pb.d.ts +14 -8
- package/dist/gen/toshi/workspace/v1/artifacts_pb.js +10 -7
- package/dist/gen/toshi/workspace/v1/audit_events_pb.d.ts +191 -6
- package/dist/gen/toshi/workspace/v1/audit_events_pb.js +12 -1
- package/dist/gen/toshi/workspace/v1/channels_pb.d.ts +1194 -21
- package/dist/gen/toshi/workspace/v1/channels_pb.js +186 -39
- package/dist/gen/toshi/workspace/v1/connections_pb.d.ts +1481 -0
- package/dist/gen/toshi/workspace/v1/connections_pb.js +208 -0
- package/dist/gen/toshi/workspace/v1/discovery_pb.d.ts +924 -0
- package/dist/gen/toshi/workspace/v1/discovery_pb.js +231 -0
- package/dist/gen/toshi/workspace/v1/display_pb.d.ts +198 -15
- package/dist/gen/toshi/workspace/v1/display_pb.js +53 -2
- package/dist/gen/toshi/workspace/v1/domains_pb.d.ts +864 -0
- package/dist/gen/toshi/workspace/v1/domains_pb.js +152 -0
- package/dist/gen/toshi/workspace/v1/fillers_pb.d.ts +12 -4
- package/dist/gen/toshi/workspace/v1/fillers_pb.js +2 -1
- package/dist/gen/toshi/workspace/v1/grants_pb.d.ts +1297 -0
- package/dist/gen/toshi/workspace/v1/grants_pb.js +271 -0
- package/dist/gen/toshi/workspace/v1/hostjobs_pb.d.ts +315 -15
- package/dist/gen/toshi/workspace/v1/hostjobs_pb.js +11 -5
- package/dist/gen/toshi/workspace/v1/hosts_pb.d.ts +196 -7
- package/dist/gen/toshi/workspace/v1/hosts_pb.js +13 -7
- package/dist/gen/toshi/workspace/v1/images_pb.d.ts +1463 -0
- package/dist/gen/toshi/workspace/v1/images_pb.js +263 -0
- package/dist/gen/toshi/workspace/v1/products_pb.d.ts +506 -0
- package/dist/gen/toshi/workspace/v1/products_pb.js +60 -0
- package/dist/gen/toshi/workspace/v1/projects_pb.d.ts +1474 -99
- package/dist/gen/toshi/workspace/v1/projects_pb.js +151 -33
- package/dist/gen/toshi/workspace/v1/recordings_pb.d.ts +181 -14
- package/dist/gen/toshi/workspace/v1/recordings_pb.js +55 -14
- package/dist/gen/toshi/workspace/v1/roles_pb.d.ts +1994 -0
- package/dist/gen/toshi/workspace/v1/roles_pb.js +355 -0
- package/dist/gen/toshi/workspace/v1/secrets_pb.d.ts +314 -8
- package/dist/gen/toshi/workspace/v1/secrets_pb.js +43 -18
- package/dist/gen/toshi/workspace/v1/storage_providers_pb.d.ts +14 -0
- package/dist/gen/toshi/workspace/v1/storage_providers_pb.js +2 -1
- package/dist/gen/toshi/workspace/v1/tokens_pb.d.ts +434 -5
- package/dist/gen/toshi/workspace/v1/tokens_pb.js +66 -8
- package/dist/gen/toshi/workspace/v1/triggers_pb.d.ts +1099 -0
- package/dist/gen/toshi/workspace/v1/triggers_pb.js +185 -0
- package/dist/gen/toshi/workspace/v1/volumes_pb.d.ts +1052 -33
- package/dist/gen/toshi/workspace/v1/volumes_pb.js +170 -11
- package/dist/gen/toshi/workspace/v1/webhook_pb.d.ts +66 -8
- package/dist/gen/toshi/workspace/v1/webhook_pb.js +5 -4
- package/dist/gen/toshi/workspace/v1/workloads_pb.d.ts +2043 -54
- package/dist/gen/toshi/workspace/v1/workloads_pb.js +205 -54
- package/dist/gen/toshi/workspace/v1/workspace_pb.d.ts +6292 -939
- package/dist/gen/toshi/workspace/v1/workspace_pb.js +801 -88
- package/dist/gen/toshi/workspace/v1/workspace_service_pb.d.ts +2176 -630
- package/dist/gen/toshi/workspace/v1/workspace_service_pb.js +192 -74
- package/dist/index.d.ts +10 -1
- package/dist/index.js +10 -1
- package/dist/interceptors.d.ts +11 -1
- package/dist/interceptors.js +38 -4
- package/dist/retry.d.ts +18 -0
- package/dist/retry.js +228 -22
- package/dist/test/procedures.js +100 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wait.d.ts +4 -0
- package/dist/wait.js +24 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A TypeScript client for the Toshi Workspace API, `toshi.workspace.v1`,
|
|
|
4
4
|
published as ES modules with type declarations.
|
|
5
5
|
|
|
6
6
|
```sh
|
|
7
|
-
npm install @toshicloud/sdk @connectrpc/connect
|
|
7
|
+
npm install @toshicloud/sdk @bufbuild/protobuf @connectrpc/connect
|
|
8
8
|
```
|
|
9
9
|
|
|
10
10
|
The browser entry needs a transport such as `@connectrpc/connect-web`; the
|
|
@@ -68,13 +68,16 @@ entry reads `TOSHI_SERVER`, `TOSHI_TOKEN`, `TOSHI_TOKEN_FILE` and
|
|
|
68
68
|
`environment` fields when they are empty. A value in the request wins.
|
|
69
69
|
`environment` is left empty on a request with `shared: true`.
|
|
70
70
|
- `retry`: `{ maxAttempts, initialBackoffMs, maxBackoffMs }`, by default
|
|
71
|
-
5, 200 ms and 10 s, with full jitter.
|
|
72
|
-
and
|
|
71
|
+
5, 200 ms and 10 s, with full jitter. Reads, and the calls whose request
|
|
72
|
+
takes a `request_key`, are retried; a stream and every other call is not.
|
|
73
|
+
`retry: false` turns off retries and watch reconnects.
|
|
73
74
|
- `defaultTimeoutMs`: bounds each unary call except the Wait calls,
|
|
74
75
|
which their request's timeout bounds; streams ignore it.
|
|
75
76
|
|
|
76
77
|
A call may set `timeoutMs` instead: it bounds the whole call, retries
|
|
77
78
|
included, and on a watch it bounds the open. It composes with `signal`.
|
|
79
|
+
`ToshiOptions` is the object the client takes, and `CallOptions` the second
|
|
80
|
+
argument of each call, which carries `signal` and `timeoutMs`.
|
|
78
81
|
|
|
79
82
|
### Node options
|
|
80
83
|
|
|
@@ -135,13 +138,16 @@ picked up without a new client.
|
|
|
135
138
|
The client has one field per Workspace API service: `project`, `secret`,
|
|
136
139
|
`webhook`, `display`, `channel`, `recording`, `volume`, `artifact`,
|
|
137
140
|
`artifactUpload`, `workspace`, `hostJob`, `host`, `token`, `auditEvent`,
|
|
138
|
-
`filler`
|
|
139
|
-
|
|
141
|
+
`filler`, `grant`, `storageProvider`, `product`, `discovery`, `connection`,
|
|
142
|
+
`role`, `trigger`, `account`, `image` and `domain`, each holding that service's
|
|
143
|
+
generated client.
|
|
140
144
|
`workload` holds `WorkloadService`'s calls, grouped by the type they
|
|
141
145
|
name: `workload.jobs`, `workload.sandboxes` and `workload.services`, one
|
|
142
|
-
method for each call (`create`, `get`, `list`, `update`, `delete`,
|
|
143
|
-
`
|
|
144
|
-
`stop`, `setMode`, `listRuns`, `wake`, `hold
|
|
146
|
+
method for each call (`create`, `get`, `list`, `update`, `delete`, `wait`,
|
|
147
|
+
`watch`, and `cancel` on a job, `execute`, `start` and `stop` on a sandbox,
|
|
148
|
+
`start`, `stop`, `setMode`, `listRuns`, `wake`, `hold`, `release`,
|
|
149
|
+
`listRevisions`, `getRevision`, `rollback` and `listActivations` on a
|
|
150
|
+
service). The calls that
|
|
145
151
|
span the three types sit on `workload` itself: `listEvents`, `watchEvents`,
|
|
146
152
|
`getOperation` and `waitOperation`. `run` sits at the top of the client, as
|
|
147
153
|
`toshi run` sits at the top of the CLI.
|
|
@@ -156,7 +162,8 @@ console.log(job?.id);
|
|
|
156
162
|
|
|
157
163
|
### Lists
|
|
158
164
|
|
|
159
|
-
`workload.jobs.all`, `workload.sandboxes.all`,
|
|
165
|
+
`workload.jobs.all`, `workload.sandboxes.all`,
|
|
166
|
+
`workload.sandboxes.allPreviewShareLinks`, `workload.services.all`,
|
|
160
167
|
`workload.services.allRuns` and `workload.allEvents` take the request their
|
|
161
168
|
`list` method takes and yield every item, one page after another. Each
|
|
162
169
|
response's `nextPageToken` becomes the next request's `pageToken`, and a
|
|
@@ -190,6 +197,9 @@ for await (const project of paginate(
|
|
|
190
197
|
fields. Every page is a call of its own, so `opts` goes to each one, and
|
|
191
198
|
`timeoutMs` bounds a page and not the whole iteration. An error throws once
|
|
192
199
|
and ends the iteration; leaving the loop sends no further request.
|
|
200
|
+
`PageRequest` is a list request, which may name the page to read first with
|
|
201
|
+
`pageToken`, and `PageResponse` a list response, which names the page after
|
|
202
|
+
it with `nextPageToken`.
|
|
193
203
|
|
|
194
204
|
### Retries
|
|
195
205
|
|
|
@@ -199,18 +209,35 @@ connection reset or destroyed stream that `@connectrpc/connect-node`
|
|
|
199
209
|
reports, or a stream the server refused before reading it
|
|
200
210
|
(`REFUSED_STREAM`). A write that takes a request key gets a random one when the
|
|
201
211
|
request has none, so the server applies a retried write once. Other
|
|
202
|
-
writes are never retried.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
212
|
+
writes are never retried.
|
|
213
|
+
|
|
214
|
+
A `ResourceExhausted` refusal that names how long to wait, as the API's
|
|
215
|
+
rate limit does, is retried the same way. The wait comes from its
|
|
216
|
+
`google.rpc.RetryInfo` detail, else from its `Retry-After` header. So is an
|
|
217
|
+
HTTP 429 with a `Retry-After`, which reaches the client as `Unavailable`.
|
|
218
|
+
The client waits the longer of that wait and the backoff, never more than
|
|
219
|
+
`maxBackoffMs`, and stops when the call's signal aborts. A
|
|
220
|
+
`ResourceExhausted` that names no wait, such as a plan's limit, reaches the
|
|
221
|
+
caller unchanged, as do every other error the server sends, including
|
|
222
|
+
`Aborted` and `InvalidArgument`, and any connection failure the client
|
|
223
|
+
cannot tell apart from a server error.
|
|
224
|
+
|
|
225
|
+
`RetryPolicy` says how often and how long a call is retried, `maxAttempts`
|
|
226
|
+
counting the first try; `defaultRetryPolicy` is the default — five
|
|
227
|
+
attempts, a 200 ms initial backoff and a 10 s cap.
|
|
206
228
|
|
|
207
229
|
### Waiting and watching
|
|
208
230
|
|
|
209
231
|
- `workload.jobs.wait(req)`, `workload.sandboxes.wait(req)` and
|
|
210
232
|
`workload.services.wait(req)` ask again until the workload reaches the
|
|
211
|
-
state; `workload.waitOperation(req)` asks until the operation is done.
|
|
233
|
+
state; `workload.waitOperation(req)` asks until the operation is done. A
|
|
234
|
+
call starts at least a second, and at most 1.2 seconds, after the start of
|
|
235
|
+
the one before, and a signal ends a pause with its own error.
|
|
212
236
|
- `workload.getOperation(req)` returns one operation by id: a call that
|
|
213
237
|
takes long hands one back, and this asks for it again.
|
|
238
|
+
- An event's payload says what happened: a trigger's `TriggerResult` names
|
|
239
|
+
the key's `reason` and its workload, and with `process_exited` or
|
|
240
|
+
`setup_failed` it carries the sandbox's `exitCode` and `message`.
|
|
214
241
|
- `workload.listEvents(req)` returns the events after a cursor, oldest
|
|
215
242
|
first, a page at a time, for a client that polls or catches up after
|
|
216
243
|
downtime; `workload.watchEvents(req)` is the live form.
|
|
@@ -305,6 +332,57 @@ await run.wait(); // rejects with JobExitError on a non-zero exit
|
|
|
305
332
|
Stopping the loop stops only the output stream: the job keeps running,
|
|
306
333
|
and `workload.jobs.cancel` ends it.
|
|
307
334
|
|
|
335
|
+
## Products that are off
|
|
336
|
+
|
|
337
|
+
A call for a product that is off for the workspace rejects with a
|
|
338
|
+
`ProductError`, `wait`, the watches and `execute` included.
|
|
339
|
+
`isProductError(err)` tells it apart. It is still a `ConnectError` with the
|
|
340
|
+
same `code`, and it has the product's ID (`product`), the `reason`
|
|
341
|
+
(`ProductReason.Unavailable`), the input that turned the product off
|
|
342
|
+
(`productCause`: `build`, `operator`, `plan` or `workspace`) and, for a
|
|
343
|
+
product the deployment turns off, how far it has wound down (`state`:
|
|
344
|
+
`no_new_work`, `draining` or `stopped`).
|
|
345
|
+
|
|
346
|
+
<!-- examples/product-error.ts -->
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
import { isProductError } from "@toshicloud/sdk";
|
|
350
|
+
|
|
351
|
+
import { toshi } from "./client.js";
|
|
352
|
+
|
|
353
|
+
// Turn a product on for the workspace.
|
|
354
|
+
const enable = { id: "acme_ci", enabled: true };
|
|
355
|
+
try {
|
|
356
|
+
await toshi.product.updateProduct(enable);
|
|
357
|
+
} catch (err) {
|
|
358
|
+
if (!isProductError(err)) {
|
|
359
|
+
throw err;
|
|
360
|
+
}
|
|
361
|
+
// Off for the workspace: which product, the input that turns it off, and,
|
|
362
|
+
// for the deployment's config, how far it has wound down.
|
|
363
|
+
console.log(err.product, err.productCause, err.state);
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Refusals with a reason
|
|
368
|
+
|
|
369
|
+
A refusal that is not a product's rejects with a `RefusalError`;
|
|
370
|
+
`isRefusalError(err)` tells it apart. It is still a `ConnectError` with the
|
|
371
|
+
same `code`, and its `reason` is one of `RefusalReason`:
|
|
372
|
+
`RefusalReason.ImageInUse` when an image a workload or a revision still uses
|
|
373
|
+
cannot be deleted, `RefusalReason.ImageNotReady` when a job, a sandbox or a
|
|
374
|
+
service revision names a workspace image with no ready version,
|
|
375
|
+
`RefusalReason.PlanExcludesImages` when the plan has no images, `RefusalReason.LastIdentity` when the caller's last identity cannot
|
|
376
|
+
be unlinked, and so on for images, volumes, roles and display sessions.
|
|
377
|
+
|
|
378
|
+
`workload.services.rollback` asks the revision's registry whether it still
|
|
379
|
+
serves the revision's image before it selects it, and refuses with
|
|
380
|
+
`RefusalReason.ImageNotServed` when the registry answered that it does not
|
|
381
|
+
serve the image, or `RefusalReason.ImageCheckFailed` when it could not say.
|
|
382
|
+
A revision's `imageCheck` carries the last answer: its `outcome`, the
|
|
383
|
+
registry's `status` and `message`, and when it was asked, `checkedAt`.
|
|
384
|
+
Reading a revision asks no registry.
|
|
385
|
+
|
|
308
386
|
## Testing with `@toshicloud/sdk/test`
|
|
309
387
|
|
|
310
388
|
`createFake()` serves the whole Workspace API in memory: no server, no port,
|
|
@@ -340,17 +418,21 @@ first, with the procedure, the request and the headers.
|
|
|
340
418
|
[`protoc-gen-es`](https://github.com/bufbuild/protobuf-es) from the protos
|
|
341
419
|
in `proto/toshi/workspace/v1` of the
|
|
342
420
|
[toshi-api](https://github.com/toshicloud/toshi-api) repository, one
|
|
343
|
-
`*_pb.ts` file per proto
|
|
421
|
+
`*_pb.ts` file per proto, and `src/gen/toshi/permission_pb.ts` from
|
|
422
|
+
`proto/toshi/permission.proto`, which they import. The generated code is committed and imports
|
|
344
423
|
only `@bufbuild/protobuf`, so installing the package needs no generator.
|
|
345
424
|
|
|
346
|
-
`pin.env` names the toshi-api commit
|
|
347
|
-
|
|
348
|
-
|
|
425
|
+
`pin.env` names the toshi-api commit the code is generated from:
|
|
426
|
+
`2184ae8440834bb5b91991b3e4d62d14ce9dd15a` today, the commit of the
|
|
427
|
+
release tag `v0.4.1`. `mise.toml` pins the versions of Node, pnpm and `buf`;
|
|
428
|
+
`package.json` pins `protoc-gen-es` at the same version as the
|
|
429
|
+
`@bufbuild/protobuf` development dependency.
|
|
349
430
|
|
|
350
431
|
To regenerate:
|
|
351
432
|
|
|
352
433
|
```sh
|
|
353
434
|
mise install
|
|
435
|
+
pnpm install --frozen-lockfile
|
|
354
436
|
mise exec -- scripts/generate.sh
|
|
355
437
|
```
|
|
356
438
|
|
|
@@ -364,7 +446,8 @@ and fails if the result differs from what is committed
|
|
|
364
446
|
The package's major version follows the API's: `1.x` will serve
|
|
365
447
|
`toshi.workspace.v1`, and a `toshi.workspace.v2` gets a new major
|
|
366
448
|
version. Until a Toshi release serves the API, the package stays at
|
|
367
|
-
`0.x` and is generated from a pinned commit.
|
|
449
|
+
`0.x` and is generated from a pinned commit. `VERSION` is the package
|
|
450
|
+
version, the one `package.json` carries.
|
|
368
451
|
|
|
369
452
|
## Publishing
|
|
370
453
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
import type { MessageInitShape } from "@bufbuild/protobuf";
|
|
2
2
|
import type { Client, Interceptor, Transport } from "@connectrpc/connect";
|
|
3
|
+
import { AccountService } from "./gen/toshi/workspace/v1/account_pb.js";
|
|
3
4
|
import { ArtifactService, ArtifactUploadService } from "./gen/toshi/workspace/v1/artifacts_pb.js";
|
|
4
5
|
import { AuditEventService } from "./gen/toshi/workspace/v1/audit_events_pb.js";
|
|
5
6
|
import { ChannelService } from "./gen/toshi/workspace/v1/channels_pb.js";
|
|
7
|
+
import { ConnectionService } from "./gen/toshi/workspace/v1/connections_pb.js";
|
|
8
|
+
import { DiscoveryService } from "./gen/toshi/workspace/v1/discovery_pb.js";
|
|
6
9
|
import { DisplayService } from "./gen/toshi/workspace/v1/display_pb.js";
|
|
10
|
+
import { DomainService } from "./gen/toshi/workspace/v1/domains_pb.js";
|
|
7
11
|
import { FillerService } from "./gen/toshi/workspace/v1/fillers_pb.js";
|
|
12
|
+
import { GrantService } from "./gen/toshi/workspace/v1/grants_pb.js";
|
|
13
|
+
import { ImageService } from "./gen/toshi/workspace/v1/images_pb.js";
|
|
8
14
|
import { HostJobService } from "./gen/toshi/workspace/v1/hostjobs_pb.js";
|
|
9
15
|
import { HostService } from "./gen/toshi/workspace/v1/hosts_pb.js";
|
|
16
|
+
import { ProductService } from "./gen/toshi/workspace/v1/products_pb.js";
|
|
10
17
|
import { ProjectService } from "./gen/toshi/workspace/v1/projects_pb.js";
|
|
11
18
|
import { RecordingService } from "./gen/toshi/workspace/v1/recordings_pb.js";
|
|
19
|
+
import { RoleService } from "./gen/toshi/workspace/v1/roles_pb.js";
|
|
12
20
|
import { SecretService } from "./gen/toshi/workspace/v1/secrets_pb.js";
|
|
13
21
|
import { StorageProviderService } from "./gen/toshi/workspace/v1/storage_providers_pb.js";
|
|
14
22
|
import { TokenService } from "./gen/toshi/workspace/v1/tokens_pb.js";
|
|
23
|
+
import { TriggerService } from "./gen/toshi/workspace/v1/triggers_pb.js";
|
|
15
24
|
import { VolumeService } from "./gen/toshi/workspace/v1/volumes_pb.js";
|
|
16
25
|
import { WebhookService } from "./gen/toshi/workspace/v1/webhook_pb.js";
|
|
17
26
|
import { WorkspaceService } from "./gen/toshi/workspace/v1/workspace_service_pb.js";
|
|
27
|
+
import { CreatePreviewShareLinkRequestSchema, ListPreviewShareLinksRequestSchema, RevokePreviewShareLinkRequestSchema, StartSandboxRequestSchema, StopSandboxRequestSchema } from "./gen/toshi/workspace/v1/workspace_pb.js";
|
|
28
|
+
import type { CreatePreviewShareLinkResponse, ListPreviewShareLinksResponse, RevokePreviewShareLinkResponse, StartSandboxResponse, StopSandboxResponse } from "./gen/toshi/workspace/v1/workspace_pb.js";
|
|
18
29
|
import { CancelJobRequestSchema, CreateJobRequestSchema, CreateSandboxRequestSchema, CreateServiceRequestSchema, DeleteJobRequestSchema, DeleteSandboxRequestSchema, DeleteServiceRequestSchema, GetJobRequestSchema, GetSandboxRequestSchema, GetServiceRequestSchema, ListJobsRequestSchema, ListSandboxesRequestSchema, ListServicesRequestSchema, UpdateJobRequestSchema, UpdateSandboxRequestSchema, UpdateServiceRequestSchema, WaitJobRequestSchema, WaitSandboxRequestSchema, WaitServiceRequestSchema, WatchJobsRequestSchema, WatchSandboxesRequestSchema, WatchServicesRequestSchema } from "./gen/toshi/workspace/v1/workloads_pb.js";
|
|
19
30
|
import type { CancelJobResponse, CreateJobResponse, CreateSandboxResponse, CreateServiceResponse, DeleteJobResponse, DeleteSandboxResponse, DeleteServiceResponse, GetJobResponse, GetSandboxResponse, GetServiceResponse, ListJobsResponse, ListSandboxesResponse, ListServicesResponse, UpdateJobResponse, UpdateSandboxResponse, UpdateServiceResponse, WaitJobResponse, WaitSandboxResponse, WaitServiceResponse, WatchJobsResponse, WatchSandboxesResponse, WatchServicesResponse } from "./gen/toshi/workspace/v1/workloads_pb.js";
|
|
20
|
-
import { ExecuteStartSchema, GetOperationRequestSchema, HoldServiceRequestSchema, ListEventsRequestSchema, ListServiceRunsRequestSchema, ReleaseServiceRequestSchema, SetServiceModeRequestSchema, StartServiceRequestSchema, StopServiceRequestSchema, WaitOperationRequestSchema, WakeServiceRequestSchema, WatchEventsRequestSchema, WatchOutputRequestSchema } from "./gen/toshi/workspace/v1/workspace_pb.js";
|
|
21
|
-
import type { Event, GetOperationResponse, HoldServiceResponse, Job, ListEventsResponse, ListServiceRunsResponse, Operation, ReleaseServiceResponse, Sandbox, Service, ServiceRun, SetServiceModeResponse, StartServiceResponse, StopServiceResponse, WakeServiceResponse, WatchEventsResponse, WatchOutputResponse } from "./gen/toshi/workspace/v1/workspace_pb.js";
|
|
31
|
+
import { ExecuteStartSchema, GetOperationRequestSchema, GetServiceRevisionRequestSchema, HoldServiceRequestSchema, ListEventsRequestSchema, ListServiceActivationsRequestSchema, ListServiceRevisionsRequestSchema, ListServiceRunsRequestSchema, ReleaseServiceRequestSchema, RollbackServiceRequestSchema, SetServiceModeRequestSchema, StartServiceRequestSchema, StopServiceRequestSchema, WaitOperationRequestSchema, WakeServiceRequestSchema, WatchEventsRequestSchema, WatchOutputRequestSchema } from "./gen/toshi/workspace/v1/workspace_pb.js";
|
|
32
|
+
import type { Event, GetOperationResponse, GetServiceRevisionResponse, HoldServiceResponse, Job, ListEventsResponse, ListServiceActivationsResponse, ListServiceRevisionsResponse, ListServiceRunsResponse, Operation, PreviewShareLink, ReleaseServiceResponse, RollbackServiceResponse, Sandbox, Service, ServiceRun, SetServiceModeResponse, StartServiceResponse, StopServiceResponse, WakeServiceResponse, WatchEventsResponse, WatchOutputResponse } from "./gen/toshi/workspace/v1/workspace_pb.js";
|
|
22
33
|
import type { RetryPolicy } from "./retry.js";
|
|
23
34
|
/** How the client is configured; the caller builds the transport. */
|
|
24
35
|
export interface ToshiOptions {
|
|
@@ -63,7 +74,16 @@ export interface ToshiClient {
|
|
|
63
74
|
readonly token: Client<typeof TokenService>;
|
|
64
75
|
readonly auditEvent: Client<typeof AuditEventService>;
|
|
65
76
|
readonly filler: Client<typeof FillerService>;
|
|
77
|
+
readonly grant: Client<typeof GrantService>;
|
|
66
78
|
readonly storageProvider: Client<typeof StorageProviderService>;
|
|
79
|
+
readonly product: Client<typeof ProductService>;
|
|
80
|
+
readonly discovery: Client<typeof DiscoveryService>;
|
|
81
|
+
readonly connection: Client<typeof ConnectionService>;
|
|
82
|
+
readonly role: Client<typeof RoleService>;
|
|
83
|
+
readonly trigger: Client<typeof TriggerService>;
|
|
84
|
+
readonly account: Client<typeof AccountService>;
|
|
85
|
+
readonly image: Client<typeof ImageService>;
|
|
86
|
+
readonly domain: Client<typeof DomainService>;
|
|
67
87
|
run(req: MessageInitShape<typeof CreateJobRequestSchema>, opts?: CallOptions): Promise<JobRun>;
|
|
68
88
|
}
|
|
69
89
|
/** WorkloadService's calls, grouped by the type they name. */
|
|
@@ -103,9 +123,16 @@ export interface SandboxesClient {
|
|
|
103
123
|
all(req: MessageInitShape<typeof ListSandboxesRequestSchema>, opts?: CallOptions): AsyncIterable<Sandbox>;
|
|
104
124
|
update(req: MessageInitShape<typeof UpdateSandboxRequestSchema>, opts?: CallOptions): Promise<UpdateSandboxResponse>;
|
|
105
125
|
delete(req: MessageInitShape<typeof DeleteSandboxRequestSchema>, opts?: CallOptions): Promise<DeleteSandboxResponse>;
|
|
126
|
+
stop(req: MessageInitShape<typeof StopSandboxRequestSchema>, opts?: CallOptions): Promise<StopSandboxResponse>;
|
|
127
|
+
start(req: MessageInitShape<typeof StartSandboxRequestSchema>, opts?: CallOptions): Promise<StartSandboxResponse>;
|
|
106
128
|
wait(req: MessageInitShape<typeof WaitSandboxRequestSchema>, opts?: CallOptions): Promise<WaitSandboxResponse>;
|
|
107
129
|
watch(req: MessageInitShape<typeof WatchSandboxesRequestSchema>, opts?: CallOptions): Promise<SandboxWatch>;
|
|
108
130
|
execute(start: MessageInitShape<typeof ExecuteStartSchema>, opts?: CallOptions): Promise<Process>;
|
|
131
|
+
createPreviewShareLink(req: MessageInitShape<typeof CreatePreviewShareLinkRequestSchema>, opts?: CallOptions): Promise<CreatePreviewShareLinkResponse>;
|
|
132
|
+
listPreviewShareLinks(req: MessageInitShape<typeof ListPreviewShareLinksRequestSchema>, opts?: CallOptions): Promise<ListPreviewShareLinksResponse>;
|
|
133
|
+
/** Yields every share link that matches every filter that is set, following the page token from one page to the next. */
|
|
134
|
+
allPreviewShareLinks(req: MessageInitShape<typeof ListPreviewShareLinksRequestSchema>, opts?: CallOptions): AsyncIterable<PreviewShareLink>;
|
|
135
|
+
revokePreviewShareLink(req: MessageInitShape<typeof RevokePreviewShareLinkRequestSchema>, opts?: CallOptions): Promise<RevokePreviewShareLinkResponse>;
|
|
109
136
|
}
|
|
110
137
|
/** A service's calls: one method for each of WorkloadService's service calls. */
|
|
111
138
|
export interface ServicesClient {
|
|
@@ -127,6 +154,14 @@ export interface ServicesClient {
|
|
|
127
154
|
listRuns(req: MessageInitShape<typeof ListServiceRunsRequestSchema>, opts?: CallOptions): Promise<ListServiceRunsResponse>;
|
|
128
155
|
/** Yields every run listRuns returns, the newest first, following the page token from one page to the next. */
|
|
129
156
|
allRuns(req: MessageInitShape<typeof ListServiceRunsRequestSchema>, opts?: CallOptions): AsyncIterable<ServiceRun>;
|
|
157
|
+
/** Returns a service's revisions, oldest first. */
|
|
158
|
+
listRevisions(req: MessageInitShape<typeof ListServiceRevisionsRequestSchema>, opts?: CallOptions): Promise<ListServiceRevisionsResponse>;
|
|
159
|
+
/** Returns one revision of a service. */
|
|
160
|
+
getRevision(req: MessageInitShape<typeof GetServiceRevisionRequestSchema>, opts?: CallOptions): Promise<GetServiceRevisionResponse>;
|
|
161
|
+
/** Selects a revision the service already has as its current one. */
|
|
162
|
+
rollback(req: MessageInitShape<typeof RollbackServiceRequestSchema>, opts?: CallOptions): Promise<RollbackServiceResponse>;
|
|
163
|
+
/** Returns a service's activations, oldest first. */
|
|
164
|
+
listActivations(req: MessageInitShape<typeof ListServiceActivationsRequestSchema>, opts?: CallOptions): Promise<ListServiceActivationsResponse>;
|
|
130
165
|
}
|
|
131
166
|
/** A live stream of a job's changes. */
|
|
132
167
|
export interface JobWatch extends AsyncIterable<WatchJobsResponse> {
|
|
@@ -181,8 +216,9 @@ export interface JobRun extends AsyncIterable<OutputChunk> {
|
|
|
181
216
|
wait(): Promise<void>;
|
|
182
217
|
}
|
|
183
218
|
/**
|
|
184
|
-
* Creates the client: one normalized retry setting, the scope, key,
|
|
185
|
-
* auth interceptors (
|
|
219
|
+
* Creates the client: one normalized retry setting, the product, scope, key,
|
|
220
|
+
* retry and auth interceptors (product outermost, so a product's refusal
|
|
221
|
+
* reaches the caller as a ProductError; auth innermost, so no interceptor sees
|
|
186
222
|
* the Authorization header), one transport for every client and helper.
|
|
187
223
|
*
|
|
188
224
|
* Since 0.2.0 the workload calls are grouped by the type they name under
|
package/dist/client.js
CHANGED
|
@@ -1,34 +1,45 @@
|
|
|
1
1
|
import { create } from "@bufbuild/protobuf";
|
|
2
2
|
import { createClient } from "@connectrpc/connect";
|
|
3
3
|
import { executeCommand } from "./execute.js";
|
|
4
|
+
import { AccountService } from "./gen/toshi/workspace/v1/account_pb.js";
|
|
4
5
|
import { ArtifactService, ArtifactUploadService } from "./gen/toshi/workspace/v1/artifacts_pb.js";
|
|
5
6
|
import { AuditEventService } from "./gen/toshi/workspace/v1/audit_events_pb.js";
|
|
6
7
|
import { ChannelService } from "./gen/toshi/workspace/v1/channels_pb.js";
|
|
8
|
+
import { ConnectionService } from "./gen/toshi/workspace/v1/connections_pb.js";
|
|
9
|
+
import { DiscoveryService } from "./gen/toshi/workspace/v1/discovery_pb.js";
|
|
7
10
|
import { DisplayService } from "./gen/toshi/workspace/v1/display_pb.js";
|
|
11
|
+
import { DomainService } from "./gen/toshi/workspace/v1/domains_pb.js";
|
|
8
12
|
import { FillerService } from "./gen/toshi/workspace/v1/fillers_pb.js";
|
|
13
|
+
import { GrantService } from "./gen/toshi/workspace/v1/grants_pb.js";
|
|
14
|
+
import { ImageService } from "./gen/toshi/workspace/v1/images_pb.js";
|
|
9
15
|
import { HostJobService } from "./gen/toshi/workspace/v1/hostjobs_pb.js";
|
|
10
16
|
import { HostService } from "./gen/toshi/workspace/v1/hosts_pb.js";
|
|
17
|
+
import { ProductService } from "./gen/toshi/workspace/v1/products_pb.js";
|
|
11
18
|
import { ProjectService } from "./gen/toshi/workspace/v1/projects_pb.js";
|
|
12
19
|
import { RecordingService } from "./gen/toshi/workspace/v1/recordings_pb.js";
|
|
20
|
+
import { RoleService } from "./gen/toshi/workspace/v1/roles_pb.js";
|
|
13
21
|
import { SecretService } from "./gen/toshi/workspace/v1/secrets_pb.js";
|
|
14
22
|
import { StorageProviderService } from "./gen/toshi/workspace/v1/storage_providers_pb.js";
|
|
15
23
|
import { TokenService } from "./gen/toshi/workspace/v1/tokens_pb.js";
|
|
24
|
+
import { TriggerService } from "./gen/toshi/workspace/v1/triggers_pb.js";
|
|
16
25
|
import { VolumeService } from "./gen/toshi/workspace/v1/volumes_pb.js";
|
|
17
26
|
import { WebhookService } from "./gen/toshi/workspace/v1/webhook_pb.js";
|
|
18
27
|
import { WorkspaceService } from "./gen/toshi/workspace/v1/workspace_service_pb.js";
|
|
28
|
+
import { CreatePreviewShareLinkRequestSchema, ListPreviewShareLinksRequestSchema, RevokePreviewShareLinkRequestSchema, StartSandboxRequestSchema, StopSandboxRequestSchema, } from "./gen/toshi/workspace/v1/workspace_pb.js";
|
|
19
29
|
import { CancelJobRequestSchema, CreateJobRequestSchema, CreateSandboxRequestSchema, CreateServiceRequestSchema, DeleteJobRequestSchema, DeleteSandboxRequestSchema, DeleteServiceRequestSchema, GetJobRequestSchema, GetSandboxRequestSchema, GetServiceRequestSchema, ListJobsRequestSchema, ListSandboxesRequestSchema, ListServicesRequestSchema, UpdateJobRequestSchema, UpdateSandboxRequestSchema, UpdateServiceRequestSchema, WaitJobRequestSchema, WaitSandboxRequestSchema, WaitServiceRequestSchema, WatchJobsRequestSchema, WatchSandboxesRequestSchema, WatchServicesRequestSchema, WorkloadService, } from "./gen/toshi/workspace/v1/workloads_pb.js";
|
|
20
|
-
import { ExecuteStartSchema, GetOperationRequestSchema, HoldServiceRequestSchema, ListEventsRequestSchema, ListServiceRunsRequestSchema, ReleaseServiceRequestSchema, SetServiceModeRequestSchema, StartServiceRequestSchema, StopServiceRequestSchema, WaitOperationRequestSchema, WakeServiceRequestSchema, WatchEventsRequestSchema, WatchOutputRequestSchema, } from "./gen/toshi/workspace/v1/workspace_pb.js";
|
|
30
|
+
import { ExecuteStartSchema, GetOperationRequestSchema, GetServiceRevisionRequestSchema, HoldServiceRequestSchema, ListEventsRequestSchema, ListServiceActivationsRequestSchema, ListServiceRevisionsRequestSchema, ListServiceRunsRequestSchema, ReleaseServiceRequestSchema, RollbackServiceRequestSchema, SetServiceModeRequestSchema, StartServiceRequestSchema, StopServiceRequestSchema, WaitOperationRequestSchema, WakeServiceRequestSchema, WatchEventsRequestSchema, WatchOutputRequestSchema, } from "./gen/toshi/workspace/v1/workspace_pb.js";
|
|
21
31
|
import { openOutputWatch } from "./output.js";
|
|
22
32
|
import { paginate } from "./paginate.js";
|
|
23
|
-
import { authInterceptor, keyInterceptor, retryInterceptor, scopeInterceptor } from "./interceptors.js";
|
|
33
|
+
import { authInterceptor, keyInterceptor, refusalInterceptor, retryInterceptor, scopeInterceptor, } from "./interceptors.js";
|
|
24
34
|
import { normalizeRetry } from "./retry.js";
|
|
25
35
|
import { withDefaultUnaryTimeout } from "./timeout.js";
|
|
26
36
|
import { openEventWatch, openJobWatch, openSandboxWatch, openServiceWatch } from "./watch.js";
|
|
27
37
|
import { runJob } from "./run.js";
|
|
28
38
|
import { waitJob, waitOperation, waitSandbox, waitService } from "./wait.js";
|
|
29
39
|
/**
|
|
30
|
-
* Creates the client: one normalized retry setting, the scope, key,
|
|
31
|
-
* auth interceptors (
|
|
40
|
+
* Creates the client: one normalized retry setting, the product, scope, key,
|
|
41
|
+
* retry and auth interceptors (product outermost, so a product's refusal
|
|
42
|
+
* reaches the caller as a ProductError; auth innermost, so no interceptor sees
|
|
32
43
|
* the Authorization header), one transport for every client and helper.
|
|
33
44
|
*
|
|
34
45
|
* Since 0.2.0 the workload calls are grouped by the type they name under
|
|
@@ -38,6 +49,7 @@ import { waitJob, waitOperation, waitSandbox, waitService } from "./wait.js";
|
|
|
38
49
|
export function createToshiClient(options) {
|
|
39
50
|
const retry = normalizeRetry(options.retry);
|
|
40
51
|
const interceptors = [
|
|
52
|
+
refusalInterceptor(),
|
|
41
53
|
scopeInterceptor(options.project ?? "", options.environment ?? ""),
|
|
42
54
|
keyInterceptor(),
|
|
43
55
|
retryInterceptor(retry),
|
|
@@ -75,9 +87,15 @@ export function createToshiClient(options) {
|
|
|
75
87
|
all: (req, opts) => paginate(req, workloadService.listSandboxes, (resp) => resp.sandboxes, opts),
|
|
76
88
|
update: (req, opts) => workloadService.updateSandbox(req, opts),
|
|
77
89
|
delete: (req, opts) => workloadService.deleteSandbox(req, opts),
|
|
90
|
+
stop: (req, opts) => workloadService.stopSandbox(req, opts),
|
|
91
|
+
start: (req, opts) => workloadService.startSandbox(req, opts),
|
|
78
92
|
wait: (req, opts) => waitSandbox(workloadService, create(WaitSandboxRequestSchema, req), opts),
|
|
79
93
|
watch: (req, opts) => openSandboxWatch(workloadService, retry, create(WatchSandboxesRequestSchema, req), opts),
|
|
80
94
|
execute: (start, opts) => executeCommand(workloadService, start, opts),
|
|
95
|
+
createPreviewShareLink: (req, opts) => workloadService.createPreviewShareLink(req, opts),
|
|
96
|
+
listPreviewShareLinks: (req, opts) => workloadService.listPreviewShareLinks(req, opts),
|
|
97
|
+
allPreviewShareLinks: (req, opts) => paginate(req, workloadService.listPreviewShareLinks, (resp) => resp.shareLinks, opts),
|
|
98
|
+
revokePreviewShareLink: (req, opts) => workloadService.revokePreviewShareLink(req, opts),
|
|
81
99
|
},
|
|
82
100
|
services: {
|
|
83
101
|
create: (req, opts) => workloadService.createService(req, opts),
|
|
@@ -96,6 +114,10 @@ export function createToshiClient(options) {
|
|
|
96
114
|
hold: (req, opts) => workloadService.holdService(req, opts),
|
|
97
115
|
listRuns: (req, opts) => workloadService.listServiceRuns(req, opts),
|
|
98
116
|
allRuns: (req, opts) => paginate(req, workloadService.listServiceRuns, (resp) => resp.runs, opts),
|
|
117
|
+
listRevisions: (req, opts) => workloadService.listServiceRevisions(req, opts),
|
|
118
|
+
getRevision: (req, opts) => workloadService.getServiceRevision(req, opts),
|
|
119
|
+
rollback: (req, opts) => workloadService.rollbackService(req, opts),
|
|
120
|
+
listActivations: (req, opts) => workloadService.listServiceActivations(req, opts),
|
|
99
121
|
},
|
|
100
122
|
waitOperation: (req, opts) => waitOperation(workloadService, create(WaitOperationRequestSchema, req), opts),
|
|
101
123
|
listEvents: (req, opts) => workloadService.listEvents(req, opts),
|
|
@@ -110,6 +132,15 @@ export function createToshiClient(options) {
|
|
|
110
132
|
token: createClient(TokenService, transport),
|
|
111
133
|
auditEvent: createClient(AuditEventService, transport),
|
|
112
134
|
filler: createClient(FillerService, transport),
|
|
135
|
+
grant: createClient(GrantService, transport),
|
|
113
136
|
storageProvider: createClient(StorageProviderService, transport),
|
|
137
|
+
product: createClient(ProductService, transport),
|
|
138
|
+
discovery: createClient(DiscoveryService, transport),
|
|
139
|
+
connection: createClient(ConnectionService, transport),
|
|
140
|
+
role: createClient(RoleService, transport),
|
|
141
|
+
trigger: createClient(TriggerService, transport),
|
|
142
|
+
account: createClient(AccountService, transport),
|
|
143
|
+
image: createClient(ImageService, transport),
|
|
144
|
+
domain: createClient(DomainService, transport),
|
|
114
145
|
};
|
|
115
146
|
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ConnectError } from "@connectrpc/connect";
|
|
1
2
|
import type { ExecutionExit, OutputEnd } from "./gen/toshi/workspace/v1/workspace_pb.js";
|
|
2
3
|
/** A command that ended non-zero, or was cancelled before it had a status (errors.go:9-26). */
|
|
3
4
|
export declare class ExitError extends Error {
|
|
@@ -26,3 +27,101 @@ export declare class StreamLostError extends Error {
|
|
|
26
27
|
readonly requestKey: string;
|
|
27
28
|
constructor(executionId: string, requestKey: string, cause?: unknown);
|
|
28
29
|
}
|
|
30
|
+
/** Why the API refused a call for a product: the reason of the refusal's ErrorInfo detail. */
|
|
31
|
+
export type ProductReason = "PRODUCT_UNAVAILABLE";
|
|
32
|
+
/** The reasons a call is refused for a product. */
|
|
33
|
+
export declare const ProductReason: {
|
|
34
|
+
/**
|
|
35
|
+
* The product is off for the workspace; the code is FailedPrecondition, and
|
|
36
|
+
* `cause` says which input turned it off.
|
|
37
|
+
*/
|
|
38
|
+
readonly Unavailable: "PRODUCT_UNAVAILABLE";
|
|
39
|
+
};
|
|
40
|
+
/** The input that turned a product off: a ProductError's `cause`. */
|
|
41
|
+
export type ProductCause = "build" | "operator" | "plan" | "workspace";
|
|
42
|
+
/** The inputs that turn a product off. */
|
|
43
|
+
export declare const ProductCause: {
|
|
44
|
+
/** The deployment's build does not include the product. */
|
|
45
|
+
readonly Build: "build";
|
|
46
|
+
/** The deployment's config turns the product off. */
|
|
47
|
+
readonly Operator: "operator";
|
|
48
|
+
/** The workspace's plan leaves the product out. */
|
|
49
|
+
readonly Plan: "plan";
|
|
50
|
+
/** The workspace's settings turn the product off. */
|
|
51
|
+
readonly Workspace: "workspace";
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Why the API refused a call and named the reason: the reason of the
|
|
55
|
+
* refusal's ErrorInfo detail, for a refusal that is not a product's.
|
|
56
|
+
*/
|
|
57
|
+
export type RefusalReason = "DISPLAY_INPUT_NOT_ENABLED" | "IMAGE_BUILD_IN_PROGRESS" | "IMAGE_CHECK_FAILED" | "IMAGE_IN_USE" | "IMAGE_NAME_TAKEN" | "IMAGE_NOT_READY" | "IMAGE_NOT_SERVED" | "LAST_IDENTITY" | "LAST_MEMBER" | "LAST_OWNER" | "PERMISSION_MISSING" | "PLAN_EXCLUDES_IMAGES" | "TOSHI_LICENSED_WINDOWS";
|
|
58
|
+
/** The reasons the API names on a refusal that is not a product's. */
|
|
59
|
+
export declare const RefusalReason: {
|
|
60
|
+
/** The Windows VM takes no display input; the code is FailedPrecondition. */
|
|
61
|
+
readonly DisplayInputNotEnabled: "DISPLAY_INPUT_NOT_ENABLED";
|
|
62
|
+
/** The image already has a build running; the code is FailedPrecondition. */
|
|
63
|
+
readonly ImageBuildInProgress: "IMAGE_BUILD_IN_PROGRESS";
|
|
64
|
+
/** The registry of the revision's image could not say whether it serves the digest; the code is FailedPrecondition. */
|
|
65
|
+
readonly ImageCheckFailed: "IMAGE_CHECK_FAILED";
|
|
66
|
+
/** A workload or a service revision still uses the image; the code is FailedPrecondition. */
|
|
67
|
+
readonly ImageInUse: "IMAGE_IN_USE";
|
|
68
|
+
/** Another live image of the workspace has the name; the code is AlreadyExists. */
|
|
69
|
+
readonly ImageNameTaken: "IMAGE_NAME_TAKEN";
|
|
70
|
+
/** A workspace image named by a job, a sandbox or a service revision has no ready version; the code is FailedPrecondition. */
|
|
71
|
+
readonly ImageNotReady: "IMAGE_NOT_READY";
|
|
72
|
+
/** The revision's registry answered that it does not serve the image digest; the code is FailedPrecondition. */
|
|
73
|
+
readonly ImageNotServed: "IMAGE_NOT_SERVED";
|
|
74
|
+
/** The call would remove the caller's last identity; the code is FailedPrecondition. */
|
|
75
|
+
readonly LastIdentity: "LAST_IDENTITY";
|
|
76
|
+
/** The call would remove the workspace's last member; the code is FailedPrecondition. */
|
|
77
|
+
readonly LastMember: "LAST_MEMBER";
|
|
78
|
+
/** The call would leave the workspace without an owner; the code is FailedPrecondition. */
|
|
79
|
+
readonly LastOwner: "LAST_OWNER";
|
|
80
|
+
/** A role change names a permission the caller does not hold where the role applies; the code is PermissionDenied. */
|
|
81
|
+
readonly PermissionMissing: "PERMISSION_MISSING";
|
|
82
|
+
/** The workspace's plan does not include images; the code is FailedPrecondition. */
|
|
83
|
+
readonly PlanExcludesImages: "PLAN_EXCLUDES_IMAGES";
|
|
84
|
+
/** A Windows job Toshi licenses opens no display session; the code is FailedPrecondition. */
|
|
85
|
+
readonly ToshiLicensedWindows: "TOSHI_LICENSED_WINDOWS";
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The API's refusal of a call for a product that is off for the workspace.
|
|
89
|
+
* Every call the client makes throws it in place of the ConnectError, wait,
|
|
90
|
+
* watch and execute included. It is a ConnectError, so `instanceof
|
|
91
|
+
* ConnectError` and `code` read as before; test for it with
|
|
92
|
+
* {@link isProductError}.
|
|
93
|
+
*/
|
|
94
|
+
export declare class ProductError extends ConnectError {
|
|
95
|
+
/** The product's ID, such as `runners`. */
|
|
96
|
+
readonly product: string;
|
|
97
|
+
readonly reason: ProductReason;
|
|
98
|
+
/** The input that turned the product off, the refusal's `cause` metadata: `build`, `operator`, `plan` or `workspace`. */
|
|
99
|
+
readonly productCause: ProductCause;
|
|
100
|
+
/** How far a product the deployment turns off has wound down: `no_new_work`, `draining` or `stopped`; empty otherwise. */
|
|
101
|
+
readonly state: string;
|
|
102
|
+
constructor(err: ConnectError, reason: ProductReason, metadata: ReadonlyMap<string, string>);
|
|
103
|
+
static [Symbol.hasInstance](v: unknown): boolean;
|
|
104
|
+
}
|
|
105
|
+
/** Reports whether err is a product's refusal. */
|
|
106
|
+
export declare function isProductError(err: unknown): err is ProductError;
|
|
107
|
+
/**
|
|
108
|
+
* The API's refusal that names a reason: an image still in use, a plan
|
|
109
|
+
* without images, a last identity, a rollback whose revision's image is gone,
|
|
110
|
+
* and the rest of {@link RefusalReason}. Every call the client makes throws
|
|
111
|
+
* it in place of the ConnectError. It is a ConnectError, so `instanceof
|
|
112
|
+
* ConnectError` and `code` read as before; test for it with
|
|
113
|
+
* {@link isRefusalError}.
|
|
114
|
+
*/
|
|
115
|
+
export declare class RefusalError extends ConnectError {
|
|
116
|
+
readonly reason: RefusalReason;
|
|
117
|
+
constructor(err: ConnectError, reason: RefusalReason);
|
|
118
|
+
static [Symbol.hasInstance](v: unknown): boolean;
|
|
119
|
+
}
|
|
120
|
+
/** Reports whether err is a refusal that names a reason this module knows. */
|
|
121
|
+
export declare function isRefusalError(err: unknown): err is RefusalError;
|
|
122
|
+
/** err as a ProductError when it is a product's refusal, and err unchanged otherwise. */
|
|
123
|
+
export declare function asProductError(err: unknown): unknown;
|
|
124
|
+
/** err as a RefusalError when it is a refusal that names a reason this module knows, and err unchanged otherwise. */
|
|
125
|
+
export declare function asRefusalError(err: unknown): unknown;
|
|
126
|
+
/** err as one of this module's typed errors when the API's ErrorInfo detail names a reason it knows, and err unchanged otherwise. */
|
|
127
|
+
export declare function asTypedError(err: unknown): unknown;
|