noofpi 2.0.1 → 3.0.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-W5VMPOTQ.js +212 -0
- package/dist/chunk-A7XQWIA6.js +562 -0
- package/dist/chunk-GOJZ36X5.js +217 -0
- package/dist/{chunk-YJVMBHNL.js → chunk-JUVQEKLE.js} +43 -12
- package/dist/chunk-LJEKK4AK.js +51 -0
- package/dist/{chunk-G35DW4NA.js → chunk-PC3ZJN4D.js} +11 -1
- package/dist/{chunk-NHBXVKEQ.js → chunk-ROMSHDCI.js} +160 -86
- package/dist/{chunk-IE3WF5XF.js → chunk-SUECMRBX.js} +87 -4
- package/dist/{chunk-MN5PVHC5.js → chunk-W7ASRDAJ.js} +229 -7
- package/dist/cli.js +21 -9
- package/dist/{dev-OAGCOGHA.js → dev-2DM7VOYX.js} +7 -6
- package/dist/{devtools-PLUN2DYV.js → devtools-C3PFU57C.js} +1 -1
- package/dist/handler-BpyI3a5D.d.ts +26 -0
- package/dist/index.d.ts +26 -11
- package/dist/index.js +3 -2
- package/dist/payload-Cgul9YUP.d.ts +66 -0
- package/dist/{prepare-BN7NMCVQ.js → prepare-APN2E6PX.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-CAP_PIlN.d.ts +272 -0
- package/dist/{start-ITRND3BY.js → start-PXOLWPL4.js} +7 -6
- package/dist/{types-B6rQOOxS.d.ts → types-B7xDyUbg.d.ts} +30 -5
- package/package.json +6 -1
- 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
package/dist/chunk-X3DYEZLK.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PROXY_PREFIX,
|
|
3
|
-
SSR_OUTLET
|
|
4
|
-
} from "./chunk-MTXQR32N.js";
|
|
5
|
-
import {
|
|
6
|
-
applyCookies,
|
|
7
|
-
createCookieJar,
|
|
8
|
-
injectPayload
|
|
9
|
-
} from "./chunk-EZPJF4D4.js";
|
|
10
|
-
import {
|
|
11
|
-
applyHead,
|
|
12
|
-
resolveHead
|
|
13
|
-
} from "./chunk-G35DW4NA.js";
|
|
14
|
-
import {
|
|
15
|
-
applyRouteSecurity,
|
|
16
|
-
applySecurityHeaders,
|
|
17
|
-
buildCspHeader,
|
|
18
|
-
generateNonce,
|
|
19
|
-
injectNonce,
|
|
20
|
-
isAllowedHost,
|
|
21
|
-
isCrossSiteWrite,
|
|
22
|
-
isServerRendered,
|
|
23
|
-
limitRequestBody,
|
|
24
|
-
matchRouteRules,
|
|
25
|
-
usesFetchMode,
|
|
26
|
-
usesNonce
|
|
27
|
-
} from "./chunk-MN5PVHC5.js";
|
|
28
|
-
|
|
29
|
-
// src/server/cookies.ts
|
|
30
|
-
var JAR = /* @__PURE__ */ Symbol.for("noofpi.request-cookies");
|
|
31
|
-
function bindRequestCookies(request, jar) {
|
|
32
|
-
request[JAR] = jar;
|
|
33
|
-
}
|
|
34
|
-
function getRequestCookies(request) {
|
|
35
|
-
const jar = request[JAR];
|
|
36
|
-
if (!jar)
|
|
37
|
-
throw new Error(
|
|
38
|
-
"[noofpi] getRequestCookies() needs the original Request of a request handled by the noofpi server"
|
|
39
|
-
);
|
|
40
|
-
return jar;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// src/server/proxy.ts
|
|
44
|
-
var FORWARDED_REQUEST_HEADERS = [
|
|
45
|
-
"accept",
|
|
46
|
-
"accept-language",
|
|
47
|
-
"authorization",
|
|
48
|
-
"cookie",
|
|
49
|
-
"content-type",
|
|
50
|
-
"if-none-match",
|
|
51
|
-
"if-modified-since",
|
|
52
|
-
"range"
|
|
53
|
-
];
|
|
54
|
-
var DROPPED_RESPONSE_HEADERS = [
|
|
55
|
-
"content-encoding",
|
|
56
|
-
"content-length",
|
|
57
|
-
"transfer-encoding",
|
|
58
|
-
"connection",
|
|
59
|
-
"keep-alive"
|
|
60
|
-
];
|
|
61
|
-
var json = (status, message) => new Response(JSON.stringify({ message }), {
|
|
62
|
-
status,
|
|
63
|
-
headers: { "Content-Type": "application/json" }
|
|
64
|
-
});
|
|
65
|
-
function resolveProxyTarget(pathname, search, base, root) {
|
|
66
|
-
if (!pathname.startsWith(PROXY_PREFIX + "/")) return null;
|
|
67
|
-
const rest = pathname.slice(PROXY_PREFIX.length);
|
|
68
|
-
let target;
|
|
69
|
-
try {
|
|
70
|
-
target = new URL(rest + search, base);
|
|
71
|
-
} catch {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
const afterRoot = target.pathname.charAt(root.length);
|
|
75
|
-
const insideRoot = target.pathname.startsWith(root) && (afterRoot === "" || afterRoot === "." || afterRoot === "/");
|
|
76
|
-
return target.origin === new URL(base).origin && insideRoot ? target : null;
|
|
77
|
-
}
|
|
78
|
-
async function proxyRequest(request, options) {
|
|
79
|
-
const url = new URL(request.url);
|
|
80
|
-
const target = resolveProxyTarget(
|
|
81
|
-
url.pathname,
|
|
82
|
-
url.search,
|
|
83
|
-
options.base,
|
|
84
|
-
options.root
|
|
85
|
-
);
|
|
86
|
-
if (!target) return json(404, "Not found");
|
|
87
|
-
const headers = new Headers();
|
|
88
|
-
for (const name of FORWARDED_REQUEST_HEADERS) {
|
|
89
|
-
const value = request.headers.get(name);
|
|
90
|
-
if (value !== null) headers.set(name, value);
|
|
91
|
-
}
|
|
92
|
-
const hooked = await options.hook?.({ request, headers, target });
|
|
93
|
-
if (hooked instanceof Response) return hooked;
|
|
94
|
-
const hasBody = request.method !== "GET" && request.method !== "HEAD";
|
|
95
|
-
let upstream;
|
|
96
|
-
try {
|
|
97
|
-
upstream = await fetch(target, {
|
|
98
|
-
method: request.method,
|
|
99
|
-
headers,
|
|
100
|
-
// Body is streamed through untouched (binary uploads and JSON alike)
|
|
101
|
-
body: hasBody ? request.body : void 0,
|
|
102
|
-
redirect: "manual",
|
|
103
|
-
...hasBody ? { duplex: "half" } : {}
|
|
104
|
-
});
|
|
105
|
-
} catch {
|
|
106
|
-
return json(502, "Bad gateway");
|
|
107
|
-
}
|
|
108
|
-
const responseHeaders = new Headers(upstream.headers);
|
|
109
|
-
for (const name of DROPPED_RESPONSE_HEADERS) responseHeaders.delete(name);
|
|
110
|
-
return new Response(upstream.body, {
|
|
111
|
-
status: upstream.status,
|
|
112
|
-
headers: responseHeaders
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// src/server/handler.ts
|
|
117
|
-
var isUnder = (pathname, root) => pathname === root || pathname.startsWith(root + ".") || pathname.startsWith(root + "/");
|
|
118
|
-
function routeSecurity(mod, url) {
|
|
119
|
-
const rules = mod.config.routeRules;
|
|
120
|
-
return applyRouteSecurity(
|
|
121
|
-
mod.config.security,
|
|
122
|
-
rules && matchRouteRules(rules, url.pathname).security
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
function createHandler(options) {
|
|
126
|
-
const reportError = (error) => {
|
|
127
|
-
options.onError?.(error);
|
|
128
|
-
if (!options.onError) console.error(error);
|
|
129
|
-
};
|
|
130
|
-
const respond = async (mod, request, env, cookies) => {
|
|
131
|
-
const url = new URL(request.url);
|
|
132
|
-
const { ssr, doofpi } = mod.config;
|
|
133
|
-
const security = routeSecurity(mod, url);
|
|
134
|
-
const isProxy = usesFetchMode(doofpi.fetch, mod.config.routeRules, "pfetch") && url.pathname.startsWith(PROXY_PREFIX + "/");
|
|
135
|
-
const isApi = !!mod.doofpi && isUnder(url.pathname, doofpi.root);
|
|
136
|
-
if (security?.csrf && (isProxy || isApi) && isCrossSiteWrite(request, url, security.csrf)) {
|
|
137
|
-
return new Response(JSON.stringify({ message: "Forbidden" }), {
|
|
138
|
-
status: 403,
|
|
139
|
-
headers: { "Content-Type": "application/json" }
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
if (isProxy) {
|
|
143
|
-
return await proxyRequest(request, {
|
|
144
|
-
base: doofpi.url,
|
|
145
|
-
root: doofpi.root,
|
|
146
|
-
hook: mod.proxyHook
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
if (isApi) {
|
|
150
|
-
return await mod.doofpi.fetch(request, env);
|
|
151
|
-
}
|
|
152
|
-
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
153
|
-
return new Response("Method Not Allowed", { status: 405 });
|
|
154
|
-
}
|
|
155
|
-
if (/\.[a-z0-9]+$/i.test(url.pathname))
|
|
156
|
-
return new Response("Not Found", { status: 404 });
|
|
157
|
-
const template = await options.getTemplate(url.pathname + url.search);
|
|
158
|
-
let html = "";
|
|
159
|
-
let head = resolveHead(mod.config.head);
|
|
160
|
-
let payload;
|
|
161
|
-
let status = 200;
|
|
162
|
-
if (mod.render && isServerRendered(ssr, mod.config.routeRules, url.pathname)) {
|
|
163
|
-
const result = await mod.render(url.pathname + url.search, {
|
|
164
|
-
origin: url.origin,
|
|
165
|
-
cookie: request.headers.get("cookie") ?? void 0,
|
|
166
|
-
cookies,
|
|
167
|
-
acceptLanguage: request.headers.get("accept-language") ?? void 0,
|
|
168
|
-
fetch: (input, init) => handler(new Request(input, init), env)
|
|
169
|
-
});
|
|
170
|
-
if (result.redirect)
|
|
171
|
-
return new Response(null, {
|
|
172
|
-
status: result.status,
|
|
173
|
-
headers: { Location: result.redirect }
|
|
174
|
-
});
|
|
175
|
-
if (result.error !== void 0) reportError(result.error);
|
|
176
|
-
html = result.html;
|
|
177
|
-
head = result.head ?? head;
|
|
178
|
-
payload = result.payload;
|
|
179
|
-
status = result.status;
|
|
180
|
-
}
|
|
181
|
-
let shell = applyHead(template, head);
|
|
182
|
-
const { csp } = security ?? {};
|
|
183
|
-
const nonce = usesNonce(csp) ? generateNonce() : void 0;
|
|
184
|
-
if (nonce) shell = injectNonce(shell, nonce);
|
|
185
|
-
let body = shell.replace(SSR_OUTLET, () => html);
|
|
186
|
-
if (payload) body = injectPayload(body, payload);
|
|
187
|
-
const headers = new Headers({ "Content-Type": "text/html; charset=utf-8" });
|
|
188
|
-
if (csp) {
|
|
189
|
-
const [name, value] = buildCspHeader(csp, nonce);
|
|
190
|
-
headers.set(name, value);
|
|
191
|
-
}
|
|
192
|
-
return new Response(request.method === "HEAD" ? null : body, {
|
|
193
|
-
status,
|
|
194
|
-
headers
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
|
-
const handler = async (incoming, env) => {
|
|
198
|
-
let request = incoming;
|
|
199
|
-
let tooLarge = () => false;
|
|
200
|
-
const payloadTooLarge = () => new Response("Payload Too Large", { status: 413 });
|
|
201
|
-
try {
|
|
202
|
-
const mod = await options.load();
|
|
203
|
-
const middleware = mod.middleware ?? [];
|
|
204
|
-
const url = new URL(request.url);
|
|
205
|
-
if (!isAllowedHost(url, mod.config.security?.allowedHosts))
|
|
206
|
-
return new Response("Invalid Host", { status: 400 });
|
|
207
|
-
const security = routeSecurity(mod, url);
|
|
208
|
-
if (security?.bodyLimit) {
|
|
209
|
-
const limited = limitRequestBody(request, security.bodyLimit);
|
|
210
|
-
request = limited.request;
|
|
211
|
-
tooLarge = limited.tooLarge;
|
|
212
|
-
}
|
|
213
|
-
const finish = (response2) => applySecurityHeaders(
|
|
214
|
-
response2,
|
|
215
|
-
security?.headers ?? {},
|
|
216
|
-
url.protocol === "https:"
|
|
217
|
-
);
|
|
218
|
-
if (tooLarge()) return finish(payloadTooLarge());
|
|
219
|
-
const cookies = createCookieJar({
|
|
220
|
-
cookie: request.headers.get("cookie"),
|
|
221
|
-
defaults: { secure: url.protocol === "https:" }
|
|
222
|
-
});
|
|
223
|
-
bindRequestCookies(request, cookies);
|
|
224
|
-
const run = async (index) => {
|
|
225
|
-
const current = middleware[index];
|
|
226
|
-
if (!current) return respond(mod, request, env, cookies);
|
|
227
|
-
const response2 = await current(
|
|
228
|
-
{ request, url, env, cookies },
|
|
229
|
-
() => run(index + 1)
|
|
230
|
-
);
|
|
231
|
-
if (!(response2 instanceof Response))
|
|
232
|
-
throw new Error(
|
|
233
|
-
"[noofpi] Server middleware must return a Response (return next() to continue)."
|
|
234
|
-
);
|
|
235
|
-
return response2;
|
|
236
|
-
};
|
|
237
|
-
const response = applyCookies(await run(0), cookies);
|
|
238
|
-
return finish(tooLarge() ? payloadTooLarge() : response);
|
|
239
|
-
} catch (error) {
|
|
240
|
-
if (tooLarge()) return payloadTooLarge();
|
|
241
|
-
reportError(error);
|
|
242
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
return handler;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export {
|
|
249
|
-
getRequestCookies,
|
|
250
|
-
resolveProxyTarget,
|
|
251
|
-
proxyRequest,
|
|
252
|
-
createHandler
|
|
253
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { e as ServerModule } from './types-B6rQOOxS.js';
|
|
2
|
-
|
|
3
|
-
interface HandlerOptions {
|
|
4
|
-
/** Returns the generated server module (`virtual:noofpi/server`, or the built bundle in production) */
|
|
5
|
-
load: () => Promise<ServerModule>;
|
|
6
|
-
/** Returns the HTML shell for a page URL */
|
|
7
|
-
getTemplate: (url: string) => Promise<string>;
|
|
8
|
-
onError?: (error: unknown) => void;
|
|
9
|
-
}
|
|
10
|
-
type Handler = (request: Request, env?: unknown) => Promise<Response>;
|
|
11
|
-
/**: one web-standard `fetch(Request) -> Response` handler.
|
|
12
|
-
* Order: proxy (pfetch) -> local doofpi API -> HTML (SSR render or SPA shell).
|
|
13
|
-
*/
|
|
14
|
-
declare function createHandler(options: HandlerOptions): Handler;
|
|
15
|
-
|
|
16
|
-
export { createHandler as c };
|
|
17
|
-
export type { Handler as H, HandlerOptions as a };
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { F as FetchMode } from './route-rules-COilNsVT.js';
|
|
2
|
-
|
|
3
|
-
interface CookieOptions {
|
|
4
|
-
/** Lifetime in seconds. Without `maxAge` / `expires` the cookie lasts for the browser session */
|
|
5
|
-
maxAge?: number;
|
|
6
|
-
expires?: Date;
|
|
7
|
-
domain?: string;
|
|
8
|
-
/** Default: `/` */
|
|
9
|
-
path?: string;
|
|
10
|
-
/** Default: `true` over https. Forced on for `SameSite=None`, `Partitioned` and `__Secure-` / `__Host-` names */
|
|
11
|
-
secure?: boolean;
|
|
12
|
-
/** Hides the cookie from `document.cookie`. Default on the server: `true`. Cannot be set from the browser. */
|
|
13
|
-
httpOnly?: boolean;
|
|
14
|
-
/** Default: `lax` */
|
|
15
|
-
sameSite?: "lax" | "strict" | "none";
|
|
16
|
-
partitioned?: boolean;
|
|
17
|
-
}
|
|
18
|
-
/** Converts a typed value to the cookie's string value and back. `decode` throws on a value it does not accept. */
|
|
19
|
-
interface CookieCodec<T> {
|
|
20
|
-
encode(value: T): string;
|
|
21
|
-
decode(raw: string): T;
|
|
22
|
-
}
|
|
23
|
-
/** A named, typed cookie that can be shared by server code and components */
|
|
24
|
-
interface CookieDefinition<T> {
|
|
25
|
-
name: string;
|
|
26
|
-
codec: CookieCodec<T>;
|
|
27
|
-
options: CookieOptions;
|
|
28
|
-
}
|
|
29
|
-
declare const stringCodec: CookieCodec<string>;
|
|
30
|
-
declare const numberCodec: CookieCodec<number>;
|
|
31
|
-
declare const booleanCodec: CookieCodec<boolean>;
|
|
32
|
-
/** JSON for objects, arrays and anything else `JSON.stringify` handles. The type is not validated at runtime. */
|
|
33
|
-
declare function jsonCodec<T>(): CookieCodec<T>;
|
|
34
|
-
/** A string union: any other cookie value counts as absent */
|
|
35
|
-
declare function enumCodec<const T extends string>(values: readonly T[]): CookieCodec<T>;
|
|
36
|
-
declare function defineCookie(name: string, options?: CookieOptions): CookieDefinition<string>;
|
|
37
|
-
declare function defineCookie<T>(name: string, options: CookieOptions & {
|
|
38
|
-
codec: CookieCodec<T>;
|
|
39
|
-
}): CookieDefinition<T>;
|
|
40
|
-
interface CookieJar {
|
|
41
|
-
has(name: string): boolean;
|
|
42
|
-
get(name: string): string | undefined;
|
|
43
|
-
get<T>(name: string, codec: CookieCodec<T>): T | undefined;
|
|
44
|
-
get<T>(cookie: CookieDefinition<T>): T | undefined;
|
|
45
|
-
/** Every cookie as its raw string value */
|
|
46
|
-
getAll(): Record<string, string>;
|
|
47
|
-
set(name: string, value: string, options?: CookieOptions): void;
|
|
48
|
-
set<T>(name: string, value: T, options: CookieOptions & {
|
|
49
|
-
codec: CookieCodec<T>;
|
|
50
|
-
}): void;
|
|
51
|
-
set<T>(cookie: CookieDefinition<T>, value: T, options?: CookieOptions): void;
|
|
52
|
-
/** Expires the cookie. Pass the `path` / `domain` it was set with when they are not the defaults. */
|
|
53
|
-
remove(cookie: string | CookieDefinition<any>, options?: Pick<CookieOptions, "path" | "domain">): void;
|
|
54
|
-
/** `Set-Cookie` values queued by `set` / `remove`, for the response (empty when `write` is used) */
|
|
55
|
-
toSetCookieHeaders(): string[];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** The error shown by `app/error.vue`: what the page receives in its `error` prop */
|
|
59
|
-
interface NoofpiErrorData {
|
|
60
|
-
statusCode: number;
|
|
61
|
-
statusMessage: string;
|
|
62
|
-
message: string;
|
|
63
|
-
/** The URL that was being rendered */
|
|
64
|
-
url?: string;
|
|
65
|
-
}
|
|
66
|
-
interface CreateErrorInput {
|
|
67
|
-
statusCode?: number;
|
|
68
|
-
statusMessage?: string;
|
|
69
|
-
message?: string;
|
|
70
|
-
}
|
|
71
|
-
/** Marks errors made by `createError()`, which stay recognizable when the module is loaded twice */
|
|
72
|
-
declare const BRAND = "__noofpiError";
|
|
73
|
-
declare class NoofpiError extends Error implements NoofpiErrorData {
|
|
74
|
-
readonly [BRAND] = true;
|
|
75
|
-
statusCode: number;
|
|
76
|
-
statusMessage: string;
|
|
77
|
-
url?: string;
|
|
78
|
-
constructor(input?: CreateErrorInput);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Creates an error to `throw` from a page's setup, a route middleware (or pass it to
|
|
82
|
-
* `showError()`): when the project has an `app/error.vue`, it is rendered with this error and the response gets its status.
|
|
83
|
-
*/
|
|
84
|
-
declare function createError(input: string | CreateErrorInput): NoofpiError;
|
|
85
|
-
|
|
86
|
-
/** A doofpi request seen by the dev request inspector */
|
|
87
|
-
interface RequestEntry {
|
|
88
|
-
/** Where the request was made: while rendering on the server or in the browser */
|
|
89
|
-
side: "server" | "browser";
|
|
90
|
-
mode: FetchMode;
|
|
91
|
-
/** `in-process` never touches the network (SSR `lfetch` / `pfetch` call the noofpi server directly) */
|
|
92
|
-
transport: "in-process" | "http";
|
|
93
|
-
method: string;
|
|
94
|
-
url: string;
|
|
95
|
-
/** `undefined` while the request is pending or when it failed before a response */
|
|
96
|
-
status?: number;
|
|
97
|
-
/** Milliseconds until the response headers arrived (or the request failed) */
|
|
98
|
-
ms?: number;
|
|
99
|
-
error?: string;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** Data collected during SSR and handed to the browser so it does not fetch again */
|
|
103
|
-
interface PayloadData {
|
|
104
|
-
data: Record<string, unknown>;
|
|
105
|
-
errors: Record<string, AsyncDataError>;
|
|
106
|
-
/** Values of `useState` by key */
|
|
107
|
-
state?: Record<string, unknown>;
|
|
108
|
-
/** Set when the server rendered the error page, so the browser hydrates the same one */
|
|
109
|
-
error?: NoofpiErrorData;
|
|
110
|
-
/** The locale the server rendered in (only with `i18n`), so the browser hydrates in the same one */
|
|
111
|
-
locale?: string;
|
|
112
|
-
/** Dev only: the doofpi requests the server made while rendering, for the dev request inspector */
|
|
113
|
-
requests?: RequestEntry[];
|
|
114
|
-
}
|
|
115
|
-
interface AsyncDataError {
|
|
116
|
-
message: string;
|
|
117
|
-
status?: number;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export { NoofpiError as a, booleanCodec as f, createError as g, defineCookie as h, enumCodec as i, jsonCodec as j, numberCodec as n, stringCodec as s };
|
|
121
|
-
export type { AsyncDataError as A, CreateErrorInput as C, NoofpiErrorData as N, PayloadData as P, RequestEntry as R, CookieJar as b, CookieOptions as c, CookieCodec as d, CookieDefinition as e };
|
|
@@ -1,127 +0,0 @@
|
|
|
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
|
-
/** 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 */
|
|
35
|
-
type CspDirectiveValue = string | string[] | boolean;
|
|
36
|
-
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 & {});
|
|
37
|
-
interface CspConfig {
|
|
38
|
-
/**
|
|
39
|
-
* Directives of the `Content-Security-Policy` header sent with every HTML page.
|
|
40
|
-
* Put `'nonce'` in a directive (typically `script-src` / `style-src`) to get a fresh nonce per request: it becomes
|
|
41
|
-
* `'nonce-<value>'` in the header and `nonce="<value>"` is added to every `<script>`, `<style>` and stylesheet /
|
|
42
|
-
* preload `<link>` of the page shell.
|
|
43
|
-
*/
|
|
44
|
-
directives: Partial<Record<CspDirectiveName, CspDirectiveValue>>;
|
|
45
|
-
/** Send `Content-Security-Policy-Report-Only` instead, so violations are reported but not blocked */
|
|
46
|
-
reportOnly?: boolean;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
interface CsrfConfig {
|
|
50
|
-
/** Extra origins (`https://app.example.com`) allowed to send state-changing requests to the API. The site's own origin is always allowed */
|
|
51
|
-
allowedOrigins?: string[];
|
|
52
|
-
/** 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 */
|
|
53
|
-
publicOrigin?: string;
|
|
54
|
-
}
|
|
55
|
-
interface SecurityConfig {
|
|
56
|
-
/** `Content-Security-Policy` of every HTML page. A `'nonce'` source gets a per-request nonce, added to the page's scripts and styles automatically */
|
|
57
|
-
csp?: CspConfig;
|
|
58
|
-
/**
|
|
59
|
-
* Security response headers added to every response that does not already set them. `false` turns them all off;
|
|
60
|
-
* an object overrides single headers (`{ "X-Frame-Options": "DENY" }`) or removes one (`{ "Referrer-Policy": false }`).
|
|
61
|
-
* Defaults: `X-Content-Type-Options: nosniff`, `X-Frame-Options: SAMEORIGIN` (skipped when the CSP has
|
|
62
|
-
* `frame-ancestors`), `Referrer-Policy: strict-origin-when-cross-origin`, `Permissions-Policy` (camera, microphone and
|
|
63
|
-
* geolocation off) and, over https only, `Strict-Transport-Security`.
|
|
64
|
-
*/
|
|
65
|
-
headers?: boolean | Record<string, string | false>;
|
|
66
|
-
/**
|
|
67
|
-
* Blocks cross-site state-changing requests (POST, PUT, PATCH, DELETE) to the doofpi API and the pfetch proxy by
|
|
68
|
-
* checking `Origin` / `Sec-Fetch-Site`. On by default; `false` turns it off.
|
|
69
|
-
*/
|
|
70
|
-
csrf?: boolean | CsrfConfig;
|
|
71
|
-
/**
|
|
72
|
-
* Largest request body in bytes the server accepts (for the doofpi API, the pfetch proxy and server middleware);
|
|
73
|
-
* bigger ones get a `413`. Default 10 MiB (10485760); `false` turns it off.
|
|
74
|
-
*/
|
|
75
|
-
bodyLimit?: number | false;
|
|
76
|
-
/**
|
|
77
|
-
* Hostnames (`app.example.com`, `app.example.com:8080` or `*.example.com` for any subdomain) the server answers to;
|
|
78
|
-
* requests with another `Host` get a `400`. Not set by default: any host is accepted.
|
|
79
|
-
*/
|
|
80
|
-
allowedHosts?: string[];
|
|
81
|
-
}
|
|
82
|
-
interface ResolvedSecurity {
|
|
83
|
-
csp?: CspConfig;
|
|
84
|
-
headers: Record<string, string>;
|
|
85
|
-
csrf: {
|
|
86
|
-
allowedOrigins: string[];
|
|
87
|
-
publicOrigin?: string;
|
|
88
|
-
} | false;
|
|
89
|
-
bodyLimit: number | false;
|
|
90
|
-
allowedHosts?: string[];
|
|
91
|
-
}
|
|
92
|
-
/** What a `routeRules` entry may change: each option replaces (`csp`, `csrf`, `bodyLimit`) or is applied on top of (`headers`) the global one */
|
|
93
|
-
interface RouteSecurityConfig {
|
|
94
|
-
/** CSP of the matching pages instead of the global one. `false` sends none */
|
|
95
|
-
csp?: CspConfig | false;
|
|
96
|
-
/** Applied on top of the global headers (`false` value removes one, `false` alone removes them all) */
|
|
97
|
-
headers?: boolean | Record<string, string | false>;
|
|
98
|
-
/** CSRF protection of matching API / proxy paths instead of the global one. `false` turns it off */
|
|
99
|
-
csrf?: boolean | CsrfConfig;
|
|
100
|
-
/** Request body limit in bytes of matching paths instead of the global one. `false` turns it off */
|
|
101
|
-
bodyLimit?: number | false;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** Options that apply to every page whose URL matches a `routeRules` pattern */
|
|
105
|
-
interface RouteRule {
|
|
106
|
-
/** `false` serves the client-only shell for matching pages, even when `ssr` is on globally */
|
|
107
|
-
ssr?: boolean;
|
|
108
|
-
/**
|
|
109
|
-
* How the doofpi client reaches the API on matching pages, instead of `doofpi.fetch`, e.g. `"sfetch"` to keep the
|
|
110
|
-
* API out of the browser for `/admin/**`. Needs `doofpi.url` unless it is `lfetch`; `sfetch` needs SSR.
|
|
111
|
-
* `useDoofpi()` picks it from the page it is called on, so call it in that page's `setup()`.
|
|
112
|
-
*/
|
|
113
|
-
fetch?: FetchMode;
|
|
114
|
-
/**
|
|
115
|
-
* Overrides the global `security` options for matching URL paths (pages, and the API / proxy for `csrf`).
|
|
116
|
-
* Server-only: never sent to the browser.
|
|
117
|
-
*/
|
|
118
|
-
security?: RouteSecurityConfig;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Keyed by URL path pattern: `/about` (exact), `/users/*` (one segment) or `/admin/**` (the path itself and
|
|
122
|
-
* everything below it). When several patterns match, the most specific one (the longest) wins per option.
|
|
123
|
-
*/
|
|
124
|
-
type RouteRules = Record<string, RouteRule>;
|
|
125
|
-
|
|
126
|
-
export { FETCH_MODES as d };
|
|
127
|
-
export type { CspConfig as C, FetchMode as F, HeadConfig as H, RouteRules as R, SecurityConfig as S, CspDirectiveName as a, CspDirectiveValue as b, CsrfConfig as c, HeadInput as e, HeadTag as f, RouteRule as g, ResolvedHead as h, ResolvedSecurity as i };
|