@superforge/infra 0.1.0 → 0.2.0
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 +50 -33
- package/output/agents.d.ts +50 -69
- package/output/agents.js +120 -85
- package/output/choose.d.ts +3 -1
- package/output/choose.js +20 -13
- package/output/client.d.ts +10 -9
- package/output/client.js +85 -106
- package/output/contract/agents.d.ts +203 -0
- package/output/contract/agents.js +94 -0
- package/output/contract/comments.d.ts +101 -0
- package/output/contract/comments.js +66 -0
- package/output/contract/errors.d.ts +123 -0
- package/output/contract/errors.js +61 -0
- package/output/contract/index.d.ts +6 -0
- package/output/contract/index.js +11 -0
- package/output/contract/login.d.ts +152 -0
- package/output/contract/login.js +93 -0
- package/output/contract/people.d.ts +9 -0
- package/output/contract/people.js +16 -0
- package/output/contract/project.d.ts +38 -0
- package/output/contract/project.js +36 -0
- package/output/index.d.ts +4 -4
- package/output/index.js +10 -6
- package/output/infra.d.ts +44 -58
- package/output/primitives.d.ts +0 -8
- package/output/primitives.js +0 -7
- package/output/stand-in.d.ts +18 -16
- package/output/stand-in.js +74 -39
- package/output/version.d.ts +4 -0
- package/output/version.js +10 -0
- package/package.json +5 -1
- package/output/answers.d.ts +0 -154
- package/output/answers.js +0 -153
- package/output/comments.d.ts +0 -37
- package/output/comments.js +0 -58
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The most a comment says, in characters */
|
|
3
|
+
export declare const LONGEST_COMMENT = 5000;
|
|
4
|
+
/** How big one comment's body can be, in bytes */
|
|
5
|
+
export declare const COMMENT_BODY_LIMIT: number;
|
|
6
|
+
/**
|
|
7
|
+
* `POST /v1/comments`: what was written, the page's path and title, the
|
|
8
|
+
* element it's about (a CSS selector from the page's body, its tag, the
|
|
9
|
+
* text it shows or null, its `class`, and its box on the page) or null for
|
|
10
|
+
* the page as a whole, the window's size, who filed it (the app's ID for
|
|
11
|
+
* them, never their email, and the name it shows), and their browser's
|
|
12
|
+
* User-Agent, for what they were on, which Infra doesn't keep
|
|
13
|
+
*/
|
|
14
|
+
export declare const filed_comment: z.ZodObject<{
|
|
15
|
+
body: z.ZodString;
|
|
16
|
+
path: z.ZodString;
|
|
17
|
+
title: z.ZodNullable<z.ZodString>;
|
|
18
|
+
element: z.ZodNullable<z.ZodObject<{
|
|
19
|
+
selector: z.ZodString;
|
|
20
|
+
tag: z.ZodString;
|
|
21
|
+
text: z.ZodNullable<z.ZodString>;
|
|
22
|
+
classes: z.ZodNullable<z.ZodString>;
|
|
23
|
+
box: z.ZodObject<{
|
|
24
|
+
x: z.ZodNumber;
|
|
25
|
+
y: z.ZodNumber;
|
|
26
|
+
width: z.ZodNumber;
|
|
27
|
+
height: z.ZodNumber;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
viewport: z.ZodNullable<z.ZodObject<{
|
|
31
|
+
width: z.ZodNumber;
|
|
32
|
+
height: z.ZodNumber;
|
|
33
|
+
}, z.core.$strip>>;
|
|
34
|
+
user_id: z.ZodString;
|
|
35
|
+
user_name: z.ZodString;
|
|
36
|
+
user_agent: z.ZodNullable<z.ZodString>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
export type FiledComment = z.input<typeof filed_comment>;
|
|
39
|
+
/** What `POST /v1/comments` answers: the comment's ID, and when */
|
|
40
|
+
export declare const kept_comment: z.ZodPipe<z.ZodObject<{
|
|
41
|
+
comment: z.ZodObject<{
|
|
42
|
+
id: z.ZodString;
|
|
43
|
+
created_at: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
44
|
+
}, z.core.$strip>;
|
|
45
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
46
|
+
id: string;
|
|
47
|
+
created_at: Date;
|
|
48
|
+
}, {
|
|
49
|
+
comment: {
|
|
50
|
+
id: string;
|
|
51
|
+
created_at: Date;
|
|
52
|
+
};
|
|
53
|
+
}>>;
|
|
54
|
+
export type KeptComment = z.output<typeof kept_comment>;
|
|
55
|
+
/**
|
|
56
|
+
* Why Infra didn't keep a comment. Either is a bug in what the app sent, so
|
|
57
|
+
* sending it again won't help.
|
|
58
|
+
*/
|
|
59
|
+
export declare const comment_refused: z.ZodUnion<readonly [z.ZodPipe<z.ZodObject<{
|
|
60
|
+
error: z.ZodObject<{
|
|
61
|
+
reason: z.ZodLiteral<"invalid">;
|
|
62
|
+
message: z.ZodString;
|
|
63
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
64
|
+
path: z.ZodString;
|
|
65
|
+
message: z.ZodString;
|
|
66
|
+
}, z.core.$strip>>;
|
|
67
|
+
}, z.core.$strip>;
|
|
68
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
69
|
+
reason: "invalid";
|
|
70
|
+
message: string;
|
|
71
|
+
issues: {
|
|
72
|
+
path: string;
|
|
73
|
+
message: string;
|
|
74
|
+
}[];
|
|
75
|
+
}, {
|
|
76
|
+
error: {
|
|
77
|
+
reason: "invalid";
|
|
78
|
+
message: string;
|
|
79
|
+
issues: {
|
|
80
|
+
path: string;
|
|
81
|
+
message: string;
|
|
82
|
+
}[];
|
|
83
|
+
};
|
|
84
|
+
}>>, z.ZodPipe<z.ZodObject<{
|
|
85
|
+
error: z.ZodObject<{
|
|
86
|
+
reason: z.ZodLiteral<"too-large">;
|
|
87
|
+
message: z.ZodString;
|
|
88
|
+
limit: z.ZodNumber;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
91
|
+
reason: "too-large";
|
|
92
|
+
message: string;
|
|
93
|
+
limit: number;
|
|
94
|
+
}, {
|
|
95
|
+
error: {
|
|
96
|
+
reason: "too-large";
|
|
97
|
+
message: string;
|
|
98
|
+
limit: number;
|
|
99
|
+
};
|
|
100
|
+
}>>]>;
|
|
101
|
+
export type CommentRefused = z.output<typeof comment_refused>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { invalid_refusal, too_large_refusal } from "./errors.js";
|
|
3
|
+
import { user_id } from "./people.js";
|
|
4
|
+
// What an app's people say about it, from the toolbar on its pages: the app's
|
|
5
|
+
// server sends each comment to `POST /v1/comments` with who filed it, and
|
|
6
|
+
// Infra keeps it and files it on the app's board. Infra's README,
|
|
7
|
+
// "Comments", has the call.
|
|
8
|
+
/** The most a comment says, in characters */
|
|
9
|
+
export const LONGEST_COMMENT = 5000;
|
|
10
|
+
/** How big one comment's body can be, in bytes */
|
|
11
|
+
export const COMMENT_BODY_LIMIT = 32 * 1024;
|
|
12
|
+
// A place or a length on the page, in whole CSS pixels: a page can be
|
|
13
|
+
// scrolled far, and an element can sit above its top
|
|
14
|
+
const coordinate = z.number().int().min(-1_000_000).max(10_000_000);
|
|
15
|
+
const length = z.number().int().min(0).max(10_000_000);
|
|
16
|
+
/**
|
|
17
|
+
* `POST /v1/comments`: what was written, the page's path and title, the
|
|
18
|
+
* element it's about (a CSS selector from the page's body, its tag, the
|
|
19
|
+
* text it shows or null, its `class`, and its box on the page) or null for
|
|
20
|
+
* the page as a whole, the window's size, who filed it (the app's ID for
|
|
21
|
+
* them, never their email, and the name it shows), and their browser's
|
|
22
|
+
* User-Agent, for what they were on, which Infra doesn't keep
|
|
23
|
+
*/
|
|
24
|
+
export const filed_comment = z.object({
|
|
25
|
+
body: z.string().trim().min(1).max(LONGEST_COMMENT),
|
|
26
|
+
path: z
|
|
27
|
+
.string()
|
|
28
|
+
.max(2048)
|
|
29
|
+
.regex(/^\/[^?#]*$/),
|
|
30
|
+
title: z.string().trim().max(200).nullable(),
|
|
31
|
+
element: z
|
|
32
|
+
.object({
|
|
33
|
+
selector: z.string().trim().min(1).max(1000),
|
|
34
|
+
tag: z
|
|
35
|
+
.string()
|
|
36
|
+
.max(64)
|
|
37
|
+
.regex(/^[a-z][a-z0-9-]*$/),
|
|
38
|
+
text: z.string().max(1000).nullable(),
|
|
39
|
+
classes: z.string().max(1000).nullable(),
|
|
40
|
+
box: z.object({
|
|
41
|
+
x: coordinate,
|
|
42
|
+
y: coordinate,
|
|
43
|
+
width: length,
|
|
44
|
+
height: length
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
.nullable(),
|
|
48
|
+
viewport: z.object({ width: length, height: length }).nullable(),
|
|
49
|
+
user_id,
|
|
50
|
+
user_name: z.string().trim().min(1).max(80),
|
|
51
|
+
user_agent: z.string().max(1024).nullable()
|
|
52
|
+
});
|
|
53
|
+
/** What `POST /v1/comments` answers: the comment's ID, and when */
|
|
54
|
+
export const kept_comment = z
|
|
55
|
+
.object({
|
|
56
|
+
comment: z.object({
|
|
57
|
+
id: z.string(),
|
|
58
|
+
created_at: z.iso.datetime().transform((value) => new Date(value))
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
.transform(({ comment }) => comment);
|
|
62
|
+
/**
|
|
63
|
+
* Why Infra didn't keep a comment. Either is a bug in what the app sent, so
|
|
64
|
+
* sending it again won't help.
|
|
65
|
+
*/
|
|
66
|
+
export const comment_refused = z.union([invalid_refusal, too_large_refusal]);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Every reason Infra refuses a call with, and what it means */
|
|
3
|
+
export declare const INFRA_ERRORS: {
|
|
4
|
+
readonly "no-key": "The call came without a key Infra can read: none, or not a key's shape";
|
|
5
|
+
readonly "unknown-key": "No project has this key";
|
|
6
|
+
readonly "revoked-key": "The key was revoked: whatever sends it still has the old one";
|
|
7
|
+
readonly "expired-key": "A test key that went its lifetime without a call: make a new one";
|
|
8
|
+
readonly invalid: "The call's body, query or path isn't what it takes; `issues` says what";
|
|
9
|
+
readonly "too-large": "The call's body is over its limit; `limit` is how many bytes";
|
|
10
|
+
readonly "not-found": "No such call, or nothing at the address it names";
|
|
11
|
+
readonly unexpected: "Infra broke answering it: a bug on Superforge's side";
|
|
12
|
+
readonly "rate-limited": "Too many login messages for now; `limit` says which and `retry_after` when";
|
|
13
|
+
readonly "not-sent": "The login message didn't go out; asking again can work at once";
|
|
14
|
+
readonly "wrong-code": "Not the code; `attempts_left` says how many tries are left";
|
|
15
|
+
readonly "no-code": "No code is waiting: never sent, expired, used, or out of tries";
|
|
16
|
+
readonly "no-link": "The link is spent, expired, or never was this project's";
|
|
17
|
+
readonly "not-asked": "Claude didn't ask for any of the scopes allowed";
|
|
18
|
+
readonly "unknown-client": "Who's asking to connect isn't Claude, by its return address";
|
|
19
|
+
readonly "unknown-origin": "The app's origin isn't one its key may log Claude in at";
|
|
20
|
+
};
|
|
21
|
+
/** A reason Infra refuses a call with */
|
|
22
|
+
export type InfraErrorReason = keyof typeof INFRA_ERRORS;
|
|
23
|
+
/** What didn't fit, for `invalid`: a dotted path, and why */
|
|
24
|
+
export declare const infra_issue: z.ZodObject<{
|
|
25
|
+
path: z.ZodString;
|
|
26
|
+
message: z.ZodString;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export type InfraIssue = z.infer<typeof infra_issue>;
|
|
29
|
+
/** Any refusal of Infra's, read for its reason and its words */
|
|
30
|
+
export declare const infra_failure: z.ZodObject<{
|
|
31
|
+
error: z.ZodObject<{
|
|
32
|
+
reason: z.ZodString;
|
|
33
|
+
message: z.ZodString;
|
|
34
|
+
}, z.core.$loose>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
/**
|
|
37
|
+
* One kind of refusal, as a call answers it: its `reason`, its `message`,
|
|
38
|
+
* and the fields it adds (`details`, `{}` for none), read as the `error`
|
|
39
|
+
* alone
|
|
40
|
+
*/
|
|
41
|
+
export declare function refusal<Reason extends InfraErrorReason, Details extends z.ZodRawShape>(reason: Reason, details: Details): z.ZodPipe<z.ZodObject<{
|
|
42
|
+
error: z.ZodObject<(("message" | "reason") & keyof Details extends never ? {
|
|
43
|
+
reason: z.ZodLiteral<Reason>;
|
|
44
|
+
message: z.ZodString;
|
|
45
|
+
} & { -readonly [P in keyof Details]: Details[P]; } : ({
|
|
46
|
+
reason: z.ZodLiteral<Reason>;
|
|
47
|
+
message: z.ZodString;
|
|
48
|
+
} extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof Details ? never : K]: T_1[K]; } : never) & { [K_1 in keyof { -readonly [P in keyof Details]: Details[P]; }]: { -readonly [P in keyof Details]: Details[P]; }[K_1]; }) extends infer T ? { [k in keyof T]: T[k]; } : never, z.core.$strip>;
|
|
49
|
+
}, z.core.$strip>, z.ZodTransform<Awaited<z.core.$InferObjectOutput<(("message" | "reason") & keyof Details extends never ? {
|
|
50
|
+
reason: z.ZodLiteral<Reason>;
|
|
51
|
+
message: z.ZodString;
|
|
52
|
+
} & { -readonly [P in keyof Details]: Details[P]; } : ({
|
|
53
|
+
reason: z.ZodLiteral<Reason>;
|
|
54
|
+
message: z.ZodString;
|
|
55
|
+
} extends infer T_3 extends z.core.util.SomeObject ? { [K in keyof T_3 as K extends keyof Details ? never : K]: T_3[K]; } : never) & { [K_1 in keyof { -readonly [P in keyof Details]: Details[P]; }]: { -readonly [P in keyof Details]: Details[P]; }[K_1]; }) extends infer T_2 ? { [k in keyof T_2]: T_2[k]; } : never, {}>>, {
|
|
56
|
+
error: z.core.$InferObjectOutput<(("message" | "reason") & keyof Details extends never ? {
|
|
57
|
+
reason: z.ZodLiteral<Reason>;
|
|
58
|
+
message: z.ZodString;
|
|
59
|
+
} & { -readonly [P in keyof Details]: Details[P]; } : ({
|
|
60
|
+
reason: z.ZodLiteral<Reason>;
|
|
61
|
+
message: z.ZodString;
|
|
62
|
+
} extends infer T_5 extends z.core.util.SomeObject ? { [K in keyof T_5 as K extends keyof Details ? never : K]: T_5[K]; } : never) & { [K_1 in keyof { -readonly [P in keyof Details]: Details[P]; }]: { -readonly [P in keyof Details]: Details[P]; }[K_1]; }) extends infer T_4 ? { [k in keyof T_4]: T_4[k]; } : never, {}>;
|
|
63
|
+
}>>;
|
|
64
|
+
/** `invalid`, with what didn't fit */
|
|
65
|
+
export declare const invalid_refusal: z.ZodPipe<z.ZodObject<{
|
|
66
|
+
error: z.ZodObject<{
|
|
67
|
+
reason: z.ZodLiteral<"invalid">;
|
|
68
|
+
message: z.ZodString;
|
|
69
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
70
|
+
path: z.ZodString;
|
|
71
|
+
message: z.ZodString;
|
|
72
|
+
}, z.core.$strip>>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
75
|
+
reason: "invalid";
|
|
76
|
+
message: string;
|
|
77
|
+
issues: {
|
|
78
|
+
path: string;
|
|
79
|
+
message: string;
|
|
80
|
+
}[];
|
|
81
|
+
}, {
|
|
82
|
+
error: {
|
|
83
|
+
reason: "invalid";
|
|
84
|
+
message: string;
|
|
85
|
+
issues: {
|
|
86
|
+
path: string;
|
|
87
|
+
message: string;
|
|
88
|
+
}[];
|
|
89
|
+
};
|
|
90
|
+
}>>;
|
|
91
|
+
/** `too-large`, with the most bytes the call takes */
|
|
92
|
+
export declare const too_large_refusal: z.ZodPipe<z.ZodObject<{
|
|
93
|
+
error: z.ZodObject<{
|
|
94
|
+
reason: z.ZodLiteral<"too-large">;
|
|
95
|
+
message: z.ZodString;
|
|
96
|
+
limit: z.ZodNumber;
|
|
97
|
+
}, z.core.$strip>;
|
|
98
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
99
|
+
reason: "too-large";
|
|
100
|
+
message: string;
|
|
101
|
+
limit: number;
|
|
102
|
+
}, {
|
|
103
|
+
error: {
|
|
104
|
+
reason: "too-large";
|
|
105
|
+
message: string;
|
|
106
|
+
limit: number;
|
|
107
|
+
};
|
|
108
|
+
}>>;
|
|
109
|
+
/** `not-found` */
|
|
110
|
+
export declare const not_found_refusal: z.ZodPipe<z.ZodObject<{
|
|
111
|
+
error: z.ZodObject<{
|
|
112
|
+
reason: z.ZodLiteral<"not-found">;
|
|
113
|
+
message: z.ZodString;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
116
|
+
reason: "not-found";
|
|
117
|
+
message: string;
|
|
118
|
+
}, {
|
|
119
|
+
error: {
|
|
120
|
+
reason: "not-found";
|
|
121
|
+
message: string;
|
|
122
|
+
};
|
|
123
|
+
}>>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// How Infra says no. Every refusal is JSON in one shape, the same as a
|
|
3
|
+
// Superforge template's own API answers, `{ error: { reason, message, … } }`,
|
|
4
|
+
// so an app passes Infra's `error` on as its own result's, unchanged:
|
|
5
|
+
//
|
|
6
|
+
// - `reason`: for code to branch on, one of `INFRA_ERRORS`, which never
|
|
7
|
+
// changes once a call answers it
|
|
8
|
+
// - `message`: what went wrong and what fixes it, in plain words, for whoever
|
|
9
|
+
// runs the app and their agent; never parsed, and reworded any time
|
|
10
|
+
// - `issues`: for `invalid`, what didn't fit, field by field
|
|
11
|
+
// - anything else a call says it adds, like a 429's `retry_after`
|
|
12
|
+
//
|
|
13
|
+
// The OAuth calls Claude makes are the one exception: they answer OAuth's
|
|
14
|
+
// own `{ error, error_description }` (RFC 6749 5.2), which Claude reads.
|
|
15
|
+
/** Every reason Infra refuses a call with, and what it means */
|
|
16
|
+
export const INFRA_ERRORS = {
|
|
17
|
+
"no-key": "The call came without a key Infra can read: none, or not a key's shape",
|
|
18
|
+
"unknown-key": "No project has this key",
|
|
19
|
+
"revoked-key": "The key was revoked: whatever sends it still has the old one",
|
|
20
|
+
"expired-key": "A test key that went its lifetime without a call: make a new one",
|
|
21
|
+
invalid: "The call's body, query or path isn't what it takes; `issues` says what",
|
|
22
|
+
"too-large": "The call's body is over its limit; `limit` is how many bytes",
|
|
23
|
+
"not-found": "No such call, or nothing at the address it names",
|
|
24
|
+
unexpected: "Infra broke answering it: a bug on Superforge's side",
|
|
25
|
+
"rate-limited": "Too many login messages for now; `limit` says which and `retry_after` when",
|
|
26
|
+
"not-sent": "The login message didn't go out; asking again can work at once",
|
|
27
|
+
"wrong-code": "Not the code; `attempts_left` says how many tries are left",
|
|
28
|
+
"no-code": "No code is waiting: never sent, expired, used, or out of tries",
|
|
29
|
+
"no-link": "The link is spent, expired, or never was this project's",
|
|
30
|
+
"not-asked": "Claude didn't ask for any of the scopes allowed",
|
|
31
|
+
"unknown-client": "Who's asking to connect isn't Claude, by its return address",
|
|
32
|
+
"unknown-origin": "The app's origin isn't one its key may log Claude in at"
|
|
33
|
+
};
|
|
34
|
+
/** What didn't fit, for `invalid`: a dotted path, and why */
|
|
35
|
+
export const infra_issue = z.object({ path: z.string(), message: z.string() });
|
|
36
|
+
/** Any refusal of Infra's, read for its reason and its words */
|
|
37
|
+
export const infra_failure = z.object({
|
|
38
|
+
error: z.looseObject({ reason: z.string(), message: z.string() })
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* One kind of refusal, as a call answers it: its `reason`, its `message`,
|
|
42
|
+
* and the fields it adds (`details`, `{}` for none), read as the `error`
|
|
43
|
+
* alone
|
|
44
|
+
*/
|
|
45
|
+
export function refusal(reason, details) {
|
|
46
|
+
return z
|
|
47
|
+
.object({
|
|
48
|
+
error: z
|
|
49
|
+
.object({ reason: z.literal(reason), message: z.string() })
|
|
50
|
+
.extend(details)
|
|
51
|
+
})
|
|
52
|
+
.transform((body) => body.error);
|
|
53
|
+
}
|
|
54
|
+
/** `invalid`, with what didn't fit */
|
|
55
|
+
export const invalid_refusal = refusal("invalid", {
|
|
56
|
+
issues: z.array(infra_issue)
|
|
57
|
+
});
|
|
58
|
+
/** `too-large`, with the most bytes the call takes */
|
|
59
|
+
export const too_large_refusal = refusal("too-large", { limit: z.number() });
|
|
60
|
+
/** `not-found` */
|
|
61
|
+
export const not_found_refusal = refusal("not-found", {});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Infra's contract: every call's request and answer, as zod schemas, and
|
|
2
|
+
// every reason it refuses one, which Infra itself checks what it's sent
|
|
3
|
+
// with and answers by, and the client reads its answers with. Nothing here
|
|
4
|
+
// runs in Node alone, so a page can import it too, at
|
|
5
|
+
// `@superforge/infra/contract`. Infra's README has the calls.
|
|
6
|
+
export * from "./agents.js";
|
|
7
|
+
export * from "./comments.js";
|
|
8
|
+
export * from "./errors.js";
|
|
9
|
+
export * from "./login.js";
|
|
10
|
+
export * from "./people.js";
|
|
11
|
+
export * from "./project.js";
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* How a login message reaches someone. Only email today; a text is a new
|
|
4
|
+
* channel, not a new call.
|
|
5
|
+
*/
|
|
6
|
+
export declare const LOGIN_CHANNELS: readonly ["email"];
|
|
7
|
+
export declare const login_channel: z.ZodEnum<{
|
|
8
|
+
email: "email";
|
|
9
|
+
}>;
|
|
10
|
+
export type LoginChannel = z.infer<typeof login_channel>;
|
|
11
|
+
/** An email address as Infra keeps it: trimmed, lowercased and checked */
|
|
12
|
+
export declare const email_address: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
13
|
+
/** A login's six-digit code, forgiving the spaces a pasted code can carry */
|
|
14
|
+
export declare const login_code: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodString>;
|
|
15
|
+
/**
|
|
16
|
+
* A login link's token, from the link's fragment (`/login#<token>`): 32
|
|
17
|
+
* random bytes in base64url, which identify the login by themselves
|
|
18
|
+
*/
|
|
19
|
+
export declare const login_token: z.ZodString;
|
|
20
|
+
/** The person's IP address, which Infra's limits count by network */
|
|
21
|
+
export declare const visitor_ip: z.ZodUnion<readonly [z.ZodIPv4, z.ZodIPv6]>;
|
|
22
|
+
/**
|
|
23
|
+
* The page a login link opens, like `https://vmdsystem.com/login`: Infra
|
|
24
|
+
* adds `#<token>`, and links only to the project's domains and localhost
|
|
25
|
+
*/
|
|
26
|
+
export declare const link_to: z.ZodURL;
|
|
27
|
+
/** `POST /v1/login/start`: sends a code, and a link with `link_to` */
|
|
28
|
+
export declare const login_start: z.ZodObject<{
|
|
29
|
+
channel: z.ZodLiteral<"email">;
|
|
30
|
+
address: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
31
|
+
ip: z.ZodUnion<readonly [z.ZodIPv4, z.ZodIPv6]>;
|
|
32
|
+
link_to: z.ZodOptional<z.ZodURL>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
export type LoginStart = z.input<typeof login_start>;
|
|
35
|
+
/** What `login/start` answers once the message went out */
|
|
36
|
+
export declare const started_login: z.ZodObject<{
|
|
37
|
+
channel: z.ZodEnum<{
|
|
38
|
+
email: "email";
|
|
39
|
+
}>;
|
|
40
|
+
address: z.ZodString;
|
|
41
|
+
with_link: z.ZodBoolean;
|
|
42
|
+
expires_at: z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>;
|
|
43
|
+
test: z.ZodNullable<z.ZodObject<{
|
|
44
|
+
code: z.ZodString;
|
|
45
|
+
link: z.ZodNullable<z.ZodString>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export type StartedLogin = z.output<typeof started_login>;
|
|
49
|
+
/** Why `login/start` sent nothing */
|
|
50
|
+
export declare const start_refused: z.ZodUnion<readonly [z.ZodPipe<z.ZodObject<{
|
|
51
|
+
error: z.ZodObject<{
|
|
52
|
+
reason: z.ZodLiteral<"rate-limited">;
|
|
53
|
+
message: z.ZodString;
|
|
54
|
+
limit: z.ZodEnum<{
|
|
55
|
+
project: "project";
|
|
56
|
+
address: "address";
|
|
57
|
+
network: "network";
|
|
58
|
+
}>;
|
|
59
|
+
retry_after: z.ZodNumber;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
62
|
+
reason: "rate-limited";
|
|
63
|
+
message: string;
|
|
64
|
+
limit: "project" | "address" | "network";
|
|
65
|
+
retry_after: number;
|
|
66
|
+
}, {
|
|
67
|
+
error: {
|
|
68
|
+
reason: "rate-limited";
|
|
69
|
+
message: string;
|
|
70
|
+
limit: "project" | "address" | "network";
|
|
71
|
+
retry_after: number;
|
|
72
|
+
};
|
|
73
|
+
}>>, z.ZodPipe<z.ZodObject<{
|
|
74
|
+
error: z.ZodObject<{
|
|
75
|
+
reason: z.ZodLiteral<"not-sent">;
|
|
76
|
+
message: z.ZodString;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
79
|
+
reason: "not-sent";
|
|
80
|
+
message: string;
|
|
81
|
+
}, {
|
|
82
|
+
error: {
|
|
83
|
+
reason: "not-sent";
|
|
84
|
+
message: string;
|
|
85
|
+
};
|
|
86
|
+
}>>]>;
|
|
87
|
+
export type StartRefused = z.output<typeof start_refused>;
|
|
88
|
+
/**
|
|
89
|
+
* `POST /v1/login/verify`: the code, with the address it went to, or the
|
|
90
|
+
* link's token alone
|
|
91
|
+
*/
|
|
92
|
+
export declare const login_verify: z.ZodUnion<readonly [z.ZodObject<{
|
|
93
|
+
channel: z.ZodLiteral<"email">;
|
|
94
|
+
address: z.ZodPipe<z.ZodString, z.ZodEmail>;
|
|
95
|
+
code: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodString>;
|
|
96
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
97
|
+
token: z.ZodString;
|
|
98
|
+
}, z.core.$strip>]>;
|
|
99
|
+
export type LoginProof = z.input<typeof login_verify>;
|
|
100
|
+
/** Whose address the code or the link was */
|
|
101
|
+
export declare const verified_login: z.ZodObject<{
|
|
102
|
+
channel: z.ZodEnum<{
|
|
103
|
+
email: "email";
|
|
104
|
+
}>;
|
|
105
|
+
address: z.ZodString;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
export type VerifiedLogin = z.output<typeof verified_login>;
|
|
108
|
+
/** Why `login/verify` didn't log them in */
|
|
109
|
+
export declare const verify_refused: z.ZodUnion<readonly [z.ZodPipe<z.ZodObject<{
|
|
110
|
+
error: z.ZodObject<{
|
|
111
|
+
reason: z.ZodLiteral<"wrong-code">;
|
|
112
|
+
message: z.ZodString;
|
|
113
|
+
attempts_left: z.ZodNumber;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
116
|
+
reason: "wrong-code";
|
|
117
|
+
message: string;
|
|
118
|
+
attempts_left: number;
|
|
119
|
+
}, {
|
|
120
|
+
error: {
|
|
121
|
+
reason: "wrong-code";
|
|
122
|
+
message: string;
|
|
123
|
+
attempts_left: number;
|
|
124
|
+
};
|
|
125
|
+
}>>, z.ZodPipe<z.ZodObject<{
|
|
126
|
+
error: z.ZodObject<{
|
|
127
|
+
reason: z.ZodLiteral<"no-code">;
|
|
128
|
+
message: z.ZodString;
|
|
129
|
+
}, z.core.$strip>;
|
|
130
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
131
|
+
reason: "no-code";
|
|
132
|
+
message: string;
|
|
133
|
+
}, {
|
|
134
|
+
error: {
|
|
135
|
+
reason: "no-code";
|
|
136
|
+
message: string;
|
|
137
|
+
};
|
|
138
|
+
}>>, z.ZodPipe<z.ZodObject<{
|
|
139
|
+
error: z.ZodObject<{
|
|
140
|
+
reason: z.ZodLiteral<"no-link">;
|
|
141
|
+
message: z.ZodString;
|
|
142
|
+
}, z.core.$strip>;
|
|
143
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
144
|
+
reason: "no-link";
|
|
145
|
+
message: string;
|
|
146
|
+
}, {
|
|
147
|
+
error: {
|
|
148
|
+
reason: "no-link";
|
|
149
|
+
message: string;
|
|
150
|
+
};
|
|
151
|
+
}>>]>;
|
|
152
|
+
export type VerifyRefused = z.output<typeof verify_refused>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { refusal } from "./errors.js";
|
|
3
|
+
// Logging in an app's people, with no password: Infra sends a code, and a
|
|
4
|
+
// link when the app says where it goes, and says whose address it was when
|
|
5
|
+
// the person brings either back. The app keeps its own users and sessions.
|
|
6
|
+
// Infra's README, "Login", has the calls.
|
|
7
|
+
/**
|
|
8
|
+
* How a login message reaches someone. Only email today; a text is a new
|
|
9
|
+
* channel, not a new call.
|
|
10
|
+
*/
|
|
11
|
+
export const LOGIN_CHANNELS = ["email"];
|
|
12
|
+
export const login_channel = z.enum(LOGIN_CHANNELS);
|
|
13
|
+
/** An email address as Infra keeps it: trimmed, lowercased and checked */
|
|
14
|
+
export const email_address = z
|
|
15
|
+
.string()
|
|
16
|
+
.trim()
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.pipe(z.email().max(254));
|
|
19
|
+
/** A login's six-digit code, forgiving the spaces a pasted code can carry */
|
|
20
|
+
export const login_code = z
|
|
21
|
+
.string()
|
|
22
|
+
.transform((value) => value.replace(/\s/g, ""))
|
|
23
|
+
.pipe(z.string().regex(/^\d{6}$/));
|
|
24
|
+
/**
|
|
25
|
+
* A login link's token, from the link's fragment (`/login#<token>`): 32
|
|
26
|
+
* random bytes in base64url, which identify the login by themselves
|
|
27
|
+
*/
|
|
28
|
+
export const login_token = z.string().regex(/^[\w-]{43}$/);
|
|
29
|
+
/** The person's IP address, which Infra's limits count by network */
|
|
30
|
+
export const visitor_ip = z.union([z.ipv4(), z.ipv6()]);
|
|
31
|
+
/**
|
|
32
|
+
* The page a login link opens, like `https://vmdsystem.com/login`: Infra
|
|
33
|
+
* adds `#<token>`, and links only to the project's domains and localhost
|
|
34
|
+
*/
|
|
35
|
+
export const link_to = z
|
|
36
|
+
.url({ protocol: /^https?$/ })
|
|
37
|
+
.max(2048)
|
|
38
|
+
.refine((value) => !value.includes("#"), {
|
|
39
|
+
message: "Without a fragment: Infra adds the token after #"
|
|
40
|
+
});
|
|
41
|
+
/** Who a login is for: the channel, and their address on it */
|
|
42
|
+
const login_address = z.object({
|
|
43
|
+
channel: z.literal("email"),
|
|
44
|
+
address: email_address
|
|
45
|
+
});
|
|
46
|
+
/** `POST /v1/login/start`: sends a code, and a link with `link_to` */
|
|
47
|
+
export const login_start = login_address.extend({
|
|
48
|
+
ip: visitor_ip,
|
|
49
|
+
link_to: link_to.optional()
|
|
50
|
+
});
|
|
51
|
+
/** What `login/start` answers once the message went out */
|
|
52
|
+
export const started_login = z.object({
|
|
53
|
+
channel: login_channel,
|
|
54
|
+
// The address as Infra keeps it, which verifying the code takes
|
|
55
|
+
address: z.string(),
|
|
56
|
+
// Whether the message holds a link as well as the code
|
|
57
|
+
with_link: z.boolean(),
|
|
58
|
+
// When the code and the link stop working
|
|
59
|
+
expires_at: z.iso.datetime().transform((value) => new Date(value)),
|
|
60
|
+
// With a test key, which sends nothing: what the message would have
|
|
61
|
+
// held, for a dev server to show on the page. Null with a secret key.
|
|
62
|
+
test: z.object({ code: z.string(), link: z.string().nullable() }).nullable()
|
|
63
|
+
});
|
|
64
|
+
/** Why `login/start` sent nothing */
|
|
65
|
+
export const start_refused = z.union([
|
|
66
|
+
// Over one of Infra's limits: this address (one a minute, five an
|
|
67
|
+
// hour), the person's network, or the project's
|
|
68
|
+
refusal("rate-limited", {
|
|
69
|
+
limit: z.enum(["address", "network", "project"]),
|
|
70
|
+
retry_after: z.number()
|
|
71
|
+
}),
|
|
72
|
+
// The message didn't go out, and nothing was counted
|
|
73
|
+
refusal("not-sent", {})
|
|
74
|
+
]);
|
|
75
|
+
/**
|
|
76
|
+
* `POST /v1/login/verify`: the code, with the address it went to, or the
|
|
77
|
+
* link's token alone
|
|
78
|
+
*/
|
|
79
|
+
export const login_verify = z.union([
|
|
80
|
+
login_address.extend({ code: login_code }),
|
|
81
|
+
z.object({ token: login_token })
|
|
82
|
+
]);
|
|
83
|
+
/** Whose address the code or the link was */
|
|
84
|
+
export const verified_login = z.object({
|
|
85
|
+
channel: login_channel,
|
|
86
|
+
address: z.string()
|
|
87
|
+
});
|
|
88
|
+
/** Why `login/verify` didn't log them in */
|
|
89
|
+
export const verify_refused = z.union([
|
|
90
|
+
refusal("wrong-code", { attempts_left: z.number() }),
|
|
91
|
+
refusal("no-code", {}),
|
|
92
|
+
refusal("no-link", {})
|
|
93
|
+
]);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The app's own ID for one of its people: what Infra names them by, on a
|
|
4
|
+
* comment and on Claude's connections, and what Claude's tokens act as
|
|
5
|
+
* (`sub`). It never changes and is never given to someone else, so it's
|
|
6
|
+
* never an email, a phone number or a nickname, which all can. Infra keeps
|
|
7
|
+
* it as an opaque string; the templates send their users' row IDs.
|
|
8
|
+
*/
|
|
9
|
+
export declare const user_id: z.ZodString;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The app's own ID for one of its people: what Infra names them by, on a
|
|
4
|
+
* comment and on Claude's connections, and what Claude's tokens act as
|
|
5
|
+
* (`sub`). It never changes and is never given to someone else, so it's
|
|
6
|
+
* never an email, a phone number or a nickname, which all can. Infra keeps
|
|
7
|
+
* it as an opaque string; the templates send their users' row IDs.
|
|
8
|
+
*/
|
|
9
|
+
export const user_id = z
|
|
10
|
+
.string()
|
|
11
|
+
.trim()
|
|
12
|
+
.min(1)
|
|
13
|
+
.max(128)
|
|
14
|
+
.refine((id) => !id.includes("@"), {
|
|
15
|
+
message: "An ID that never changes, never an email"
|
|
16
|
+
});
|