@arkstack/driver-express 0.14.21 → 0.15.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.
@@ -22,6 +22,25 @@ declare class FormDataMiddleware {
22
22
  handler(req: Request, res: Response, next: NextFunction): unknown;
23
23
  }
24
24
  //#endregion
25
+ //#region src/middlewares/inertia.d.ts
26
+ /**
27
+ * Bind the Inertia request context for Express.
28
+ *
29
+ * Normalizes the Express request into the adapter's driver-agnostic shape and
30
+ * runs the downstream handler inside Inertia's async-local context (mirroring the
31
+ * `resora` middleware), so `inertia()` / `Inertia.*` resolve the active request.
32
+ *
33
+ * It also upgrades `302` redirects to `303 See Other` for `PUT`/`PATCH`/`DELETE`
34
+ * Inertia visits, which the Inertia client requires to follow the redirect with
35
+ * a `GET`.
36
+ *
37
+ * `@arkstack/inertia` is imported dynamically so the package stays optional.
38
+ */
39
+ declare const inertia: () => Handler;
40
+ declare class InertiaMiddleware {
41
+ handler(req: Request, res: Response, next: NextFunction): unknown;
42
+ }
43
+ //#endregion
25
44
  //#region src/middlewares/limiter.d.ts
26
45
  /**
27
46
  * create a rate limiter middleware
@@ -66,4 +85,4 @@ declare class RequestLoggerMiddleware {
66
85
  */
67
86
  declare const resora: () => Handler;
68
87
  //#endregion
69
- export { AuthMiddleware, FormDataMiddleware, RequestLoggerMiddleware, auth, formdata, limiter, requestLogger, resora };
88
+ export { AuthMiddleware, FormDataMiddleware, InertiaMiddleware, RequestLoggerMiddleware, auth, formdata, inertia, limiter, requestLogger, resora };
@@ -74,6 +74,53 @@ var FormDataMiddleware = class {
74
74
  }
75
75
  };
76
76
  //#endregion
77
+ //#region src/middlewares/inertia.ts
78
+ /**
79
+ * Bind the Inertia request context for Express.
80
+ *
81
+ * Normalizes the Express request into the adapter's driver-agnostic shape and
82
+ * runs the downstream handler inside Inertia's async-local context (mirroring the
83
+ * `resora` middleware), so `inertia()` / `Inertia.*` resolve the active request.
84
+ *
85
+ * It also upgrades `302` redirects to `303 See Other` for `PUT`/`PATCH`/`DELETE`
86
+ * Inertia visits, which the Inertia client requires to follow the redirect with
87
+ * a `GET`.
88
+ *
89
+ * `@arkstack/inertia` is imported dynamically so the package stays optional.
90
+ */
91
+ const inertia = () => {
92
+ return async (req, res, next) => {
93
+ try {
94
+ const { runInertia, shouldUpgradeRedirect } = await import("@arkstack/inertia");
95
+ const request = {
96
+ method: String(req.method ?? "GET").toUpperCase(),
97
+ url: req.originalUrl || req.url || "/",
98
+ header: (name) => {
99
+ const value = req.headers[name.toLowerCase()];
100
+ return Array.isArray(value) ? value[0] : value;
101
+ }
102
+ };
103
+ if (request.header("x-inertia") === "true") {
104
+ const original = res.redirect.bind(res);
105
+ res.redirect = ((...args) => {
106
+ let status = typeof args[0] === "number" ? args[0] : 302;
107
+ const url = typeof args[0] === "number" ? args[1] : args[0];
108
+ if (shouldUpgradeRedirect(request.method, status)) status = 303;
109
+ return original(status, url);
110
+ });
111
+ }
112
+ runInertia(request, () => next());
113
+ } catch (error) {
114
+ next(error);
115
+ }
116
+ };
117
+ };
118
+ var InertiaMiddleware = class {
119
+ handler(req, res, next) {
120
+ return inertia()(req, res, next);
121
+ }
122
+ };
123
+ //#endregion
77
124
  //#region src/Exceptions/RateLimitExceededException.ts
78
125
  var RateLimitExceededException = class extends Exception {
79
126
  statusCode = 429;
@@ -180,4 +227,4 @@ const resora = () => {
180
227
  };
181
228
  };
182
229
  //#endregion
183
- export { AuthMiddleware, FormDataMiddleware, RequestLoggerMiddleware, auth, formdata, limiter, requestLogger, resora };
230
+ export { AuthMiddleware, FormDataMiddleware, InertiaMiddleware, RequestLoggerMiddleware, auth, formdata, inertia, limiter, requestLogger, resora };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/driver-express",
3
- "version": "0.14.21",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "description": "Express driver for Arkstack, providing Express-based runtime integration for the framework.",
6
6
  "homepage": "https://arkstack.toneflix.net",
@@ -38,22 +38,26 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@ngrok/ngrok": "^1.7.0",
41
- "@resora/plugin-clear-router": "^1.0.65",
42
- "clear-router": "^2.8.9",
41
+ "@resora/plugin-clear-router": "^1.0.66",
42
+ "clear-router": "^2.9.0",
43
43
  "express-rate-limit": "^8.4.1",
44
44
  "multer": "^2.1.1",
45
45
  "resora": "^1.3.27",
46
- "@arkstack/contract": "^0.14.21"
46
+ "@arkstack/contract": "^0.15.0"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "express": "^5.2.1",
50
- "@arkstack/auth": "^0.14.21",
51
- "@arkstack/foundry": "^0.14.21",
52
- "@arkstack/common": "^0.14.21"
50
+ "@arkstack/foundry": "^0.15.0",
51
+ "@arkstack/common": "^0.15.0",
52
+ "@arkstack/inertia": "^0.15.0",
53
+ "@arkstack/auth": "^0.15.0"
53
54
  },
54
55
  "peerDependenciesMeta": {
55
56
  "@arkstack/auth": {
56
57
  "optional": true
58
+ },
59
+ "@arkstack/inertia": {
60
+ "optional": true
57
61
  }
58
62
  },
59
63
  "devDependencies": {