@sealant/api-contracts-next 0.40.0-next.864 → 0.40.0-next.868

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.
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Boat accounts wire contracts — the Boat API keys an install keeps beside its default one.
3
+ *
4
+ * An install's default Boat account is its env key (`SEALANT_BOAT_API_KEY`). A product that serves
5
+ * several organizations (Mend) stores one more account per organization, so each organization's
6
+ * Boat VMs run in, and are billed to, that organization's own Boat account. Core has no notion of
7
+ * organizations: it knows the account by id, and the caller keeps the mapping.
8
+ *
9
+ * A workspace names its account at create (`spec.runtime.boatAccountId`; SDK `boatAccountId`) and
10
+ * every run of it stays in that account. Install-scoped: a caller that reached this surface holds
11
+ * a service key. A key goes in and never comes out: no answer, error or log carries it.
12
+ */
13
+ import { Schema } from "effect";
14
+ import { HttpApiEndpoint, HttpApiGroup } from "effect/http-api";
15
+ export declare const boatAccountSchema: Schema.Struct<{
16
+ readonly boatAccountId: Schema.String;
17
+ readonly label: Schema.String;
18
+ /** `active`: workspaces may run in it. `removing`: its removal was asked; none may. */
19
+ readonly state: Schema.Literals<readonly ["active", "removing"]>;
20
+ readonly createdAt: Schema.String;
21
+ /** When its key was last replaced; null when it still has the key it was created with. */
22
+ readonly keyRotatedAt: Schema.NullOr<Schema.String>;
23
+ }>;
24
+ export type BoatAccountWire = typeof boatAccountSchema.Type;
25
+ export declare const createBoatAccountRequestSchema: Schema.Struct<{
26
+ /** The caller's name for the account (an organization's name, say). At most 200 characters. */
27
+ readonly label: Schema.String;
28
+ /** The Boat API key. Checked with Boat by one read-only call before it is stored. */
29
+ readonly apiKey: Schema.String;
30
+ }>;
31
+ export type CreateBoatAccountRequest = typeof createBoatAccountRequestSchema.Type;
32
+ export declare const rotateBoatAccountKeyRequestSchema: Schema.Struct<{
33
+ /** The new Boat API key, for the same Boat account: it must see every VM the account runs. */
34
+ readonly apiKey: Schema.String;
35
+ }>;
36
+ export type RotateBoatAccountKeyRequest = typeof rotateBoatAccountKeyRequestSchema.Type;
37
+ export declare const listBoatAccountsResponseSchema: Schema.Struct<{
38
+ readonly items: Schema.$Array<Schema.Struct<{
39
+ readonly boatAccountId: Schema.String;
40
+ readonly label: Schema.String;
41
+ /** `active`: workspaces may run in it. `removing`: its removal was asked; none may. */
42
+ readonly state: Schema.Literals<readonly ["active", "removing"]>;
43
+ readonly createdAt: Schema.String;
44
+ /** When its key was last replaced; null when it still has the key it was created with. */
45
+ readonly keyRotatedAt: Schema.NullOr<Schema.String>;
46
+ }>>;
47
+ }>;
48
+ export type ListBoatAccountsResponse = typeof listBoatAccountsResponseSchema.Type;
49
+ declare const BoatAccountBadRequestError_base: Schema.Class<BoatAccountBadRequestError, Schema.TaggedStruct<"BoatAccountBadRequestError", {
50
+ readonly message: Schema.String;
51
+ }>, import("effect/Cause").YieldableError>;
52
+ export declare class BoatAccountBadRequestError extends BoatAccountBadRequestError_base {
53
+ }
54
+ declare const BoatAccountKeyRefusedError_base: Schema.Class<BoatAccountKeyRefusedError, Schema.TaggedStruct<"BoatAccountKeyRefusedError", {
55
+ readonly message: Schema.String;
56
+ readonly code: Schema.Literals<readonly ["boat-key-refused", "boat-key-unverified"]>;
57
+ }>, import("effect/Cause").YieldableError>;
58
+ /**
59
+ * Boat refused the key (`boat-key-refused`: it answered that the key is not valid), or did not
60
+ * answer whether it is (`boat-key-unverified`: Boat was unreachable; try again). Nothing was
61
+ * stored or changed. The message never names the key or any part of it.
62
+ */
63
+ export declare class BoatAccountKeyRefusedError extends BoatAccountKeyRefusedError_base {
64
+ }
65
+ declare const BoatAccountNotFoundError_base: Schema.Class<BoatAccountNotFoundError, Schema.TaggedStruct<"BoatAccountNotFoundError", {
66
+ readonly message: Schema.String;
67
+ }>, import("effect/Cause").YieldableError>;
68
+ export declare class BoatAccountNotFoundError extends BoatAccountNotFoundError_base {
69
+ }
70
+ declare const BoatAccountConflictError_base: Schema.Class<BoatAccountConflictError, Schema.TaggedStruct<"BoatAccountConflictError", {
71
+ readonly message: Schema.String;
72
+ readonly code: Schema.Literals<readonly ["boat-account-in-use", "boat-key-cannot-see", "boat-account-removing", "boat-account-changed"]>;
73
+ readonly liveRuns: Schema.optional<Schema.Int>;
74
+ readonly buildsInFlight: Schema.optional<Schema.Int>;
75
+ readonly unseen: Schema.optional<Schema.Int>;
76
+ }>, import("effect/Cause").YieldableError>;
77
+ /**
78
+ * The account is in a state that refuses the call. `boat-account-in-use`: a removal while it still
79
+ * has runs whose VMs Boat may hold (`liveRuns`) or an image build in flight (`buildsInFlight`), or
80
+ * a rotation while a launch's create is unresolved (`liveRuns`: only the current key can find
81
+ * its VM).
82
+ * `boat-key-cannot-see`: a rotation to a key that cannot see VMs or saved images the account has
83
+ * now (`unseen`), so it is most likely another Boat account's key. `boat-account-removing`: the
84
+ * account's removal was asked. `boat-account-changed`: another rotation won; read and try again.
85
+ */
86
+ export declare class BoatAccountConflictError extends BoatAccountConflictError_base {
87
+ }
88
+ declare const BoatAccountServiceUnavailableError_base: Schema.Class<BoatAccountServiceUnavailableError, Schema.TaggedStruct<"BoatAccountServiceUnavailableError", {
89
+ readonly message: Schema.String;
90
+ }>, import("effect/Cause").YieldableError>;
91
+ /** The install serves no Boat (no env key), or keeps no credentials (`SEALANT_CREDENTIALS_KEY`). */
92
+ export declare class BoatAccountServiceUnavailableError extends BoatAccountServiceUnavailableError_base {
93
+ }
94
+ declare const BoatAccountInternalServerError_base: Schema.Class<BoatAccountInternalServerError, Schema.TaggedStruct<"BoatAccountInternalServerError", {
95
+ readonly message: Schema.String;
96
+ }>, import("effect/Cause").YieldableError>;
97
+ export declare class BoatAccountInternalServerError extends BoatAccountInternalServerError_base {
98
+ }
99
+ export declare const BoatAccountsGroup: HttpApiGroup.HttpApiGroup<"boatAccounts", HttpApiEndpoint.HttpApiEndpoint<"createBoatAccount", "POST", "/", never, never, Schema.toCodecJson<Schema.Struct<{
100
+ /** The caller's name for the account (an organization's name, say). At most 200 characters. */
101
+ readonly label: Schema.String;
102
+ /** The Boat API key. Checked with Boat by one read-only call before it is stored. */
103
+ readonly apiKey: Schema.String;
104
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
105
+ readonly boatAccountId: Schema.String;
106
+ readonly label: Schema.String;
107
+ /** `active`: workspaces may run in it. `removing`: its removal was asked; none may. */
108
+ readonly state: Schema.Literals<readonly ["active", "removing"]>;
109
+ readonly createdAt: Schema.String;
110
+ /** When its key was last replaced; null when it still has the key it was created with. */
111
+ readonly keyRotatedAt: Schema.NullOr<Schema.String>;
112
+ }>>, Schema.toCodecJson<typeof BoatAccountBadRequestError | typeof BoatAccountKeyRefusedError | typeof BoatAccountServiceUnavailableError | typeof BoatAccountInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"listBoatAccounts", "GET", "/", never, never, never, never, Schema.toCodecJson<Schema.Struct<{
113
+ readonly items: Schema.$Array<Schema.Struct<{
114
+ readonly boatAccountId: Schema.String;
115
+ readonly label: Schema.String;
116
+ /** `active`: workspaces may run in it. `removing`: its removal was asked; none may. */
117
+ readonly state: Schema.Literals<readonly ["active", "removing"]>;
118
+ readonly createdAt: Schema.String;
119
+ /** When its key was last replaced; null when it still has the key it was created with. */
120
+ readonly keyRotatedAt: Schema.NullOr<Schema.String>;
121
+ }>>;
122
+ }>>, Schema.toCodecJson<typeof BoatAccountServiceUnavailableError | typeof BoatAccountInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"removeBoatAccount", "DELETE", "/:boatAccountId", Schema.toCodecStringTree<Schema.Struct<{
123
+ readonly boatAccountId: Schema.String;
124
+ }>>, never, never, never, Schema.toCodecJson<Schema.Struct<{
125
+ readonly boatAccountId: Schema.String;
126
+ readonly label: Schema.String;
127
+ /** `active`: workspaces may run in it. `removing`: its removal was asked; none may. */
128
+ readonly state: Schema.Literals<readonly ["active", "removing"]>;
129
+ readonly createdAt: Schema.String;
130
+ /** When its key was last replaced; null when it still has the key it was created with. */
131
+ readonly keyRotatedAt: Schema.NullOr<Schema.String>;
132
+ }>>, Schema.toCodecJson<typeof BoatAccountNotFoundError | typeof BoatAccountConflictError | typeof BoatAccountServiceUnavailableError | typeof BoatAccountInternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"rotateBoatAccountKey", "PUT", "/:boatAccountId/key", Schema.toCodecStringTree<Schema.Struct<{
133
+ readonly boatAccountId: Schema.String;
134
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
135
+ /** The new Boat API key, for the same Boat account: it must see every VM the account runs. */
136
+ readonly apiKey: Schema.String;
137
+ }>>, never, Schema.toCodecJson<Schema.Struct<{
138
+ readonly boatAccountId: Schema.String;
139
+ readonly label: Schema.String;
140
+ /** `active`: workspaces may run in it. `removing`: its removal was asked; none may. */
141
+ readonly state: Schema.Literals<readonly ["active", "removing"]>;
142
+ readonly createdAt: Schema.String;
143
+ /** When its key was last replaced; null when it still has the key it was created with. */
144
+ readonly keyRotatedAt: Schema.NullOr<Schema.String>;
145
+ }>>, Schema.toCodecJson<typeof BoatAccountBadRequestError | typeof BoatAccountKeyRefusedError | typeof BoatAccountNotFoundError | typeof BoatAccountConflictError | typeof BoatAccountServiceUnavailableError | typeof BoatAccountInternalServerError>, never, never>, false>;
146
+ export {};
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Boat accounts wire contracts — the Boat API keys an install keeps beside its default one.
3
+ *
4
+ * An install's default Boat account is its env key (`SEALANT_BOAT_API_KEY`). A product that serves
5
+ * several organizations (Mend) stores one more account per organization, so each organization's
6
+ * Boat VMs run in, and are billed to, that organization's own Boat account. Core has no notion of
7
+ * organizations: it knows the account by id, and the caller keeps the mapping.
8
+ *
9
+ * A workspace names its account at create (`spec.runtime.boatAccountId`; SDK `boatAccountId`) and
10
+ * every run of it stays in that account. Install-scoped: a caller that reached this surface holds
11
+ * a service key. A key goes in and never comes out: no answer, error or log carries it.
12
+ */
13
+ import { Schema } from "effect";
14
+ import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api";
15
+ const NonEmptyString = Schema.String.check(Schema.isNonEmpty(), Schema.isTrimmed());
16
+ /**
17
+ * A key is checked only for being there: a check that failed on its value would print it in the
18
+ * client's encoding error. The control plane refuses a malformed key without naming it.
19
+ */
20
+ const SecretString = Schema.String.check(Schema.isNonEmpty());
21
+ 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}$/));
22
+ export const boatAccountSchema = Schema.Struct({
23
+ boatAccountId: BoatAccountId,
24
+ label: NonEmptyString,
25
+ /** `active`: workspaces may run in it. `removing`: its removal was asked; none may. */
26
+ state: Schema.Literals(["active", "removing"]),
27
+ createdAt: Schema.String,
28
+ /** When its key was last replaced; null when it still has the key it was created with. */
29
+ keyRotatedAt: Schema.NullOr(Schema.String),
30
+ });
31
+ export const createBoatAccountRequestSchema = Schema.Struct({
32
+ /** The caller's name for the account (an organization's name, say). At most 200 characters. */
33
+ label: NonEmptyString,
34
+ /** The Boat API key. Checked with Boat by one read-only call before it is stored. */
35
+ apiKey: SecretString,
36
+ });
37
+ export const rotateBoatAccountKeyRequestSchema = Schema.Struct({
38
+ /** The new Boat API key, for the same Boat account: it must see every VM the account runs. */
39
+ apiKey: SecretString,
40
+ });
41
+ export const listBoatAccountsResponseSchema = Schema.Struct({
42
+ items: Schema.Array(boatAccountSchema),
43
+ });
44
+ export class BoatAccountBadRequestError extends Schema.TaggedError()("BoatAccountBadRequestError", { message: Schema.String }, { httpApiStatus: 400 }) {
45
+ }
46
+ /**
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.
50
+ */
51
+ export class BoatAccountKeyRefusedError extends Schema.TaggedError()("BoatAccountKeyRefusedError", {
52
+ message: Schema.String,
53
+ code: Schema.Literals(["boat-key-refused", "boat-key-unverified"]),
54
+ }, { httpApiStatus: 422 }) {
55
+ }
56
+ export class BoatAccountNotFoundError extends Schema.TaggedError()("BoatAccountNotFoundError", { message: Schema.String }, { httpApiStatus: 404 }) {
57
+ }
58
+ /**
59
+ * The account is in a state that refuses the call. `boat-account-in-use`: a removal while it still
60
+ * has runs whose VMs Boat may hold (`liveRuns`) or an image build in flight (`buildsInFlight`), or
61
+ * a rotation while a launch's create is unresolved (`liveRuns`: only the current key can find
62
+ * its VM).
63
+ * `boat-key-cannot-see`: a rotation to a key that cannot see VMs or saved images the account has
64
+ * now (`unseen`), so it is most likely another Boat account's key. `boat-account-removing`: the
65
+ * account's removal was asked. `boat-account-changed`: another rotation won; read and try again.
66
+ */
67
+ export class BoatAccountConflictError extends Schema.TaggedError()("BoatAccountConflictError", {
68
+ message: Schema.String,
69
+ code: Schema.Literals([
70
+ "boat-account-in-use",
71
+ "boat-key-cannot-see",
72
+ "boat-account-removing",
73
+ "boat-account-changed",
74
+ ]),
75
+ liveRuns: Schema.optional(Schema.Int),
76
+ buildsInFlight: Schema.optional(Schema.Int),
77
+ unseen: Schema.optional(Schema.Int),
78
+ }, { httpApiStatus: 409 }) {
79
+ }
80
+ /** The install serves no Boat (no env key), or keeps no credentials (`SEALANT_CREDENTIALS_KEY`). */
81
+ export class BoatAccountServiceUnavailableError extends Schema.TaggedError()("BoatAccountServiceUnavailableError", { message: Schema.String }, { httpApiStatus: 503 }) {
82
+ }
83
+ export class BoatAccountInternalServerError extends Schema.TaggedError()("BoatAccountInternalServerError", { message: Schema.String }, { httpApiStatus: 500 }) {
84
+ }
85
+ const boatAccountIdParams = Schema.Struct({ boatAccountId: BoatAccountId });
86
+ export const BoatAccountsGroup = HttpApiGroup.make("boatAccounts")
87
+ .add(HttpApiEndpoint.post("createBoatAccount", "/", {
88
+ payload: createBoatAccountRequestSchema,
89
+ success: boatAccountSchema.pipe(HttpApiSchema.status(201)),
90
+ error: [
91
+ BoatAccountBadRequestError,
92
+ BoatAccountKeyRefusedError,
93
+ BoatAccountServiceUnavailableError,
94
+ BoatAccountInternalServerError,
95
+ ],
96
+ }))
97
+ .add(HttpApiEndpoint.get("listBoatAccounts", "/", {
98
+ success: listBoatAccountsResponseSchema,
99
+ error: [BoatAccountServiceUnavailableError, BoatAccountInternalServerError],
100
+ }))
101
+ .add(HttpApiEndpoint.put("rotateBoatAccountKey", "/:boatAccountId/key", {
102
+ params: boatAccountIdParams,
103
+ payload: rotateBoatAccountKeyRequestSchema,
104
+ success: boatAccountSchema,
105
+ error: [
106
+ BoatAccountBadRequestError,
107
+ BoatAccountKeyRefusedError,
108
+ BoatAccountNotFoundError,
109
+ BoatAccountConflictError,
110
+ BoatAccountServiceUnavailableError,
111
+ BoatAccountInternalServerError,
112
+ ],
113
+ }))
114
+ .add(
115
+ // The removal's first step: the account takes no new workspace at once, and its saved images
116
+ // are deleted from Boat by the worker before it is gone from the list.
117
+ HttpApiEndpoint.delete("removeBoatAccount", "/:boatAccountId", {
118
+ params: boatAccountIdParams,
119
+ success: boatAccountSchema,
120
+ error: [
121
+ BoatAccountNotFoundError,
122
+ BoatAccountConflictError,
123
+ BoatAccountServiceUnavailableError,
124
+ BoatAccountInternalServerError,
125
+ ],
126
+ }))
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.");