@middy/http-router 7.3.3 → 7.3.4

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 (2) hide show
  1. package/index.js +10 -7
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -2,11 +2,14 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  import { createError, validateOptions } from "@middy/util";
4
4
 
5
+ const name = "http-router";
6
+ const pkg = `@middy/${name}`;
7
+
5
8
  const defaults = {
6
9
  routes: [],
7
10
  notFoundResponse: ({ method, path }) => {
8
11
  const err = createError(404, "Route does not exist", {
9
- cause: { package: "@middy/http-router", data: { method, path } },
12
+ cause: { package: pkg, data: { method, path } },
10
13
  });
11
14
  throw err;
12
15
  },
@@ -27,8 +30,8 @@ const optionSchema = {
27
30
  method: { type: "string", enum: [...methods, "ANY"] },
28
31
  path: {
29
32
  allOf: [
30
- { type: "string", pattern: "^/" },
31
- { type: "string", pattern: "^(/|.*[^/])$" },
33
+ { type: "string", pattern: /^\// },
34
+ { type: "string", pattern: /^(\/|.*[^/])$/ },
32
35
  ],
33
36
  examples: ["/", "/users", "/users/{id}"],
34
37
  },
@@ -43,7 +46,7 @@ const optionSchema = {
43
46
  };
44
47
 
45
48
  export const httpRouterValidateOptions = (options) =>
46
- validateOptions("@middy/http-router", optionSchema, options);
49
+ validateOptions(pkg, optionSchema, options);
47
50
 
48
51
  const httpRouteHandler = (opts = {}) => {
49
52
  let options;
@@ -62,7 +65,7 @@ const httpRouteHandler = (opts = {}) => {
62
65
  // Prevents `routesType[method][path] = handler` from flagging: This assignment may alter Object.prototype if a malicious '__proto__' string is injected from library input.
63
66
  if (!enumMethods.includes(method)) {
64
67
  throw new Error("Method not allowed", {
65
- cause: { package: "@middy/http-router", data: { method } },
68
+ cause: { package: pkg, data: { method } },
66
69
  });
67
70
  }
68
71
 
@@ -88,7 +91,7 @@ const httpRouteHandler = (opts = {}) => {
88
91
  throw new Error(
89
92
  "Unknown HTTP event format: missing HTTP method. Expected 'httpMethod' (v1), 'requestContext.http.method' (v2), or 'method' (VPC)",
90
93
  {
91
- cause: { package: "@middy/http-router", data: { method } },
94
+ cause: { package: pkg, data: { method } },
92
95
  },
93
96
  );
94
97
  }
@@ -96,7 +99,7 @@ const httpRouteHandler = (opts = {}) => {
96
99
  throw new Error(
97
100
  "Unknown HTTP event format: missing path. Expected 'path' (v1), 'requestContext.http.path' (v2), or 'raw_path' (VPC)",
98
101
  {
99
- cause: { package: "@middy/http-router", data: { path } },
102
+ cause: { package: pkg, data: { path } },
100
103
  },
101
104
  );
102
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-router",
3
- "version": "7.3.3",
3
+ "version": "7.3.4",
4
4
  "description": "HTTP event router for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -62,10 +62,10 @@
62
62
  "url": "https://github.com/sponsors/willfarrell"
63
63
  },
64
64
  "dependencies": {
65
- "@middy/util": "7.3.3"
65
+ "@middy/util": "7.3.4"
66
66
  },
67
67
  "devDependencies": {
68
- "@middy/core": "7.3.3",
68
+ "@middy/core": "7.3.4",
69
69
  "@types/aws-lambda": "^8.0.0",
70
70
  "@types/node": "^22.0.0"
71
71
  }