noofpi 2.0.0 → 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-LL3NO5EI.js → chunk-ROMSHDCI.js} +167 -88
- 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-HTWUY27O.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-KKQ2AEBW.js → prepare-APN2E6PX.js} +6 -5
- package/dist/runtime/entry-client.js +10 -7
- 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-AJKNZRJQ.js → start-PXOLWPL4.js} +7 -6
- package/dist/{types-B6rQOOxS.d.ts → types-B7xDyUbg.d.ts} +30 -5
- package/package.json +8 -3
- package/dist/build-PFCGDPPJ.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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createNoofpiApp
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-JUVQEKLE.js";
|
|
4
4
|
import "../chunk-6OWKWAIW.js";
|
|
5
5
|
import "../chunk-ELXCFUA4.js";
|
|
6
6
|
import "../chunk-EZPJF4D4.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-PC3ZJN4D.js";
|
|
8
|
+
import "../chunk-W7ASRDAJ.js";
|
|
9
9
|
|
|
10
10
|
// src/runtime/entry-client.ts
|
|
11
11
|
import { publicConfig } from "virtual:noofpi/config";
|
|
@@ -47,9 +47,13 @@ async function mount() {
|
|
|
47
47
|
const { app, router, payload, error, log, loaders, i18n } = createNoofpiApp({
|
|
48
48
|
server: false
|
|
49
49
|
});
|
|
50
|
+
const navigated = router.isReady().then(
|
|
51
|
+
() => void 0,
|
|
52
|
+
(failure) => ({ failure })
|
|
53
|
+
);
|
|
50
54
|
await i18n?.ready;
|
|
51
55
|
if (import.meta.env.DEV && publicConfig.devtools) {
|
|
52
|
-
const { mountDevtools } = await import("../devtools-
|
|
56
|
+
const { mountDevtools } = await import("../devtools-C3PFU57C.js");
|
|
53
57
|
mountDevtools({
|
|
54
58
|
router,
|
|
55
59
|
config: publicConfig,
|
|
@@ -65,9 +69,8 @@ async function mount() {
|
|
|
65
69
|
}
|
|
66
70
|
});
|
|
67
71
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
72
|
+
const outcome = await navigated;
|
|
73
|
+
if (outcome && !error.value) throw outcome.failure;
|
|
71
74
|
app.mount("#app");
|
|
72
75
|
listenForPrefetch(loaders.prefetch);
|
|
73
76
|
payload.data = {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { RenderContext, RenderResult } from '../server/index.js';
|
|
1
|
+
import { RenderContext, RenderResult, StreamRenderResult } from '../server/index.js';
|
|
2
2
|
import 'doofpi';
|
|
3
|
-
import '../
|
|
4
|
-
import '../payload-
|
|
3
|
+
import '../session-CAP_PIlN.js';
|
|
4
|
+
import '../payload-Cgul9YUP.js';
|
|
5
5
|
|
|
6
6
|
declare function render(url: string, ctx: RenderContext): Promise<RenderResult>;
|
|
7
|
+
/** Like `render`, but the page markup is returned as a stream (see `renderRouteStream`) */
|
|
8
|
+
declare function renderStream(url: string, ctx: RenderContext): Promise<RenderResult | StreamRenderResult>;
|
|
7
9
|
|
|
8
|
-
export { render };
|
|
10
|
+
export { render, renderStream };
|
|
@@ -4,67 +4,119 @@ import {
|
|
|
4
4
|
notFoundError,
|
|
5
5
|
setServerStateSource,
|
|
6
6
|
snapshotEntries
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-JUVQEKLE.js";
|
|
8
8
|
import "../chunk-6OWKWAIW.js";
|
|
9
9
|
import "../chunk-ELXCFUA4.js";
|
|
10
10
|
import {
|
|
11
11
|
isNoofpiError,
|
|
12
12
|
toErrorData
|
|
13
13
|
} from "../chunk-EZPJF4D4.js";
|
|
14
|
-
import "../chunk-
|
|
15
|
-
import "../chunk-
|
|
14
|
+
import "../chunk-PC3ZJN4D.js";
|
|
15
|
+
import "../chunk-W7ASRDAJ.js";
|
|
16
16
|
|
|
17
17
|
// src/runtime/entry-server.ts
|
|
18
18
|
import { AsyncLocalStorage } from "async_hooks";
|
|
19
|
-
import { renderToString } from "vue/server-renderer";
|
|
19
|
+
import { renderToString, renderToWebStream } from "vue/server-renderer";
|
|
20
20
|
import ErrorPage from "virtual:noofpi/error";
|
|
21
21
|
var requestScope = new AsyncLocalStorage();
|
|
22
22
|
setServerStateSource(() => requestScope.getStore()?.payload);
|
|
23
|
-
async function
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
...ctx
|
|
27
|
-
});
|
|
23
|
+
async function prepareRoute(url, ctx) {
|
|
24
|
+
const created = createNoofpiApp({ server: true, ...ctx });
|
|
25
|
+
const { app, router, payload, error } = created;
|
|
28
26
|
requestScope.getStore().payload = payload;
|
|
29
27
|
const failure = await router.push(url);
|
|
30
28
|
await router.isReady();
|
|
31
29
|
if (failure) {
|
|
32
|
-
if (!ErrorPage) return { html: "", status: 404 };
|
|
30
|
+
if (!ErrorPage) return { early: { html: "", status: 404 } };
|
|
33
31
|
error.value = notFoundError(url);
|
|
34
32
|
} else {
|
|
35
33
|
const requested = router.resolve(url).fullPath;
|
|
36
34
|
const current = router.currentRoute.value.fullPath;
|
|
37
35
|
if (current !== requested) {
|
|
38
36
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
early: {
|
|
38
|
+
html: "",
|
|
39
|
+
status: 302,
|
|
40
|
+
// One leading slash only, so a redirect can never turn into a protocol-relative (external) URL
|
|
41
|
+
redirect: "/" + current.replace(/^\/+/, "")
|
|
42
|
+
}
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
if (ErrorPage && !router.currentRoute.value.matched.length)
|
|
46
46
|
error.value = notFoundError(url);
|
|
47
47
|
}
|
|
48
|
+
return { prepared: created };
|
|
49
|
+
}
|
|
50
|
+
var statusOf = ({ router, error }) => error.value ? error.value.statusCode : router.currentRoute.value.matched.length ? 200 : 404;
|
|
51
|
+
function payloadOf({ payload, error, log, i18n }) {
|
|
52
|
+
return {
|
|
53
|
+
data: payload.data,
|
|
54
|
+
errors: payload.errors,
|
|
55
|
+
state: collectState(payload),
|
|
56
|
+
...error.value ? { error: error.value } : {},
|
|
57
|
+
...i18n ? { locale: i18n.locale.value } : {},
|
|
58
|
+
...log ? { requests: snapshotEntries(log) } : {}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async function renderRoute(url, ctx) {
|
|
62
|
+
const route = await prepareRoute(url, ctx);
|
|
63
|
+
if ("early" in route) return route.early;
|
|
64
|
+
const prepared = route.prepared;
|
|
65
|
+
const { app, head } = prepared;
|
|
48
66
|
const failures = [];
|
|
49
67
|
if (ErrorPage)
|
|
50
|
-
app.config.errorHandler = (
|
|
68
|
+
app.config.errorHandler = (failure) => void failures.push(failure);
|
|
51
69
|
const html = await renderToString(app);
|
|
52
70
|
if (failures.length) throw failures[0];
|
|
53
71
|
return {
|
|
54
72
|
html,
|
|
55
|
-
status:
|
|
56
|
-
payload:
|
|
57
|
-
data: payload.data,
|
|
58
|
-
errors: payload.errors,
|
|
59
|
-
state: collectState(payload),
|
|
60
|
-
...error.value ? { error: error.value } : {},
|
|
61
|
-
...i18n ? { locale: i18n.locale.value } : {},
|
|
62
|
-
...log ? { requests: snapshotEntries(log) } : {}
|
|
63
|
-
},
|
|
73
|
+
status: statusOf(prepared),
|
|
74
|
+
payload: payloadOf(prepared),
|
|
64
75
|
// Resolved after rendering, so titles that depend on fetched data are included
|
|
65
76
|
head: head.resolve()
|
|
66
77
|
};
|
|
67
78
|
}
|
|
79
|
+
async function renderRouteStream(url, ctx) {
|
|
80
|
+
const route = await prepareRoute(url, ctx);
|
|
81
|
+
if ("early" in route) return route.early;
|
|
82
|
+
const prepared = route.prepared;
|
|
83
|
+
const { app, head } = prepared;
|
|
84
|
+
const failures = [];
|
|
85
|
+
if (ErrorPage)
|
|
86
|
+
app.config.errorHandler = (failure) => void failures.push(failure);
|
|
87
|
+
const stream = renderToWebStream(app);
|
|
88
|
+
const reader = stream.getReader();
|
|
89
|
+
const first = await reader.read();
|
|
90
|
+
if (failures.length) {
|
|
91
|
+
await reader.cancel().catch(() => {
|
|
92
|
+
});
|
|
93
|
+
throw failures[0];
|
|
94
|
+
}
|
|
95
|
+
let queued = first.done ? void 0 : first.value;
|
|
96
|
+
const body = new ReadableStream({
|
|
97
|
+
async pull(controller) {
|
|
98
|
+
if (queued) {
|
|
99
|
+
controller.enqueue(queued);
|
|
100
|
+
queued = void 0;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const { done, value } = await reader.read();
|
|
104
|
+
if (done) controller.close();
|
|
105
|
+
else controller.enqueue(value);
|
|
106
|
+
},
|
|
107
|
+
cancel: (reason) => reader.cancel(reason)
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
status: statusOf(prepared),
|
|
111
|
+
head: head.resolve(),
|
|
112
|
+
body,
|
|
113
|
+
finish: () => ({
|
|
114
|
+
payload: payloadOf(prepared),
|
|
115
|
+
head: head.resolve(),
|
|
116
|
+
...failures.length ? { error: failures[0] } : {}
|
|
117
|
+
})
|
|
118
|
+
};
|
|
119
|
+
}
|
|
68
120
|
async function renderErrorPage(url, ctx, failure) {
|
|
69
121
|
const { app, payload, head, error, log, i18n } = createNoofpiApp({
|
|
70
122
|
server: true,
|
|
@@ -102,6 +154,17 @@ function render(url, ctx) {
|
|
|
102
154
|
}
|
|
103
155
|
});
|
|
104
156
|
}
|
|
157
|
+
function renderStream(url, ctx) {
|
|
158
|
+
return requestScope.run({}, async () => {
|
|
159
|
+
try {
|
|
160
|
+
return await renderRouteStream(url, ctx);
|
|
161
|
+
} catch (failure) {
|
|
162
|
+
if (!ErrorPage) throw failure;
|
|
163
|
+
return await renderErrorPage(url, ctx, failure);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
105
167
|
export {
|
|
106
|
-
render
|
|
168
|
+
render,
|
|
169
|
+
renderStream
|
|
107
170
|
};
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import * as vue from 'vue';
|
|
|
2
2
|
import { Ref, ComputedRef, ShallowRef, MaybeRefOrGetter, App, PropType, VNode } from 'vue';
|
|
3
3
|
import * as vue_router from 'vue-router';
|
|
4
4
|
import { RouteLocationNormalized, RouteParams, LocationQuery, Router, NavigationGuardReturn, LocationQueryRaw, NavigationFailure, RouteLocationRaw } from 'vue-router';
|
|
5
|
-
import { A as AsyncDataError, R as RequestEntry, N as NoofpiErrorData, C as CreateErrorInput, a as NoofpiError
|
|
5
|
+
import { A as AsyncDataError, R as RequestEntry, N as NoofpiErrorData, C as CreateErrorInput, a as NoofpiError } from '../payload-Cgul9YUP.js';
|
|
6
6
|
import { PayloadData } from '../server/index.js';
|
|
7
|
-
export {
|
|
7
|
+
export { c as createError } from '../payload-Cgul9YUP.js';
|
|
8
8
|
import Doofpi, { createClient, ClientFetch } from 'doofpi';
|
|
9
|
-
import {
|
|
9
|
+
import { h as HeadInput, o as CookieJar, m as SessionData, p as CookieOptions, q as CookieCodec, r as CookieDefinition } from '../session-CAP_PIlN.js';
|
|
10
10
|
import { FetchMode } from '../index.js';
|
|
11
11
|
import { ResolvedHead } from '../server/index.js';
|
|
12
|
-
export { H as HeadConfig,
|
|
12
|
+
export { C as CacheRule, b as CorsOptions, H as HeadConfig, i as HeadTag, j as RedirectRule, k as RouteRule, R as RouteRules, s as booleanCodec, t as defineCookie, u as enumCodec, v as jsonCodec, w as numberCodec, x as stringCodec } from '../session-CAP_PIlN.js';
|
|
13
13
|
import { M as Messages, c as MessageParamValue, d as ImageSource } from '../images-BNwTAi50.js';
|
|
14
14
|
import { F as FormErrors, a as FormSchema } from '../validation-Dwpex2JZ.js';
|
|
15
15
|
export { b as FORM_ERROR_KEY, I as InferSchema, V as ValidationIssue, c as ValidationResult, e as errorsFromFailure, i as issuesToErrors, v as validate } from '../validation-Dwpex2JZ.js';
|
|
@@ -269,6 +269,8 @@ interface NoofpiAppContext extends Omit<DoofpiClientContext, "origin"> {
|
|
|
269
269
|
acceptLanguage?: string;
|
|
270
270
|
/** The server's jar for the request; without it the server builds one from `cookie` and the browser uses `document.cookie` */
|
|
271
271
|
cookies?: CookieJar;
|
|
272
|
+
/** The part of the session the browser may see (server only), shown by `useSession()` */
|
|
273
|
+
session?: SessionData;
|
|
272
274
|
}
|
|
273
275
|
declare function createNoofpiApp(ctx: NoofpiAppContext): {
|
|
274
276
|
app: App;
|
|
@@ -329,6 +331,22 @@ declare function useCookie<T>(cookie: CookieDefinition<T>, options: UseCookieOpt
|
|
|
329
331
|
}): Ref<T>;
|
|
330
332
|
declare function useCookie<T>(cookie: CookieDefinition<T>, options?: UseCookieOptions<T>): Ref<T | undefined>;
|
|
331
333
|
|
|
334
|
+
interface UseSession<T extends SessionData = SessionData> {
|
|
335
|
+
/**
|
|
336
|
+
* The part of the session the `session.expose` option lists: set by the server while it renders, so SSR and hydration
|
|
337
|
+
* agree. Read-only here; change the session on the server (a doofpi endpoint, a server middleware)
|
|
338
|
+
*/
|
|
339
|
+
data: Readonly<Ref<Readonly<T>>>;
|
|
340
|
+
/** Fetches the session again, e.g. after logging in or out through the API. It does nothing on the server */
|
|
341
|
+
refresh(): Promise<void>;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* The visitor's session as far as the browser may see it (the keys of `session.expose`), on the server and in the
|
|
345
|
+
* browser. The full session, with what must stay private, is only reachable on the server with `getSession(request)`
|
|
346
|
+
* from `noofpi/server`. Call it inside `setup()`, a route middleware or any code that runs while rendering.
|
|
347
|
+
*/
|
|
348
|
+
declare function useSession<T extends SessionData = SessionData>(): UseSession<T>;
|
|
349
|
+
|
|
332
350
|
/**
|
|
333
351
|
* `useAsyncData` with the doofpi client handed to the handler: fetched on the server, transferred to the browser,
|
|
334
352
|
* not fetched again while hydrating. The client is typed by the `Register` routes of its mode (`localRoutes` for
|
|
@@ -556,5 +574,5 @@ declare function navigateTo<T extends RouteLocationRaw>(to: T extends keyof Regi
|
|
|
556
574
|
params?: Record<string, RouteParamValue>;
|
|
557
575
|
}): Promise<NavigationFailure | void | undefined>;
|
|
558
576
|
|
|
559
|
-
export { AsyncDataError, ClientOnly, CookieCodec, CookieDefinition, CookieJar, CookieOptions, CreateErrorInput, FormErrors, FormSchema, HeadInput, ImageSource, MessageParamValue, Messages, NoofpiError, NoofpiErrorData, NoofpiImage, NoofpiLayout, NoofpiLink, NoofpiPage, RequestEntry, clearError, createDoofpiClient, createNoofpiApp, defineMessages, defineNoofpiPlugin, definePage, defineRouteMiddleware, navigateTo, showError, useAsyncData, useCookie, useCookies, useDoofpi, useDoofpiFetch, useDoofpiForm, useError, useHead, useI18n, useLayout, useLoaderData, useMiddleware, useState };
|
|
560
|
-
export type { AsyncData, DoofpiClient, DoofpiClientConfig, DoofpiClientContext, DoofpiForm, I18n, LoaderContext, LoaderData, Locale, LocaleMessages, MessageArgs, MessageKey, NavigateToOptions, NoofpiPlugin, NoofpiPluginContext, PageDefinition, PageLoader, Register, RegisteredLocalRoutes, RegisteredMessages, RegisteredPages, RegisteredRemoteRoutes, RegisteredRoutes, RouteMiddleware, RouteParamValue, RoutesForMode, SubmitResult, TranslateFunction, UseAsyncDataOptions, UseCookieCodecOptions, UseCookieOptions, UseDoofpiFormOptions, UseDoofpiOptions };
|
|
577
|
+
export { AsyncDataError, ClientOnly, CookieCodec, CookieDefinition, CookieJar, CookieOptions, CreateErrorInput, FormErrors, FormSchema, HeadInput, ImageSource, MessageParamValue, Messages, NoofpiError, NoofpiErrorData, NoofpiImage, NoofpiLayout, NoofpiLink, NoofpiPage, RequestEntry, SessionData, clearError, createDoofpiClient, createNoofpiApp, defineMessages, defineNoofpiPlugin, definePage, defineRouteMiddleware, navigateTo, showError, useAsyncData, useCookie, useCookies, useDoofpi, useDoofpiFetch, useDoofpiForm, useError, useHead, useI18n, useLayout, useLoaderData, useMiddleware, useSession, useState };
|
|
578
|
+
export type { AsyncData, DoofpiClient, DoofpiClientConfig, DoofpiClientContext, DoofpiForm, I18n, LoaderContext, LoaderData, Locale, LocaleMessages, MessageArgs, MessageKey, NavigateToOptions, NoofpiPlugin, NoofpiPluginContext, PageDefinition, PageLoader, Register, RegisteredLocalRoutes, RegisteredMessages, RegisteredPages, RegisteredRemoteRoutes, RegisteredRoutes, RouteMiddleware, RouteParamValue, RoutesForMode, SubmitResult, TranslateFunction, UseAsyncDataOptions, UseCookieCodecOptions, UseCookieOptions, UseDoofpiFormOptions, UseDoofpiOptions, UseSession };
|
package/dist/runtime/index.js
CHANGED
|
@@ -15,8 +15,9 @@ import {
|
|
|
15
15
|
useHead,
|
|
16
16
|
useI18n,
|
|
17
17
|
useLoaderData,
|
|
18
|
+
useSession,
|
|
18
19
|
useState
|
|
19
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-JUVQEKLE.js";
|
|
20
21
|
import {
|
|
21
22
|
defineRouteMiddleware,
|
|
22
23
|
useMiddleware
|
|
@@ -37,8 +38,8 @@ import {
|
|
|
37
38
|
numberCodec,
|
|
38
39
|
stringCodec
|
|
39
40
|
} from "../chunk-EZPJF4D4.js";
|
|
40
|
-
import "../chunk-
|
|
41
|
-
import "../chunk-
|
|
41
|
+
import "../chunk-PC3ZJN4D.js";
|
|
42
|
+
import "../chunk-W7ASRDAJ.js";
|
|
42
43
|
import {
|
|
43
44
|
NoofpiLayout,
|
|
44
45
|
NoofpiLink,
|
|
@@ -219,6 +220,7 @@ export {
|
|
|
219
220
|
useLayout,
|
|
220
221
|
useLoaderData,
|
|
221
222
|
useMiddleware,
|
|
223
|
+
useSession,
|
|
222
224
|
useState,
|
|
223
225
|
validate
|
|
224
226
|
};
|
package/dist/server/bun.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Handler } from './index.js';
|
|
2
|
-
import '../types-
|
|
2
|
+
import '../types-B7xDyUbg.js';
|
|
3
3
|
import 'doofpi';
|
|
4
|
-
import '../
|
|
5
|
-
import '../payload-
|
|
4
|
+
import '../session-CAP_PIlN.js';
|
|
5
|
+
import '../payload-Cgul9YUP.js';
|
|
6
6
|
|
|
7
7
|
/** Serves a handler with `Bun.serve`: static files of `publicDir` first, then the handler. */
|
|
8
8
|
declare function serveBun(options: {
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { H as Handler, a as HandlerOptions, c as createHandler } from '../handler-
|
|
2
|
-
import { P as ProxyHook,
|
|
3
|
-
export {
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
1
|
+
export { H as Handler, a as HandlerContext, b as HandlerOptions, c as createHandler } from '../handler-BpyI3a5D.js';
|
|
2
|
+
import { P as ProxyHook, b as ServerMiddleware } from '../types-B7xDyUbg.js';
|
|
3
|
+
export { c as PROXY_PREFIX, R as RenderContext, a as RenderResult, d as ServerConfig, e as ServerMiddlewareContext, f as ServerModule, S as StreamRenderResult } from '../types-B7xDyUbg.js';
|
|
4
|
+
import { o as CookieJar, l as Session, m as SessionData } from '../session-CAP_PIlN.js';
|
|
5
|
+
export { C as CacheRule, q as CookieCodec, r as CookieDefinition, p as CookieOptions, b as CorsOptions, j as RedirectRule, n as ResolvedHead, y as ResolvedSecurity, k as RouteRule, S as SessionConfig, s as booleanCodec, t as defineCookie, u as enumCodec, v as jsonCodec, w as numberCodec, x as stringCodec } from '../session-CAP_PIlN.js';
|
|
6
6
|
export { b as FORM_ERROR_KEY, F as FormErrors, a as FormSchema, I as InferSchema, V as ValidationIssue, c as ValidationResult, e as errorsFromFailure, i as issuesToErrors, v as validate } from '../validation-Dwpex2JZ.js';
|
|
7
|
-
export {
|
|
7
|
+
export { P as PayloadData } from '../payload-Cgul9YUP.js';
|
|
8
8
|
import 'doofpi';
|
|
9
9
|
|
|
10
10
|
/** Resolves a proxied path to a URL on the remote API, or `null` when it is not allowed */
|
|
@@ -13,6 +13,8 @@ declare function proxyRequest(request: Request, options: {
|
|
|
13
13
|
base: string;
|
|
14
14
|
root: string;
|
|
15
15
|
hook?: ProxyHook;
|
|
16
|
+
/** Name of a cookie (the session's) that is not forwarded */
|
|
17
|
+
omitCookie?: string;
|
|
16
18
|
}): Promise<Response>;
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -22,7 +24,33 @@ declare function proxyRequest(request: Request, options: {
|
|
|
22
24
|
*/
|
|
23
25
|
declare function getRequestCookies(request: Request): CookieJar;
|
|
24
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The session of a request the noofpi server is handling (needs the `session` option). Pass the `Request` you were
|
|
29
|
+
* given (a doofpi endpoint's `req`, a server middleware's `request`, a `server/proxy.ts` hook's `request`); a copy of
|
|
30
|
+
* it is not known to the server. Changes are saved with the response.
|
|
31
|
+
*/
|
|
32
|
+
declare function getSession<T extends SessionData = SessionData>(request: Request): Session<T>;
|
|
33
|
+
interface SessionGuardOptions {
|
|
34
|
+
/** Path patterns (`/admin/**`, `/account`, like `routeRules`) the guard protects. Default: every path */
|
|
35
|
+
match?: string | string[];
|
|
36
|
+
/** Patterns that stay open although they match, e.g. `/login` and the API that logs in */
|
|
37
|
+
exclude?: string | string[];
|
|
38
|
+
/** Whether the session may pass. Default: it has data */
|
|
39
|
+
allow?: (session: Session) => boolean | Promise<boolean>;
|
|
40
|
+
/** Where a browser asking for a page is sent instead of getting a 401, with the page it wanted in `?redirect=` */
|
|
41
|
+
redirect?: string;
|
|
42
|
+
/** Name of that query parameter. Default: `redirect` */
|
|
43
|
+
redirectParam?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A `server/middleware/*.ts` that only lets requests with an allowed session through. Others get a `401` JSON answer,
|
|
47
|
+
* or, for pages, a redirect to `redirect`. Because it runs around every request, it also protects the doofpi API and the
|
|
48
|
+
* pfetch proxy under the patterns it matches.
|
|
49
|
+
*/
|
|
50
|
+
declare function sessionGuard(options?: SessionGuardOptions): ServerMiddleware;
|
|
51
|
+
|
|
25
52
|
/** Typing helper for `server/middleware/*.ts` */
|
|
26
53
|
declare function defineServerMiddleware(middleware: ServerMiddleware): ServerMiddleware;
|
|
27
54
|
|
|
28
|
-
export { CookieJar, ProxyHook, ServerMiddleware, defineServerMiddleware, getRequestCookies, proxyRequest, resolveProxyTarget };
|
|
55
|
+
export { CookieJar, ProxyHook, ServerMiddleware, Session, SessionData, defineServerMiddleware, getRequestCookies, getSession, proxyRequest, resolveProxyTarget, sessionGuard };
|
|
56
|
+
export type { SessionGuardOptions };
|
package/dist/server/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createHandler,
|
|
3
3
|
getRequestCookies,
|
|
4
|
+
getSession,
|
|
4
5
|
proxyRequest,
|
|
5
|
-
resolveProxyTarget
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
resolveProxyTarget,
|
|
7
|
+
sessionGuard
|
|
8
|
+
} from "../chunk-A7XQWIA6.js";
|
|
9
|
+
import "../chunk-LJEKK4AK.js";
|
|
10
|
+
import "../chunk-GOJZ36X5.js";
|
|
10
11
|
import {
|
|
11
12
|
FORM_ERROR_KEY,
|
|
12
13
|
errorsFromFailure,
|
|
@@ -21,8 +22,10 @@ import {
|
|
|
21
22
|
numberCodec,
|
|
22
23
|
stringCodec
|
|
23
24
|
} from "../chunk-EZPJF4D4.js";
|
|
24
|
-
import
|
|
25
|
-
|
|
25
|
+
import {
|
|
26
|
+
PROXY_PREFIX
|
|
27
|
+
} from "../chunk-PC3ZJN4D.js";
|
|
28
|
+
import "../chunk-W7ASRDAJ.js";
|
|
26
29
|
|
|
27
30
|
// src/server/index.ts
|
|
28
31
|
function defineServerMiddleware(middleware) {
|
|
@@ -38,11 +41,13 @@ export {
|
|
|
38
41
|
enumCodec,
|
|
39
42
|
errorsFromFailure,
|
|
40
43
|
getRequestCookies,
|
|
44
|
+
getSession,
|
|
41
45
|
issuesToErrors,
|
|
42
46
|
jsonCodec,
|
|
43
47
|
numberCodec,
|
|
44
48
|
proxyRequest,
|
|
45
49
|
resolveProxyTarget,
|
|
50
|
+
sessionGuard,
|
|
46
51
|
stringCodec,
|
|
47
52
|
validate
|
|
48
53
|
};
|
package/dist/server/node.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Server, ServerResponse, IncomingMessage } from 'node:http';
|
|
2
2
|
import { Handler } from './index.js';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-B7xDyUbg.js';
|
|
4
4
|
import 'doofpi';
|
|
5
|
-
import '../
|
|
6
|
-
import '../payload-
|
|
5
|
+
import '../session-CAP_PIlN.js';
|
|
6
|
+
import '../payload-Cgul9YUP.js';
|
|
7
7
|
|
|
8
8
|
declare function toWebRequest(req: IncomingMessage): Request;
|
|
9
9
|
declare function sendWebResponse(res: ServerResponse, response: Response): Promise<void>;
|