@middy/cloudformation-router 7.2.3 → 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.d.ts +4 -0
- package/index.js +46 -6
- 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,47 @@ const defaults = {
|
|
|
12
14
|
throw err;
|
|
13
15
|
},
|
|
14
16
|
};
|
|
17
|
+
|
|
18
|
+
const requestTypes = ["Create", "Update", "Delete"];
|
|
19
|
+
|
|
20
|
+
const optionSchema = {
|
|
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,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const cloudformationRouterValidateOptions = (options) => {
|
|
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
|
+
};
|
|
15
58
|
const cloudformationCustomResourceRouteHandler = (opts = {}) => {
|
|
16
59
|
let options;
|
|
17
60
|
if (Array.isArray(opts)) {
|
|
@@ -28,14 +71,11 @@ const cloudformationCustomResourceRouteHandler = (opts = {}) => {
|
|
|
28
71
|
routesStatic[requestType] = handler;
|
|
29
72
|
}
|
|
30
73
|
|
|
31
|
-
const requestTypes = {
|
|
32
|
-
Create: true,
|
|
33
|
-
Update: true,
|
|
34
|
-
Delete: true,
|
|
35
|
-
};
|
|
36
74
|
return (event, context, abort) => {
|
|
37
75
|
const { RequestType: requestType } = event;
|
|
38
|
-
|
|
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)) {
|
|
39
79
|
throw new Error(
|
|
40
80
|
`Unknown CloudFormation Custom Resource event format: 'RequestType' must be one of Create, Update, Delete. Received: ${requestType ?? "undefined"}`,
|
|
41
81
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/cloudformation-router",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.1",
|
|
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.
|
|
65
|
+
"@middy/core": "7.3.1",
|
|
69
66
|
"@types/aws-lambda": "^8.0.0",
|
|
70
67
|
"@types/node": "^22.0.0"
|
|
71
68
|
}
|