ovr 6.2.5 → 7.0.0-next.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 +3 -1
- package/dist/app/index.d.ts +51 -7
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +163 -28
- package/dist/auth/auth-data.d.ts +26 -0
- package/dist/auth/auth-data.d.ts.map +1 -0
- package/dist/auth/auth-data.js +42 -0
- package/dist/auth/cbor.d.ts +50 -0
- package/dist/auth/cbor.d.ts.map +1 -0
- package/dist/auth/cbor.js +200 -0
- package/dist/auth/client-source.d.ts +3 -0
- package/dist/auth/client-source.d.ts.map +1 -0
- package/dist/auth/client-source.js +3 -0
- package/dist/auth/client.d.ts +3 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/client.js +186 -0
- package/dist/auth/configure.d.ts +28 -0
- package/dist/auth/configure.d.ts.map +1 -0
- package/dist/auth/configure.js +228 -0
- package/dist/auth/der.d.ts +6 -0
- package/dist/auth/der.d.ts.map +1 -0
- package/dist/auth/der.js +36 -0
- package/dist/auth/index.d.ts +242 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +152 -0
- package/dist/auth/issue.d.ts +36 -0
- package/dist/auth/issue.d.ts.map +1 -0
- package/dist/auth/issue.js +47 -0
- package/dist/auth/metadata.d.ts +22 -0
- package/dist/auth/metadata.d.ts.map +1 -0
- package/dist/auth/metadata.js +134 -0
- package/dist/auth/oauth.d.ts +29 -0
- package/dist/auth/oauth.d.ts.map +1 -0
- package/dist/auth/oauth.js +724 -0
- package/dist/auth/passkey.d.ts +101 -0
- package/dist/auth/passkey.d.ts.map +1 -0
- package/dist/auth/passkey.js +393 -0
- package/dist/auth/state.d.ts +49 -0
- package/dist/auth/state.d.ts.map +1 -0
- package/dist/auth/state.js +184 -0
- package/dist/auth/storage.d.ts +193 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +410 -0
- package/dist/auth/token.d.ts +12 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/auth/token.js +39 -0
- package/dist/context/index.d.ts +86 -16
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +166 -42
- package/dist/cookie/index.d.ts +3 -0
- package/dist/cookie/index.d.ts.map +1 -1
- package/dist/cookie/index.js +1 -0
- package/dist/database/index.d.ts +262 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +807 -0
- package/dist/form/index.d.ts +699 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +901 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/jsx/elements.d.ts +28 -2
- package/dist/jsx/elements.d.ts.map +1 -1
- package/dist/jsx/index.d.ts +20 -4
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/jsx/index.js +6 -65
- package/dist/limiter/index.d.ts +65 -0
- package/dist/limiter/index.d.ts.map +1 -0
- package/dist/limiter/index.js +157 -0
- package/dist/markdown/index.d.ts +61 -0
- package/dist/markdown/index.d.ts.map +1 -0
- package/dist/markdown/index.js +1160 -0
- package/dist/markup/index.d.ts +188 -0
- package/dist/markup/index.d.ts.map +1 -0
- package/dist/markup/index.js +718 -0
- package/dist/mcp/index.d.ts +73 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +988 -0
- package/dist/middleware/index.d.ts +3 -4
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/multipart/index.d.ts +53 -7
- package/dist/multipart/index.d.ts.map +1 -1
- package/dist/multipart/index.js +289 -123
- package/dist/route/index.d.ts +226 -80
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/index.js +239 -99
- package/dist/schema/index.d.ts +307 -734
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +783 -1050
- package/dist/table/index.d.ts +132 -0
- package/dist/table/index.d.ts.map +1 -0
- package/dist/table/index.js +188 -0
- package/dist/trie/index.js +4 -4
- package/dist/util/index.d.ts +37 -5
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +156 -41
- package/package.json +11 -4
- package/src/app/index.ts +230 -42
- package/src/auth/auth-data.ts +56 -0
- package/src/auth/cbor.ts +231 -0
- package/src/auth/client-source.ts +3 -0
- package/src/auth/client.ts +205 -0
- package/src/auth/configure.ts +279 -0
- package/src/auth/der.ts +35 -0
- package/src/auth/index.ts +387 -0
- package/src/auth/issue.ts +52 -0
- package/src/auth/metadata.ts +149 -0
- package/src/auth/oauth.ts +882 -0
- package/src/auth/passkey.ts +556 -0
- package/src/auth/state.ts +213 -0
- package/src/auth/storage.ts +572 -0
- package/src/auth/token.ts +67 -0
- package/src/context/index.ts +240 -65
- package/src/cookie/index.ts +3 -0
- package/src/database/index.ts +1193 -0
- package/src/form/index.ts +1720 -0
- package/src/index.ts +10 -3
- package/src/jsx/elements.ts +45 -25
- package/src/jsx/index.ts +24 -69
- package/src/limiter/index.ts +221 -0
- package/src/markdown/index.ts +1322 -0
- package/src/markup/index.ts +853 -0
- package/src/mcp/conformance.2025-11-25.yml +39 -0
- package/src/mcp/conformance.2026-07-28.yml +56 -0
- package/src/mcp/index.ts +1262 -0
- package/src/middleware/index.ts +5 -6
- package/src/multipart/index.ts +360 -148
- package/src/route/index.ts +559 -278
- package/src/schema/index.ts +1542 -2256
- package/src/table/index.ts +387 -0
- package/src/trie/index.ts +4 -4
- package/src/util/index.ts +163 -49
- package/dist/render/index.d.ts +0 -79
- package/dist/render/index.d.ts.map +0 -1
- package/dist/render/index.js +0 -265
- package/src/render/index.ts +0 -318
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Context } from "../context/index.js";
|
|
2
|
+
import { Limit, Malformed } from "../multipart/index.js";
|
|
3
|
+
import { Size } from "../util/index.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Auth validation issue.
|
|
7
|
+
*
|
|
8
|
+
* Used for non-schema auth/passkey validation failures.
|
|
9
|
+
*/
|
|
10
|
+
export class Issue extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* Read the body in Auth's handlers, bounded in size. A body that is too
|
|
13
|
+
* large or not form data is answered like any other failed form.
|
|
14
|
+
*
|
|
15
|
+
* @template T Parsed form data
|
|
16
|
+
* @param c Request context
|
|
17
|
+
* @returns The parsed form data, or `null` for a body the client got wrong
|
|
18
|
+
* @throws Any other error
|
|
19
|
+
*/
|
|
20
|
+
static async data<T>(c: {
|
|
21
|
+
data: (options: { payload: number }) => Promise<T>;
|
|
22
|
+
}) {
|
|
23
|
+
try {
|
|
24
|
+
return await c.data({ payload: 128 * Size.kb });
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error instanceof Limit || error instanceof Malformed) return null;
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Answer a request over one of Auth's limits.
|
|
33
|
+
*
|
|
34
|
+
* @param c Request context
|
|
35
|
+
* @param seconds When to try again
|
|
36
|
+
*/
|
|
37
|
+
static limited(c: Pick<Context, "res" | "text">, seconds: number) {
|
|
38
|
+
c.res.headers.set("retry-after", String(seconds));
|
|
39
|
+
c.text("Too many authentication requests. Try again later.", 429);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a new auth issue.
|
|
44
|
+
*
|
|
45
|
+
* @param expected Expected auth value/state
|
|
46
|
+
*/
|
|
47
|
+
constructor(expected: string) {
|
|
48
|
+
super(`Invalid ${expected}`);
|
|
49
|
+
|
|
50
|
+
this.name = "Auth.Issue";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Codec, Mime, Size, Time } from "../util/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Fetches OAuth client ID metadata documents, from public addresses only.
|
|
6
|
+
*
|
|
7
|
+
* A client ID is a URL the agent chooses, so a hostname could resolve to the
|
|
8
|
+
* server's own network. The address is checked when the connection resolves
|
|
9
|
+
* it, so the name cannot pass the check and then resolve somewhere else.
|
|
10
|
+
* This needs Node.js or Bun, other runtimes cannot check the connection's
|
|
11
|
+
* address.
|
|
12
|
+
*/
|
|
13
|
+
export class Metadata {
|
|
14
|
+
/** Largest document, as the specification recommends */
|
|
15
|
+
static readonly #limit = 5 * Size.kb;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Special-use addresses, RFC 6890 and the IANA registries. IPv4-mapped
|
|
19
|
+
* addresses are checked against the IPv4 ranges, so `::ffff:0:0/96` is not
|
|
20
|
+
* listed, it would block every IPv4 address.
|
|
21
|
+
*/
|
|
22
|
+
static readonly #special = [
|
|
23
|
+
"0.0.0.0/8",
|
|
24
|
+
"10.0.0.0/8",
|
|
25
|
+
"100.64.0.0/10",
|
|
26
|
+
"127.0.0.0/8",
|
|
27
|
+
"169.254.0.0/16",
|
|
28
|
+
"172.16.0.0/12",
|
|
29
|
+
"192.0.0.0/24",
|
|
30
|
+
"192.0.2.0/24",
|
|
31
|
+
"192.88.99.0/24",
|
|
32
|
+
"192.168.0.0/16",
|
|
33
|
+
"198.18.0.0/15",
|
|
34
|
+
"198.51.100.0/24",
|
|
35
|
+
"203.0.113.0/24",
|
|
36
|
+
"224.0.0.0/4",
|
|
37
|
+
"240.0.0.0/4",
|
|
38
|
+
"::/128",
|
|
39
|
+
"::1/128",
|
|
40
|
+
"64:ff9b::/96",
|
|
41
|
+
"64:ff9b:1::/48",
|
|
42
|
+
"100::/64",
|
|
43
|
+
"2001::/23",
|
|
44
|
+
"2001:db8::/32",
|
|
45
|
+
"2002::/16",
|
|
46
|
+
"fc00::/7",
|
|
47
|
+
"fe80::/10",
|
|
48
|
+
"ff00::/8",
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
/** `true` in Node.js and Bun, where the connection's address can be checked */
|
|
52
|
+
static get supported() {
|
|
53
|
+
return /^(?:Node\.js|Bun)\//.test(navigator.userAgent);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param url Client ID
|
|
58
|
+
* @returns The parsed document, `undefined` when the host's answer is final,
|
|
59
|
+
* such as a 404 or an invalid document, or `null` when a retry may succeed:
|
|
60
|
+
* a timeout, a network error, or a 5xx or 429 response
|
|
61
|
+
*/
|
|
62
|
+
static async fetch(url: URL): Promise<unknown> {
|
|
63
|
+
const https = process.getBuiltinModule("node:https");
|
|
64
|
+
const dns = process.getBuiltinModule("node:dns");
|
|
65
|
+
const net = process.getBuiltinModule("node:net");
|
|
66
|
+
|
|
67
|
+
const family = (address: string) => (net.isIPv6(address) ? "ipv6" : "ipv4");
|
|
68
|
+
|
|
69
|
+
const blocked = new net.BlockList();
|
|
70
|
+
for (const subnet of Metadata.#special) {
|
|
71
|
+
const [address = "", prefix] = subnet.split("/");
|
|
72
|
+
blocked.addSubnet(address, Number(prefix), family(address));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const special = (address: string) =>
|
|
76
|
+
blocked.check(address, family(address));
|
|
77
|
+
|
|
78
|
+
// an address in the URL is connected to without a lookup
|
|
79
|
+
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
80
|
+
if (net.isIP(host) && special(host)) return;
|
|
81
|
+
|
|
82
|
+
// set when the failure is the host's final answer, not a passing one
|
|
83
|
+
let final = false;
|
|
84
|
+
|
|
85
|
+
const bytes = await new Promise<Uint8Array | undefined>((resolve) => {
|
|
86
|
+
// for the whole download, a response sent slowly cannot hold it open
|
|
87
|
+
const deadline = setTimeout(() => {
|
|
88
|
+
req.destroy();
|
|
89
|
+
done();
|
|
90
|
+
}, 5 * Time.second);
|
|
91
|
+
const done = (bytes?: Uint8Array) => {
|
|
92
|
+
clearTimeout(deadline);
|
|
93
|
+
resolve(bytes);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const req = https.get(
|
|
97
|
+
url,
|
|
98
|
+
{
|
|
99
|
+
// a new connection, a pooled one may not have had its address checked
|
|
100
|
+
agent: false,
|
|
101
|
+
headers: { accept: Mime.type.json },
|
|
102
|
+
lookup: (hostname, options, callback) =>
|
|
103
|
+
dns.lookup(hostname, { ...options, all: true }, (error, all) => {
|
|
104
|
+
if (error) return callback(error, "", 0);
|
|
105
|
+
if (!all.length || all.some(({ address }) => special(address))) {
|
|
106
|
+
final = true;
|
|
107
|
+
return callback(new Error("Special-use address"), "", 0);
|
|
108
|
+
}
|
|
109
|
+
if (options.all) return (callback as Function)(null, all);
|
|
110
|
+
callback(null, all[0]!.address, all[0]!.family);
|
|
111
|
+
}),
|
|
112
|
+
},
|
|
113
|
+
(res) => {
|
|
114
|
+
// redirects are not followed
|
|
115
|
+
if (res.statusCode !== 200) {
|
|
116
|
+
const status = res.statusCode ?? 0;
|
|
117
|
+
final = status < 500 && status !== 429;
|
|
118
|
+
res.destroy();
|
|
119
|
+
return done();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const chunks: Uint8Array[] = [];
|
|
123
|
+
let size = 0;
|
|
124
|
+
res.on("data", (chunk: Uint8Array) => {
|
|
125
|
+
if ((size += chunk.length) > Metadata.#limit) {
|
|
126
|
+
final = true;
|
|
127
|
+
res.destroy();
|
|
128
|
+
return done();
|
|
129
|
+
}
|
|
130
|
+
chunks.push(chunk);
|
|
131
|
+
});
|
|
132
|
+
res.on("end", () => done(Buffer.concat(chunks)));
|
|
133
|
+
// the first of these settles the download, closing early is a failure
|
|
134
|
+
res.on("close", () => done());
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
req.on("error", () => done());
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (!bytes) return final ? undefined : null;
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
// a document of `null` is invalid, not a passing failure
|
|
144
|
+
return JSON.parse(Codec.decode(bytes)) ?? undefined;
|
|
145
|
+
} catch {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|