@guren/server 2.13.0 → 2.14.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.
Files changed (45) hide show
  1. package/dist/{McpServiceProvider-D6D9nhgn.js → McpServiceProvider-BawsYjgN.js} +72 -0
  2. package/dist/agent/derive.d.ts +155 -0
  3. package/dist/agent/dispatch.d.ts +123 -0
  4. package/dist/agent/events.d.ts +80 -0
  5. package/dist/agent/redact.d.ts +55 -0
  6. package/dist/agent/scopes.d.ts +115 -0
  7. package/dist/auth/AuthManager.d.ts +64 -0
  8. package/dist/auth/RequestAuthContext.d.ts +3 -5
  9. package/dist/auth/TokenGuard.d.ts +61 -0
  10. package/dist/auth/api-token.d.ts +25 -5
  11. package/dist/auth/context.d.ts +24 -0
  12. package/dist/auth/index.d.ts +5 -2
  13. package/dist/auth/index.js +2 -2
  14. package/dist/auth/providers/UserProvider.d.ts +7 -0
  15. package/dist/auth/types.d.ts +6 -0
  16. package/dist/{auth-C7sVmYgc.js → auth-BSUc14CD.js} +313 -122
  17. package/dist/authorization/index.js +1 -1
  18. package/dist/authorization/middleware.d.ts +28 -1
  19. package/dist/{authorization-Dbcuc5ZK.js → authorization-CdfbCj8J.js} +119 -12
  20. package/dist/broadcasting/index.js +1 -1
  21. package/dist/{broadcasting-Dw-FhyjN.js → broadcasting-BxU-LIfF.js} +2 -45
  22. package/dist/context-DoD0c7J_.js +26 -0
  23. package/dist/http/middleware/auth.d.ts +2 -2
  24. package/dist/http/middleware/capabilities.d.ts +57 -0
  25. package/dist/http/middleware/csrf.d.ts +3 -0
  26. package/dist/http/request.d.ts +51 -2
  27. package/dist/index.d.ts +12 -3
  28. package/dist/index.js +1015 -84
  29. package/dist/internal/agent-preflight.d.ts +28 -0
  30. package/dist/internal/request.d.ts +19 -0
  31. package/dist/internal/request.js +2 -0
  32. package/dist/internal/route-path.d.ts +28 -0
  33. package/dist/internal/route-path.js +33 -0
  34. package/dist/internal/zod-compat.d.ts +201 -0
  35. package/dist/internal/zod-compat.js +193 -0
  36. package/dist/internal/zod-json-schema.d.ts +102 -0
  37. package/dist/internal/zod-json-schema.js +461 -0
  38. package/dist/mcp/create-mcp-server.d.ts +29 -0
  39. package/dist/mcp/index.js +1 -1
  40. package/dist/mvc/Controller.d.ts +46 -0
  41. package/dist/mvc/Router.d.ts +53 -0
  42. package/dist/request-CRVuIiQr.js +78 -0
  43. package/dist/runtime/index.js +5 -2
  44. package/dist/{vite-manifest-gdONBsM3.js → vite-manifest-BGfWbPYp.js} +1 -1
  45. package/package.json +17 -1
