@middy/cloudformation-router 7.2.2 → 7.3.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 (3) hide show
  1. package/index.d.ts +4 -0
  2. package/index.js +18 -5
  3. package/package.json +2 -5
package/index.d.ts CHANGED
@@ -24,4 +24,8 @@ declare function cloudformationRouterHandler(
24
24
  options: Options | Route[],
25
25
  ): middy.MiddyfiedHandler<CloudFormationCustomResourceEvent, void>;
26
26
 
27
+ export declare function cloudformationRouterValidateOptions(
28
+ options?: Record<string, unknown>,
29
+ ): void;
30
+
27
31
  export default cloudformationRouterHandler;
package/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // Copyright 2017 - 2026 will Farrell, Luciano Mammino, and Middy contributors.
2
2
  // SPDX-License-Identifier: MIT
3
+ import { validateOptions } from "@middy/util";
4
+
3
5
  const defaults = {
4
6
  routes: [],
5
7
  notFoundResponse: ({ requestType }) => {
@@ -12,6 +14,14 @@ const defaults = {
12
14
  throw err;
13
15
  },
14
16
  };
17
+
18
+ const optionSchema = {
19
+ routes: "array?",
20
+ notFoundResponse: "function?",
21
+ };
22
+
23
+ export const cloudformationRouterValidateOptions = (options) =>
24
+ validateOptions("@middy/cloudformation-router", optionSchema, options);
15
25
  const cloudformationCustomResourceRouteHandler = (opts = {}) => {
16
26
  let options;
17
27
  if (Array.isArray(opts)) {
@@ -36,12 +46,15 @@ const cloudformationCustomResourceRouteHandler = (opts = {}) => {
36
46
  return (event, context, abort) => {
37
47
  const { RequestType: requestType } = event;
38
48
  if (!requestType || !Object.hasOwn(requestTypes, requestType)) {
39
- throw new Error("Unknown CloudFormation Custom Response event format", {
40
- cause: {
41
- package: "@middy/cloudformation-router",
42
- data: { requestType },
49
+ throw new Error(
50
+ `Unknown CloudFormation Custom Resource event format: 'RequestType' must be one of Create, Update, Delete. Received: ${requestType ?? "undefined"}`,
51
+ {
52
+ cause: {
53
+ package: "@middy/cloudformation-router",
54
+ data: { requestType },
55
+ },
43
56
  },
44
- });
57
+ );
45
58
  }
46
59
 
47
60
  // Static
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/cloudformation-router",
3
- "version": "7.2.2",
3
+ "version": "7.3.0",
4
4
  "description": "CloudFormation Custom Response event router for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -17,9 +17,6 @@
17
17
  "import": {
18
18
  "types": "./index.d.ts",
19
19
  "default": "./index.js"
20
- },
21
- "require": {
22
- "default": "./index.js"
23
20
  }
24
21
  }
25
22
  },
@@ -65,7 +62,7 @@
65
62
  "url": "https://github.com/sponsors/willfarrell"
66
63
  },
67
64
  "devDependencies": {
68
- "@middy/core": "7.2.2",
65
+ "@middy/core": "7.3.0",
69
66
  "@types/aws-lambda": "^8.0.0",
70
67
  "@types/node": "^22.0.0"
71
68
  }