@middy/cloudformation-router 7.3.0 → 7.3.2

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 +23 -8
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -15,9 +15,27 @@ const defaults = {
15
15
  },
16
16
  };
17
17
 
18
+ const requestTypes = ["Create", "Update", "Delete"];
19
+
18
20
  const optionSchema = {
19
- routes: "array?",
20
- notFoundResponse: "function?",
21
+ type: "object",
22
+ properties: {
23
+ routes: {
24
+ type: "array",
25
+ uniqueItems: true,
26
+ items: {
27
+ type: "object",
28
+ required: ["requestType", "handler"],
29
+ properties: {
30
+ requestType: { type: "string", enum: requestTypes },
31
+ handler: { instanceof: "Function" },
32
+ },
33
+ additionalProperties: false,
34
+ },
35
+ },
36
+ notFoundResponse: { instanceof: "Function" },
37
+ },
38
+ additionalProperties: false,
21
39
  };
22
40
 
23
41
  export const cloudformationRouterValidateOptions = (options) =>
@@ -38,14 +56,11 @@ const cloudformationCustomResourceRouteHandler = (opts = {}) => {
38
56
  routesStatic[requestType] = handler;
39
57
  }
40
58
 
41
- const requestTypes = {
42
- Create: true,
43
- Update: true,
44
- Delete: true,
45
- };
46
59
  return (event, context, abort) => {
47
60
  const { RequestType: requestType } = event;
48
- if (!requestType || !Object.hasOwn(requestTypes, requestType)) {
61
+ // Schema `enum` only validates route config at setup; this guard
62
+ // validates the incoming AWS event shape at invocation time.
63
+ if (!requestType || !requestTypes.includes(requestType)) {
49
64
  throw new Error(
50
65
  `Unknown CloudFormation Custom Resource event format: 'RequestType' must be one of Create, Update, Delete. Received: ${requestType ?? "undefined"}`,
51
66
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/cloudformation-router",
3
- "version": "7.3.0",
3
+ "version": "7.3.2",
4
4
  "description": "CloudFormation Custom Response event router for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -62,7 +62,7 @@
62
62
  "url": "https://github.com/sponsors/willfarrell"
63
63
  },
64
64
  "devDependencies": {
65
- "@middy/core": "7.3.0",
65
+ "@middy/core": "7.3.2",
66
66
  "@types/aws-lambda": "^8.0.0",
67
67
  "@types/node": "^22.0.0"
68
68
  }