@@ -0,0 +1,78 @@
1
+ //#region src/http/request.ts
2
+ function isPlainObject(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
5
+ /**
6
+ * Parses the incoming request body and returns the parsed value as-is: a JSON
7
+ * array stays an array, a JSON string stays a string. Use this wherever the
8
+ * result is handed to a schema and *that* decides the shape — a route
9
+ * contract's `body`, `Controller.validateBody()`, `validateRequest()`.
10
+ *
11
+ * Falls back to an empty object when the body cannot be parsed (malformed
12
+ * JSON, a form body the parser cannot decode, an empty POST, an unsupported
13
+ * content type). That fallback is load bearing: an all-optional object schema
14
+ * has to keep passing on an empty body, which `undefined` would break. The
15
+ * cost is that a non-object schema sees `{}` there and fails validation,
16
+ * rather than receiving nothing.
17
+ *
18
+ * The fallback does not distinguish whose fault the failure was: a body the
19
+ * client could never have sent correctly and a body already consumed upstream
20
+ * (middleware reading `ctx.req.raw` directly, bypassing Hono's cache) both read
21
+ * as `{}` here. That is deliberate — the JSON branch above has always behaved
22
+ * this way, and telling the two apart means matching runtime-specific error
23
+ * codes, which would answer differently on Bun, Node and Workers. A parser
24
+ * error is a poor signal for a middleware-ordering bug either way.
25
+ *
26
+ * Form submissions have no non-object shape to preserve, so they normalize to
27
+ * a record exactly as {@link parseRequestPayload} does.
28
+ */
29
+ async function parseRequestBody(ctx) {
30
+ if ((ctx.req.header("content-type") ?? "").includes("application/json")) return ctx.req.json().catch(() => ({}));
31
+ if (typeof ctx.req.parseBody === "function") try {
32
+ const form = await ctx.req.parseBody();
33
+ return Object.fromEntries(Object.entries(form).map(([key, value]) => [key, Array.isArray(value) ? value[0] : value]));
34
+ } catch {
35
+ return {};
36
+ }
37
+ return {};
38
+ }
39
+ /**
40
+ * The record-shaped view of {@link parseRequestBody}, for callers that read the
41
+ * payload field by field (`payload.channel`, per-field validation rules,
42
+ * `Controller.input()`/`only()`/`except()`/`has()`). A body that is not a plain
43
+ * object — an array, a string, `null` — becomes `{}`, because there is no
44
+ * field to read on one.
45
+ */
46
+ async function parseRequestPayload(ctx) {
47
+ return asRecord(await parseRequestBody(ctx));
48
+ }
49
+ /** Narrow a parsed body to the record view described on {@link parseRequestPayload}. */
50
+ function asRecord(body) {
51
+ return isPlainObject(body) ? body : {};
52
+ }
53
+ /**
54
+ * Collects query parameters preserving repeated keys as arrays while keeping
55
+ * single occurrences as plain strings (`?tag=a&tag=b` → `{ tag: ['a', 'b'] }`,
56
+ * `?page=2` → `{ page: '2' }`). Use this instead of `ctx.req.query()` when
57
+ * feeding query data into validation schemas.
58
+ */
59
+ function flattenRequestQueries(ctx) {
60
+ const queries = ctx.req.queries();
61
+ const flat = {};
62
+ for (const [key, values] of Object.entries(queries)) flat[key] = values.length === 1 ? values[0] : values;
63
+ return flat;
64
+ }
65
+ /**
66
+ * Converts a Zod-style validation error into a flat record usable by forms.
67
+ */
68
+ function formatValidationErrors(error, fallbackMessage = "The provided data is invalid.") {
69
+ const errors = {};
70
+ for (const issue of error.issues ?? []) {
71
+ const field = issue.path?.[0];
72
+ if (typeof field === "string" && !errors[field]) errors[field] = issue.message;
73
+ }
74
+ if (Object.keys(errors).length === 0) errors.message = fallbackMessage;
75
+ return errors;
76
+ }
77
+ //#endregion
78
+ export { parseRequestPayload as a, parseRequestBody as i, flattenRequestQueries as n, formatValidationErrors as r, asRecord as t };
@@ -1,6 +1,6 @@
1
1
  import { n as trimTrailingSlashes } from "../trim-slashes-ZJ_VsY5s.js";
2
2
  import { n as hash } from "../Hash-CzrwKeDp.js";
3
- import { _ as parseImportMap, a as getManifestCss, c as isViteProduction, d as startViteDevServer, f as GUREN_ASCII_ART, h as logDevServerBanner, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-gdONBsM3.js";
3
+ import { _ as parseImportMap, a as getManifestCss, c as isViteProduction, d as startViteDevServer, f as GUREN_ASCII_ART, h as logDevServerBanner, i as clientManifestCandidates, l as loadViteManifest, o as getManifestFile, r as PUBLIC_ASSETS_URL_PREFIX, u as normalizeDevServerUrl } from "../vite-manifest-BGfWbPYp.js";
4
4
  import { createRequire } from "node:module";
5
5
  import { realpath } from "node:fs/promises";
6
6
  import { dirname, extname, join, resolve, sep } from "node:path";
@@ -72,7 +72,10 @@ const DEFAULT_CONTENT_TYPES = {
72
72
  ".webp": "image/webp",
73
73
  ".avif": "image/avif",
74
74
  ".webmanifest": "application/manifest+json",
75
- ".txt": "text/plain; charset=utf-8"
75
+ ".txt": "text/plain; charset=utf-8",
76
+ ".js": "text/javascript; charset=utf-8",
77
+ ".mjs": "text/javascript; charset=utf-8",
78
+ ".css": "text/css; charset=utf-8"
76
79
  };
77
80
  function registerRootPublicAssets(app, publicDir, config) {
78
81
  const normalized = normalizeConfig(config);
@@ -40,7 +40,7 @@ function parseImportMap(value, options = {}) {
40
40
  const DEFAULT_DEV_STYLES_ENTRY = "/resources/css/app.css";
41
41
  //#endregion
42
42
  //#region package.json
43
- var version = "2.13.0";
43
+ var version = "2.14.0";
44
44
  //#endregion
45
45
  //#region src/http/dev-banner.ts
46
46
  figlet.parseFont("Standard", standard);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/server",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -106,6 +106,22 @@
106
106
  "types": "./dist/support/expiry.d.ts",
107
107
  "default": "./dist/support/expiry.js"
108
108
  },
109
+ "./internal/request": {
110
+ "types": "./dist/internal/request.d.ts",
111
+ "default": "./dist/internal/request.js"
112
+ },
113
+ "./internal/route-path": {
114
+ "types": "./dist/internal/route-path.d.ts",
115
+ "default": "./dist/internal/route-path.js"
116
+ },
117
+ "./internal/zod-compat": {
118
+ "types": "./dist/internal/zod-compat.d.ts",
119
+ "default": "./dist/internal/zod-compat.js"
120
+ },
121
+ "./internal/zod-json-schema": {
122
+ "types": "./dist/internal/zod-json-schema.d.ts",
123
+ "default": "./dist/internal/zod-json-schema.js"
124
+ },
109
125
  "./jsx-runtime": {
110
126
  "types": "./dist/jsx-runtime.d.ts",
111
127
  "default": "./dist/jsx-runtime.js"