@aura-stack/router 0.3.0 → 0.5.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 (44) hide show
  1. package/README.md +2 -2
  2. package/dist/assert.cjs +17 -0
  3. package/dist/assert.d.ts +12 -2
  4. package/dist/assert.js +6 -2
  5. package/dist/{chunk-6PZEXNTS.js → chunk-4UYDR5IO.js} +2 -2
  6. package/dist/{chunk-GJC3ODME.js → chunk-B6PMGVSL.js} +9 -1
  7. package/dist/{chunk-FWDOXDWG.js → chunk-BWIKAYZV.js} +9 -9
  8. package/dist/{chunk-JNMXLKDG.js → chunk-FU35BPU7.js} +11 -2
  9. package/dist/{chunk-JIA6NLL6.js → chunk-TEDN6QMU.js} +39 -19
  10. package/dist/{chunk-PT4GU6PH.js → chunk-XB5P5CQZ.js} +22 -9
  11. package/dist/chunk-Z6JJAIWN.js +37 -0
  12. package/dist/context.cjs +27 -8
  13. package/dist/context.d.ts +12 -20
  14. package/dist/context.js +5 -5
  15. package/dist/cookie.cjs +24 -0
  16. package/dist/cookie.d.ts +1 -0
  17. package/dist/cookie.js +2 -0
  18. package/dist/endpoint.d.ts +2 -0
  19. package/dist/endpoint.js +3 -3
  20. package/dist/error.cjs +9 -0
  21. package/dist/error.d.ts +7 -1
  22. package/dist/error.js +3 -1
  23. package/dist/headers.cjs +61 -0
  24. package/dist/headers.d.ts +20 -0
  25. package/dist/headers.js +6 -0
  26. package/dist/index.cjs +105 -28
  27. package/dist/index.d.ts +4 -2
  28. package/dist/index.js +14 -8
  29. package/dist/middlewares.cjs +8 -8
  30. package/dist/middlewares.d.ts +5 -3
  31. package/dist/middlewares.js +2 -2
  32. package/dist/router.cjs +101 -28
  33. package/dist/router.d.ts +2 -0
  34. package/dist/router.js +6 -5
  35. package/dist/types.d.ts +29 -6
  36. package/package.json +39 -13
  37. package/dist/assert.d.cts +0 -52
  38. package/dist/context.d.cts +0 -85
  39. package/dist/endpoint.d.cts +0 -60
  40. package/dist/error.d.cts +0 -65
  41. package/dist/index.d.cts +0 -6
  42. package/dist/middlewares.d.cts +0 -23
  43. package/dist/router.d.cts +0 -37
  44. package/dist/types.d.cts +0 -191
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # `@aura-stack/router`
2
-
3
1
  <div align="center">
4
2
 
3
+ <h1>Aura Router</h1>
4
+
5
5
  **A modern, TypeScript-first router and endpoint definition library**
6
6
 
7
7
  Build fully-typed APIs with declarative endpoints, automatic parameter inference, and first-class middleware support — all returning native `Response` objects.
package/dist/assert.cjs CHANGED
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/assert.ts
21
21
  var assert_exports = {};
