@middy/cloudformation-router 7.3.0 → 7.3.1
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.
- package/index.js +39 -9
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -15,13 +15,46 @@ const defaults = {
|
|
|
15
15
|
},
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
const requestTypes = ["Create", "Update", "Delete"];
|
|
19
|
+
|
|
18
20
|
const optionSchema = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
routes: {
|
|
24
|
+
type: "array",
|
|
25
|
+
items: {
|
|
26
|
+
type: "object",
|
|
27
|
+
required: ["requestType", "handler"],
|
|
28
|
+
properties: {
|
|
29
|
+
requestType: { type: "string", enum: requestTypes },
|
|
30
|
+
handler: { instanceof: "Function" },
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
notFoundResponse: { instanceof: "Function" },
|
|
36
|
+
},
|
|
37
|
+
additionalProperties: false,
|
|
21
38
|
};
|
|
22
39
|
|
|
23
|
-
export const cloudformationRouterValidateOptions = (options) =>
|
|
40
|
+
export const cloudformationRouterValidateOptions = (options) => {
|
|
24
41
|
validateOptions("@middy/cloudformation-router", optionSchema, options);
|
|
42
|
+
const routes = options?.routes;
|
|
43
|
+
if (routes === undefined) return options;
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
for (const { requestType } of routes) {
|
|
46
|
+
if (seen.has(requestType)) {
|
|
47
|
+
throw new Error("Duplicate route", {
|
|
48
|
+
cause: {
|
|
49
|
+
package: "@middy/cloudformation-router",
|
|
50
|
+
data: { requestType },
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
seen.add(requestType);
|
|
55
|
+
}
|
|
56
|
+
return options;
|
|
57
|
+
};
|
|
25
58
|
const cloudformationCustomResourceRouteHandler = (opts = {}) => {
|
|
26
59
|
let options;
|
|
27
60
|
if (Array.isArray(opts)) {
|
|
@@ -38,14 +71,11 @@ const cloudformationCustomResourceRouteHandler = (opts = {}) => {
|
|
|
38
71
|
routesStatic[requestType] = handler;
|
|
39
72
|
}
|
|
40
73
|
|
|
41
|
-
const requestTypes = {
|
|
42
|
-
Create: true,
|
|
43
|
-
Update: true,
|
|
44
|
-
Delete: true,
|
|
45
|
-
};
|
|
46
74
|
return (event, context, abort) => {
|
|
47
75
|
const { RequestType: requestType } = event;
|
|
48
|
-
|
|
76
|
+
// Schema `enum` only validates route config at setup; this guard
|
|
77
|
+
// validates the incoming AWS event shape at invocation time.
|
|
78
|
+
if (!requestType || !requestTypes.includes(requestType)) {
|
|
49
79
|
throw new Error(
|
|
50
80
|
`Unknown CloudFormation Custom Resource event format: 'RequestType' must be one of Create, Update, Delete. Received: ${requestType ?? "undefined"}`,
|
|
51
81
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/cloudformation-router",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.1",
|
|
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.
|
|
65
|
+
"@middy/core": "7.3.1",
|
|
66
66
|
"@types/aws-lambda": "^8.0.0",
|
|
67
67
|
"@types/node": "^22.0.0"
|
|
68
68
|
}
|