ovr 6.2.4 → 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.
Files changed (136) hide show
  1. package/README.md +3 -1
  2. package/dist/app/index.d.ts +51 -7
  3. package/dist/app/index.d.ts.map +1 -1
  4. package/dist/app/index.js +163 -28
  5. package/dist/auth/auth-data.d.ts +26 -0
  6. package/dist/auth/auth-data.d.ts.map +1 -0
  7. package/dist/auth/auth-data.js +42 -0
  8. package/dist/auth/cbor.d.ts +50 -0
  9. package/dist/auth/cbor.d.ts.map +1 -0
  10. package/dist/auth/cbor.js +200 -0
  11. package/dist/auth/client-source.d.ts +3 -0
  12. package/dist/auth/client-source.d.ts.map +1 -0
  13. package/dist/auth/client-source.js +3 -0
  14. package/dist/auth/client.d.ts +3 -0
  15. package/dist/auth/client.d.ts.map +1 -0
  16. package/dist/auth/client.js +186 -0
  17. package/dist/auth/configure.d.ts +28 -0
  18. package/dist/auth/configure.d.ts.map +1 -0
  19. package/dist/auth/configure.js +228 -0
  20. package/dist/auth/der.d.ts +6 -0
  21. package/dist/auth/der.d.ts.map +1 -0
  22. package/dist/auth/der.js +36 -0
  23. package/dist/auth/index.d.ts +242 -0
  24. package/dist/auth/index.d.ts.map +1 -0
  25. package/dist/auth/index.js +152 -0
  26. package/dist/auth/issue.d.ts +36 -0
  27. package/dist/auth/issue.d.ts.map +1 -0
  28. package/dist/auth/issue.js +47 -0
  29. package/dist/auth/metadata.d.ts +22 -0
  30. package/dist/auth/metadata.d.ts.map +1 -0
  31. package/dist/auth/metadata.js +134 -0
  32. package/dist/auth/oauth.d.ts +29 -0
  33. package/dist/auth/oauth.d.ts.map +1 -0
  34. package/dist/auth/oauth.js +724 -0
  35. package/dist/auth/passkey.d.ts +101 -0
  36. package/dist/auth/passkey.d.ts.map +1 -0
  37. package/dist/auth/passkey.js +393 -0
  38. package/dist/auth/state.d.ts +49 -0
  39. package/dist/auth/state.d.ts.map +1 -0
  40. package/dist/auth/state.js +184 -0
  41. package/dist/auth/storage.d.ts +193 -0
  42. package/dist/auth/storage.d.ts.map +1 -0
  43. package/dist/auth/storage.js +410 -0
  44. package/dist/auth/token.d.ts +12 -0
  45. package/dist/auth/token.d.ts.map +1 -0
  46. package/dist/auth/token.js +39 -0
  47. package/dist/context/index.d.ts +86 -16
  48. package/dist/context/index.d.ts.map +1 -1
  49. package/dist/context/index.js +166 -42
  50. package/dist/cookie/index.d.ts +3 -0
  51. package/dist/cookie/index.d.ts.map +1 -1
  52. package/dist/cookie/index.js +1 -0
  53. package/dist/database/index.d.ts +262 -0
  54. package/dist/database/index.d.ts.map +1 -0
  55. package/dist/database/index.js +807 -0
  56. package/dist/form/index.d.ts +699 -0
  57. package/dist/form/index.d.ts.map +1 -0
  58. package/dist/form/index.js +901 -0
  59. package/dist/index.d.ts +10 -3
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +9 -3
  62. package/dist/jsx/elements.d.ts +28 -2
  63. package/dist/jsx/elements.d.ts.map +1 -1
  64. package/dist/jsx/index.d.ts +20 -4
  65. package/dist/jsx/index.d.ts.map +1 -1
  66. package/dist/jsx/index.js +6 -65
  67. package/dist/limiter/index.d.ts +65 -0
  68. package/dist/limiter/index.d.ts.map +1 -0
  69. package/dist/limiter/index.js +157 -0
  70. package/dist/markdown/index.d.ts +61 -0
  71. package/dist/markdown/index.d.ts.map +1 -0
  72. package/dist/markdown/index.js +1160 -0
  73. package/dist/markup/index.d.ts +188 -0
  74. package/dist/markup/index.d.ts.map +1 -0
  75. package/dist/markup/index.js +718 -0
  76. package/dist/mcp/index.d.ts +73 -0
  77. package/dist/mcp/index.d.ts.map +1 -0
  78. package/dist/mcp/index.js +988 -0
  79. package/dist/middleware/index.d.ts +3 -4
  80. package/dist/middleware/index.d.ts.map +1 -1
  81. package/dist/multipart/index.d.ts +53 -7
  82. package/dist/multipart/index.d.ts.map +1 -1
  83. package/dist/multipart/index.js +332 -124
  84. package/dist/route/index.d.ts +226 -80
  85. package/dist/route/index.d.ts.map +1 -1
  86. package/dist/route/index.js +239 -99
  87. package/dist/schema/index.d.ts +307 -734
  88. package/dist/schema/index.d.ts.map +1 -1
  89. package/dist/schema/index.js +783 -1050
  90. package/dist/table/index.d.ts +132 -0
  91. package/dist/table/index.d.ts.map +1 -0
  92. package/dist/table/index.js +188 -0
  93. package/dist/trie/index.js +4 -4
  94. package/dist/util/index.d.ts +37 -5
  95. package/dist/util/index.d.ts.map +1 -1
  96. package/dist/util/index.js +156 -41
  97. package/package.json +11 -4
  98. package/src/app/index.ts +230 -42
  99. package/src/auth/auth-data.ts +56 -0
  100. package/src/auth/cbor.ts +231 -0
  101. package/src/auth/client-source.ts +3 -0
  102. package/src/auth/client.ts +205 -0
  103. package/src/auth/configure.ts +279 -0
  104. package/src/auth/der.ts +35 -0
  105. package/src/auth/index.ts +387 -0
  106. package/src/auth/issue.ts +52 -0
  107. package/src/auth/metadata.ts +149 -0
  108. package/src/auth/oauth.ts +882 -0
  109. package/src/auth/passkey.ts +556 -0
  110. package/src/auth/state.ts +213 -0
  111. package/src/auth/storage.ts +572 -0
  112. package/src/auth/token.ts +67 -0
  113. package/src/context/index.ts +240 -65
  114. package/src/cookie/index.ts +3 -0
  115. package/src/database/index.ts +1193 -0
  116. package/src/form/index.ts +1720 -0
  117. package/src/index.ts +10 -3
  118. package/src/jsx/elements.ts +45 -25
  119. package/src/jsx/index.ts +24 -69
  120. package/src/limiter/index.ts +221 -0
  121. package/src/markdown/index.ts +1322 -0
  122. package/src/markup/index.ts +853 -0
  123. package/src/mcp/conformance.2025-11-25.yml +39 -0
  124. package/src/mcp/conformance.2026-07-28.yml +56 -0
  125. package/src/mcp/index.ts +1262 -0
  126. package/src/middleware/index.ts +5 -6
  127. package/src/multipart/index.ts +410 -158
  128. package/src/route/index.ts +559 -278
  129. package/src/schema/index.ts +1542 -2256
  130. package/src/table/index.ts +387 -0
  131. package/src/trie/index.ts +4 -4
  132. package/src/util/index.ts +163 -49
  133. package/dist/render/index.d.ts +0 -79
  134. package/dist/render/index.d.ts.map +0 -1
  135. package/dist/render/index.js +0 -257
  136. package/src/render/index.ts +0 -314
