toiljs 0.0.130 → 0.0.132

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.0.132] - 2026-10-19
4
+
5
+ - Declare the compiler-provided `AuthUser` type and `__toildbResolve` collection resolver in the shipped server globals so editors recognize them without application shims or generated lint output. Preserve custom `@user` fields through the generated principal declarations.
6
+
7
+ ## [v0.0.131] - 2026-10-19
8
+
9
+ - Preserve the browser Host header through the development Vite proxy so application origin-specific response policies, including localhost popup handoffs, receive the public origin instead of the internal loopback address. Retain multiple Set-Cookie headers, manual redirects, binary bodies, and HEAD handling.
10
+
3
11
  ## [v0.0.130] - 2026-10-19
4
12
 
5
13
  - Format browser security deployment instructions with colored headings and actions, aligned hosting guidance, and spaced rule blocks. Preserve complete copyable expressions and header values, generic project rules, and plain output when terminal colors are disabled.
@@ -1,3 +1,4 @@
1
+ import { request as httpRequest } from 'node:http';
1
2
  import { writeResponseHeader } from 'toiljs/backend';
2
3
  import { builtContentSecurityPolicy } from 'toiljs/shared';
3
4
  const SKIP_REQUEST_HEADERS = new Set([
@@ -20,28 +21,48 @@ const SKIP_RESPONSE_HEADERS = new Set([
20
21
  'transfer-encoding',
21
22
  ]);
22
23
  export async function proxyToVite(request, response, target) {
23
- const url = `http://${target.host}:${String(target.port)}${request.url}`;
24
- const headers = new Headers();
24
+ const headers = { 'accept-encoding': 'identity' };
25
25
  for (const [name, value] of Object.entries(request.headers)) {
26
26
  if (!SKIP_REQUEST_HEADERS.has(name.toLowerCase()))
27
- headers.set(name, value);
27
+ headers[name] = value;
28
28
  }
29
29
  const hasBody = request.method !== 'GET' && request.method !== 'HEAD';
30
30
  const body = hasBody ? await request.buffer() : undefined;
31
- const upstream = await fetch(url, {
32
- method: request.method === 'HEAD' ? 'GET' : request.method,
33
- headers,
34
- body: body && body.length > 0 ? new Uint8Array(body) : undefined,
35
- redirect: 'manual',
31
+ const upstream = await new Promise((resolve, reject) => {
32
+ const outgoing = httpRequest({
33
+ hostname: target.host,
34
+ port: target.port,
35
+ path: request.url,
36
+ method: request.method === 'HEAD' ? 'GET' : request.method,
37
+ headers,
38
+ }, (incoming) => {
39
+ const chunks = [];
40
+ incoming.on('data', (chunk) => chunks.push(chunk));
41
+ incoming.on('error', reject);
42
+ incoming.on('aborted', () => reject(new Error('Vite response aborted')));
43
+ incoming.on('end', () => resolve({
44
+ status: incoming.statusCode ?? 502,
45
+ headers: incoming.headers,
46
+ body: Buffer.concat(chunks),
47
+ }));
48
+ });
49
+ outgoing.on('error', reject);
50
+ outgoing.end(body);
36
51
  });
37
52
  response.status(upstream.status);
38
- upstream.headers.forEach((value, name) => {
39
- if (!SKIP_RESPONSE_HEADERS.has(name))
40
- writeResponseHeader(response, name, value);
41
- });
42
- const buf = Buffer.from(await upstream.arrayBuffer());
43
- if (upstream.headers.get('content-type')?.includes('text/html') &&
44
- !upstream.headers.has('content-security-policy')) {
53
+ for (const [name, value] of Object.entries(upstream.headers)) {
54
+ if (value === undefined || SKIP_RESPONSE_HEADERS.has(name))
55
+ continue;
56
+ if (name === 'set-cookie' && Array.isArray(value)) {
57
+ for (const cookie of value)
58
+ writeResponseHeader(response, name, cookie);
59
+ }
60
+ else
61
+ writeResponseHeader(response, name, Array.isArray(value) ? value.join(', ') : value);
62
+ }
63
+ const buf = upstream.body;
64
+ if (upstream.headers['content-type']?.includes('text/html') &&
65
+ !upstream.headers['content-security-policy']) {
45
66
  const policy = builtContentSecurityPolicy(buf.toString('utf8'));
46
67
  if (policy !== null)
47
68
  response.header('content-security-policy', policy, true);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "toiljs",
3
3
  "type": "module",
4
- "version": "0.0.130",
4
+ "version": "0.0.132",
5
5
  "author": "Dacely",
6
6
  "description": "The modern React framework: a file-based React frontend and a ToilScript-compiled WebAssembly backend.",
7
7
  "repository": {
@@ -33,5 +33,11 @@ declare class TwoFactorChallenge { token: string; status: EmailStatus; construct
33
33
  declare namespace TwoFactor { const DEFAULT_TTL_SECS: u64; const DEFAULT_DIGITS: i32; function setSecret(secret: Uint8Array): void; function issue(recipient: string, purpose: string, ttlSecs?: u64, digits?: i32): TwoFactorIssue; function send(recipient: string, purpose: string, ttlSecs?: u64, digits?: i32): TwoFactorChallenge; function verify(token: string, recipient: string, code: string): bool; }
34
34
  declare namespace AuthService { function deleteUser(id: ToilUserId, realm?: string): bool; function indexUsers(limit?: i32, cursor?: Uint8Array | null): Uint8Array | null; function onRegistered(handler: (id: ToilUserId, username: string, email: string) => void): void; const SESSION_COOKIE: string; const USER_COOKIE: string; const LOGIN_CONTEXT: string; const PUBLIC_KEY_LEN: i32; const SIGNATURE_LEN: i32; const DEFAULT_SESSION_TTL_SECS: u64; function setSecret(secret: Uint8Array): void; function hasSession(): bool; function getSessionBytes(): Uint8Array | null; function getUser(): __ToilAuthUser | null; function userId(): ToilUserId | null; function enable(): void; function mintSession(userData: Uint8Array, ttlSecs?: u64, generation?: u64): Cookie; function clearSession(): Cookie; function revokeSession(): void; function revokeUserSessions(userData: Uint8Array): void; function userCookie(userData: Uint8Array, ttlSecs?: u64): Cookie; function clearUserCookie(): Cookie; function buildLoginMessage(sub: string, aud: string, cid: Uint8Array, nonce: Uint8Array, iat: u64, exp: u64, ciphertext: Uint8Array, memKiB: u32, iterations: u32, parallelism: u32, serverKemKeyId: Uint8Array): Uint8Array; function verifyLogin(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): bool; const KEM_CIPHERTEXT_LEN: i32; const KEM_SECRET_KEY_LEN: i32; const KEM_PUBLIC_KEY_LEN: i32; const SHARED_SECRET_LEN: i32; const OPRF_ELEMENT_LEN: i32; const OPRF_SEED_LEN: i32; const SESSION_KEY_LABEL: string; const SERVER_CONFIRM_LABEL: string; function setOprfSeed(seed: Uint8Array): void; function setServerKemSecretKey(secretKey: Uint8Array): void; function setServerKemPublicKey(publicKey: Uint8Array): void; function serverKemKeyId(): Uint8Array; function oprfEvaluate(username: string, blinded: Uint8Array): Uint8Array; function mlkemDecapsulate(ciphertext: Uint8Array): Uint8Array; function sha256(data: Uint8Array): Uint8Array; function deriveSessionKey(sharedSecret: Uint8Array, transcriptHash: Uint8Array): Uint8Array; function serverConfirmTag(sessionKey: Uint8Array, transcriptHash: Uint8Array): Uint8Array; const REGISTER_CONTEXT: string; function buildRegisterMessage(username: string, publicKey: Uint8Array): Uint8Array; function verifyRegister(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): bool; }
35
35
  interface __ToilAuthUser { toilUserId: Uint8Array; username: string; }
36
+
37
+ /** Authenticated principal, extended by the compiler's generated @user declarations. */
38
+ type AuthUser = __ToilAuthUser;
36
39
  declare class ToilUserId { w0: u64; w1: u64; w2: u64; w3: u64; constructor(w0?: u64, w1?: u64, w2?: u64, w3?: u64); static derive(mldsaPublicKey: Uint8Array, identifier: string, domain: string): ToilUserId; static fromBytes(b: Uint8Array): ToilUserId; toBytes(): Uint8Array; toHex(): string; isZero(): bool; equals(other: ToilUserId): bool; }
37
40
  declare function __toilEncodeAuthUser(toilUserId: Uint8Array, username: string): Uint8Array;
41
+
42
+ /** Resolve a collection name to the host handle used by compiler-generated database bindings. */
43
+ declare function __toildbResolve(name: string): u32;