@ilha/router 0.11.3 → 0.11.4
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 +75 -66
- package/dist/codegen.d.ts +3 -3
- package/dist/hash.d.ts +13 -9
- package/dist/head-BLtm0xtK.js +342 -0
- package/dist/head.d.ts +42 -28
- package/dist/http.d.ts +1 -1
- package/dist/index.d.ts +52 -55
- package/dist/index.js +339 -305
- package/dist/plugin-DCdQ9yO8.js +1140 -0
- package/dist/plugin.d.ts +15 -15
- package/dist/request-scope.d.ts +3 -5
- package/dist/route-error.d.ts +6 -0
- package/dist/route-match.d.ts +3 -3
- package/dist/rsbuild.d.ts +3 -3
- package/dist/rsbuild.js +2 -4
- package/dist/server-island.d.ts +26 -15
- package/dist/server-island.js +166 -136
- package/dist/server-islands.d.ts +15 -14
- package/dist/snapshot-XpAkSV8s.js +57 -0
- package/dist/snapshot.d.ts +15 -2
- package/dist/{ssr-CV_vNpS3.js → ssr-Dvq_qXs4.js} +170 -142
- package/dist/ssr.d.ts +38 -39
- package/dist/ssr.js +2 -2
- package/dist/vite.d.ts +3 -3
- package/dist/vite.js +2 -4
- package/oxlint.cjs +201 -122
- package/package.json +3 -3
- package/dist/head-DpYV3bHH.js +0 -285
- package/dist/plugin-Bfnn44nu.js +0 -1034
- package/dist/snapshot-C0E2OGwL.js +0 -55
package/dist/ssr.d.ts
CHANGED
|
@@ -15,26 +15,19 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import * as Effect from "effect/Effect";
|
|
17
17
|
import * as Result from "effect/Result";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* instance — same pattern as `request-scope.ts`.
|
|
25
|
-
*
|
|
26
|
-
* `.server` modules self-register when the plugin appends registration code
|
|
27
|
-
* to their server-graph copy; the `/__ilha/frame` handler below consumes the
|
|
28
|
-
* registry to re-render an island from a client state snapshot. Server pages
|
|
29
|
-
* additionally register their `load` and route pattern so frame handlers can
|
|
30
|
-
* run the loader with matched params.
|
|
31
|
-
*/
|
|
18
|
+
import type { SnapshotObject, SnapshotValue } from "./snapshot";
|
|
19
|
+
/** JSON payload for frame envelopes. */
|
|
20
|
+
export type FrameJsonValue = string | number | boolean | null | FrameJsonValue[] | FrameJsonObject;
|
|
21
|
+
export interface FrameJsonObject {
|
|
22
|
+
readonly [key: string]: FrameJsonValue | undefined;
|
|
23
|
+
}
|
|
32
24
|
/** A frame render: optionally preceded by running the page's `load`. */
|
|
33
25
|
export interface ServerIslandEntry {
|
|
34
26
|
/** Returns the renderState fn (`Symbol.for("ilha.renderState")` getter). */
|
|
35
|
-
render: () =>
|
|
27
|
+
render: () => ServerIslandRenderFn;
|
|
36
28
|
}
|
|
37
|
-
export type
|
|
29
|
+
export type ServerIslandRenderFn = (props?: SnapshotObject) => string | Promise<string> | object;
|
|
30
|
+
export type FrameGuard = (request: Request) => Response | undefined | Promise<Response | undefined>;
|
|
38
31
|
/**
|
|
39
32
|
* Install a guard consulted by every `/__ilha/frame` request (dev middleware
|
|
40
33
|
* and the production `@ilha/router/ssr` handler share this slot — both read
|
|
@@ -42,8 +35,8 @@ export type FrameGuard = (request: Request) => Response | void | Promise<Respons
|
|
|
42
35
|
* allow. Island state is world-readable through frames unless you gate them,
|
|
43
36
|
* so apps serving private data should install a session check here.
|
|
44
37
|
*/
|
|
45
|
-
export declare
|
|
46
|
-
export declare
|
|
38
|
+
export declare const setFrameGuard: (guard: FrameGuard) => void;
|
|
39
|
+
export declare const getFrameGuard: () => FrameGuard | undefined;
|
|
47
40
|
/** Frame-authorization policy, installed via {@link setFrameAuth}. */
|
|
48
41
|
export interface FrameAuthPolicy {
|
|
49
42
|
/**
|
|
@@ -71,8 +64,8 @@ export interface FrameAuthPolicy {
|
|
|
71
64
|
* `@ilha/router/ssr` handler. `trustedOrigins` and `csrf` are also applied by
|
|
72
65
|
* the dev middleware (via `IlhaPagesOptions`).
|
|
73
66
|
*/
|
|
74
|
-
export declare
|
|
75
|
-
export declare
|
|
67
|
+
export declare const setFrameAuth: (policy: FrameAuthPolicy) => void;
|
|
68
|
+
export declare const getFrameAuth: () => FrameAuthPolicy | undefined;
|
|
76
69
|
/**
|
|
77
70
|
* Same-origin check for frame/loader requests. Browsers always send `Origin`
|
|
78
71
|
* on cross-origin and same-origin `POST`; its absence implies a non-browser
|
|
@@ -80,39 +73,40 @@ export declare function getFrameAuth(): FrameAuthPolicy | undefined;
|
|
|
80
73
|
* present it must match the configured trusted origins, else the request's
|
|
81
74
|
* own `Host`.
|
|
82
75
|
*/
|
|
83
|
-
export declare
|
|
76
|
+
export declare const isTrustedOrigin: (request: Request, policy: FrameAuthPolicy | undefined) => boolean;
|
|
84
77
|
/**
|
|
85
78
|
* Path-only route context for frame/loader scoped requests. Leading slash,
|
|
86
79
|
* no `//` or backslash (WHATWG URLs treat `\` as `/` for http(s), so a
|
|
87
80
|
* `\evil.com` prefix would smuggle a foreign authority past a plain `//`
|
|
88
81
|
* check), bounded length. `false` for anything else.
|
|
89
82
|
*/
|
|
90
|
-
export declare
|
|
83
|
+
export declare const isSafeFramePath: (framePath: string) => boolean;
|
|
91
84
|
/**
|
|
92
85
|
* Build the scoped frame render URL from the incoming request URL and frame
|
|
93
86
|
* path. Absolute `incomingUrl` values supply the origin. Relative values (for
|
|
94
87
|
* example Vite's `req.url`) require an explicit trusted `serverOrigin` — never
|
|
95
88
|
* a client `Host` header.
|
|
96
89
|
*/
|
|
97
|
-
export declare
|
|
90
|
+
export declare const frameScopedUrl: (incomingUrl: string, framePath: string, serverOrigin?: string) => string;
|
|
91
|
+
type HeaderSource = Headers | Readonly<Record<string, string | string[] | undefined>>;
|
|
98
92
|
/**
|
|
99
93
|
* Copy identity headers (cookie, authorization, user-agent) onto a fresh
|
|
100
94
|
* `Headers`. Accepts a `Headers` or a Node `IncomingHttpHeaders`-style plain
|
|
101
95
|
* object. Client-supplied `x-forwarded-for` is deliberately NOT forwarded —
|
|
102
96
|
* it is spoofable and must not be trusted by loaders for IP checks.
|
|
103
97
|
*/
|
|
104
|
-
export declare
|
|
98
|
+
export declare const forwardIdentityHeaders: (source: HeaderSource) => Headers;
|
|
105
99
|
/** No-store JSON envelope shared by dev and production frame handlers. */
|
|
106
100
|
export interface FrameEnvelope {
|
|
107
101
|
status: number;
|
|
108
102
|
headers: Record<string, string>;
|
|
109
103
|
body: string;
|
|
110
104
|
}
|
|
111
|
-
export declare
|
|
112
|
-
/**
|
|
113
|
-
export declare
|
|
114
|
-
export declare
|
|
115
|
-
export declare
|
|
105
|
+
export declare const frameEnvelope: (status: number, body: FrameJsonObject) => FrameEnvelope;
|
|
106
|
+
/** Brand an exported server action with its generated RPC transport key. */
|
|
107
|
+
export declare const __ilhaServerAction: <A extends SnapshotValue[], R>(key: string, fn: (...args: A) => R | Promise<R>) => import("oxidejs").ServerActionHandle<A, Awaited<Awaited<R>>>;
|
|
108
|
+
export declare const registerServerIsland: (id: string, render: () => ServerIslandRenderFn) => void;
|
|
109
|
+
export declare const getServerIslandEntry: (id: string) => ServerIslandEntry | undefined;
|
|
116
110
|
declare const FrameError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
117
111
|
readonly _tag: "FrameError";
|
|
118
112
|
} & Readonly<A>;
|
|
@@ -127,21 +121,21 @@ export declare class FrameError extends FrameError_base<{
|
|
|
127
121
|
* Render a registered server island. Typed error channel: the only failure is
|
|
128
122
|
* `FrameError`; everything else is a defect surfaced as a 400 to the client.
|
|
129
123
|
*/
|
|
130
|
-
export declare
|
|
124
|
+
export declare const renderServerIsland: (id: string, request: Request, runWithScope: <T>(request: Request, fn: () => T) => T | Promise<T>, incomingProps?: SnapshotObject) => Effect.Effect<string, FrameError>;
|
|
131
125
|
/** Convenience for non-Effect callers: run the render and resolve to a Result. */
|
|
132
|
-
export declare
|
|
126
|
+
export declare const renderServerIslandResult: (id: string, request: Request, runWithScope: <T>(request: Request, fn: () => T) => T | Promise<T>, incomingProps?: SnapshotObject) => Promise<Result.Result<string, FrameError>>;
|
|
133
127
|
export declare const FRAME_ENDPOINT = "/__ilha/frame";
|
|
134
128
|
/** Max request body size — matches the dev middleware cap. */
|
|
135
129
|
export declare const MAX_BODY: number;
|
|
136
130
|
/** Parent-island props on a frame POST. Missing is fine; anything else is 400. */
|
|
137
|
-
export declare
|
|
138
|
-
export declare
|
|
131
|
+
export declare const parseFrameProps: <T>(value?: T) => SnapshotObject | undefined;
|
|
132
|
+
export declare const json: (status: number, body: FrameJsonObject) => Response;
|
|
139
133
|
/**
|
|
140
134
|
* Read a request body as UTF-8, streaming it with a hard byte cap. Returns
|
|
141
135
|
* `null` when the body exceeds `maxBytes` (the reader is cancelled before the
|
|
142
136
|
* cap is far exceeded) or when decoding fails.
|
|
143
137
|
*/
|
|
144
|
-
export declare
|
|
138
|
+
export declare const readBodyBounded: (request: Request, maxBytes: number) => Promise<string | null>;
|
|
145
139
|
/**
|
|
146
140
|
* Shared frame-request authorization used by both the production handler
|
|
147
141
|
* below and the Vite/Rsbuild dev middleware: same-origin check against the
|
|
@@ -152,15 +146,20 @@ export declare function readBodyBounded(request: Request, maxBytes: number): Pro
|
|
|
152
146
|
* Returns the forwarded identity headers on success so callers render frames
|
|
153
147
|
* with cookie/auth/UA context, or the HTTP status to reject with.
|
|
154
148
|
*/
|
|
155
|
-
export declare
|
|
149
|
+
export declare const authorizeFrameRequest: (request: Request, options: {
|
|
156
150
|
defaultAction: "open" | "deny";
|
|
157
|
-
onGuardError?: (error:
|
|
158
|
-
})
|
|
151
|
+
onGuardError?: <E>(error: E) => void;
|
|
152
|
+
}) => Promise<{
|
|
159
153
|
ok: true;
|
|
160
154
|
identityHeaders: Headers;
|
|
161
155
|
} | {
|
|
162
156
|
ok: false;
|
|
163
157
|
status: number;
|
|
164
158
|
}>;
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
/** Side-effect imports required alongside this handler. */
|
|
160
|
+
interface SsrMiddleware {
|
|
161
|
+
(request: Request): Promise<Response | undefined>;
|
|
162
|
+
imports: string[];
|
|
163
|
+
}
|
|
164
|
+
declare const ssrWithImports: SsrMiddleware;
|
|
165
|
+
export default ssrWithImports;
|
package/dist/ssr.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { S as
|
|
1
|
+
import { S as ssrWithImports, _ as registerServerIsland, a as authorizeFrameRequest, b as setFrameAuth, c as frameScopedUrl, d as getServerIslandEntry, f as isSafeFramePath, g as readBodyBounded, h as parseFrameProps, i as __ilhaServerAction, l as getFrameAuth, m as json, n as FrameError, o as forwardIdentityHeaders, p as isTrustedOrigin, r as MAX_BODY, s as frameEnvelope, t as FRAME_ENDPOINT, u as getFrameGuard, v as renderServerIsland, x as setFrameGuard, y as renderServerIslandResult } from "./ssr-Dvq_qXs4.js";
|
|
2
2
|
|
|
3
|
-
export { FRAME_ENDPOINT, FrameError, MAX_BODY, __ilhaServerAction, authorizeFrameRequest,
|
|
3
|
+
export { FRAME_ENDPOINT, FrameError, MAX_BODY, __ilhaServerAction, authorizeFrameRequest, ssrWithImports as default, forwardIdentityHeaders, frameEnvelope, frameScopedUrl, getFrameAuth, getFrameGuard, getServerIslandEntry, isSafeFramePath, isTrustedOrigin, json, parseFrameProps, readBodyBounded, registerServerIsland, renderServerIsland, renderServerIslandResult, setFrameAuth, setFrameGuard };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
-
|
|
2
|
+
import type { IlhaPagesOptions } from "./plugin";
|
|
3
|
+
export type { LayoutHandler, ErrorHandler, RouteSnapshot, AppError, } from "./index";
|
|
3
4
|
export { ilhaPages, type IlhaPagesOptions } from "./plugin";
|
|
4
|
-
import { type IlhaPagesOptions } from "./plugin";
|
|
5
5
|
/** Vite plugin — use via `@ilha/router/vite`. */
|
|
6
|
-
export declare
|
|
6
|
+
export declare const pages: (options?: IlhaPagesOptions) => Plugin;
|
|
7
7
|
export default pages;
|
package/dist/vite.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { t as ilhaPages } from "./plugin-
|
|
1
|
+
import { t as ilhaPages } from "./plugin-DCdQ9yO8.js";
|
|
2
2
|
|
|
3
3
|
//#region src/vite.ts
|
|
4
4
|
/** Vite plugin — use via `@ilha/router/vite`. */
|
|
5
|
-
|
|
6
|
-
return ilhaPages.vite(options);
|
|
7
|
-
}
|
|
5
|
+
const pages = (options = {}) => ilhaPages.vite(options);
|
|
8
6
|
|
|
9
7
|
//#endregion
|
|
10
8
|
export { pages as default, pages, ilhaPages };
|