@arkstack/http 0.17.2 → 0.17.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.
@@ -3,6 +3,7 @@ import { MiddlewareClass, MiddlewareInstance, RequestData } from "clear-router/t
3
3
  import { User } from "@app/models/User";
4
4
 
5
5
  //#region src/Response.d.ts
6
+ declare const setResponseResolver: (resolver?: () => Response$1<any> | undefined) => void;
6
7
  /**
7
8
  * Represents an HTTP response, providing a consistent interface for accessing response data.
8
9
  *
@@ -156,6 +157,8 @@ declare class ErrorBag extends FlashBag<string[]> {
156
157
  }
157
158
  //#endregion
158
159
  //#region src/session/Session.d.ts
160
+ declare const setSessionResolver: (resolver?: () => Session | undefined) => void;
161
+ declare const clearFallbackSession: () => void;
159
162
  declare class Session {
160
163
  readonly errors: ErrorBag;
161
164
  readonly flashBag: FlashBag;
@@ -424,6 +427,11 @@ type ResponseSource = {
424
427
  redirect?: (status: number, path: string) => unknown;
425
428
  };
426
429
  type RequestOptions<TUser = unknown> = {
430
+ body?: Record<string, any>;
431
+ query?: Record<string, any>;
432
+ params?: Record<string, any>;
433
+ route?: any;
434
+ ctx?: any;
427
435
  headers?: HeaderSource;
428
436
  method?: string;
429
437
  url?: string;
@@ -454,6 +462,7 @@ interface OldHelper {
454
462
  }
455
463
  //#endregion
456
464
  //#region src/Request.d.ts
465
+ declare const setRequestResolver: (resolver?: () => Request$1<any> | undefined) => void;
457
466
  /**
458
467
  * Represents an HTTP request, providing a consistent interface for accessing request data.
459
468
  *
@@ -514,4 +523,4 @@ declare const webMiddlewareKey: unique symbol;
514
523
  declare const web: (...args: any[]) => Promise<any>;
515
524
  declare const isWebRequest: (target: unknown) => boolean;
516
525
  //#endregion
517
- export { arkstackHttpPlugin as $, CookieSessionDriver as A, generateSessionId as B, RequestHelper as C, SessionHelper as D, ResponseSource as E, encryptSessionValue as F, signValue as G, parseCookies as H, decodeJson as I, getSessionDriver as J, configureSession as K, decodeSignedValue as L, decodeSessionPayload as M, encodeSessionPayload as N, FileSessionDriver as O, decryptSessionValue as P, registerResponseFlashSweep as Q, encodeJson as R, RedirectHelper as S, RequestSource as T, serializeCookie as U, getCookie as V, setCookie as W, ensureSession as X, attachViewState as Y, getSession as Z, FunctionMiddleware as _, cookie_options as _t, redirect as a, HttpContextLike as at, HeaderValue as b, isHeaders as c, SessionDriver as ct, normalizeHeaderValue as d, SessionErrorRecord as dt, kanunSessionPlugin as et, normalizeHeaders as f, SessionErrorSource as ft, ClassMiddleware as g, SessionPayload as gt, Request$1 as h, SessionMessageProvider as ht, old as i, DatabaseSessionDriverOptions as it, BaseSessionDriver as j, DatabaseSessionDriver as k, isRecord as l, SessionDriverResult as lt, unwrapRequestSource as m, SessionInitialState as mt, web as n, ErrorBag as nt, redirectBackTarget as o, PersistentSessionConfig as ot, resolveMiddleware as p, SessionErrorValue as pt, createSessionDriver as q, webMiddlewareKey as r, BaseSessionDriverOptions as rt, resolveRedirectTarget as s, SessionConfig as st, isWebRequest as t, Session as tt, makeHeaders as u, SessionDriverType as ut, HeaderMap as v, FlashBag as vt, RequestOptions as w, OldHelper as x, HeaderSource as y, Response$1 as yt, encodeSignedValue as z };
526
+ export { registerResponseFlashSweep as $, DatabaseSessionDriver as A, encodeSignedValue as B, RedirectHelper as C, setResponseResolver as Ct, ResponseSource as D, RequestSource as E, decryptSessionValue as F, setCookie as G, getCookie as H, encryptSessionValue as I, createSessionDriver as J, signValue as K, decodeJson as L, BaseSessionDriver as M, decodeSessionPayload as N, SessionHelper as O, encodeSessionPayload as P, getSession as Q, decodeSignedValue as R, OldHelper as S, Response$1 as St, RequestOptions as T, parseCookies as U, generateSessionId as V, serializeCookie as W, attachViewState as X, getSessionDriver as Y, ensureSession as Z, ClassMiddleware as _, SessionInitialState as _t, redirect as a, ErrorBag as at, HeaderSource as b, cookie_options as bt, isHeaders as c, HttpContextLike as ct, normalizeHeaderValue as d, SessionDriver as dt, arkstackHttpPlugin as et, normalizeHeaders as f, SessionDriverResult as ft, setRequestResolver as g, SessionErrorValue as gt, Request$1 as h, SessionErrorSource as ht, old as i, setSessionResolver as it, CookieSessionDriver as j, FileSessionDriver as k, isRecord as l, PersistentSessionConfig as lt, unwrapRequestSource as m, SessionErrorRecord as mt, web as n, Session as nt, redirectBackTarget as o, BaseSessionDriverOptions as ot, resolveMiddleware as p, SessionDriverType as pt, configureSession as q, webMiddlewareKey as r, clearFallbackSession as rt, resolveRedirectTarget as s, DatabaseSessionDriverOptions as st, isWebRequest as t, kanunSessionPlugin as tt, makeHeaders as u, SessionConfig as ut, FunctionMiddleware as v, SessionMessageProvider as vt, RequestHelper as w, HeaderValue as x, FlashBag as xt, HeaderMap as y, SessionPayload as yt, encodeJson as z };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference path="./app.d.ts" />
2
- import { $ as arkstackHttpPlugin, A as CookieSessionDriver, B as generateSessionId, C as RequestHelper, D as SessionHelper, E as ResponseSource, F as encryptSessionValue, G as signValue, H as parseCookies, I as decodeJson, J as getSessionDriver, K as configureSession, L as decodeSignedValue, M as decodeSessionPayload, N as encodeSessionPayload, O as FileSessionDriver, P as decryptSessionValue, Q as registerResponseFlashSweep, R as encodeJson, S as RedirectHelper, T as RequestSource, U as serializeCookie, V as getCookie, W as setCookie, X as ensureSession, Y as attachViewState, Z as getSession, _ as FunctionMiddleware, _t as cookie_options, a as redirect, at as HttpContextLike, b as HeaderValue, c as isHeaders, ct as SessionDriver, d as normalizeHeaderValue, dt as SessionErrorRecord, et as kanunSessionPlugin, f as normalizeHeaders, ft as SessionErrorSource, g as ClassMiddleware, gt as SessionPayload, h as Request, ht as SessionMessageProvider, i as old, it as DatabaseSessionDriverOptions, j as BaseSessionDriver, k as DatabaseSessionDriver, l as isRecord, lt as SessionDriverResult, m as unwrapRequestSource, mt as SessionInitialState, n as web, nt as ErrorBag, o as redirectBackTarget, ot as PersistentSessionConfig, p as resolveMiddleware, pt as SessionErrorValue, q as createSessionDriver, r as webMiddlewareKey, rt as BaseSessionDriverOptions, s as resolveRedirectTarget, st as SessionConfig, t as isWebRequest, tt as Session, u as makeHeaders, ut as SessionDriverType, v as HeaderMap, vt as FlashBag, w as RequestOptions, x as OldHelper, y as HeaderSource, yt as Response, z as encodeSignedValue } from "./index-AYUuBkXH.js";
3
- export { BaseSessionDriver, BaseSessionDriverOptions, ClassMiddleware, CookieSessionDriver, DatabaseSessionDriver, DatabaseSessionDriverOptions, ErrorBag, FileSessionDriver, FlashBag, FunctionMiddleware, HeaderMap, HeaderSource, HeaderValue, HttpContextLike, OldHelper, PersistentSessionConfig, RedirectHelper, Request, RequestHelper, RequestOptions, RequestSource, Response, ResponseSource, Session, SessionConfig, SessionDriver, SessionDriverResult, SessionDriverType, SessionErrorRecord, SessionErrorSource, SessionErrorValue, SessionHelper, SessionInitialState, SessionMessageProvider, SessionPayload, arkstackHttpPlugin, attachViewState, configureSession, cookie_options, 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 };
2
+ import { $ as registerResponseFlashSweep, A as DatabaseSessionDriver, B as encodeSignedValue, C as RedirectHelper, Ct as setResponseResolver, D as ResponseSource, E as RequestSource, F as decryptSessionValue, G as setCookie, H as getCookie, I as encryptSessionValue, J as createSessionDriver, K as signValue, L as decodeJson, M as BaseSessionDriver, N as decodeSessionPayload, O as SessionHelper, P as encodeSessionPayload, Q as getSession, R as decodeSignedValue, S as OldHelper, St as Response, T as RequestOptions, U as parseCookies, V as generateSessionId, W as serializeCookie, X as attachViewState, Y as getSessionDriver, Z as ensureSession, _ as ClassMiddleware, _t as SessionInitialState, a as redirect, at as ErrorBag, b as HeaderSource, bt as cookie_options, c as isHeaders, ct as HttpContextLike, d as normalizeHeaderValue, dt as SessionDriver, et as arkstackHttpPlugin, f as normalizeHeaders, ft as SessionDriverResult, g as setRequestResolver, gt as SessionErrorValue, h as Request, ht as SessionErrorSource, i as old, it as setSessionResolver, j as CookieSessionDriver, k as FileSessionDriver, l as isRecord, lt as PersistentSessionConfig, m as unwrapRequestSource, mt as SessionErrorRecord, n as web, nt as Session, o as redirectBackTarget, ot as BaseSessionDriverOptions, p as resolveMiddleware, pt as SessionDriverType, q as configureSession, r as webMiddlewareKey, rt as clearFallbackSession, s as resolveRedirectTarget, st as DatabaseSessionDriverOptions, t as isWebRequest, tt as kanunSessionPlugin, u as makeHeaders, ut as SessionConfig, v as FunctionMiddleware, vt as SessionMessageProvider, w as RequestHelper, x as HeaderValue, xt as FlashBag, y as HeaderMap, yt as SessionPayload, z as encodeJson } from "./index-Dw5AaS_c.js";
3
+ export { BaseSessionDriver, BaseSessionDriverOptions, ClassMiddleware, CookieSessionDriver, DatabaseSessionDriver, DatabaseSessionDriverOptions, ErrorBag, FileSessionDriver, FlashBag, FunctionMiddleware, HeaderMap, HeaderSource, HeaderValue, HttpContextLike, OldHelper, PersistentSessionConfig, RedirectHelper, Request, RequestHelper, RequestOptions, RequestSource, Response, ResponseSource, Session, SessionConfig, SessionDriver, SessionDriverResult, SessionDriverType, SessionErrorRecord, SessionErrorSource, SessionErrorValue, SessionHelper, SessionInitialState, SessionMessageProvider, SessionPayload, arkstackHttpPlugin, attachViewState, clearFallbackSession, configureSession, cookie_options, 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, setRequestResolver, setResponseResolver, setSessionResolver, signValue, unwrapRequestSource, web, webMiddlewareKey };
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-BPQIvVtB.js";
1
+ import { A as registerResponseFlashSweep, B as setRequestResolver, C as parseCookies, D as attachViewState, E as signValue, F as ErrorBag, G as normalizeHeaders, H as isRecord, I as FlashBag, K as resolveMiddleware, L as Response, M as Session, N as clearFallbackSession, O as ensureSession, P as setSessionResolver, R as setResponseResolver, S as getCookie, T as setCookie, U as makeHeaders, V as isHeaders, W as normalizeHeaderValue, _ 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, q as unwrapRequestSource, 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 Request } from "./redirect-BzYZk5xe.js";
2
2
  //#region src/middlewares/web.ts
3
3
  const webMiddlewareKey = Symbol.for("arkstack:http:web");
4
4
  const markWebRequest = (target) => {
@@ -45,4 +45,4 @@ const isWebRequest = (target) => {
45
45
  return target[webMiddlewareKey] === true || target.arkstackWeb === true || isWebRequest(target.context) || isWebRequest(target.req);
46
46
  };
47
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 };
48
+ export { BaseSessionDriver, CookieSessionDriver, DatabaseSessionDriver, ErrorBag, FileSessionDriver, FlashBag, Request, Response, Session, arkstackHttpPlugin, attachViewState, clearFallbackSession, 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, setRequestResolver, setResponseResolver, setSessionResolver, signValue, unwrapRequestSource, web, webMiddlewareKey };
@@ -64,6 +64,28 @@ const resolveMiddleware = (middleware) => {
64
64
  };
65
65
  //#endregion
66
66
  //#region src/Request.ts
67
+ let fallbackRequest;
68
+ const requestResolvers = /* @__PURE__ */ new Set();
69
+ const currentRequest = () => {
70
+ for (const resolver of requestResolvers) {
71
+ const request = resolver();
72
+ if (request) return request;
73
+ }
74
+ return fallbackRequest;
75
+ };
76
+ const requestHelper = ((key) => {
77
+ const request = currentRequest();
78
+ return key ? request?.input(key) : request;
79
+ });
80
+ const setRequestResolver = (resolver) => {
81
+ if (resolver) requestResolvers.add(resolver);
82
+ else requestResolvers.clear();
83
+ globalThis.request = requestHelper;
84
+ };
85
+ const setFallbackRequest = (request) => {
86
+ fallbackRequest = request;
87
+ globalThis.request = requestHelper;
88
+ };
67
89
  /**
68
90
  * Represents an HTTP request, providing a consistent interface for accessing request data.
69
91
  *
@@ -115,13 +137,19 @@ var Request$1 = class Request$1 extends Request {
115
137
  this.authUser = options.authUser ?? sourceRequest?.authUser;
116
138
  this.authToken = options.authToken ?? sourceRequest?.authToken;
117
139
  this.source = source;
118
- globalThis.request = (key) => key ? this.input(key) : this;
140
+ setFallbackRequest(this);
119
141
  }
120
142
  static from(source) {
121
143
  if (!source) return;
122
144
  if (source instanceof Request$1) return source;
123
145
  const request = unwrapRequestSource(source);
146
+ const unified = source;
124
147
  return new Request$1({
148
+ body: unified.body,
149
+ query: unified.query,
150
+ params: unified.params,
151
+ route: unified.route,
152
+ ctx: unified.ctx,
125
153
  headers: request.headers,
126
154
  method: request.method,
127
155
  url: request.originalUrl ?? request.url,
@@ -131,7 +159,8 @@ var Request$1 = class Request$1 extends Request {
131
159
  auth: request.auth,
132
160
  authUser: request.authUser,
133
161
  authToken: request.authToken,
134
- source: request
162
+ source: request,
163
+ original: unified.original
135
164
  });
136
165
  }
137
166
  header(name) {
@@ -187,6 +216,24 @@ var Request$1 = class Request$1 extends Request {
187
216
  };
188
217
  //#endregion
189
218
  //#region src/Response.ts
219
+ let fallbackResponse;
220
+ const responseResolvers = /* @__PURE__ */ new Set();
221
+ const responseHelper = () => {
222
+ for (const resolver of responseResolvers) {
223
+ const response = resolver();
224
+ if (response) return response;
225
+ }
226
+ return fallbackResponse;
227
+ };
228
+ const setResponseResolver = (resolver) => {
229
+ if (resolver) responseResolvers.add(resolver);
230
+ else responseResolvers.clear();
231
+ globalThis.response = responseHelper;
232
+ };
233
+ const setFallbackResponse = (response) => {
234
+ fallbackResponse = response;
235
+ globalThis.response = responseHelper;
236
+ };
190
237
  /**
191
238
  * Represents an HTTP response, providing a consistent interface for accessing response data.
192
239
  *
@@ -203,7 +250,7 @@ var Response$1 = class Response$1 extends Response {
203
250
  });
204
251
  this.body = options.body ?? {};
205
252
  this.source = options.source;
206
- globalThis.response = () => this;
253
+ setFallbackResponse(this);
207
254
  }
208
255
  static from(source) {
209
256
  if (!source) return;
@@ -473,6 +520,37 @@ var ErrorBag = class ErrorBag extends FlashBag {
473
520
  };
474
521
  //#endregion
475
522
  //#region src/session/Session.ts
523
+ let fallbackSession;
524
+ const sessionResolvers = /* @__PURE__ */ new Set();
525
+ const currentSession = () => {
526
+ for (const resolver of sessionResolvers) {
527
+ const session = resolver();
528
+ if (session) return session;
529
+ }
530
+ return fallbackSession;
531
+ };
532
+ const sessionHelperTarget = (key) => {
533
+ const session = currentSession();
534
+ return key ? session?.get(key) : session;
535
+ };
536
+ const sessionHelper = new Proxy(sessionHelperTarget, { get(target, property, receiver) {
537
+ if (Reflect.has(target, property)) return Reflect.get(target, property, receiver);
538
+ const session = currentSession();
539
+ const value = session?.[property];
540
+ return typeof value === "function" ? value.bind(session) : value;
541
+ } });
542
+ const setSessionResolver = (resolver) => {
543
+ if (resolver) sessionResolvers.add(resolver);
544
+ else sessionResolvers.clear();
545
+ globalThis.session = sessionHelper;
546
+ };
547
+ const clearFallbackSession = () => {
548
+ fallbackSession = void 0;
549
+ };
550
+ const setFallbackSession = (session) => {
551
+ fallbackSession = session;
552
+ globalThis.session = sessionHelper;
553
+ };
476
554
  var Session = class Session {
477
555
  errors;
478
556
  flashBag;
@@ -489,23 +567,7 @@ var Session = class Session {
489
567
  this.data = current ? current.data : { ...state.data || {} };
490
568
  this.errors = current ? current.errors : state.errors instanceof ErrorBag ? state.errors : new ErrorBag(state.errors);
491
569
  this.flashBag = current ? current.flashBag : state.flash instanceof FlashBag ? state.flash : new FlashBag(state.flash);
492
- const helper = ((key) => key ? this.get(key) : this);
493
- Object.assign(helper, {
494
- get: this.get.bind(this),
495
- put: this.put.bind(this),
496
- set: this.set.bind(this),
497
- has: this.has.bind(this),
498
- forget: this.forget.bind(this),
499
- clear: this.clear.bind(this),
500
- all: this.all.bind(this),
501
- flash: this.flash.bind(this),
502
- getFlash: this.getFlash.bind(this),
503
- hasErrors: this.hasErrors.bind(this),
504
- clearErrors: this.clearErrors.bind(this),
505
- errors: this.errors,
506
- flashBag: this.flashBag
507
- });
508
- globalThis.session = helper;
570
+ setFallbackSession(this);
509
571
  }
510
572
  snapshot() {
511
573
  return {
@@ -1277,9 +1339,25 @@ const getSessionDriver = () => {
1277
1339
  };
1278
1340
  //#endregion
1279
1341
  //#region src/plugins.ts
1342
+ const requestBindingKey = Symbol.for("arkstack:http:request");
1343
+ const responseBindingKey = Symbol.for("arkstack:http:response");
1280
1344
  const arkstackHttpPlugin = definePlugin({
1281
1345
  name: "arkstack-http",
1282
- setup: ({ bind, useHttpContext }) => {
1346
+ setup: ({ bind, getRequest, getResponse, useHttpContext }) => {
1347
+ setRequestResolver(() => {
1348
+ const request = getRequest();
1349
+ const bound = request?.ctx?.[requestBindingKey];
1350
+ return bound instanceof Request$1 ? bound : request instanceof Request$1 ? request : Request$1.from(request);
1351
+ });
1352
+ setResponseResolver(() => {
1353
+ const response = getResponse();
1354
+ const bound = getRequest()?.ctx?.[responseBindingKey];
1355
+ return bound instanceof Response$1 ? bound : response instanceof Response$1 ? response : Response$1.from(response);
1356
+ });
1357
+ setSessionResolver(() => {
1358
+ const request = getRequest();
1359
+ return getSession(request?.ctx ?? request);
1360
+ });
1283
1361
  bind(Session, async ({ ctx }) => {
1284
1362
  const existing = getSession(ctx);
1285
1363
  if (existing) return existing;
@@ -1288,10 +1366,26 @@ const arkstackHttpPlugin = definePlugin({
1288
1366
  attachViewState(ctx, session);
1289
1367
  registerResponseFlashSweep(ctx, session);
1290
1368
  return session;
1291
- });
1369
+ }, { scope: "request" });
1292
1370
  bind(Request$1, ({ request, ctx }) => {
1293
- return (request instanceof Request$1 ? request : Request$1.from(request ?? ctx)).syncFromSource();
1294
- });
1371
+ const httpContext = ctx;
1372
+ const cached = httpContext[requestBindingKey];
1373
+ if (cached instanceof Request$1) return cached;
1374
+ const current = request instanceof Request$1 ? request : Request$1.from(request ?? ctx);
1375
+ current.ctx = httpContext;
1376
+ httpContext[requestBindingKey] = current;
1377
+ httpContext.clearRequest = current;
1378
+ return current.syncFromSource();
1379
+ }, { scope: "request" });
1380
+ bind(Response$1, ({ response, ctx }) => {
1381
+ const httpContext = ctx;
1382
+ const cached = httpContext[responseBindingKey];
1383
+ if (cached instanceof Response$1) return cached;
1384
+ const current = response instanceof Response$1 ? response : Response$1.from(response ?? ctx);
1385
+ httpContext[responseBindingKey] = current;
1386
+ httpContext.clearResponse = current;
1387
+ return current;
1388
+ }, { scope: "request" });
1295
1389
  useHttpContext((context) => {
1296
1390
  const session = getSession(context.ctx);
1297
1391
  if (session) {
@@ -1301,8 +1395,7 @@ const arkstackHttpPlugin = definePlugin({
1301
1395
  attachViewState(context.ctx, session);
1302
1396
  attachViewState(context, session);
1303
1397
  registerResponseFlashSweep(context, session);
1304
- } else delete globalThis.session;
1305
- globalThis.request = (key) => key ? context.request.input(key) : context.request;
1398
+ } else clearFallbackSession();
1306
1399
  });
1307
1400
  }
1308
1401
  });
@@ -1344,4 +1437,4 @@ const redirect = (to = "back", status = defaultRedirectStatus) => {
1344
1437
  return response;
1345
1438
  };
1346
1439
  //#endregion
1347
- export { registerResponseFlashSweep as A, normalizeHeaderValue as B, parseCookies as C, attachViewState as D, signValue as E, Response$1 as F, resolveMiddleware as H, Request$1 as I, isHeaders as L, Session as M, ErrorBag as N, ensureSession as O, FlashBag as P, isRecord as R, getCookie as S, setCookie as T, unwrapRequestSource as U, normalizeHeaders as V, decodeJson as _, kanunSessionPlugin as a, encodeSignedValue as b, getSessionDriver as c, CookieSessionDriver as d, BaseSessionDriver as f, encodeSessionPayload as g, decodeSessionPayload as h, arkstackHttpPlugin as i, old as j, getSession as k, FileSessionDriver as l, encryptSessionValue as m, redirectBackTarget as n, configureSession as o, decryptSessionValue as p, resolveRedirectTarget as r, createSessionDriver as s, redirect as t, DatabaseSessionDriver as u, decodeSignedValue as v, serializeCookie as w, generateSessionId as x, encodeJson as y, makeHeaders as z };
1440
+ export { registerResponseFlashSweep as A, setRequestResolver as B, parseCookies as C, attachViewState as D, signValue as E, ErrorBag as F, normalizeHeaders as G, isRecord as H, FlashBag as I, resolveMiddleware as K, Response$1 as L, Session as M, clearFallbackSession as N, ensureSession as O, setSessionResolver as P, setResponseResolver as R, getCookie as S, setCookie as T, makeHeaders as U, isHeaders as V, normalizeHeaderValue as W, decodeJson as _, kanunSessionPlugin as a, encodeSignedValue as b, getSessionDriver as c, CookieSessionDriver as d, BaseSessionDriver as f, encodeSessionPayload as g, decodeSessionPayload as h, arkstackHttpPlugin as i, old as j, getSession as k, FileSessionDriver as l, encryptSessionValue as m, redirectBackTarget as n, configureSession as o, decryptSessionValue as p, unwrapRequestSource as q, resolveRedirectTarget as r, createSessionDriver as s, redirect as t, DatabaseSessionDriver as u, decodeSignedValue as v, serializeCookie as w, generateSessionId as x, encodeJson as y, Request$1 as z };
package/dist/setup.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as RequestHelper, D as SessionHelper, S as RedirectHelper, x as OldHelper, yt as Response } from "./index-AYUuBkXH.js";
1
+ import { C as RedirectHelper, O as SessionHelper, S as OldHelper, St as Response, w as RequestHelper } from "./index-Dw5AaS_c.js";
2
2
  import { User } from "@app/models/User";
3
3
 
4
4
  //#region src/setup.d.ts
package/dist/setup.js CHANGED
@@ -1,8 +1,9 @@
1
- import { F as Response$1, I as Request$1, a as kanunSessionPlugin, i as arkstackHttpPlugin, j as old, t as redirect } from "./redirect-BPQIvVtB.js";
1
+ import { L as Response$1, a as kanunSessionPlugin, i as arkstackHttpPlugin, j as old, t as redirect, z as Request$1 } from "./redirect-BzYZk5xe.js";
2
2
  import { CoreRouter } from "clear-router";
3
3
  import { Validator } from "kanun";
4
4
  import { dirname, join } from "node:path";
5
5
  import "dotenv/config";
6
+ import "clear-router/decorators/setup";
6
7
  import { Publisher } from "@arkstack/common";
7
8
  import { fileURLToPath } from "node:url";
8
9
  //#region src/setup.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/http",
3
- "version": "0.17.2",
3
+ "version": "0.17.3",
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",
@@ -29,10 +29,10 @@
29
29
  "./package.json": "./package.json"
30
30
  },
31
31
  "dependencies": {
32
- "clear-router": "^2.9.1",
32
+ "clear-router": "^2.9.2",
33
33
  "dotenv": "^17.4.2",
34
- "@arkstack/contract": "^0.17.2",
35
- "@arkstack/common": "^0.17.2"
34
+ "@arkstack/contract": "^0.17.3",
35
+ "@arkstack/common": "^0.17.3"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "arkormx": "^2.11.4",