@arkstack/http 0.5.1 → 0.5.3
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 +2 -0
- package/dist/app.d.ts +46 -0
- package/dist/index-C-YhZgaG.d.ts +520 -0
- package/dist/index.d.ts +3 -80
- package/dist/index.js +48 -2
- package/dist/redirect-CsrtLK0U.js +1349 -0
- package/dist/setup.d.ts +11 -1
- package/dist/setup.js +7 -3
- package/package.json +9 -2
- package/dist/Response-DxFGT4o4.js +0 -143
- package/dist/Response-DxFGT4o4.js.map +0 -1
- package/dist/setup.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,48 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
1
|
+
import { A as registerResponseFlashSweep, B as normalizeHeaderValue, C as parseCookies, D as attachViewState, E as signValue, F as Response, H as resolveMiddleware, I as Request, L as isHeaders, M as Session, N as ErrorBag, O as ensureSession, P as FlashBag, R as isRecord, S as getCookie, T as setCookie, U as unwrapRequestSource, V as normalizeHeaders, _ as decodeJson, a as kanunSessionPlugin, b as encodeSignedValue, c as getSessionDriver, d as CookieSessionDriver, f as BaseSessionDriver, g as encodeSessionPayload, h as decodeSessionPayload, i as arkstackHttpPlugin, j as old, k as getSession, l as FileSessionDriver, m as encryptSessionValue, n as redirectBackTarget, o as configureSession, p as decryptSessionValue, r as resolveRedirectTarget, s as createSessionDriver, t as redirect, u as DatabaseSessionDriver, v as decodeSignedValue, w as serializeCookie, x as generateSessionId, y as encodeJson, z as makeHeaders } from "./redirect-CsrtLK0U.js";
|
|
2
|
+
//#region src/middlewares/web.ts
|
|
3
|
+
const webMiddlewareKey = Symbol.for("arkstack:http:web");
|
|
4
|
+
const markWebRequest = (target) => {
|
|
5
|
+
if (isRecord(target)) {
|
|
6
|
+
target[webMiddlewareKey] = true;
|
|
7
|
+
target.arkstackWeb = true;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const startWebSession = async (args) => {
|
|
11
|
+
const [first, second, third] = args;
|
|
12
|
+
const context = typeof third === "function" ? {
|
|
13
|
+
ctx: {
|
|
14
|
+
req: first,
|
|
15
|
+
res: second
|
|
16
|
+
},
|
|
17
|
+
req: first,
|
|
18
|
+
res: second
|
|
19
|
+
} : first;
|
|
20
|
+
if (!isRecord(context)) return;
|
|
21
|
+
const existingSession = context.httpSession || (context.session instanceof Session ? context.session : void 0) || (isRecord(context.req) ? context.req.httpSession : void 0) || (isRecord(context.context) ? context.context.httpSession : void 0);
|
|
22
|
+
if (existingSession instanceof Session) return existingSession;
|
|
23
|
+
const persistent = await getSessionDriver().start(context);
|
|
24
|
+
return ensureSession(context, persistent.state, persistent);
|
|
25
|
+
};
|
|
26
|
+
const web = async (...args) => {
|
|
27
|
+
const [first, second, third] = args;
|
|
28
|
+
markWebRequest(first);
|
|
29
|
+
markWebRequest(first?.context);
|
|
30
|
+
markWebRequest(first?.req);
|
|
31
|
+
if (isRecord(second)) markWebRequest(second);
|
|
32
|
+
const session = await startWebSession(args);
|
|
33
|
+
if (typeof third === "function") {
|
|
34
|
+
registerResponseFlashSweep({ res: second }, session);
|
|
35
|
+
return third();
|
|
36
|
+
}
|
|
37
|
+
if (typeof second === "function") {
|
|
38
|
+
const result = await second();
|
|
39
|
+
await session?.sweepFlash();
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const isWebRequest = (target) => {
|
|
44
|
+
if (!isRecord(target)) return false;
|
|
45
|
+
return target[webMiddlewareKey] === true || target.arkstackWeb === true || isWebRequest(target.context) || isWebRequest(target.req);
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { BaseSessionDriver, CookieSessionDriver, DatabaseSessionDriver, ErrorBag, FileSessionDriver, FlashBag, Request, Response, Session, arkstackHttpPlugin, attachViewState, configureSession, createSessionDriver, decodeJson, decodeSessionPayload, decodeSignedValue, decryptSessionValue, encodeJson, encodeSessionPayload, encodeSignedValue, encryptSessionValue, ensureSession, generateSessionId, getCookie, getSession, getSessionDriver, isHeaders, isRecord, isWebRequest, kanunSessionPlugin, makeHeaders, normalizeHeaderValue, normalizeHeaders, old, parseCookies, redirect, redirectBackTarget, registerResponseFlashSweep, resolveMiddleware, resolveRedirectTarget, serializeCookie, setCookie, signValue, unwrapRequestSource, web, webMiddlewareKey };
|