@sealant/api-contracts-next 0.40.0-next.870 → 0.40.0-next.874

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Boat accounts wire contracts — the Boat API keys an install keeps beside its default one.
2
+ * Boat accounts wire contracts — the Boat keys an install keeps beside its default one.
3
3
  *
4
4
  * An install's default Boat account is its env key (`SEALANT_BOAT_API_KEY`). A product that serves
5
5
  * several organizations (Mend) stores one more account per organization, so each organization's
@@ -12,6 +12,7 @@
12
12
  */
13
13
  import { Schema } from "effect";
14
14
  import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api";
15
+ import { boatFailureSchema } from "./boat-failures.js";
15
16
  const NonEmptyString = Schema.String.check(Schema.isNonEmpty(), Schema.isTrimmed());
16
17
  /**
17
18
  * A key is checked only for being there: a check that failed on its value would print it in the
@@ -19,6 +20,128 @@ const NonEmptyString = Schema.String.check(Schema.isNonEmpty(), Schema.isTrimmed
19
20
  */
20
21
  const SecretString = Schema.String.check(Schema.isNonEmpty());
21
22
  const BoatAccountId = Schema.String.check(Schema.isPattern(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/));
23
+ /**
24
+ * The install's own Boat key (its env key), as rotation and removal refuse it
25
+ * (`boat-account-environment`). It is read through `install-key`, never listed: `list` answers
26
+ * stored accounts only, with ids every released client decodes.
27
+ */
28
+ export const BOAT_DEFAULT_ACCOUNT_ID = "default";
29
+ const BoatAccountRef = Schema.Union([BoatAccountId, Schema.Literal(BOAT_DEFAULT_ACCOUNT_ID)]);
30
+ /**
31
+ * A fact Boat did not let Core observe, and why. `refused`: Boat refused the read (`boat` says
32
+ * how; an organization key is refused Boat's key list). `no-answer`: Boat did not answer.
33
+ * `not-listed`: Boat's key list did not include this key (a key limited to some VMs gets an empty
34
+ * list), or included more than one that could be it. `unreadable`: Boat answered with something
35
+ * Core could not read. Core never guesses a fact it did not observe.
36
+ */
37
+ export const boatKeyNotObservedSchema = Schema.Struct({
38
+ observed: Schema.Literal(false),
39
+ reason: Schema.Literals(["refused", "no-answer", "not-listed", "unreadable"]),
40
+ boat: Schema.optional(boatFailureSchema),
41
+ });
42
+ const observedOr = (fields) => Schema.Union([
43
+ Schema.Struct({ observed: Schema.Literal(true), ...fields }),
44
+ boatKeyNotObservedSchema,
45
+ ]);
46
+ /**
47
+ * What Core observed of a Boat key, from Boat's own answers, at `observedAt`. Each fact is
48
+ * `observed: true` with its value, or `observed: false` with the reason Boat did not show it.
49
+ */
50
+ export const boatKeyReportSchema = Schema.Struct({
51
+ observedAt: Schema.String,
52
+ /** The Boat organization the account bills (`X-Boat-Org` on every request), or null. */
53
+ organization: Schema.NullOr(Schema.String),
54
+ /** Who the key is (`GET /me`). */
55
+ identity: observedOr({
56
+ /**
57
+ * Boat's id for the account the key belongs to (`GET /me` `user.id`). A Boat account, never a
58
+ * Sealant person: it is not a `PersonId` and names no one on this install.
59
+ */
60
+ accountId: Schema.optional(Schema.String),
61
+ login: Schema.optional(Schema.String),
62
+ displayName: Schema.optional(Schema.String),
63
+ serviceAccount: Schema.optional(Schema.Boolean),
64
+ accountStatus: Schema.Literals(["active", "suspended", "closed", "unknown"]),
65
+ }),
66
+ /** A personal (account) key, or an organization's key. */
67
+ keyKind: observedOr({ kind: Schema.Literals(["personal", "organization"]) }),
68
+ /** Which wallet a VM started with the key bills (`GET /limits`). */
69
+ wallet: observedOr({
70
+ kind: Schema.Literals(["personal", "organization"]),
71
+ organizationId: Schema.optional(Schema.String),
72
+ organizationName: Schema.optional(Schema.String),
73
+ role: Schema.optional(Schema.String),
74
+ }),
75
+ /** The permissions Core needs of every key, from the Boat calls it makes. */
76
+ requiredPermissions: Schema.Array(Schema.String),
77
+ /** The key's permissions (`GET /api-keys`), and which of the required ones it lacks. */
78
+ permissions: observedOr({
79
+ held: Schema.Array(Schema.String),
80
+ missing: Schema.Array(Schema.String),
81
+ /** The key is limited to some VMs or environments: it cannot reach VMs Core creates. */
82
+ limitedToSandboxes: Schema.Boolean,
83
+ }),
84
+ /** When the key expires; `expiresAt` null: it never does. */
85
+ expiry: observedOr({
86
+ expiresAt: Schema.NullOr(Schema.String),
87
+ expired: Schema.Boolean,
88
+ expiringSoon: Schema.Boolean,
89
+ }),
90
+ /** Whether the wallet can start a VM now, why not, and its running and allowed VMs. */
91
+ start: observedOr({
92
+ canStart: Schema.Boolean,
93
+ blockedReason: Schema.optional(Schema.String),
94
+ billingStatus: Schema.optional(Schema.String),
95
+ runningVms: Schema.Int,
96
+ allowedVms: Schema.Int,
97
+ }),
98
+ /** Saved snapshot slots of the wallet (`GET /saved-snapshots`). */
99
+ snapshots: observedOr({ used: Schema.Int, included: Schema.Int }),
100
+ });
101
+ /** The steps of a Boat key's full check, in order: the last two are also its cleanup. */
102
+ export const BOAT_KEY_PROOF_STEPS = [
103
+ "start-vm",
104
+ "run-command",
105
+ "publish-port",
106
+ "save-snapshot",
107
+ "delete-snapshot",
108
+ "delete-vm",
109
+ ];
110
+ /**
111
+ * One step of a full check. `passed`: Boat did it. `refused`: Boat refused it, `boat` says why.
112
+ * `no-answer`: Boat did not answer (the step may have happened; cleanup assumes it did).
113
+ * `not-reached`: an earlier step stopped the check, and this one was not tried.
114
+ */
115
+ export const boatKeyProofStepSchema = Schema.Struct({
116
+ step: Schema.Literals(BOAT_KEY_PROOF_STEPS),
117
+ outcome: Schema.Literals(["passed", "refused", "no-answer", "not-reached"]),
118
+ boat: Schema.optional(boatFailureSchema),
119
+ });
120
+ /**
121
+ * A full check of a Boat key: Core started the smallest VM, ran a command in it, published a port,
122
+ * saved a snapshot, then deleted the snapshot and the VM, and says how far it got. `outcome`:
123
+ * `passed` (every step), `refused` (Boat refused a step; the first refused or unanswered step
124
+ * says why), or `interrupted` (the check stopped before it finished; what it made was removed by
125
+ * the sweep). `starts`: how many VM starts it asked Boat for (0 or 1). `leftBehind`: what Boat
126
+ * may still hold of it when the answer was given. `removalConfirmed` true: Core saw Boat delete
127
+ * everything it made. False: the worker's sweep owns what is left and keeps deleting it, with
128
+ * `vm` (an id) and `snapshot` (a name) naming what is known; `vm` is null when a VM may exist
129
+ * whose id Boat never answered (the sweep finds it by its label). Until the sweep has finished,
130
+ * the account's key is neither rotated nor removed.
131
+ */
132
+ export const boatKeyProofSchema = Schema.Struct({
133
+ proofId: Schema.String,
134
+ startedAt: Schema.String,
135
+ finishedAt: Schema.String,
136
+ outcome: Schema.Literals(["passed", "refused", "interrupted"]),
137
+ steps: Schema.Array(boatKeyProofStepSchema),
138
+ starts: Schema.Int,
139
+ leftBehind: Schema.Struct({
140
+ vm: Schema.NullOr(Schema.String),
141
+ snapshot: Schema.NullOr(Schema.String),
142
+ removalConfirmed: Schema.Boolean,
143
+ }),
144
+ });
22
145
  export const boatAccountSchema = Schema.Struct({
23
146
  boatAccountId: BoatAccountId,
24
147
  label: NonEmptyString,
@@ -27,15 +150,36 @@ export const boatAccountSchema = Schema.Struct({
27
150
  createdAt: Schema.String,
28
151
  /** When its key was last replaced; null when it still has the key it was created with. */
29
152
  keyRotatedAt: Schema.NullOr(Schema.String),
153
+ /** The Boat organization the account bills, sent on every request for it; null: none named. */
154
+ organization: Schema.optional(Schema.NullOr(Schema.String)),
155
+ /** The key's last report, with when it was observed; null until the key is checked. */
156
+ report: Schema.optional(Schema.NullOr(boatKeyReportSchema)),
157
+ /** The account's last full check (`prove`), kept beside its report; null until it is proven. */
158
+ lastProof: Schema.optional(Schema.NullOr(boatKeyProofSchema)),
159
+ });
160
+ /**
161
+ * The install's own Boat key (`SEALANT_BOAT_API_KEY`), which workspaces run in when they name no
162
+ * account: never its value, only its last report. It is set in the install's environment, so it
163
+ * cannot be rotated or removed through this API.
164
+ */
165
+ export const boatInstallKeySchema = Schema.Struct({
166
+ label: NonEmptyString,
167
+ /** The key's last report, with when it was observed; null until it is checked. */
168
+ report: Schema.NullOr(boatKeyReportSchema),
30
169
  });
31
170
  export const createBoatAccountRequestSchema = Schema.Struct({
32
171
  /** The caller's name for the account (an organization's name, say). At most 200 characters. */
33
172
  label: NonEmptyString,
34
- /** The Boat API key. Checked with Boat by one read-only call before it is stored. */
173
+ /** The Boat key. Checked with Boat by read-only calls before it is stored; whitespace around it is trimmed. */
35
174
  apiKey: SecretString,
175
+ /**
176
+ * For a personal key: the Boat organization to bill (its id or name), sent as `X-Boat-Org` on
177
+ * every request for the account, so billing never follows the key's active wallet.
178
+ */
179
+ organization: Schema.optional(NonEmptyString),
36
180
  });
37
181
  export const rotateBoatAccountKeyRequestSchema = Schema.Struct({
38
- /** The new Boat API key, for the same Boat account: it must see every VM the account runs. */
182
+ /** The new Boat key, for the same Boat account: it must see every VM the account runs. */
39
183
  apiKey: SecretString,
40
184
  });
41
185
  export const listBoatAccountsResponseSchema = Schema.Struct({
@@ -44,13 +188,22 @@ export const listBoatAccountsResponseSchema = Schema.Struct({
44
188
  export class BoatAccountBadRequestError extends Schema.TaggedError()("BoatAccountBadRequestError", { message: Schema.String }, { httpApiStatus: 400 }) {
45
189
  }
46
190
  /**
47
- * Boat refused the key (`boat-key-refused`: it answered that the key is not valid), or did not
48
- * answer whether it is (`boat-key-unverified`: Boat was unreachable; try again). Nothing was
49
- * stored or changed. The message never names the key or any part of it.
191
+ * Boat refused the key (`boat-key-refused`: it answered that the key is not valid, has expired or
192
+ * belongs to another organization; `boat` says which), the key provably lacks permissions Core
193
+ * needs (`boat-key-missing-permissions`, named in `missingPermissions`), or Boat did not answer
194
+ * whether it is valid (`boat-key-unverified`: try again). Nothing was stored or changed. The
195
+ * message never names the key or any part of it.
50
196
  */
51
197
  export class BoatAccountKeyRefusedError extends Schema.TaggedError()("BoatAccountKeyRefusedError", {
52
198
  message: Schema.String,
53
- code: Schema.Literals(["boat-key-refused", "boat-key-unverified"]),
199
+ code: Schema.Literals([
200
+ "boat-key-refused",
201
+ "boat-key-unverified",
202
+ "boat-key-missing-permissions",
203
+ ]),
204
+ missingPermissions: Schema.optional(Schema.Array(Schema.String)),
205
+ boat: Schema.optional(boatFailureSchema),
206
+ report: Schema.optional(boatKeyReportSchema),
54
207
  }, { httpApiStatus: 422 }) {
55
208
  }
56
209
  export class BoatAccountNotFoundError extends Schema.TaggedError()("BoatAccountNotFoundError", { message: Schema.String }, { httpApiStatus: 404 }) {
@@ -63,6 +216,10 @@ export class BoatAccountNotFoundError extends Schema.TaggedError()("BoatAccountN
63
216
  * `boat-key-cannot-see`: a rotation to a key that cannot see VMs or saved images the account has
64
217
  * now (`unseen`), so it is most likely another Boat account's key. `boat-account-removing`: the
65
218
  * account's removal was asked. `boat-account-changed`: another rotation won; read and try again.
219
+ * `boat-account-environment`: the install's own key (`default`) is set in its environment, not
220
+ * through this API. `boat-proof-running`: a full check of the account is running, or Boat may
221
+ * still hold what one made (the message names the VM and the snapshot): a second check, a key
222
+ * rotation and a removal wait until Core has deleted it.
66
223
  */
67
224
  export class BoatAccountConflictError extends Schema.TaggedError()("BoatAccountConflictError", {
68
225
  message: Schema.String,
@@ -71,6 +228,8 @@ export class BoatAccountConflictError extends Schema.TaggedError()("BoatAccountC
71
228
  "boat-key-cannot-see",
72
229
  "boat-account-removing",
73
230
  "boat-account-changed",
231
+ "boat-account-environment",
232
+ "boat-proof-running",
74
233
  ]),
75
234
  liveRuns: Schema.optional(Schema.Int),
76
235
  buildsInFlight: Schema.optional(Schema.Int),
@@ -83,6 +242,8 @@ export class BoatAccountServiceUnavailableError extends Schema.TaggedError()("Bo
83
242
  export class BoatAccountInternalServerError extends Schema.TaggedError()("BoatAccountInternalServerError", { message: Schema.String }, { httpApiStatus: 500 }) {
84
243
  }
85
244
  const boatAccountIdParams = Schema.Struct({ boatAccountId: BoatAccountId });
245
+ /** Rotation and removal also take `default`, to refuse it by name (`boat-account-environment`). */
246
+ const boatAccountRefParams = Schema.Struct({ boatAccountId: BoatAccountRef });
86
247
  export const BoatAccountsGroup = HttpApiGroup.make("boatAccounts")
87
248
  .add(HttpApiEndpoint.post("createBoatAccount", "/", {
88
249
  payload: createBoatAccountRequestSchema,
@@ -99,7 +260,7 @@ export const BoatAccountsGroup = HttpApiGroup.make("boatAccounts")
99
260
  error: [BoatAccountServiceUnavailableError, BoatAccountInternalServerError],
100
261
  }))
101
262
  .add(HttpApiEndpoint.put("rotateBoatAccountKey", "/:boatAccountId/key", {
102
- params: boatAccountIdParams,
263
+ params: boatAccountRefParams,
103
264
  payload: rotateBoatAccountKeyRequestSchema,
104
265
  success: boatAccountSchema,
105
266
  error: [
@@ -112,10 +273,51 @@ export const BoatAccountsGroup = HttpApiGroup.make("boatAccounts")
112
273
  ],
113
274
  }))
114
275
  .add(
276
+ // The install's own key's last report (never the key).
277
+ HttpApiEndpoint.get("getBoatInstallKey", "/install-key", {
278
+ success: boatInstallKeySchema,
279
+ error: [BoatAccountServiceUnavailableError, BoatAccountInternalServerError],
280
+ }))
281
+ .add(
282
+ // Checks the install's own key with Boat now (read-only) and stores the report it answers.
283
+ HttpApiEndpoint.post("checkBoatInstallKey", "/install-key", {
284
+ success: boatInstallKeySchema,
285
+ error: [
286
+ BoatAccountKeyRefusedError,
287
+ BoatAccountServiceUnavailableError,
288
+ BoatAccountInternalServerError,
289
+ ],
290
+ }))
291
+ .add(
292
+ // Checks a stored account's key with Boat again (read-only) and stores the report it answers.
293
+ HttpApiEndpoint.post("checkBoatAccount", "/:boatAccountId/check", {
294
+ params: boatAccountIdParams,
295
+ success: boatAccountSchema,
296
+ error: [
297
+ BoatAccountKeyRefusedError,
298
+ BoatAccountNotFoundError,
299
+ BoatAccountServiceUnavailableError,
300
+ BoatAccountInternalServerError,
301
+ ],
302
+ }))
303
+ .add(
304
+ // A full check: a throwaway VM is started, used and deleted, with a snapshot saved and
305
+ // deleted; whatever it made is removed on every path. One per account at a time.
306
+ HttpApiEndpoint.post("proveBoatAccount", "/:boatAccountId/prove", {
307
+ params: Schema.Struct({ boatAccountId: BoatAccountId }),
308
+ success: boatKeyProofSchema,
309
+ error: [
310
+ BoatAccountNotFoundError,
311
+ BoatAccountConflictError,
312
+ BoatAccountServiceUnavailableError,
313
+ BoatAccountInternalServerError,
314
+ ],
315
+ }))
316
+ .add(
115
317
  // The removal's first step: the account takes no new workspace at once, and its saved images
116
318
  // are deleted from Boat by the worker before it is gone from the list.
117
319
  HttpApiEndpoint.delete("removeBoatAccount", "/:boatAccountId", {
118
- params: boatAccountIdParams,
320
+ params: boatAccountRefParams,
119
321
  success: boatAccountSchema,
120
322
  error: [
121
323
  BoatAccountNotFoundError,
@@ -124,4 +326,4 @@ HttpApiEndpoint.delete("removeBoatAccount", "/:boatAccountId", {
124
326
  BoatAccountInternalServerError,
125
327
  ],
126
328
  }))
127
- .annotate(OpenApi.Description, "The Boat API keys an install keeps beside its default one: one Boat account each, for the workspaces that name it.");
329
+ .annotate(OpenApi.Description, "The Boat keys an install keeps beside its default one: one Boat account each, for the workspaces that name it.");
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Why Boat refused, or did not answer, a request Core made for a workspace: a launch's VM create, an
3
+ * image build's VM or saved snapshot, a key check. One closed set of kinds, each with what a caller
4
+ * can do about it, plus what Boat itself said: its error code, its own message, its request id (for
5
+ * Boat's support), when to retry and its billing link.
6
+ *
7
+ * Nothing else of Boat's answer is kept, and no part of a Boat key is ever in it.
8
+ */
9
+ import { Schema } from "effect";
10
+ /**
11
+ * - `key-refused`: Boat does not accept the key (401: unknown, revoked or malformed).
12
+ * - `key-expired`: the key's lifetime ended (`api_key_expired`). Make a new key.
13
+ * - `permission-missing`: the key lacks a permission the call needs (`api_key_action_forbidden`);
14
+ * `permission` names it.
15
+ * - `sandbox-outside-key`: the key is limited to some VMs or environments, and this is not one of
16
+ * them (`api_key_sandbox_forbidden`).
17
+ * - `organization-mismatch`: the key belongs to another Boat organization than the one the request
18
+ * names, or an organization key was refused a call only personal keys may make
19
+ * (`api_key_org_mismatch`, `api_key_org_forbidden`).
20
+ * - `account-suspended`: the Boat account or organization is suspended (`org_suspended`).
21
+ * - `billing-required`: the wallet must be paid or topped up first (`billing_required`,
22
+ * `insufficient_balance`, `credit_required`); `billingUrl` is Boat's link when it sent one.
23
+ * - `running-limit`: the plan's limit of running VMs is reached (`limit_reached`).
24
+ * - `member-cap`: the organization's member cap is reached (`member_limit_reached`,
25
+ * `team_member_cap_reached`).
26
+ * - `rate-limited`: too many starts or requests in a window (`rate_limited`); `retryAfterSeconds`
27
+ * and `retryAt` say when.
28
+ * - `trial-restricted`: the account is on a trial and the call needs a paid plan
29
+ * (`trial_*`, `machine_class_plan_required`).
30
+ * - `no-machine`: Boat has no machine of the size right now (`no_ready_machine`, `out_of_capacity`).
31
+ * - `snapshot-allowance-full`: the wallet keeps all its included saved snapshots and cannot pay for
32
+ * another (`credit_required` on a save).
33
+ * - `no-answer`: Boat did not answer, or answered with a server error or a reply Core cannot read.
34
+ * - `refused`: Boat refused for another reason; `code` is Boat's own.
35
+ */
36
+ export declare const BOAT_FAILURE_KINDS: readonly ["key-refused", "key-expired", "permission-missing", "sandbox-outside-key", "organization-mismatch", "account-suspended", "billing-required", "running-limit", "member-cap", "rate-limited", "trial-restricted", "no-machine", "snapshot-allowance-full", "no-answer", "refused"];
37
+ export type BoatFailureKind = (typeof BOAT_FAILURE_KINDS)[number];
38
+ /** Kinds that can succeed on a later try with the same key and request. The others cannot. */
39
+ export declare const BOAT_RETRYABLE_FAILURE_KINDS: ReadonlySet<BoatFailureKind>;
40
+ export declare const boatFailureKindSchema: Schema.Literals<readonly ["key-refused", "key-expired", "permission-missing", "sandbox-outside-key", "organization-mismatch", "account-suspended", "billing-required", "running-limit", "member-cap", "rate-limited", "trial-restricted", "no-machine", "snapshot-allowance-full", "no-answer", "refused"]>;
41
+ export declare const boatFailureSchema: Schema.Struct<{
42
+ readonly kind: Schema.Literals<readonly ["key-refused", "key-expired", "permission-missing", "sandbox-outside-key", "organization-mismatch", "account-suspended", "billing-required", "running-limit", "member-cap", "rate-limited", "trial-restricted", "no-machine", "snapshot-allowance-full", "no-answer", "refused"]>;
43
+ /** Whether the same call may succeed later as it stands (see `BOAT_RETRYABLE_FAILURE_KINDS`). */
44
+ readonly retryable: Schema.Boolean;
45
+ /** Core's call that Boat refused (`create`, `saveSnapshot`, `verify`), when known. */
46
+ readonly operation: Schema.optional<Schema.String>;
47
+ /** Boat's error code (`api_key_expired`). Absent when Boat did not answer with one. */
48
+ readonly code: Schema.optional<Schema.String>;
49
+ /** Boat's own message, bounded and with anything shaped like a secret removed. */
50
+ readonly message: Schema.optional<Schema.String>;
51
+ /** Boat's request id (`req_…`), to give Boat's support. */
52
+ readonly requestId: Schema.optional<Schema.String>;
53
+ /** The HTTP status Boat answered with. Absent when it did not answer. */
54
+ readonly status: Schema.optional<Schema.Int>;
55
+ /** The Boat permission the call needs (`sandbox.create`), for `permission-missing`. */
56
+ readonly permission: Schema.optional<Schema.String>;
57
+ /** Seconds Boat asked to wait before trying again. */
58
+ readonly retryAfterSeconds: Schema.optional<Schema.Int>;
59
+ /** When Boat said the next start is allowed (ISO 8601). */
60
+ readonly retryAt: Schema.optional<Schema.String>;
61
+ /** Boat's billing link, for `billing-required`. */
62
+ readonly billingUrl: Schema.optional<Schema.String>;
63
+ }>;
64
+ export type BoatFailure = typeof boatFailureSchema.Type;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Why Boat refused, or did not answer, a request Core made for a workspace: a launch's VM create, an
3
+ * image build's VM or saved snapshot, a key check. One closed set of kinds, each with what a caller
4
+ * can do about it, plus what Boat itself said: its error code, its own message, its request id (for
5
+ * Boat's support), when to retry and its billing link.
6
+ *
7
+ * Nothing else of Boat's answer is kept, and no part of a Boat key is ever in it.
8
+ */
9
+ import { Schema } from "effect";
10
+ /**
11
+ * - `key-refused`: Boat does not accept the key (401: unknown, revoked or malformed).
12
+ * - `key-expired`: the key's lifetime ended (`api_key_expired`). Make a new key.
13
+ * - `permission-missing`: the key lacks a permission the call needs (`api_key_action_forbidden`);
14
+ * `permission` names it.
15
+ * - `sandbox-outside-key`: the key is limited to some VMs or environments, and this is not one of
16
+ * them (`api_key_sandbox_forbidden`).
17
+ * - `organization-mismatch`: the key belongs to another Boat organization than the one the request
18
+ * names, or an organization key was refused a call only personal keys may make
19
+ * (`api_key_org_mismatch`, `api_key_org_forbidden`).
20
+ * - `account-suspended`: the Boat account or organization is suspended (`org_suspended`).
21
+ * - `billing-required`: the wallet must be paid or topped up first (`billing_required`,
22
+ * `insufficient_balance`, `credit_required`); `billingUrl` is Boat's link when it sent one.
23
+ * - `running-limit`: the plan's limit of running VMs is reached (`limit_reached`).
24
+ * - `member-cap`: the organization's member cap is reached (`member_limit_reached`,
25
+ * `team_member_cap_reached`).
26
+ * - `rate-limited`: too many starts or requests in a window (`rate_limited`); `retryAfterSeconds`
27
+ * and `retryAt` say when.
28
+ * - `trial-restricted`: the account is on a trial and the call needs a paid plan
29
+ * (`trial_*`, `machine_class_plan_required`).
30
+ * - `no-machine`: Boat has no machine of the size right now (`no_ready_machine`, `out_of_capacity`).
31
+ * - `snapshot-allowance-full`: the wallet keeps all its included saved snapshots and cannot pay for
32
+ * another (`credit_required` on a save).
33
+ * - `no-answer`: Boat did not answer, or answered with a server error or a reply Core cannot read.
34
+ * - `refused`: Boat refused for another reason; `code` is Boat's own.
35
+ */
36
+ export const BOAT_FAILURE_KINDS = [
37
+ "key-refused",
38
+ "key-expired",
39
+ "permission-missing",
40
+ "sandbox-outside-key",
41
+ "organization-mismatch",
42
+ "account-suspended",
43
+ "billing-required",
44
+ "running-limit",
45
+ "member-cap",
46
+ "rate-limited",
47
+ "trial-restricted",
48
+ "no-machine",
49
+ "snapshot-allowance-full",
50
+ "no-answer",
51
+ "refused",
52
+ ];
53
+ /** Kinds that can succeed on a later try with the same key and request. The others cannot. */
54
+ export const BOAT_RETRYABLE_FAILURE_KINDS = new Set([
55
+ "rate-limited",
56
+ "no-machine",
57
+ "no-answer",
58
+ ]);
59
+ export const boatFailureKindSchema = Schema.Literals(BOAT_FAILURE_KINDS);
60
+ export const boatFailureSchema = Schema.Struct({
61
+ kind: boatFailureKindSchema,
62
+ /** Whether the same call may succeed later as it stands (see `BOAT_RETRYABLE_FAILURE_KINDS`). */
63
+ retryable: Schema.Boolean,
64
+ /** Core's call that Boat refused (`create`, `saveSnapshot`, `verify`), when known. */
65
+ operation: Schema.optional(Schema.String),
66
+ /** Boat's error code (`api_key_expired`). Absent when Boat did not answer with one. */
67
+ code: Schema.optional(Schema.String),
68
+ /** Boat's own message, bounded and with anything shaped like a secret removed. */
69
+ message: Schema.optional(Schema.String),
70
+ /** Boat's request id (`req_…`), to give Boat's support. */
71
+ requestId: Schema.optional(Schema.String),
72
+ /** The HTTP status Boat answered with. Absent when it did not answer. */
73
+ status: Schema.optional(Schema.Int),
74
+ /** The Boat permission the call needs (`sandbox.create`), for `permission-missing`. */
75
+ permission: Schema.optional(Schema.String),
76
+ /** Seconds Boat asked to wait before trying again. */
77
+ retryAfterSeconds: Schema.optional(Schema.Int),
78
+ /** When Boat said the next start is allowed (ISO 8601). */
79
+ retryAt: Schema.optional(Schema.String),
80
+ /** Boat's billing link, for `billing-required`. */
81
+ billingUrl: Schema.optional(Schema.String),
82
+ });