@sealant/api-contracts-next 0.40.0-next.892 → 0.40.0-next.894
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/dist/core-api/control-plane.d.ts +1741 -1741
- package/dist/core-api/endpoint-url.js +15 -8
- package/dist/core-api/person-id.js +2 -1
- package/dist/core-api/refusal-words.d.ts +15 -0
- package/dist/core-api/refusal-words.js +11 -0
- package/dist/core-api/registries.js +3 -2
- package/dist/core-api/request-refusal.d.ts +10 -3
- package/dist/core-api/request-refusal.js +56 -30
- package/dist/core-api/resource-domains.js +5 -4
- package/dist/core-api/resource-instances.js +14 -7
- package/dist/core-api/sessions.js +4 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +2 -2
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* gateway: Anthropic-compatible for a Claude login, OpenAI-compatible for a Codex login.
|
|
4
4
|
*/
|
|
5
5
|
import { Schema, SchemaGetter } from "effect";
|
|
6
|
+
import { refusalWords } from "./refusal-words.js";
|
|
6
7
|
const parsed = (value) => {
|
|
7
8
|
try {
|
|
8
9
|
return new URL(value);
|
|
@@ -11,21 +12,27 @@ const parsed = (value) => {
|
|
|
11
12
|
return undefined;
|
|
12
13
|
}
|
|
13
14
|
};
|
|
15
|
+
const PROBLEM = {
|
|
16
|
+
notHttp: "must be an absolute http: or https: URL",
|
|
17
|
+
noHost: "must name a host",
|
|
18
|
+
credentials: "must not carry a user name or password; the key is sent on its own",
|
|
19
|
+
query: "must not have a query string",
|
|
20
|
+
fragment: "must not have a fragment",
|
|
21
|
+
};
|
|
14
22
|
/** Why `value` is not an endpoint URL, or `undefined` when it is one. */
|
|
15
23
|
const endpointUrlProblem = (value) => {
|
|
16
24
|
const url = parsed(value);
|
|
17
25
|
if (url === undefined || (url.protocol !== "http:" && url.protocol !== "https:")) {
|
|
18
|
-
return
|
|
26
|
+
return PROBLEM.notHttp;
|
|
19
27
|
}
|
|
20
28
|
if (url.hostname === "")
|
|
21
|
-
return
|
|
22
|
-
if (url.username !== "" || url.password !== "")
|
|
23
|
-
return
|
|
24
|
-
}
|
|
29
|
+
return PROBLEM.noHost;
|
|
30
|
+
if (url.username !== "" || url.password !== "")
|
|
31
|
+
return PROBLEM.credentials;
|
|
25
32
|
if (url.search !== "" || value.includes("?"))
|
|
26
|
-
return
|
|
33
|
+
return PROBLEM.query;
|
|
27
34
|
if (url.hash !== "" || value.includes("#"))
|
|
28
|
-
return
|
|
35
|
+
return PROBLEM.fragment;
|
|
29
36
|
return undefined;
|
|
30
37
|
};
|
|
31
38
|
/** Scheme, host (with a port that is not the scheme's default) and path, without a trailing slash. */
|
|
@@ -38,7 +45,7 @@ const canonicalEndpointUrl = (value) => {
|
|
|
38
45
|
* fragment. Decoding normalizes it: the host as the URL standard writes it, and the path without a
|
|
39
46
|
* trailing slash. `http:` is allowed, since an endpoint on a private network often has no TLS.
|
|
40
47
|
*/
|
|
41
|
-
export const EndpointUrl = Schema.String.check(Schema.makeFilter(endpointUrlProblem)).pipe(Schema.decode({
|
|
48
|
+
export const EndpointUrl = Schema.String.check(Schema.makeFilter(endpointUrlProblem, refusalWords(...Object.values(PROBLEM)))).pipe(Schema.decode({
|
|
42
49
|
decode: SchemaGetter.transform(canonicalEndpointUrl),
|
|
43
50
|
encode: SchemaGetter.passthrough(),
|
|
44
51
|
}), Schema.brand("EndpointUrl"));
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
* endpoint of the control plane API and fails on a person field that is not one.
|
|
11
11
|
*/
|
|
12
12
|
import { Schema } from "effect";
|
|
13
|
+
import { refusalWords } from "./refusal-words.js";
|
|
13
14
|
export const RESOURCE_DOMAIN_ID_PREFIX = "rdm:";
|
|
14
15
|
export const isResourceDomainId = (id) => id.startsWith(RESOURCE_DOMAIN_ID_PREFIX);
|
|
15
16
|
/** Why an id cannot name a person, after the field's name. Never quotes the id. */
|
|
16
17
|
export const NOT_A_PERSON = "names a resource domain, which never holds a login or a provider credential and never runs a harness";
|
|
17
|
-
export const PersonId = Schema.String.check(Schema.isNonEmpty(), Schema.isTrimmed(), Schema.makeFilter((id) => (isResourceDomainId(id) ? NOT_A_PERSON : undefined)));
|
|
18
|
+
export const PersonId = Schema.String.check(Schema.isNonEmpty(), Schema.isTrimmed(), Schema.makeFilter((id) => (isResourceDomainId(id) ? NOT_A_PERSON : undefined), refusalWords(NOT_A_PERSON)));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words a check may return while a request is decoded, declared when the contract is built, so
|
|
3
|
+
* that a refusal (`request-refusal.ts`) can repeat them. A refusal repeats a check's returned text
|
|
4
|
+
* only when it is one of these strings exactly or matches one of these patterns whole; any other
|
|
5
|
+
* text the check returns reads "is invalid". Declare only words built from constants, positions and
|
|
6
|
+
* sizes, never from the value checked.
|
|
7
|
+
*/
|
|
8
|
+
/** The filter annotation that holds a check's declared words. */
|
|
9
|
+
export declare const REFUSAL_WORDS = "@sealant/api-contracts/refusalWords";
|
|
10
|
+
/** One declared word: a constant, or a pattern the whole text must match. */
|
|
11
|
+
export type RefusalWord = string | RegExp;
|
|
12
|
+
/** Filter annotations declaring `words`, for `Schema.makeFilter(check, refusalWords(...))`. */
|
|
13
|
+
export declare const refusalWords: (...words: ReadonlyArray<RefusalWord>) => {
|
|
14
|
+
readonly [REFUSAL_WORDS]: ReadonlyArray<RefusalWord>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words a check may return while a request is decoded, declared when the contract is built, so
|
|
3
|
+
* that a refusal (`request-refusal.ts`) can repeat them. A refusal repeats a check's returned text
|
|
4
|
+
* only when it is one of these strings exactly or matches one of these patterns whole; any other
|
|
5
|
+
* text the check returns reads "is invalid". Declare only words built from constants, positions and
|
|
6
|
+
* sizes, never from the value checked.
|
|
7
|
+
*/
|
|
8
|
+
/** The filter annotation that holds a check's declared words. */
|
|
9
|
+
export const REFUSAL_WORDS = "@sealant/api-contracts/refusalWords";
|
|
10
|
+
/** Filter annotations declaring `words`, for `Schema.makeFilter(check, refusalWords(...))`. */
|
|
11
|
+
export const refusalWords = (...words) => ({ [REFUSAL_WORDS]: words });
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api";
|
|
3
3
|
import { isOciReference, isOciRepository, OCI_REFERENCE_MESSAGE, OCI_REPOSITORY_MESSAGE, } from "./oci-names.js";
|
|
4
|
+
import { refusalWords } from "./refusal-words.js";
|
|
4
5
|
const NonEmptyString = Schema.String.check(Schema.isNonEmpty(), Schema.isTrimmed());
|
|
5
6
|
/** Refused, never repaired: these become registry URL path segments (CORE-08). */
|
|
6
|
-
const OciRepository = NonEmptyString.check(Schema.makeFilter((value) => isOciRepository(value) ? undefined : `repository ${OCI_REPOSITORY_MESSAGE}`));
|
|
7
|
-
const OciReference = NonEmptyString.check(Schema.makeFilter((value) => isOciReference(value) ? undefined : `reference ${OCI_REFERENCE_MESSAGE}`));
|
|
7
|
+
const OciRepository = NonEmptyString.check(Schema.makeFilter((value) => isOciRepository(value) ? undefined : `repository ${OCI_REPOSITORY_MESSAGE}`, refusalWords(`repository ${OCI_REPOSITORY_MESSAGE}`)));
|
|
8
|
+
const OciReference = NonEmptyString.check(Schema.makeFilter((value) => (isOciReference(value) ? undefined : `reference ${OCI_REFERENCE_MESSAGE}`), refusalWords(`reference ${OCI_REFERENCE_MESSAGE}`)));
|
|
8
9
|
export const registryIdParamsSchema = Schema.Struct({
|
|
9
10
|
registryId: NonEmptyString,
|
|
10
11
|
});
|
|
@@ -7,9 +7,16 @@
|
|
|
7
7
|
* excerpt of a malformed body; Effect 4 reports input only to a parse that asks for it. A request
|
|
8
8
|
* body can carry a process's arguments, a script or a credential, so `RequestRefusal`, applied to
|
|
9
9
|
* the whole API, answers `400` `RequestRefusedError` instead, with a reason that names where the
|
|
10
|
-
* request is wrong and never what it held, and Effect's failure goes no further.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* request is wrong and never what it held, and Effect's failure goes no further.
|
|
11
|
+
*
|
|
12
|
+
* `describeRequestIssue` words that reason from the decode issue alone, and says only words that
|
|
13
|
+
* existed before the request did: field names the contract declares, array positions, what the
|
|
14
|
+
* schema expected (`expected` and `message` annotations, set when the contract is built), and its
|
|
15
|
+
* own wording. A key the caller chose (an `env` or `metadata` name) reads `[…]`. Text a check
|
|
16
|
+
* returns while decoding is said only when the check declared it up front (`refusal-words.ts`):
|
|
17
|
+
* that text is computed from the value, so whether it quotes the value cannot be told from the text
|
|
18
|
+
* itself. Anything else reads "is invalid". The rule does not depend on where Effect keeps the
|
|
19
|
+
* rejected value, which it does not report at all to a parse that does not ask (SLNT-960).
|
|
13
20
|
*/
|
|
14
21
|
import { Schema, SchemaIssue } from "effect";
|
|
15
22
|
import { HttpApiMiddleware } from "effect/http-api";
|
|
@@ -7,12 +7,20 @@
|
|
|
7
7
|
* excerpt of a malformed body; Effect 4 reports input only to a parse that asks for it. A request
|
|
8
8
|
* body can carry a process's arguments, a script or a credential, so `RequestRefusal`, applied to
|
|
9
9
|
* the whole API, answers `400` `RequestRefusedError` instead, with a reason that names where the
|
|
10
|
-
* request is wrong and never what it held, and Effect's failure goes no further.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* request is wrong and never what it held, and Effect's failure goes no further.
|
|
11
|
+
*
|
|
12
|
+
* `describeRequestIssue` words that reason from the decode issue alone, and says only words that
|
|
13
|
+
* existed before the request did: field names the contract declares, array positions, what the
|
|
14
|
+
* schema expected (`expected` and `message` annotations, set when the contract is built), and its
|
|
15
|
+
* own wording. A key the caller chose (an `env` or `metadata` name) reads `[…]`. Text a check
|
|
16
|
+
* returns while decoding is said only when the check declared it up front (`refusal-words.ts`):
|
|
17
|
+
* that text is computed from the value, so whether it quotes the value cannot be told from the text
|
|
18
|
+
* itself. Anything else reads "is invalid". The rule does not depend on where Effect keeps the
|
|
19
|
+
* rejected value, which it does not report at all to a parse that does not ask (SLNT-960).
|
|
13
20
|
*/
|
|
14
21
|
import { Schema, SchemaAST, SchemaIssue } from "effect";
|
|
15
22
|
import { HttpApiMiddleware } from "effect/http-api";
|
|
23
|
+
import { REFUSAL_WORDS } from "./refusal-words.js";
|
|
16
24
|
export class RequestRefusedError extends Schema.TaggedError()("RequestRefusedError", {
|
|
17
25
|
/** Where the request is wrong and what was expected; never a value it held. */
|
|
18
26
|
message: Schema.String,
|
|
@@ -55,57 +63,75 @@ const stringAnnotation = (annotations, key) => {
|
|
|
55
63
|
const value = Reflect.get(annotations, key);
|
|
56
64
|
return typeof value === "string" ? value : undefined;
|
|
57
65
|
};
|
|
66
|
+
/** A check's declared words (`refusal-words.ts`), or none. */
|
|
67
|
+
const declaredWords = (annotations) => {
|
|
68
|
+
if (typeof annotations !== "object" || annotations === null)
|
|
69
|
+
return [];
|
|
70
|
+
const words = Reflect.get(annotations, REFUSAL_WORDS);
|
|
71
|
+
return Array.isArray(words)
|
|
72
|
+
? words.filter((word) => typeof word === "string" || word instanceof RegExp)
|
|
73
|
+
: [];
|
|
74
|
+
};
|
|
75
|
+
const matchesWhole = (pattern, text) => {
|
|
76
|
+
const match = new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, "")).exec(text);
|
|
77
|
+
return match !== null && match.index === 0 && match[0].length === text.length;
|
|
78
|
+
};
|
|
79
|
+
/** Text a check returned while decoding, when it is one of the words the check declared. */
|
|
80
|
+
const declared = (text, words) => text !== undefined &&
|
|
81
|
+
words.some((word) => (typeof word === "string" ? word === text : matchesWhole(word, text)))
|
|
82
|
+
? text
|
|
83
|
+
: undefined;
|
|
58
84
|
/**
|
|
59
|
-
* A
|
|
60
|
-
*
|
|
85
|
+
* A path segment: a field its object declares by name, a position in an array by index, anything
|
|
86
|
+
* else (a key the caller chose, a path a check built) as `[…]`.
|
|
61
87
|
*/
|
|
62
|
-
const authoredMessage = (message, actual) => {
|
|
63
|
-
if (message === undefined)
|
|
64
|
-
return undefined;
|
|
65
|
-
if (typeof actual === "string" && actual.length >= 3 && message.includes(actual)) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
return message;
|
|
69
|
-
};
|
|
70
|
-
/** A path segment: a declared field by name, a position by index, anything else as `[…]`. */
|
|
71
88
|
const segment = (key, parent) => {
|
|
72
|
-
if (typeof key === "number")
|
|
73
|
-
return `[${key}]
|
|
74
|
-
|
|
89
|
+
if (typeof key === "number") {
|
|
90
|
+
return parent !== undefined && SchemaAST.isArrays(parent) ? `[${key}]` : "[…]";
|
|
91
|
+
}
|
|
92
|
+
const named = typeof key === "string" &&
|
|
93
|
+
parent !== undefined &&
|
|
75
94
|
SchemaAST.isObjects(parent) &&
|
|
76
95
|
parent.propertySignatures.some((signature) => signature.name === key);
|
|
77
|
-
return
|
|
96
|
+
return named ? `.${key}` : "[…]";
|
|
78
97
|
};
|
|
79
98
|
const leaf = (path, message) => [{ path, message }];
|
|
80
|
-
|
|
99
|
+
/**
|
|
100
|
+
* `words` are those the nearest check declared: text inside its issue is said only when it is one
|
|
101
|
+
* of them. A transformation declares none.
|
|
102
|
+
*/
|
|
103
|
+
const reasonsOf = (issue, path, parent, words) => {
|
|
81
104
|
if (issue instanceof SchemaIssue.Composite) {
|
|
82
|
-
return issue.issues.flatMap((inner) => reasonsOf(inner, path, issue.ast));
|
|
105
|
+
return issue.issues.flatMap((inner) => reasonsOf(inner, path, issue.ast, words));
|
|
83
106
|
}
|
|
84
107
|
if (issue instanceof SchemaIssue.Pointer) {
|
|
85
108
|
const at = issue.path.reduce((acc, key) => acc + segment(key, parent), path);
|
|
86
|
-
return reasonsOf(issue.issue, at, undefined);
|
|
109
|
+
return reasonsOf(issue.issue, at, undefined, words);
|
|
87
110
|
}
|
|
88
111
|
if (issue instanceof SchemaIssue.Encoding) {
|
|
89
|
-
return reasonsOf(issue.issue, path, parent);
|
|
112
|
+
return reasonsOf(issue.issue, path, parent, []);
|
|
90
113
|
}
|
|
91
114
|
if (issue instanceof SchemaIssue.AnyOf) {
|
|
92
115
|
return issue.issues.length === 0
|
|
93
116
|
? leaf(path, `must be ${expectedOf(issue.ast) ?? "one of the allowed values"}`)
|
|
94
|
-
: issue.issues.flatMap((inner) => reasonsOf(inner, path, parent));
|
|
117
|
+
: issue.issues.flatMap((inner) => reasonsOf(inner, path, parent, words));
|
|
95
118
|
}
|
|
96
119
|
if (issue instanceof SchemaIssue.Filter) {
|
|
97
|
-
const
|
|
98
|
-
|
|
120
|
+
const { annotations } = issue.filter;
|
|
121
|
+
const own = declaredWords(annotations);
|
|
122
|
+
const returned = issue.issue instanceof SchemaIssue.InvalidValue
|
|
123
|
+
? declared(stringAnnotation(issue.issue.annotations, "message"), own)
|
|
99
124
|
: undefined;
|
|
100
|
-
const message =
|
|
125
|
+
const message = returned ?? stringAnnotation(annotations, "message");
|
|
101
126
|
if (message !== undefined)
|
|
102
127
|
return leaf(path, message);
|
|
103
|
-
const expected = stringAnnotation(
|
|
128
|
+
const expected = stringAnnotation(annotations, "expected");
|
|
104
129
|
if (expected !== undefined)
|
|
105
130
|
return leaf(path, `must be ${expected}`);
|
|
131
|
+
// The check's own path is the check's to choose: its keys read `[…]`.
|
|
106
132
|
return issue.issue instanceof SchemaIssue.InvalidValue
|
|
107
133
|
? leaf(path, "is invalid")
|
|
108
|
-
: reasonsOf(issue.issue, path,
|
|
134
|
+
: reasonsOf(issue.issue, path, undefined, own);
|
|
109
135
|
}
|
|
110
136
|
if (issue instanceof SchemaIssue.InvalidType) {
|
|
111
137
|
return leaf(path, `must be ${expectedOf(issue.ast) ?? "present"}`);
|
|
@@ -113,7 +139,7 @@ const reasonsOf = (issue, path, parent) => {
|
|
|
113
139
|
if (issue instanceof SchemaIssue.MissingKey)
|
|
114
140
|
return leaf(path, "is required");
|
|
115
141
|
if (issue instanceof SchemaIssue.InvalidValue) {
|
|
116
|
-
return leaf(path,
|
|
142
|
+
return leaf(path, declared(stringAnnotation(issue.annotations, "message"), words) ?? "is invalid");
|
|
117
143
|
}
|
|
118
144
|
if (issue instanceof SchemaIssue.OneOf)
|
|
119
145
|
return leaf(path, "matches more than one allowed shape");
|
|
@@ -124,7 +150,7 @@ const reasonsOf = (issue, path, parent) => {
|
|
|
124
150
|
* decode issue: up to three places, each with what was expected. Never a value the request held.
|
|
125
151
|
*/
|
|
126
152
|
export const describeRequestIssue = (part, issue) => {
|
|
127
|
-
const reasons = reasonsOf(issue, "", undefined);
|
|
153
|
+
const reasons = reasonsOf(issue, "", undefined, []);
|
|
128
154
|
const shown = reasons.slice(0, MAX_REASONS).map(({ path, message }) => {
|
|
129
155
|
const where = path === "" ? `the request ${part}` : path.replace(/^\./, "");
|
|
130
156
|
// A check that names its own position (`argv[1] contains a NUL byte`) needs no prefix.
|
|
@@ -41,12 +41,13 @@ import { Schema } from "effect";
|
|
|
41
41
|
import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api";
|
|
42
42
|
import * as Rec from "effect/Record";
|
|
43
43
|
import { PersonId, RESOURCE_DOMAIN_ID_PREFIX } from "./person-id.js";
|
|
44
|
+
import { refusalWords } from "./refusal-words.js";
|
|
44
45
|
const RESOURCE_DOMAIN_ID_PATTERN = new RegExp(`^${RESOURCE_DOMAIN_ID_PREFIX}[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`);
|
|
45
46
|
const RESOURCE_DOMAIN_KEY_PATTERN = /^[a-z][a-z0-9-]{0,31}:[A-Za-z0-9._:/@+=-]{1,223}$/;
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
const NOT_A_DOMAIN_ID = "must be a resource domain id (rdm:<uuid>)";
|
|
48
|
+
const NOT_A_DOMAIN_KEY = "must be <application>:<name>: a lower-case application name (letters, digits, '-'), a colon, then at most 223 letters, digits, '.', '_', ':', '/', '@', '+', '=' or '-'";
|
|
49
|
+
export const ResourceDomainId = Schema.String.check(Schema.makeFilter((id) => (RESOURCE_DOMAIN_ID_PATTERN.test(id) ? undefined : NOT_A_DOMAIN_ID), refusalWords(NOT_A_DOMAIN_ID)));
|
|
50
|
+
const ResourceDomainKey = Schema.String.check(Schema.makeFilter((key) => (RESOURCE_DOMAIN_KEY_PATTERN.test(key) ? undefined : NOT_A_DOMAIN_KEY), refusalWords(NOT_A_DOMAIN_KEY)));
|
|
50
51
|
const Amount = Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }));
|
|
51
52
|
const BudgetRevision = Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }));
|
|
52
53
|
/**
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { Result, Schema } from "effect";
|
|
14
14
|
import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api";
|
|
15
|
+
import { refusalWords } from "./refusal-words.js";
|
|
15
16
|
import { describeRequestIssue } from "./request-refusal.js";
|
|
16
17
|
import { ResourceDomainForbiddenError, ResourceDomainId, ResourceDomainInternalServerError, ResourceDomainNotFoundError, } from "./resource-domains.js";
|
|
17
18
|
export const RESOURCE_INSTANCE_ID_PREFIX = "rin:";
|
|
18
19
|
const RESOURCE_INSTANCE_ID_PATTERN = new RegExp(`^${RESOURCE_INSTANCE_ID_PREFIX}[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`);
|
|
19
|
-
const matching = (pattern, message) => Schema.makeFilter((value) => (pattern.test(value) ? undefined : message));
|
|
20
|
+
const matching = (pattern, message) => Schema.makeFilter((value) => (pattern.test(value) ? undefined : message), refusalWords(message));
|
|
20
21
|
export const ResourceInstanceId = Schema.String.check(matching(RESOURCE_INSTANCE_ID_PATTERN, "must be a resource instance id (rin:<uuid>)")).pipe(Schema.brand("ResourceInstanceId"));
|
|
21
22
|
export const ResourceInstanceKey = Schema.String.check(matching(/^[a-z0-9][a-z0-9._@-]{0,127}$/, "must be 1 to 128 lower-case letters, digits, '.', '_', '@' or '-', starting with a letter or digit")).pipe(Schema.brand("ResourceInstanceKey"));
|
|
22
23
|
/** One DNS label: the name a linked workspace resolves the instance by. */
|
|
@@ -26,20 +27,26 @@ export const ResourceWorktreeKey = Schema.String.check(matching(/^[A-Za-z0-9][A-
|
|
|
26
27
|
/** An image pinned by digest (a tag may precede it). sealant never resolves a tag. */
|
|
27
28
|
export const ResourcePinnedImage = Schema.String.check(matching(/^[a-z0-9][a-z0-9._/:-]*@sha256:[0-9a-f]{64}$/, "must be an image pinned by digest (<repository>[:tag]@sha256:<64 hex>)")).pipe(Schema.brand("ResourcePinnedImage"));
|
|
28
29
|
const VolumeName = Schema.String.check(matching(/^[a-z][a-z0-9-]{0,30}$/, "must be 1 to 31 lower-case letters, digits or '-'"));
|
|
30
|
+
const MOUNT_PATH = {
|
|
31
|
+
relative: "must be an absolute path other than '/'",
|
|
32
|
+
unnormalized: "must be a normalized absolute path",
|
|
33
|
+
system: "must not be under /proc, /sys or /dev",
|
|
34
|
+
};
|
|
29
35
|
const isMountPath = (path) => {
|
|
30
36
|
if (!path.startsWith("/") || path === "/")
|
|
31
|
-
return
|
|
37
|
+
return MOUNT_PATH.relative;
|
|
32
38
|
const segments = path.slice(1).split("/");
|
|
33
39
|
if (segments.some((segment) => segment === "." || segment === ".." || !/^[A-Za-z0-9._@+-]+$/.test(segment))) {
|
|
34
|
-
return
|
|
40
|
+
return MOUNT_PATH.unnormalized;
|
|
35
41
|
}
|
|
36
42
|
if (["/proc", "/sys", "/dev"].some((root) => path === root || path.startsWith(`${root}/`)))
|
|
37
|
-
return
|
|
43
|
+
return MOUNT_PATH.system;
|
|
38
44
|
return undefined;
|
|
39
45
|
};
|
|
40
|
-
const MountPath = Schema.String.check(Schema.makeFilter(isMountPath));
|
|
46
|
+
const MountPath = Schema.String.check(Schema.makeFilter(isMountPath, refusalWords(...Object.values(MOUNT_PATH))));
|
|
41
47
|
const EnvName = Schema.String.check(matching(/^[A-Za-z_][A-Za-z0-9_]{0,127}$/, "must be an environment variable name"));
|
|
42
|
-
const
|
|
48
|
+
const HAS_NUL = "must not contain a NUL byte";
|
|
49
|
+
const withoutNul = Schema.makeFilter((value) => (value.includes("\u0000") ? HAS_NUL : undefined), refusalWords(HAS_NUL));
|
|
43
50
|
const EnvValue = Schema.String.check(withoutNul, Schema.isMaxLength(32_768));
|
|
44
51
|
const Argument = Schema.String.check(withoutNul);
|
|
45
52
|
const Port = Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 65_535 }));
|
|
@@ -80,7 +87,7 @@ export const resourceInstanceSpecSchema = Schema.Struct({
|
|
|
80
87
|
command: Schema.NullOr(Schema.Array(Argument)),
|
|
81
88
|
env: Schema.Record(EnvName, EnvValue),
|
|
82
89
|
/** Named volumes only. Every image `VOLUME` this does not cover gets a named volume too. */
|
|
83
|
-
volumes: Schema.Array(resourceInstanceVolumeSchema).check(Schema.makeFilter(distinct((volume) => volume.name, "volume names must be distinct")), Schema.makeFilter(distinct((volume) => volume.mountPath, "mount paths must be distinct")), Schema.isMaxLength(16)),
|
|
90
|
+
volumes: Schema.Array(resourceInstanceVolumeSchema).check(Schema.makeFilter(distinct((volume) => volume.name, "volume names must be distinct"), refusalWords("volume names must be distinct")), Schema.makeFilter(distinct((volume) => volume.mountPath, "mount paths must be distinct"), refusalWords("mount paths must be distinct")), Schema.isMaxLength(16)),
|
|
84
91
|
limits: Schema.Struct({
|
|
85
92
|
cpuMillicores: Schema.Int.check(Schema.isBetween({ minimum: 10, maximum: 256_000 })),
|
|
86
93
|
memoryBytes: Schema.Int.check(Schema.isBetween({ minimum: 16 * 1024 * 1024, maximum: Number.MAX_SAFE_INTEGER })),
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { Schema } from "effect";
|
|
17
17
|
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/http-api";
|
|
18
18
|
import { PersonId } from "./person-id.js";
|
|
19
|
+
import { refusalWords } from "./refusal-words.js";
|
|
19
20
|
const NonEmptyString = Schema.String.check(Schema.isNonEmpty(), Schema.isTrimmed());
|
|
20
21
|
export const sessionStatusSchema = Schema.Literals(["starting", "running", "exited", "failed"]);
|
|
21
22
|
export const sessionAuthorizationHeadersSchema = Schema.Struct({
|
|
@@ -111,7 +112,9 @@ export const sessionArgvIssue = (argv) => {
|
|
|
111
112
|
* A session's argv: the program, then its arguments, as `sessionArgvIssue` allows. One check over
|
|
112
113
|
* the whole array, because Effect's own length and whitespace checks quote the offending value.
|
|
113
114
|
*/
|
|
114
|
-
export const sessionArgvSchema = Schema.Array(Schema.String).check(Schema.makeFilter(sessionArgvIssue
|
|
115
|
+
export const sessionArgvSchema = Schema.Array(Schema.String).check(Schema.makeFilter(sessionArgvIssue,
|
|
116
|
+
// Only positions, counts and sizes vary.
|
|
117
|
+
refusalWords("argv is empty: argv[0] must name the program", /argv has \d+ words; the maximum is \d+/, "argv[0], the program, must be non-empty with no leading or trailing whitespace", /argv\[\d+\] contains a NUL byte, which no process argument can carry/, /argv\[\d+\] is not well-formed Unicode \(a lone surrogate\)/, /argv\[\d+\] is \d+ bytes; the maximum per word is \d+/, /argv totals \d+ bytes; the maximum is \d+/)));
|
|
115
118
|
export const createSessionRequestSchema = Schema.Struct({
|
|
116
119
|
workspaceId: NonEmptyString,
|
|
117
120
|
ownerUserId: PersonId,
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./core-api/budgets.js";
|
|
|
11
11
|
export * from "./core-api/oci-names.js";
|
|
12
12
|
export * from "./core-api/registries.js";
|
|
13
13
|
export * from "./core-api/runs.js";
|
|
14
|
+
export * from "./core-api/refusal-words.js";
|
|
14
15
|
export * from "./core-api/request-refusal.js";
|
|
15
16
|
export * from "./core-api/resource-domains.js";
|
|
16
17
|
export * from "./core-api/resource-instances.js";
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./core-api/budgets.js";
|
|
|
11
11
|
export * from "./core-api/oci-names.js";
|
|
12
12
|
export * from "./core-api/registries.js";
|
|
13
13
|
export * from "./core-api/runs.js";
|
|
14
|
+
export * from "./core-api/refusal-words.js";
|
|
14
15
|
export * from "./core-api/request-refusal.js";
|
|
15
16
|
export * from "./core-api/resource-domains.js";
|
|
16
17
|
export * from "./core-api/resource-instances.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealant/api-contracts-next",
|
|
3
|
-
"version": "0.40.0-next.
|
|
3
|
+
"version": "0.40.0-next.894",
|
|
4
4
|
"description": "Contract-first HTTP API definitions for Sealant services",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"effect": "^4.0.5"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "ec83f8ee57fca2755d37bbd576c4814a929c8a28",
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
}
|