@@ -0,0 +1,213 @@
1
+ import { type Context as ContextType, agent } from "../context/index.js";
2
+ import { Codec, Time, noStore } from "../util/index.js";
3
+ import type { Auth } from "./index.js";
4
+ import { Issue } from "./issue.js";
5
+ import type { Storage } from "./storage.js";
6
+ import { Token } from "./token.js";
7
+
8
+ export namespace State {
9
+ /** Session persistence and signing configuration used by internal request state. */
10
+ export type Options = Pick<
11
+ Auth.Options,
12
+ "secret" | "origin" | "idle" | "lifetime"
13
+ > &
14
+ Pick<Storage, "challenges" | "sessions">;
15
+ /** Internal capabilities needed for request-local authentication state. */
16
+ export type Context = Pick<Auth.Context, "url" | "cookie" | "res">;
17
+ }
18
+
19
+ /** Internal authentication state for exactly one service and request. */
20
+ export class State {
21
+ static readonly #cookie = "__Host-auth-session";
22
+ static readonly #binding = "__Host-auth-browser";
23
+ static readonly #return = "__Host-auth-return";
24
+ readonly #c: State.Context;
25
+ #browser: string | undefined;
26
+ #session: Promise<Auth.Session | null> | undefined;
27
+
28
+ /** Normalized authentication configuration. */
29
+ readonly options;
30
+
31
+ /** Create authentication helpers for the current request. */
32
+ constructor(c: State.Context, options: State.Options) {
33
+ this.#c = c;
34
+ const lifetime = options.lifetime ?? 30 * Time.day;
35
+ this.options = {
36
+ ...options,
37
+ lifetime,
38
+ // a session never outlives its lifetime, however recently it was used
39
+ idle: Math.min(options.idle ?? Time.week, lifetime),
40
+ };
41
+ }
42
+
43
+ /**
44
+ * A request on another host has no session there, its cookies are bound to
45
+ * Auth's origin, and passkeys cannot be used on it.
46
+ *
47
+ * @throws When the request is not on Auth's origin
48
+ */
49
+ #origin() {
50
+ if (this.#c.url.origin !== this.options.origin)
51
+ throw new Error(
52
+ `Auth serves ${this.options.origin}, this request is for ${this.#c.url.origin}`,
53
+ );
54
+ }
55
+
56
+ /** Read a browser binding; create it only while preparing a form in the handler. */
57
+ browser(create = false) {
58
+ if (create) this.#origin();
59
+ this.#browser ??= this.#c.cookie.get(State.#binding);
60
+ if (!this.#browser && create) {
61
+ this.#browser = crypto.randomUUID();
62
+ this.#set(State.#binding, this.#browser);
63
+ }
64
+ return this.#browser;
65
+ }
66
+
67
+ /**
68
+ * Set one of Auth's cookies, which only its origin's server reads.
69
+ *
70
+ * @param name Cookie name
71
+ * @param value Cookie value
72
+ * @param options How long it lasts, a browser session without it
73
+ */
74
+ #set(name: string, value: string, options?: { maxAge: number }) {
75
+ this.#c.cookie.set(name, value, {
76
+ secure: true,
77
+ httpOnly: true,
78
+ sameSite: "Lax",
79
+ ...options,
80
+ });
81
+ }
82
+
83
+ #clear() {
84
+ noStore(this.#c.res.headers);
85
+ this.#set(State.#cookie, "", { maxAge: 0 });
86
+ }
87
+
88
+ async #read() {
89
+ // an agent's tool call, authorized by its token
90
+ const { req } = this.#c as Partial<Pick<ContextType, "req">>;
91
+ const call = req && agent.get(req);
92
+ if (call?.session) return call.session as Auth.Session;
93
+
94
+ // nobody is signed in on another host, its session cookie is not sent there
95
+ if (this.#c.url.origin !== this.options.origin) return null;
96
+
97
+ noStore(this.#c.res.headers);
98
+ const cookie = this.#c.cookie.get(State.#cookie);
99
+ if (!cookie) return null;
100
+ let id: string;
101
+ try {
102
+ id = await Token.open(this.options.secret, "session", cookie);
103
+ } catch (e) {
104
+ if (!(e instanceof Issue)) throw e;
105
+ this.#clear();
106
+ return null;
107
+ }
108
+ // Storage failures must propagate, rather than appear to be successful logouts.
109
+ const session = await this.options.sessions.get(id);
110
+ const now = Date.now();
111
+ if (
112
+ session &&
113
+ session.id === id &&
114
+ session.expiration > now &&
115
+ session.started + this.options.lifetime > now
116
+ )
117
+ return this.#renew(session, now);
118
+ this.#clear();
119
+ return null;
120
+ }
121
+
122
+ /**
123
+ * Extend a session that is being used, up to its lifetime. Only the record
124
+ * changes: the cookie lasts the whole lifetime, so a renewal sets no header
125
+ * and works after the response has started streaming.
126
+ *
127
+ * @param session Valid stored session
128
+ * @param now Current time
129
+ * @returns The session with its current expiration
130
+ */
131
+ async #renew(session: Storage.Session, now: number): Promise<Auth.Session> {
132
+ const { idle, lifetime } = this.options;
133
+ let { expiration } = session;
134
+ const later = Math.min(now + idle, session.started + lifetime);
135
+ // at most once a day, or each half of a shorter idle timeout
136
+ const renewed = expiration - idle;
137
+ if (now - renewed >= Math.min(Time.day, idle / 2) && later > expiration) {
138
+ await this.options.sessions.renew(session.id, later);
139
+ expiration = later;
140
+ }
141
+ return { id: session.id, user: session.user, expiration };
142
+ }
143
+
144
+ /** Read a non-expired, non-revoked session, renewing it while it is used. */
145
+ session() {
146
+ return (this.#session ??= this.#read());
147
+ }
148
+
149
+ /**
150
+ * Return to a local path after the next login, such as an agent's
151
+ * authorization request.
152
+ *
153
+ * @param path Local path with its query
154
+ */
155
+ remember(path: string) {
156
+ this.#origin();
157
+ this.#set(State.#return, path, {
158
+ maxAge: Math.floor((15 * Time.minute) / Time.second),
159
+ });
160
+ }
161
+
162
+ /**
163
+ * @param fallback Destination without a remembered path
164
+ * @returns The remembered path, cleared, or the fallback
165
+ */
166
+ resume(fallback: string) {
167
+ this.#origin();
168
+ const path = this.#c.cookie.get(State.#return);
169
+ if (!path) return fallback;
170
+
171
+ this.#set(State.#return, "", { maxAge: 0 });
172
+
173
+ return path.startsWith("/") &&
174
+ !path.startsWith("//") &&
175
+ !path.includes("\\")
176
+ ? path
177
+ : fallback;
178
+ }
179
+
180
+ /** Replace the current session and issue a new signed, secure cookie. */
181
+ async login(user: string) {
182
+ this.#origin();
183
+ if (!user.trim() || Codec.encode(user).length > 1024)
184
+ throw new TypeError("Auth user ID must contain 1 to 1024 UTF-8 bytes");
185
+ const previous = await this.session();
186
+ if (previous) await this.options.sessions.delete(previous.id);
187
+ const now = Date.now();
188
+ const session = {
189
+ id: crypto.randomUUID(),
190
+ user,
191
+ expiration: now + this.options.idle,
192
+ };
193
+ await this.options.sessions.set(session.id, { ...session, started: now });
194
+ this.#set(
195
+ State.#cookie,
196
+ await Token.seal(this.options.secret, "session", session.id),
197
+ // renewals only change the record, so the cookie covers the lifetime
198
+ { maxAge: Math.floor(this.options.lifetime / Time.second) },
199
+ );
200
+ this.#session = Promise.resolve(session);
201
+ return session;
202
+ }
203
+
204
+ /** Revoke the current session and expire its cookie. Always await this method. */
205
+ async logout() {
206
+ this.#origin();
207
+ const session = await this.session();
208
+ if (session) await this.options.sessions.delete(session.id);
209
+ this.#clear();
210
+ this.#session = Promise.resolve(null);
211
+ return null;
212
+ }
213
+ }