22
22
  __export(assert_exports, {
23
+ isInvalidZodSchemaError: () => isInvalidZodSchemaError,
24
+ isObject: () => isObject,
23
25
  isRouterError: () => isRouterError,
24
26
  isSupportedBodyMethod: () => isSupportedBodyMethod,
25
27
  isSupportedMethod: () => isSupportedMethod,
@@ -76,6 +78,13 @@ var RouterError = class extends AuraStackRouterError {
76
78
  this.name = name ?? "RouterError";
77
79
  }
78
80
  };
81
+ var InvalidZodSchemaError = class {
82
+ constructor(type, errors) {
83
+ this.status = statusCode[type];
84
+ this.statusText = statusText[type];
85
+ this.errors = errors;
86
+ }
87
+ };
79
88
 
80
89
  // src/assert.ts
81
90
  var supportedMethods = /* @__PURE__ */ new Set(["GET", "POST", "DELETE", "PUT", "PATCH", "OPTIONS", "HEAD", "TRACE", "CONNECT"]);
@@ -97,8 +106,16 @@ var isValidHandler = (handler) => {
97
106
  var isRouterError = (error) => {
98
107
  return error instanceof RouterError;
99
108
  };
109
+ var isObject = (value) => {
110
+ return typeof value === "object" && value !== null && value !== void 0 && !Array.isArray(value);
111
+ };
112
+ var isInvalidZodSchemaError = (error) => {
113
+ return error instanceof InvalidZodSchemaError;
114
+ };
100
115
  // Annotate the CommonJS export names for ESM import in node:
101
116
  0 && (module.exports = {
117
+ isInvalidZodSchemaError,
118
+ isObject,
102
119
  isRouterError,
103
120
  isSupportedBodyMethod,
104
121
  isSupportedMethod,
package/dist/assert.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { RouterError } from './error.js';
1
+ import { RouterError, InvalidZodSchemaError } from './error.js';
2
2
  import { HTTPMethod, RoutePattern, RouteHandler } from './types.js';
3
3
  import 'zod';
4
+ import './headers.js';
5
+ import 'cookie';
4
6
 
5
7
  declare const supportedProtocols: Set<string>;
6
8
  /**
@@ -48,5 +50,13 @@ declare const isValidHandler: (handler: unknown) => handler is RouteHandler<any,
48
50
  * }
49
51
  */
50
52
  declare const isRouterError: (error: unknown) => error is RouterError;
53
+ declare const isObject: (value: unknown) => value is Record<string, unknown>;
54
+ /**
55
+ * Checks if the provided error is an instance of InvalidZodSchemaError.
56
+ *
57
+ * @param error the error to check
58
+ * @returns true if the error is an instance of InvalidZodSchemaError, false otherwise.
59
+ */
60
+ declare const isInvalidZodSchemaError: (error: unknown) => error is InvalidZodSchemaError;
51
61
 
52
- export { isRouterError, isSupportedBodyMethod, isSupportedMethod, isValidHandler, isValidRoute, supportedProtocols };
62
+ export { isInvalidZodSchemaError, isObject, isRouterError, isSupportedBodyMethod, isSupportedMethod, isValidHandler, isValidRoute, supportedProtocols };
package/dist/assert.js CHANGED
@@ -1,13 +1,17 @@
1
1
  import {
2
+ isInvalidZodSchemaError,
3
+ isObject,
2
4
  isRouterError,
3
5
  isSupportedBodyMethod,
4
6
  isSupportedMethod,
5
7
  isValidHandler,
6
8
  isValidRoute,
7
9
  supportedProtocols
8
- } from "./chunk-JNMXLKDG.js";
9
- import "./chunk-GJC3ODME.js";
10
+ } from "./chunk-FU35BPU7.js";
11
+ import "./chunk-B6PMGVSL.js";
10
12
  export {
13
+ isInvalidZodSchemaError,
14
+ isObject,
11
15
  isRouterError,
12
16
  isSupportedBodyMethod,
13
17
  isSupportedMethod,
@@ -2,10 +2,10 @@ import {
2
2
  isSupportedMethod,
3
3
  isValidHandler,
4
4
  isValidRoute
5
- } from "./chunk-JNMXLKDG.js";
5
+ } from "./chunk-FU35BPU7.js";
6
6
  import {
7
7
  RouterError
8
- } from "./chunk-GJC3ODME.js";
8
+ } from "./chunk-B6PMGVSL.js";
9
9
 
10
10
  // src/endpoint.ts
11
11
  var createEndpoint = (method, route, handler, config = {}) => {
@@ -45,10 +45,18 @@ var RouterError = class extends AuraStackRouterError {
45
45
  this.name = name ?? "RouterError";
46
46
  }
47
47
  };
48
+ var InvalidZodSchemaError = class {
49
+ constructor(type, errors) {
50
+ this.status = statusCode[type];
51
+ this.statusText = statusText[type];
52
+ this.errors = errors;
53
+ }
54
+ };
48
55
 
49
56
  export {
50
57
  statusCode,
51
58
  statusText,
52
59
  AuraStackRouterError,
53
- RouterError
60
+ RouterError,
61
+ InvalidZodSchemaError
54
62
  };
@@ -1,33 +1,33 @@
1
1
  import {
2
2
  RouterError
3
- } from "./chunk-GJC3ODME.js";
3
+ } from "./chunk-B6PMGVSL.js";
4
4
 
5
5
  // src/middlewares.ts
6
- var executeGlobalMiddlewares = async (request, middlewares) => {
7
- if (!middlewares) return request;
6
+ var executeGlobalMiddlewares = async (context, middlewares) => {
7
+ if (!middlewares) return context;
8
8
  for (const middleware of middlewares) {
9
9
  if (typeof middleware !== "function") {
10
10
  throw new RouterError("BAD_REQUEST", "Global middlewares must be functions");
11
11
  }
12
- const executed = await middleware(request);
12
+ const executed = await middleware(context);
13
13
  if (executed instanceof Response) {
14
14
  return executed;
15
15
  }
16
- request = executed;
16
+ context = executed;
17
17
  }
18
- if (!request || !(request instanceof Request)) {
18
+ if (!context || !(context.request instanceof Request)) {
19
19
  throw new RouterError("BAD_REQUEST", "Global middleware must return a Request or Response object");
20
20
  }
21
- return request;
21
+ return context;
22
22
  };
23
- var executeMiddlewares = async (request, context, middlewares = []) => {
23
+ var executeMiddlewares = async (context, middlewares = []) => {
24
24
  try {
25
25
  let ctx = context;
26
26
  for (const middleware of middlewares) {
27
27
  if (typeof middleware !== "function") {
28
28
  throw new RouterError("BAD_REQUEST", "Middleware must be a function");
29
29
  }
30
- ctx = await middleware(request, ctx);
30
+ ctx = await middleware(ctx);
31
31
  }
32
32
  return ctx;
33
33
  } catch {
@@ -1,6 +1,7 @@
1
1
  import {
2
+ InvalidZodSchemaError,
2
3
  RouterError
3
- } from "./chunk-GJC3ODME.js";
4
+ } from "./chunk-B6PMGVSL.js";
4
5
 
5
6
  // src/assert.ts
6
7
  var supportedMethods = /* @__PURE__ */ new Set(["GET", "POST", "DELETE", "PUT", "PATCH", "OPTIONS", "HEAD", "TRACE", "CONNECT"]);
@@ -22,6 +23,12 @@ var isValidHandler = (handler) => {
22
23
  var isRouterError = (error) => {
23
24
  return error instanceof RouterError;
24
25
  };
26
+ var isObject = (value) => {
27
+ return typeof value === "object" && value !== null && value !== void 0 && !Array.isArray(value);
28
+ };
29
+ var isInvalidZodSchemaError = (error) => {
30
+ return error instanceof InvalidZodSchemaError;
31
+ };
25
32
 
26
33
  export {
27
34
  supportedProtocols,
@@ -29,5 +36,7 @@ export {
29
36
  isSupportedBodyMethod,
30
37
  isValidRoute,
31
38
  isValidHandler,
32
- isRouterError
39
+ isRouterError,
40
+ isObject,
41
+ isInvalidZodSchemaError
33
42
  };
@@ -1,21 +1,24 @@
1
1
  import {
2
2
  getBody,
3
- getHeaders,
4
3
  getRouteParams,
5
4
  getSearchParams
6
- } from "./chunk-PT4GU6PH.js";
5
+ } from "./chunk-XB5P5CQZ.js";
7
6
  import {
7
+ isInvalidZodSchemaError,
8
8
  isRouterError,
9
9
  isSupportedMethod
10
- } from "./chunk-JNMXLKDG.js";
10
+ } from "./chunk-FU35BPU7.js";
11
+ import {
12
+ HeadersBuilder
13
+ } from "./chunk-Z6JJAIWN.js";
11
14
  import {
12
15
  executeGlobalMiddlewares,
13
16
  executeMiddlewares
14
- } from "./chunk-FWDOXDWG.js";
17
+ } from "./chunk-BWIKAYZV.js";
15
18
  import {
16
19
  RouterError,
17
20
  statusText
18
- } from "./chunk-GJC3ODME.js";
21
+ } from "./chunk-B6PMGVSL.js";
19
22
 
20
23
  // src/router.ts
21
24
  var createNode = () => ({
@@ -81,6 +84,17 @@ var handleError = async (error, request, config) => {
81
84
  );
82
85
  }
83
86
  }
87
+ if (isInvalidZodSchemaError(error)) {
88
+ const { errors, status, statusText: statusText2 } = error;
89
+ return Response.json(
90
+ {
91
+ message: "Invalid request data",
92
+ error: "validation_error",
93
+ details: errors
94
+ },
95
+ { status, statusText: statusText2 }
96
+ );
97
+ }
84
98
  if (isRouterError(error)) {
85
99
  const { message, status, statusText: statusText2 } = error;
86
100
  return Response.json({ message }, { status, statusText: statusText2 });
@@ -92,29 +106,35 @@ var handleRequest = async (method, request, config, root) => {
92
106
  if (!isSupportedMethod(request.method)) {
93
107
  throw new RouterError("METHOD_NOT_ALLOWED", `The HTTP method '${request.method}' is not supported`);
94
108
  }
95
- const globalRequest = await executeGlobalMiddlewares(request, config.middlewares);
96
- if (globalRequest instanceof Response) return globalRequest;
97
- const url = new URL(globalRequest.url);
109
+ const globalContext = { request, context: config.context ?? {} };
110
+ const globalRequestContext = await executeGlobalMiddlewares(globalContext, config.middlewares);
111
+ if (globalRequestContext instanceof Response) return globalRequestContext;
112
+ const url = new URL(globalRequestContext.request.url);
98
113
  const pathnameWithBase = url.pathname;
99
- if (globalRequest.method !== method) {
100
- throw new RouterError("METHOD_NOT_ALLOWED", `The HTTP method '${globalRequest.method}' is not allowed`);
114
+ if (globalRequestContext.request.method !== method) {
115
+ throw new RouterError("METHOD_NOT_ALLOWED", `The HTTP method '${globalRequestContext.request.method}' is not allowed`);
101
116
  }
102
117
  const { endpoint, params } = search(method, root, pathnameWithBase);
103
- if (endpoint.method !== globalRequest.method) {
104
- throw new RouterError("METHOD_NOT_ALLOWED", `The HTTP method '${globalRequest.method}' is not allowed`);
118
+ if (endpoint.method !== globalRequestContext.request.method) {
119
+ throw new RouterError("METHOD_NOT_ALLOWED", `The HTTP method '${globalRequestContext.request.method}' is not allowed`);
105
120
  }
106
121
  const dynamicParams = getRouteParams(params, endpoint.config);
107
- const body = await getBody(globalRequest, endpoint.config);
108
- const searchParams = getSearchParams(globalRequest.url, endpoint.config);
109
- const headers = getHeaders(globalRequest);
110
- const context = {
122
+ const body = await getBody(globalRequestContext.request, endpoint.config);
123
+ const searchParams = getSearchParams(globalRequestContext.request.url, endpoint.config);
124
+ const headers = new HeadersBuilder(globalRequestContext.request.headers);
125
+ let context = {
111
126
  params: dynamicParams,
112
127
  searchParams,
113
128
  headers,
114
- body
129
+ body,
130
+ request: globalRequestContext.request,
131
+ url,
132
+ method: globalRequestContext.request.method,
133
+ route: endpoint.route,
134
+ context: config.context ?? {}
115
135
  };
116
- await executeMiddlewares(globalRequest, context, endpoint.config.middlewares);
117
- const response = await endpoint.handler(globalRequest, context);
136
+ context = await executeMiddlewares(context, endpoint.config.middlewares);
137
+ const response = await endpoint.handler(context);
118
138
  return response;
119
139
  } catch (error) {
120
140
  return handleError(error, request, config);
@@ -1,16 +1,32 @@
1
1
  import {
2
2
  isSupportedBodyMethod
3
- } from "./chunk-JNMXLKDG.js";
3
+ } from "./chunk-FU35BPU7.js";
4
4
  import {
5
+ InvalidZodSchemaError,
5
6
  RouterError
6
- } from "./chunk-GJC3ODME.js";
7
+ } from "./chunk-B6PMGVSL.js";
7
8
 
8
9
  // src/context.ts
10
+ var formatZodError = (error) => {
11
+ if (!error.issues || error.issues.length === 0) {
12
+ return {};
13
+ }
14
+ return error.issues.reduce((previous, issue) => {
15
+ const key = issue.path.join(".");
16
+ return {
17
+ ...previous,
18
+ [key]: {
19
+ code: issue.code,
20
+ message: issue.message
21
+ }
22
+ };
23
+ }, {});
24
+ };
9
25
  var getRouteParams = (params, config) => {
10
26
  if (config.schemas?.params) {
11
27
  const parsed = config.schemas.params.safeParse(params);
12
28
  if (!parsed.success) {
13
- throw new RouterError("UNPROCESSABLE_ENTITY", "Invalid route parameters");
29
+ throw new InvalidZodSchemaError("UNPROCESSABLE_ENTITY", formatZodError(parsed.error));
14
30
  }
15
31
  return parsed.data;
16
32
  }
@@ -21,15 +37,12 @@ var getSearchParams = (url, config) => {
21
37
  if (config.schemas?.searchParams) {
22
38
  const parsed = config.schemas.searchParams.safeParse(Object.fromEntries(route.searchParams.entries()));
23
39
  if (!parsed.success) {
24
- throw new RouterError("UNPROCESSABLE_ENTITY", "Invalid search parameters");
40
+ throw new InvalidZodSchemaError("UNPROCESSABLE_ENTITY", formatZodError(parsed.error));
25
41
  }
26
42
  return parsed.data;
27
43
  }
28
44
  return new URLSearchParams(route.searchParams.toString());
29
45
  };
30
- var getHeaders = (request) => {
31
- return new Headers(request.headers);
32
- };
33
46
  var getBody = async (request, config) => {
34
47
  if (!isSupportedBodyMethod(request.method)) {
35
48
  return null;
@@ -41,7 +54,7 @@ var getBody = async (request, config) => {
41
54
  if (config.schemas?.body) {
42
55
  const parsed = config.schemas.body.safeParse(json);
43
56
  if (!parsed.success) {
44
- throw new RouterError("UNPROCESSABLE_ENTITY", "Invalid request body");
57
+ throw new InvalidZodSchemaError("UNPROCESSABLE_ENTITY", formatZodError(parsed.error));
45
58
  }
46
59
  return parsed.data;
47
60
  }
@@ -71,8 +84,8 @@ var createContentTypeRegex = (contentTypes, contenType) => {
71
84
  };
72
85
 
73
86
  export {
87
+ formatZodError,
74
88
  getRouteParams,
75
89
  getSearchParams,
76
- getHeaders,
77
90
  getBody
78
91
  };
@@ -0,0 +1,37 @@
1
+ // src/headers.ts
2
+ import { serialize, parse, parseSetCookie } from "cookie";
3
+ var HeadersBuilder = class {
4
+ constructor(initialHeaders) {
5
+ this.headers = new Headers(initialHeaders);
6
+ }
7
+ setHeader(name, value) {
8
+ this.headers.set(name, value);
9
+ return this;
10
+ }
11
+ setCookie(name, value, options) {
12
+ this.headers.append("Set-Cookie", serialize(name, value, options));
13
+ return this;
14
+ }
15
+ getHeader(name) {
16
+ return this.headers.get(name);
17
+ }
18
+ getCookie(name) {
19
+ const cookies = parse(this.headers.get("cookie") ?? "");
20
+ return cookies[name];
21
+ }
22
+ getSetCookie(name) {
23
+ const cookies = this.headers.getSetCookie();
24
+ const cookie = cookies.find((cookie2) => cookie2.startsWith(name + "="));
25
+ return cookie ? parseSetCookie(cookie).value : void 0;
26
+ }
27
+ toHeaders() {
28
+ return new Headers(this.headers);
29
+ }
30
+ toCookies() {
31
+ return parse(this.headers.get("cookie") ?? "");
32
+ }
33
+ };
34
+
35
+ export {
36
+ HeadersBuilder
37
+ };
package/dist/context.cjs CHANGED
@@ -20,8 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/context.ts
21
21
  var context_exports = {};
22
22
  __export(context_exports, {
23
+ formatZodError: () => formatZodError,
23
24
  getBody: () => getBody,
24
- getHeaders: () => getHeaders,
25
25
  getRouteParams: () => getRouteParams,
26
26
  getSearchParams: () => getSearchParams
27
27
  });
@@ -74,6 +74,13 @@ var RouterError = class extends AuraStackRouterError {
74
74
  this.name = name ?? "RouterError";
75
75
  }
76
76
  };
77
+ var InvalidZodSchemaError = class {
78
+ constructor(type, errors) {
79
+ this.status = statusCode[type];
80
+ this.statusText = statusText[type];
81
+ this.errors = errors;
82
+ }
83
+ };
77
84
 
78
85
  // src/assert.ts
79
86
  var supportedBodyMethods = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
@@ -82,11 +89,26 @@ var isSupportedBodyMethod = (method) => {
82
89
  };
83
90
 
84
91
  // src/context.ts
92
+ var formatZodError = (error) => {
93
+ if (!error.issues || error.issues.length === 0) {
94
+ return {};
95
+ }
96
+ return error.issues.reduce((previous, issue) => {
97
+ const key = issue.path.join(".");
98
+ return {
99
+ ...previous,
100
+ [key]: {
101
+ code: issue.code,
102
+ message: issue.message
103
+ }
104
+ };
105
+ }, {});
106
+ };
85
107
  var getRouteParams = (params, config) => {
86
108
  if (config.schemas?.params) {
87
109
  const parsed = config.schemas.params.safeParse(params);
88
110
  if (!parsed.success) {
89
- throw new RouterError("UNPROCESSABLE_ENTITY", "Invalid route parameters");
111
+ throw new InvalidZodSchemaError("UNPROCESSABLE_ENTITY", formatZodError(parsed.error));
90
112
  }
91
113
  return parsed.data;
92
114
  }
@@ -97,15 +119,12 @@ var getSearchParams = (url, config) => {
97
119
  if (config.schemas?.searchParams) {
98
120
  const parsed = config.schemas.searchParams.safeParse(Object.fromEntries(route.searchParams.entries()));
99
121
  if (!parsed.success) {
100
- throw new RouterError("UNPROCESSABLE_ENTITY", "Invalid search parameters");
122
+ throw new InvalidZodSchemaError("UNPROCESSABLE_ENTITY", formatZodError(parsed.error));
101
123
  }
102
124
  return parsed.data;
103
125
  }
104
126
  return new URLSearchParams(route.searchParams.toString());
105
127
  };
106
- var getHeaders = (request) => {
107
- return new Headers(request.headers);
108
- };
109
128
  var getBody = async (request, config) => {
110
129
  if (!isSupportedBodyMethod(request.method)) {
111
130
  return null;
@@ -117,7 +136,7 @@ var getBody = async (request, config) => {
117
136
  if (config.schemas?.body) {
118
137
  const parsed = config.schemas.body.safeParse(json);
119
138
  if (!parsed.success) {
120
- throw new RouterError("UNPROCESSABLE_ENTITY", "Invalid request body");
139
+ throw new InvalidZodSchemaError("UNPROCESSABLE_ENTITY", formatZodError(parsed.error));
121
140
  }
122
141
  return parsed.data;
123
142
  }
@@ -147,8 +166,8 @@ var createContentTypeRegex = (contentTypes, contenType) => {
147
166
  };
148
167
  // Annotate the CommonJS export names for ESM import in node:
149
168
  0 && (module.exports = {
169
+ formatZodError,
150
170
  getBody,
151
- getHeaders,
152
171
  getRouteParams,
153
172
  getSearchParams
154
173
  });
package/dist/context.d.ts CHANGED
@@ -1,7 +1,14 @@
1
+ import { ZodError } from 'zod';
1
2
  import { EndpointConfig, ContextSearchParams } from './types.js';
2
- import 'zod';
3
3
  import './error.js';
4
+ import './headers.js';
5
+ import 'cookie';
4
6
 
7
+ /**
8
+ * @experimental
9
+ * @param error ZodError instance
10
+ */
11
+ declare const formatZodError: (error: ZodError<Record<string, unknown>>) => {};
5
12
  /**
6
13
  * Extracts route parameters from a given path using the specified route pattern.
7
14
  *
@@ -9,9 +16,9 @@ import './error.js';
9
16
  * (e.g., "/users/:userId/posts/:postId") and returns an object mapping parameter
10
17
  * names to their decoded values.
11
18
  *
12
- * @param route - The route pattern, typically defined in the endpoint configuration.
13
- * @param path - The actual request path to extract parameters from.
14
- * @returns An object containing the extracted route parameters as key-value pairs.
19
+ * @param params - The extracted route parameters as key-value pairs.
20
+ * @param config - The endpoint configuration which may include schemas for validation.
21
+ * @returns An object containing the extracted and validated route parameters.
15
22
  *
16
23
  * @example
17
24
  * const route = "/users/:userId/posts/:postId";
@@ -53,21 +60,6 @@ declare const getRouteParams: (params: Record<string, string>, config: EndpointC
53
60
  * const searchParams2 = getSearchParams(url2, {} as EndpointConfig);
54
61
  */
55
62
  declare const getSearchParams: <Config extends EndpointConfig>(url: string, config: Config) => ContextSearchParams<Config["schemas"]>["searchParams"];
56
- /**
57
- * Extracts headers from the given Request object and returns them as a Headers instance.
58
- *
59
- * @param request - The Request object from which to extract headers.
60
- * @returns A Headers instance containing all headers from the request.
61
- * @example
62
- * const request = new Request("https://example.com/api", {
63
- * headers: {
64
- * "Content-Type": "application/json",
65
- * "Authorization": "Bearer token",
66
- * },
67
- * });
68
- * const headers = getHeaders(request);
69
- */
70
- declare const getHeaders: (request: Request) => Headers;
71
63
  /**
72
64
  * Extracts and parses the body of a Request object based on its Content-Type header.
73
65
  *
@@ -82,4 +74,4 @@ declare const getHeaders: (request: Request) => Headers;
82
74
  */
83
75
  declare const getBody: <Config extends EndpointConfig>(request: Request, config: Config) => Promise<any>;
84
76
 
85
- export { getBody, getHeaders, getRouteParams, getSearchParams };
77
+ export { formatZodError, getBody, getRouteParams, getSearchParams };
package/dist/context.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import {
2
+ formatZodError,
2
3
  getBody,
3
- getHeaders,
4
4
  getRouteParams,
5
5
  getSearchParams
6
- } from "./chunk-PT4GU6PH.js";
7
- import "./chunk-JNMXLKDG.js";
8
- import "./chunk-GJC3ODME.js";
6
+ } from "./chunk-XB5P5CQZ.js";
7
+ import "./chunk-FU35BPU7.js";
8
+ import "./chunk-B6PMGVSL.js";
9
9
  export {
10
+ formatZodError,
10
11
  getBody,
11
- getHeaders,
12
12
  getRouteParams,
13
13
  getSearchParams
14
14
  };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/cookie.ts
18
+ var cookie_exports = {};
19
+ module.exports = __toCommonJS(cookie_exports);
20
+ __reExport(cookie_exports, require("cookie"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("cookie")
24
+ });
@@ -0,0 +1 @@
1
+ export * from 'cookie';
package/dist/cookie.js ADDED
@@ -0,0 +1,2 @@
1
+ // src/cookie.ts
2
+ export * from "cookie";
@@ -1,6 +1,8 @@
1
1
  import { HTTPMethod, RoutePattern, EndpointSchemas, RouteHandler, EndpointConfig, RouteEndpoint } from './types.js';
2
2
  import 'zod';
3
3
  import './error.js';
4
+ import './headers.js';
5
+ import 'cookie';
4
6
 
5
7
  /**
6
8
  * Defines an API endpoint for the router by specifying the HTTP method, route pattern,
package/dist/endpoint.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createEndpoint,
3
3
  createEndpointConfig
4
- } from "./chunk-6PZEXNTS.js";
5
- import "./chunk-JNMXLKDG.js";
6
- import "./chunk-GJC3ODME.js";
4
+ } from "./chunk-4UYDR5IO.js";
5
+ import "./chunk-FU35BPU7.js";
6
+ import "./chunk-B6PMGVSL.js";
7
7
  export {
8
8
  createEndpoint,
9
9
  createEndpointConfig
package/dist/error.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var error_exports = {};
22
22
  __export(error_exports, {
23
23
  AuraStackRouterError: () => AuraStackRouterError,
24
+ InvalidZodSchemaError: () => InvalidZodSchemaError,
24
25
  RouterError: () => RouterError,
25
26
  statusCode: () => statusCode,
26
27
  statusText: () => statusText
@@ -72,9 +73,17 @@ var RouterError = class extends AuraStackRouterError {
72
73
  this.name = name ?? "RouterError";
73
74
  }
74
75
  };
76
+ var InvalidZodSchemaError = class {
77
+ constructor(type, errors) {
78
+ this.status = statusCode[type];
79
+ this.statusText = statusText[type];
80
+ this.errors = errors;
81
+ }
82
+ };
75
83
  // Annotate the CommonJS export names for ESM import in node:
76
84
  0 && (module.exports = {
77
85
  AuraStackRouterError,
86
+ InvalidZodSchemaError,
78
87
  RouterError,
79
88
  statusCode,
80
89
  statusText