@arkstack/http 0.12.11 → 0.12.12

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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
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-Bwrh6IHq.js";
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-C1kZMywY.js";
2
2
  //#region src/middlewares/web.ts
3
3
  const webMiddlewareKey = Symbol.for("arkstack:http:web");
4
4
  const markWebRequest = (target) => {
@@ -744,7 +744,7 @@ const ensureSession = (ctx, initial, persistent) => {
744
744
  */
745
745
  const getSession = (ctx) => {
746
746
  if (!isRecord(ctx)) return;
747
- const session = ctx[sessionKey] ?? ctx.session;
747
+ const session = ctx[sessionKey] ?? (ctx.httpSession instanceof Session ? ctx.httpSession : void 0) ?? (ctx.session instanceof Session ? ctx.session : void 0) ?? (isRecord(ctx.req) && ctx.req.httpSession instanceof Session ? ctx.req.httpSession : void 0) ?? (isRecord(ctx.context) && ctx.context.httpSession instanceof Session ? ctx.context.httpSession : void 0);
748
748
  return session instanceof Session ? session : void 0;
749
749
  };
750
750
  //#endregion
@@ -1204,16 +1204,26 @@ const getSessionDriver = () => {
1204
1204
  const arkstackHttpPlugin = definePlugin({
1205
1205
  name: "arkstack-http",
1206
1206
  setup: ({ bind, useHttpContext }) => {
1207
- bind(Session, ({ ctx }) => ensureSession(ctx));
1208
- useHttpContext(async (context) => {
1207
+ bind(Session, async ({ ctx }) => {
1208
+ const existing = getSession(ctx);
1209
+ if (existing) return existing;
1210
+ const persistent = await getSessionDriver().start(ctx);
1211
+ const session = ensureSession(ctx, persistent.state, persistent);
1212
+ attachViewState(ctx, session);
1213
+ registerResponseFlashSweep(ctx, session);
1214
+ return session;
1215
+ });
1216
+ useHttpContext((context) => {
1217
+ const session = getSession(context.ctx);
1218
+ if (session) {
1219
+ context.httpSession = session;
1220
+ if (!("session" in context) || context.session instanceof Session) context.session = session;
1221
+ context.errors = session.errors;
1222
+ attachViewState(context.ctx, session);
1223
+ attachViewState(context, session);
1224
+ registerResponseFlashSweep(context, session);
1225
+ } else delete globalThis.session;
1209
1226
  globalThis.request = (key) => key ? context.request.input(key) : context.request;
1210
- const persistent = await getSessionDriver().start(context);
1211
- const session = ensureSession(context.ctx, persistent.state, persistent);
1212
- context.httpSession = session;
1213
- if (!("session" in context) || context.session instanceof Session) context.session = session;
1214
- context.errors = session.errors;
1215
- attachViewState(context, session);
1216
- registerResponseFlashSweep(context, session);
1217
1227
  });
1218
1228
  }
1219
1229
  });
package/dist/setup.js CHANGED
@@ -1,4 +1,4 @@
1
- import { F as Response$1, I as Request$1, a as kanunSessionPlugin, i as arkstackHttpPlugin, j as old, t as redirect } from "./redirect-Bwrh6IHq.js";
1
+ import { F as Response$1, I as Request$1, a as kanunSessionPlugin, i as arkstackHttpPlugin, j as old, t as redirect } from "./redirect-C1kZMywY.js";
2
2
  import { CoreRouter } from "clear-router";
3
3
  import { Validator } from "kanun";
4
4
  import "dotenv/config";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/http",
3
- "version": "0.12.11",
3
+ "version": "0.12.12",
4
4
  "type": "module",
5
5
  "description": "HTTP module for Arkstack, providing framework-agnostic request and response primitives.",
6
6
  "homepage": "https://arkstack.toneflix.net/guide/http",
@@ -30,8 +30,8 @@
30
30
  "dependencies": {
31
31
  "clear-router": "^2.8.6",
32
32
  "dotenv": "17.3.1",
33
- "@arkstack/contract": "^0.12.11",
34
- "@arkstack/common": "^0.12.11"
33
+ "@arkstack/contract": "^0.12.12",
34
+ "@arkstack/common": "^0.12.12"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "arkormx": "^2.4.1",