noofpi 2.0.1 → 3.1.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 +6 -2
- package/client.d.ts +2 -0
- package/dist/build-YRW44BZG.js +212 -0
- package/dist/{chunk-YJVMBHNL.js → chunk-JUVQEKLE.js} +43 -12
- package/dist/chunk-LJEKK4AK.js +51 -0
- package/dist/chunk-O5JRC252.js +245 -0
- package/dist/{chunk-G35DW4NA.js → chunk-PC3ZJN4D.js} +11 -1
- package/dist/{chunk-NHBXVKEQ.js → chunk-PL3CA2JF.js} +160 -86
- package/dist/{chunk-MN5PVHC5.js → chunk-W7ASRDAJ.js} +229 -7
- package/dist/{chunk-IE3WF5XF.js → chunk-YN4TKMDX.js} +87 -4
- package/dist/chunk-YN64WQ2B.js +562 -0
- package/dist/cli.js +21 -9
- package/dist/{dev-OAGCOGHA.js → dev-A7VK5V4H.js} +7 -6
- package/dist/{devtools-PLUN2DYV.js → devtools-C3PFU57C.js} +1 -1
- package/dist/handler-oYl9j0Qa.d.ts +26 -0
- package/dist/index.d.ts +26 -11
- package/dist/index.js +3 -2
- package/dist/payload-DfhHnXAn.d.ts +66 -0
- package/dist/{prepare-BN7NMCVQ.js → prepare-JT2NPD5S.js} +6 -5
- package/dist/runtime/entry-client.js +4 -4
- package/dist/runtime/entry-server.d.ts +6 -4
- package/dist/runtime/entry-server.js +88 -25
- package/dist/runtime/index.d.ts +24 -6
- package/dist/runtime/index.js +5 -3
- package/dist/server/bun.d.ts +3 -3
- package/dist/server/index.d.ts +35 -7
- package/dist/server/index.js +12 -7
- package/dist/server/node.d.ts +3 -3
- package/dist/session-CLvYihOU.d.ts +275 -0
- package/dist/{start-ITRND3BY.js → start-J6ZIUG66.js} +7 -6
- package/dist/{types-B6rQOOxS.d.ts → types-Czld0vOH.d.ts} +30 -5
- package/package.json +12 -7
- package/dist/build-WPHZ7TYZ.js +0 -49
- package/dist/chunk-MTXQR32N.js +0 -8
- package/dist/chunk-X3DYEZLK.js +0 -253
- package/dist/handler-C6NnwBfC.d.ts +0 -17
- package/dist/payload-CL6tYBin.d.ts +0 -121
- package/dist/route-rules-COilNsVT.d.ts +0 -127
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
declare const FETCH_MODES: readonly ["dfetch", "pfetch", "lfetch", "sfetch"];
|
|
2
|
+
/**
|
|
3
|
+
* - `dfetch`: client -> doofpi API directly
|
|
4
|
+
* - `pfetch`: client -> noofpi server (proxy) -> doofpi API
|
|
5
|
+
* - `lfetch`: client -> noofpi's own doofpi API (`server/doofpi.ts`)
|
|
6
|
+
* - `sfetch`: server only, never from the browser
|
|
7
|
+
*/
|
|
8
|
+
type FetchMode = (typeof FETCH_MODES)[number];
|
|
9
|
+
|
|
10
|
+
type HeadAttrValue = string | number | boolean | null | undefined;
|
|
11
|
+
/** Attributes of a tag: `{ name: "description", content: "..." }`. `true` renders a bare attribute, `false`/`null`/`undefined` omit it */
|
|
12
|
+
type HeadTag = Record<string, HeadAttrValue>;
|
|
13
|
+
interface HeadInput {
|
|
14
|
+
/**
|
|
15
|
+
* In `useHead()`: the page title. In the config: the default title; put `%s` where the page title goes
|
|
16
|
+
* (`"%s | My site"`). Without `%s`, a page title replaces the default.
|
|
17
|
+
*/
|
|
18
|
+
title?: string;
|
|
19
|
+
meta?: HeadTag[];
|
|
20
|
+
link?: HeadTag[];
|
|
21
|
+
htmlAttrs?: Record<string, HeadAttrValue>;
|
|
22
|
+
bodyAttrs?: Record<string, HeadAttrValue>;
|
|
23
|
+
}
|
|
24
|
+
/** `head` option of `noofpi.config.ts`: defaults for every page */
|
|
25
|
+
type HeadConfig = HeadInput;
|
|
26
|
+
interface ResolvedHead {
|
|
27
|
+
title: string;
|
|
28
|
+
meta: Record<string, string>[];
|
|
29
|
+
link: Record<string, string>[];
|
|
30
|
+
htmlAttrs: Record<string, string>;
|
|
31
|
+
bodyAttrs: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface CorsOptions {
|
|
35
|
+
/** Origins allowed to read responses: `"*"` (default) for any, or a list of origins (`https://app.example.com`) */
|
|
36
|
+
origin?: "*" | string | string[];
|
|
37
|
+
/** Methods allowed in a cross-origin request. Default: `GET, HEAD, PUT, PATCH, POST, DELETE` */
|
|
38
|
+
methods?: string[];
|
|
39
|
+
/** Request headers allowed in a cross-origin request. Default: the ones the preflight asks for */
|
|
40
|
+
allowHeaders?: string[];
|
|
41
|
+
/** Response headers scripts of another origin may read */
|
|
42
|
+
exposeHeaders?: string[];
|
|
43
|
+
/** Allow cookies and `Authorization` on cross-origin requests. With `origin: "*"` the request's origin is echoed instead of `*` */
|
|
44
|
+
credentials?: boolean;
|
|
45
|
+
/** Seconds a browser may cache the preflight answer. Default: `86400` */
|
|
46
|
+
maxAge?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A directive's sources: `["'self'", "https://cdn.example.com"]` or `"'self' https://cdn.example.com"`. `true` renders a bare directive (`upgrade-insecure-requests`), `false` omits it */
|
|
50
|
+
type CspDirectiveValue = string | string[] | boolean;
|
|
51
|
+
type CspDirectiveName = "default-src" | "script-src" | "script-src-elem" | "script-src-attr" | "style-src" | "style-src-elem" | "style-src-attr" | "img-src" | "font-src" | "connect-src" | "media-src" | "object-src" | "child-src" | "frame-src" | "worker-src" | "manifest-src" | "base-uri" | "form-action" | "frame-ancestors" | "sandbox" | "report-uri" | "report-to" | "upgrade-insecure-requests" | "require-trusted-types-for" | "trusted-types" | (string & {});
|
|
52
|
+
interface CspConfig {
|
|
53
|
+
/**
|
|
54
|
+
* Directives of the `Content-Security-Policy` header sent with every HTML page.
|
|
55
|
+
* Put `'nonce'` in a directive (typically `script-src` / `style-src`) to get a fresh nonce per request: it becomes
|
|
56
|
+
* `'nonce-<value>'` in the header and `nonce="<value>"` is added to every `<script>`, `<style>` and stylesheet /
|
|
57
|
+
* preload `<link>` of the page shell.
|
|
58
|
+
*/
|
|
59
|
+
directives: Partial<Record<CspDirectiveName, CspDirectiveValue>>;
|
|
60
|
+
/** Send `Content-Security-Policy-Report-Only` instead, so violations are reported but not blocked */
|
|
61
|
+
reportOnly?: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface CsrfConfig {
|
|
65
|
+
/** Extra origins (`https://app.example.com`) allowed to send state-changing requests to the API. The site's own origin is always allowed */
|
|
66
|
+
allowedOrigins?: string[];
|
|
67
|
+
/** The site's public origin (`https://app.example.com`). When set, the `Origin` of a write must match it exactly, scheme included. Unset, only hosts are compared because a TLS-terminating proxy may hide https */
|
|
68
|
+
publicOrigin?: string;
|
|
69
|
+
}
|
|
70
|
+
interface SecurityConfig {
|
|
71
|
+
/** `Content-Security-Policy` of every HTML page. A `'nonce'` source gets a per-request nonce, added to the page's scripts and styles automatically */
|
|
72
|
+
csp?: CspConfig;
|
|
73
|
+
/**
|
|
74
|
+
* Security response headers added to every response that does not already set them. `false` turns them all off;
|
|
75
|
+
* an object overrides single headers (`{ "X-Frame-Options": "DENY" }`) or removes one (`{ "Referrer-Policy": false }`).
|
|
76
|
+
* Defaults: `X-Content-Type-Options: nosniff`, `X-Frame-Options: SAMEORIGIN` (skipped when the CSP has
|
|
77
|
+
* `frame-ancestors`), `Referrer-Policy: strict-origin-when-cross-origin`, `Permissions-Policy` (camera, microphone and
|
|
78
|
+
* geolocation off) and, over https only, `Strict-Transport-Security`.
|
|
79
|
+
*/
|
|
80
|
+
headers?: boolean | Record<string, string | false>;
|
|
81
|
+
/**
|
|
82
|
+
* Blocks cross-site state-changing requests (POST, PUT, PATCH, DELETE) to the doofpi API and the pfetch proxy by
|
|
83
|
+
* checking `Origin` / `Sec-Fetch-Site`. On by default; `false` turns it off.
|
|
84
|
+
*/
|
|
85
|
+
csrf?: boolean | CsrfConfig;
|
|
86
|
+
/**
|
|
87
|
+
* Largest request body in bytes the server accepts (for the doofpi API, the pfetch proxy and server middleware);
|
|
88
|
+
* bigger ones get a `413`. Default 10 MiB (10485760); `false` turns it off.
|
|
89
|
+
*/
|
|
90
|
+
bodyLimit?: number | false;
|
|
91
|
+
/**
|
|
92
|
+
* Hostnames (`app.example.com`, `app.example.com:8080` or `*.example.com` for any subdomain) the server answers to;
|
|
93
|
+
* requests with another `Host` get a `400`. Not set by default: any host is accepted.
|
|
94
|
+
*/
|
|
95
|
+
allowedHosts?: string[];
|
|
96
|
+
}
|
|
97
|
+
interface ResolvedSecurity {
|
|
98
|
+
csp?: CspConfig;
|
|
99
|
+
headers: Record<string, string>;
|
|
100
|
+
csrf: {
|
|
101
|
+
allowedOrigins: string[];
|
|
102
|
+
publicOrigin?: string;
|
|
103
|
+
} | false;
|
|
104
|
+
bodyLimit: number | false;
|
|
105
|
+
allowedHosts?: string[];
|
|
106
|
+
}
|
|
107
|
+
/** What a `routeRules` entry may change: each option replaces (`csp`, `csrf`, `bodyLimit`) or is applied on top of (`headers`) the global one */
|
|
108
|
+
interface RouteSecurityConfig {
|
|
109
|
+
/** CSP of the matching pages instead of the global one. `false` sends none */
|
|
110
|
+
csp?: CspConfig | false;
|
|
111
|
+
/** Applied on top of the global headers (`false` value removes one, `false` alone removes them all) */
|
|
112
|
+
headers?: boolean | Record<string, string | false>;
|
|
113
|
+
/** CSRF protection of matching API / proxy paths instead of the global one. `false` turns it off */
|
|
114
|
+
csrf?: boolean | CsrfConfig;
|
|
115
|
+
/** Request body limit in bytes of matching paths instead of the global one. `false` turns it off */
|
|
116
|
+
bodyLimit?: number | false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Server cache and `Cache-Control` of the rendered pages of matching routes */
|
|
120
|
+
interface CacheRule {
|
|
121
|
+
/** Seconds a rendered page is fresh: served from the cache without rendering */
|
|
122
|
+
maxAge: number;
|
|
123
|
+
/**
|
|
124
|
+
* Seconds after `maxAge` during which the stale page is still served at once while a fresh one renders in the
|
|
125
|
+
* background (stale-while-revalidate). Default: `0`
|
|
126
|
+
*/
|
|
127
|
+
swr?: number;
|
|
128
|
+
/** Request headers (`["accept-language"]`) that make separate cache entries. Never cached per cookie unless you list `cookie` */
|
|
129
|
+
vary?: string[];
|
|
130
|
+
/** Keep rendered pages in the server's memory (default `true`). `false` only sends `Cache-Control`, for a CDN or the browser */
|
|
131
|
+
server?: boolean;
|
|
132
|
+
}
|
|
133
|
+
declare const REDIRECT_STATUSES: readonly [301, 302, 303, 307, 308];
|
|
134
|
+
interface RedirectRule {
|
|
135
|
+
/** Path (`/new`) or absolute URL. With a pattern ending in `/**`, a target ending in `/**` keeps the rest of the path */
|
|
136
|
+
to: string;
|
|
137
|
+
/** Default: `307` (the method is kept) */
|
|
138
|
+
status?: (typeof REDIRECT_STATUSES)[number];
|
|
139
|
+
}
|
|
140
|
+
/** Options that apply to every page whose URL matches a `routeRules` pattern */
|
|
141
|
+
interface RouteRule {
|
|
142
|
+
/** `false` serves the client-only shell for matching pages, even when `ssr` is on globally */
|
|
143
|
+
ssr?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* How the doofpi client reaches the API on matching pages, instead of `doofpi.fetch`, e.g. `"sfetch"` to keep the
|
|
146
|
+
* API out of the browser for `/admin/**`. Needs `doofpi.url` unless it is `lfetch`; `sfetch` needs SSR.
|
|
147
|
+
* `useDoofpi()` picks it from the page it is called on, so call it in that page's `setup()`.
|
|
148
|
+
*/
|
|
149
|
+
fetch?: FetchMode;
|
|
150
|
+
/**
|
|
151
|
+
* Overrides the global `security` options for matching URL paths (pages, and the API / proxy for `csrf`).
|
|
152
|
+
* Server-only: never sent to the browser.
|
|
153
|
+
*/
|
|
154
|
+
security?: RouteSecurityConfig;
|
|
155
|
+
/**
|
|
156
|
+
* Writes the matching pages to HTML files with `noofpi generate` (or a static preset's `noofpi build`), so a static
|
|
157
|
+
* host serves real, SEO-friendly markup. `false` leaves a page out when everything is prerendered by default.
|
|
158
|
+
* Needs ssr. Server-only: never sent to the browser.
|
|
159
|
+
*/
|
|
160
|
+
prerender?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Streams matching pages: the HTML shell is sent as soon as the route is resolved and the page markup follows while
|
|
163
|
+
* `useAsyncData` is still fetching. Overrides the global `streaming`; ignored when `cache` applies. Needs ssr.
|
|
164
|
+
*/
|
|
165
|
+
stream?: boolean;
|
|
166
|
+
/** Caches the rendered pages (stale-while-revalidate) and sends `Cache-Control`. `false` turns off a broader rule's cache */
|
|
167
|
+
cache?: CacheRule | false;
|
|
168
|
+
/** Response headers set on everything the noofpi server answers for matching paths (pages, API, proxy, redirects) */
|
|
169
|
+
headers?: Record<string, string>;
|
|
170
|
+
/** Redirects matching requests before anything else runs. A path or `{ to, status }` */
|
|
171
|
+
redirect?: string | RedirectRule;
|
|
172
|
+
/** CORS headers (and the preflight answer) for matching paths, typically the API. `true` allows any origin */
|
|
173
|
+
cors?: boolean | CorsOptions;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Keyed by URL path pattern: `/about` (exact), `/users/*` (one segment) or `/admin/**` (the path itself and
|
|
177
|
+
* everything below it). When several patterns match, the most specific one (the longest) wins per option.
|
|
178
|
+
*/
|
|
179
|
+
type RouteRules = Record<string, RouteRule>;
|
|
180
|
+
|
|
181
|
+
interface CookieOptions {
|
|
182
|
+
/** Lifetime in seconds. Without `maxAge` / `expires` the cookie lasts for the browser session */
|
|
183
|
+
maxAge?: number;
|
|
184
|
+
expires?: Date;
|
|
185
|
+
domain?: string;
|
|
186
|
+
/** Default: `/` */
|
|
187
|
+
path?: string;
|
|
188
|
+
/** Default: `true` over https. Forced on for `SameSite=None`, `Partitioned` and `__Secure-` / `__Host-` names */
|
|
189
|
+
secure?: boolean;
|
|
190
|
+
/** Hides the cookie from `document.cookie`. Default on the server: `true`. Cannot be set from the browser. */
|
|
191
|
+
httpOnly?: boolean;
|
|
192
|
+
/** Default: `lax` */
|
|
193
|
+
sameSite?: "lax" | "strict" | "none";
|
|
194
|
+
partitioned?: boolean;
|
|
195
|
+
}
|
|
196
|
+
/** Converts a typed value to the cookie's string value and back. `decode` throws on a value it does not accept. */
|
|
197
|
+
interface CookieCodec<T> {
|
|
198
|
+
encode(value: T): string;
|
|
199
|
+
decode(raw: string): T;
|
|
200
|
+
}
|
|
201
|
+
/** A named, typed cookie that can be shared by server code and components */
|
|
202
|
+
interface CookieDefinition<T> {
|
|
203
|
+
name: string;
|
|
204
|
+
codec: CookieCodec<T>;
|
|
205
|
+
options: CookieOptions;
|
|
206
|
+
}
|
|
207
|
+
declare const stringCodec: CookieCodec<string>;
|
|
208
|
+
declare const numberCodec: CookieCodec<number>;
|
|
209
|
+
declare const booleanCodec: CookieCodec<boolean>;
|
|
210
|
+
/** JSON for objects, arrays and anything else `JSON.stringify` handles. The type is not validated at runtime. */
|
|
211
|
+
declare function jsonCodec<T>(): CookieCodec<T>;
|
|
212
|
+
/** A string union: any other cookie value counts as absent */
|
|
213
|
+
declare function enumCodec<const T extends string>(values: readonly T[]): CookieCodec<T>;
|
|
214
|
+
declare function defineCookie(name: string, options?: CookieOptions): CookieDefinition<string>;
|
|
215
|
+
declare function defineCookie<T>(name: string, options: CookieOptions & {
|
|
216
|
+
codec: CookieCodec<T>;
|
|
217
|
+
}): CookieDefinition<T>;
|
|
218
|
+
interface CookieJar {
|
|
219
|
+
has(name: string): boolean;
|
|
220
|
+
get(name: string): string | undefined;
|
|
221
|
+
get<T>(name: string, codec: CookieCodec<T>): T | undefined;
|
|
222
|
+
get<T>(cookie: CookieDefinition<T>): T | undefined;
|
|
223
|
+
/** Every cookie as its raw string value */
|
|
224
|
+
getAll(): Record<string, string>;
|
|
225
|
+
set(name: string, value: string, options?: CookieOptions): void;
|
|
226
|
+
set<T>(name: string, value: T, options: CookieOptions & {
|
|
227
|
+
codec: CookieCodec<T>;
|
|
228
|
+
}): void;
|
|
229
|
+
set<T>(cookie: CookieDefinition<T>, value: T, options?: CookieOptions): void;
|
|
230
|
+
/** Expires the cookie. Pass the `path` / `domain` it was set with when they are not the defaults. */
|
|
231
|
+
remove(cookie: string | CookieDefinition<any>, options?: Pick<CookieOptions, "path" | "domain">): void;
|
|
232
|
+
/** `Set-Cookie` values queued by `set` / `remove`, for the response (empty when `write` is used) */
|
|
233
|
+
toSetCookieHeaders(): string[];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
type SessionData = Record<string, unknown>;
|
|
237
|
+
interface SessionConfig {
|
|
238
|
+
/** Name of the session cookie. Default: `noofpi_session` */
|
|
239
|
+
name?: string;
|
|
240
|
+
/** Lifetime in seconds, renewed each time the session is saved. Default: 7 days */
|
|
241
|
+
maxAge?: number;
|
|
242
|
+
/**
|
|
243
|
+
* `"encrypted"` (default): the browser cannot read the session. `"signed"`: it can read it but not change it, which
|
|
244
|
+
* keeps the cookie smaller to inspect while debugging
|
|
245
|
+
*/
|
|
246
|
+
mode?: "encrypted" | "signed";
|
|
247
|
+
/**
|
|
248
|
+
* Keys of the session data the browser may see through `useSession()` (also in the HTML of server-rendered pages).
|
|
249
|
+
* Use a dot path (`"user.id"`) to expose only a nested value. Everything else stays on the server
|
|
250
|
+
*/
|
|
251
|
+
expose?: string[];
|
|
252
|
+
/** `sameSite` (default `lax`), `secure` (default: on over https), `domain` and `path` (default `/`) of the cookie */
|
|
253
|
+
cookie?: Pick<CookieOptions, "sameSite" | "secure" | "domain" | "path">;
|
|
254
|
+
}
|
|
255
|
+
interface ResolvedSession {
|
|
256
|
+
name: string;
|
|
257
|
+
maxAge: number;
|
|
258
|
+
mode: "encrypted" | "signed";
|
|
259
|
+
expose: string[];
|
|
260
|
+
cookie: Pick<CookieOptions, "sameSite" | "secure" | "domain" | "path">;
|
|
261
|
+
}
|
|
262
|
+
/** The session of a request. The cookie is written with the response when the data changed */
|
|
263
|
+
interface Session<T extends SessionData = SessionData> {
|
|
264
|
+
/** The data. Assign to it or call `update()`: a change is saved when the response is sent */
|
|
265
|
+
data: T;
|
|
266
|
+
/** Merges `patch` into the data */
|
|
267
|
+
update(patch: Partial<T>): void;
|
|
268
|
+
/** Ends the session: its data is dropped and the cookie removed */
|
|
269
|
+
clear(): void;
|
|
270
|
+
/** `true` while the session has no data */
|
|
271
|
+
readonly isEmpty: boolean;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { FETCH_MODES as g, booleanCodec as s, defineCookie as t, enumCodec as u, jsonCodec as v, numberCodec as w, stringCodec as x };
|
|
275
|
+
export type { CacheRule as C, FetchMode as F, HeadConfig as H, RouteRules as R, SessionConfig as S, SecurityConfig as a, CorsOptions as b, CspConfig as c, CspDirectiveName as d, CspDirectiveValue as e, CsrfConfig as f, HeadInput as h, HeadTag as i, RedirectRule as j, RouteRule as k, Session as l, SessionData as m, ResolvedHead as n, CookieJar as o, CookieOptions as p, CookieCodec as q, CookieDefinition as r, ResolvedSecurity as y, ResolvedSession as z };
|
|
@@ -5,13 +5,14 @@ import {
|
|
|
5
5
|
} from "./chunk-RUNIVVFH.js";
|
|
6
6
|
import {
|
|
7
7
|
OUTPUT_DIR
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-PL3CA2JF.js";
|
|
9
9
|
import "./chunk-OKNF6XDO.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-YN4TKMDX.js";
|
|
11
11
|
import {
|
|
12
12
|
createHandler
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-YN64WQ2B.js";
|
|
14
|
+
import "./chunk-LJEKK4AK.js";
|
|
15
|
+
import "./chunk-O5JRC252.js";
|
|
15
16
|
import {
|
|
16
17
|
sendWebResponse,
|
|
17
18
|
serveStatic,
|
|
@@ -20,8 +21,8 @@ import {
|
|
|
20
21
|
import "./chunk-PPUFFGCH.js";
|
|
21
22
|
import "./chunk-ELXCFUA4.js";
|
|
22
23
|
import "./chunk-EZPJF4D4.js";
|
|
23
|
-
import "./chunk-
|
|
24
|
-
import "./chunk-
|
|
24
|
+
import "./chunk-PC3ZJN4D.js";
|
|
25
|
+
import "./chunk-W7ASRDAJ.js";
|
|
25
26
|
import "./chunk-Y3NBZ6DW.js";
|
|
26
27
|
|
|
27
28
|
// src/vite/start.ts
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ClientFetch } from 'doofpi';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { o as CookieJar, m as SessionData, n as ResolvedHead, F as FetchMode, H as HeadConfig, R as RouteRules, y as ResolvedSecurity, z as ResolvedSession, l as Session } from './session-CLvYihOU.js';
|
|
3
|
+
import { P as PayloadData } from './payload-DfhHnXAn.js';
|
|
4
4
|
|
|
5
5
|
declare const PROXY_PREFIX = "/_noofpi/proxy";
|
|
6
6
|
/** Server-side config (includes the remote `doofpi.url`, which is never sent to the browser for pfetch/sfetch) */
|
|
7
7
|
interface ServerConfig {
|
|
8
8
|
ssr: boolean;
|
|
9
|
+
/** Stream pages by default (`routeRules[...].stream` overrides it per route) */
|
|
10
|
+
streaming?: boolean;
|
|
9
11
|
doofpi: {
|
|
10
12
|
fetch: FetchMode;
|
|
11
13
|
url: string | undefined;
|
|
@@ -14,6 +16,7 @@ interface ServerConfig {
|
|
|
14
16
|
head?: HeadConfig;
|
|
15
17
|
routeRules?: RouteRules;
|
|
16
18
|
security?: Partial<ResolvedSecurity>;
|
|
19
|
+
session?: ResolvedSession;
|
|
17
20
|
}
|
|
18
21
|
interface RenderContext {
|
|
19
22
|
origin: string;
|
|
@@ -22,6 +25,8 @@ interface RenderContext {
|
|
|
22
25
|
cookies: CookieJar;
|
|
23
26
|
/** The request's `Accept-Language` header, for the `i18n` locale detection */
|
|
24
27
|
acceptLanguage?: string;
|
|
28
|
+
/** The part of the session the browser may see (`session.expose`): what `useSession()` returns on the page */
|
|
29
|
+
session?: SessionData;
|
|
25
30
|
/** In-process fetch into the noofpi server (used for `lfetch` / `pfetch` during SSR) */
|
|
26
31
|
fetch: ClientFetch;
|
|
27
32
|
}
|
|
@@ -37,14 +42,30 @@ interface RenderResult {
|
|
|
37
42
|
/** Title, meta tags and attributes gathered by `useHead` while rendering, written into the HTML shell */
|
|
38
43
|
head?: ResolvedHead;
|
|
39
44
|
}
|
|
45
|
+
/** A page that is still rendering: the handler sends `body` as it comes and adds what `finish()` returns at the end */
|
|
46
|
+
interface StreamRenderResult {
|
|
47
|
+
status: number;
|
|
48
|
+
/** The head known before rendering (config defaults, `i18n`); it goes out with the first bytes */
|
|
49
|
+
head: ResolvedHead;
|
|
50
|
+
/** The app markup as it renders */
|
|
51
|
+
body: ReadableStream<Uint8Array>;
|
|
52
|
+
/** Call once `body` has ended: what the page gathered while rendering */
|
|
53
|
+
finish(): {
|
|
54
|
+
payload: PayloadData;
|
|
55
|
+
head: ResolvedHead;
|
|
56
|
+
error?: unknown;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
40
59
|
/**
|
|
41
60
|
* Optional `server/proxy.ts` default export. Mutate `headers` to change what is sent to the doofpi API
|
|
42
|
-
* (e.g. inject an `Authorization` token), or return a `Response` to short-circuit the request.
|
|
61
|
+
* (e.g. inject an `Authorization` token from the session), or return a `Response` to short-circuit the request.
|
|
43
62
|
*/
|
|
44
63
|
type ProxyHook = (ctx: {
|
|
45
64
|
request: Request;
|
|
46
65
|
headers: Headers;
|
|
47
66
|
target: URL;
|
|
67
|
+
/** The visitor's session (`undefined` without the `session` option) */
|
|
68
|
+
session?: Session;
|
|
48
69
|
}) => void | Response | Promise<void | Response>;
|
|
49
70
|
interface DoofpiLike {
|
|
50
71
|
fetch(request: Request, env?: any, extra?: any): Promise<Response>;
|
|
@@ -55,6 +76,8 @@ interface ServerMiddlewareContext {
|
|
|
55
76
|
env?: unknown;
|
|
56
77
|
/** Read the request's cookies and set / remove cookies on the response (also when you return your own `Response`) */
|
|
57
78
|
cookies: CookieJar;
|
|
79
|
+
/** The visitor's session (`undefined` without the `session` option) */
|
|
80
|
+
session?: Session;
|
|
58
81
|
}
|
|
59
82
|
/**
|
|
60
83
|
* A `server/middleware/*.ts` default export. Runs around every request the noofpi server handles (pages, the doofpi
|
|
@@ -70,7 +93,9 @@ interface ServerModule {
|
|
|
70
93
|
/** `server/middleware/*` in file-name order, outermost first */
|
|
71
94
|
middleware?: ServerMiddleware[];
|
|
72
95
|
render?: (url: string, ctx: RenderContext) => Promise<RenderResult>;
|
|
96
|
+
/** Like `render`, but the markup comes as a stream (or, for a redirect or an error page, as a normal result) */
|
|
97
|
+
renderStream?: (url: string, ctx: RenderContext) => Promise<RenderResult | StreamRenderResult>;
|
|
73
98
|
}
|
|
74
99
|
|
|
75
|
-
export { PROXY_PREFIX as
|
|
76
|
-
export type { ProxyHook as P, RenderContext as R,
|
|
100
|
+
export { PROXY_PREFIX as c };
|
|
101
|
+
export type { ProxyHook as P, RenderContext as R, StreamRenderResult as S, RenderResult as a, ServerMiddleware as b, ServerConfig as d, ServerMiddlewareContext as e, ServerModule as f };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "noofpi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "A minimal Vue + Vite full-stack framework built around doofpi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Lior Cohen",
|
|
@@ -79,17 +79,18 @@
|
|
|
79
79
|
"prepublishOnly": "bun run build && bun run test"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@vitejs/plugin-vue": "^6.
|
|
82
|
+
"@vitejs/plugin-vue": "^6.1.1",
|
|
83
83
|
"jiti": "^2.7.0",
|
|
84
84
|
"unplugin-auto-import": "^21.1.0",
|
|
85
85
|
"unplugin-vue-components": "^32.1.0",
|
|
86
|
-
"vite": "^8.
|
|
87
|
-
"vue": "^3.5.
|
|
88
|
-
"vue-router": "^5.
|
|
86
|
+
"vite": "^8.4.1",
|
|
87
|
+
"vue": "^3.5.47",
|
|
88
|
+
"vue-router": "^5.6.1"
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"@tailwindcss/vite": "^4.0.0",
|
|
92
92
|
"doofpi": ">=1.3.1",
|
|
93
|
+
"securegeer": "^1.0.1",
|
|
93
94
|
"sharp": ">=0.33.0",
|
|
94
95
|
"tailwindcss": "^4.0.0"
|
|
95
96
|
},
|
|
@@ -97,6 +98,9 @@
|
|
|
97
98
|
"@tailwindcss/vite": {
|
|
98
99
|
"optional": true
|
|
99
100
|
},
|
|
101
|
+
"securegeer": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
100
104
|
"sharp": {
|
|
101
105
|
"optional": true
|
|
102
106
|
},
|
|
@@ -108,10 +112,11 @@
|
|
|
108
112
|
"@tailwindcss/vite": "^4.3.5",
|
|
109
113
|
"@types/node": "^24.19.4",
|
|
110
114
|
"doofpi": "^1.3.1",
|
|
111
|
-
"
|
|
115
|
+
"securegeer": "^1.0.1",
|
|
116
|
+
"sharp": "^0.35.6",
|
|
112
117
|
"tailwindcss": "^4.3.5",
|
|
113
118
|
"zod": "^4.6.7",
|
|
114
|
-
"prettier": "^3.10.
|
|
119
|
+
"prettier": "^3.10.2",
|
|
115
120
|
"tsup": "^9.0.0",
|
|
116
121
|
"typescript": "~6.0.3",
|
|
117
122
|
"vitest": "^5.1.2"
|
package/dist/build-WPHZ7TYZ.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OUTPUT_DIR,
|
|
3
|
-
createViteConfig,
|
|
4
|
-
finishPresetBuild,
|
|
5
|
-
resolveFonts
|
|
6
|
-
} from "./chunk-NHBXVKEQ.js";
|
|
7
|
-
import "./chunk-IE3WF5XF.js";
|
|
8
|
-
import "./chunk-MTXQR32N.js";
|
|
9
|
-
import "./chunk-PPUFFGCH.js";
|
|
10
|
-
import "./chunk-ELXCFUA4.js";
|
|
11
|
-
import "./chunk-G35DW4NA.js";
|
|
12
|
-
import {
|
|
13
|
-
usesFetchMode
|
|
14
|
-
} from "./chunk-MN5PVHC5.js";
|
|
15
|
-
import "./chunk-Y3NBZ6DW.js";
|
|
16
|
-
|
|
17
|
-
// src/vite/build.ts
|
|
18
|
-
import { rm } from "fs/promises";
|
|
19
|
-
import path from "path";
|
|
20
|
-
import { build } from "vite";
|
|
21
|
-
async function buildApp(root, resolved, preset = resolved.build.preset) {
|
|
22
|
-
const config = { ...resolved, build: { ...resolved.build, preset } };
|
|
23
|
-
const isStatic = preset === "github-pages";
|
|
24
|
-
if (isStatic) {
|
|
25
|
-
const { fetch } = config.doofpi;
|
|
26
|
-
for (const mode of ["lfetch", "pfetch", "sfetch"])
|
|
27
|
-
if (usesFetchMode(fetch, config.routeRules, mode))
|
|
28
|
-
throw new Error(
|
|
29
|
-
`[noofpi] The github-pages preset has no server, so doofpi fetch "${mode}" cannot be used (use "dfetch")`
|
|
30
|
-
);
|
|
31
|
-
config.ssr = false;
|
|
32
|
-
}
|
|
33
|
-
const fonts = await resolveFonts(root, config);
|
|
34
|
-
await rm(path.join(root, OUTPUT_DIR), { recursive: true, force: true });
|
|
35
|
-
console.log(`
|
|
36
|
-
noofpi: building client (preset: ${preset})...`);
|
|
37
|
-
await build(createViteConfig(root, config, "client", fonts));
|
|
38
|
-
if (!isStatic) {
|
|
39
|
-
console.log("\nnoofpi: building server...");
|
|
40
|
-
await build(createViteConfig(root, config, "server", fonts));
|
|
41
|
-
}
|
|
42
|
-
const next = await finishPresetBuild(root, config, preset);
|
|
43
|
-
console.log(`
|
|
44
|
-
noofpi: build complete -> .output/ (${next})
|
|
45
|
-
`);
|
|
46
|
-
}
|
|
47
|
-
export {
|
|
48
|
-
buildApp
|
|
49
|
-
};
|