@middy/cloudformation-router 6.1.5 → 6.2.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.
- package/index.d.ts +8 -8
- package/index.js +52 -49
- package/package.json +65 -68
package/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import middy from
|
|
2
|
-
import { CloudFormationCustomResourceHandler } from
|
|
1
|
+
import type middy from "@middy/core";
|
|
2
|
+
import type { CloudFormationCustomResourceHandler } from "aws-lambda";
|
|
3
3
|
|
|
4
4
|
interface Route<T = never> {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
requestType: string;
|
|
6
|
+
handler: CloudFormationCustomResourceHandler<T>;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
declare function cloudformationRouterHandler
|
|
10
|
-
|
|
11
|
-
): middy.MiddyfiedHandler
|
|
9
|
+
declare function cloudformationRouterHandler(
|
|
10
|
+
routes: Route[],
|
|
11
|
+
): middy.MiddyfiedHandler;
|
|
12
12
|
|
|
13
|
-
export default cloudformationRouterHandler
|
|
13
|
+
export default cloudformationRouterHandler;
|
package/index.js
CHANGED
|
@@ -1,57 +1,60 @@
|
|
|
1
1
|
const defaults = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
2
|
+
routes: [],
|
|
3
|
+
notFoundResponse: ({ requestType }) => {
|
|
4
|
+
const err = new Error("Route does not exist", {
|
|
5
|
+
cause: {
|
|
6
|
+
package: "@middy/cloudformation-router",
|
|
7
|
+
data: { requestType },
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
throw err;
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
13
|
const cloudformationCustomResourceRouteHandler = (opts = {}) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const options = { ...defaults };
|
|
15
|
+
if (Array.isArray(opts)) {
|
|
16
|
+
Object.assign(options, { routes: opts });
|
|
17
|
+
} else {
|
|
18
|
+
Object.assign(options, opts);
|
|
19
|
+
}
|
|
20
|
+
const { routes, notFoundResponse } = options;
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
const routesStatic = {};
|
|
23
|
+
for (const route of routes) {
|
|
24
|
+
const { requestType, handler } = route;
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
// Static
|
|
27
|
+
routesStatic[requestType] = handler;
|
|
28
|
+
}
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
const requestTypes = {
|
|
31
|
+
Create: true,
|
|
32
|
+
Update: true,
|
|
33
|
+
Delete: true,
|
|
34
|
+
};
|
|
35
|
+
return (event, context, abort) => {
|
|
36
|
+
const { RequestType: requestType } = event;
|
|
37
|
+
if (
|
|
38
|
+
!requestType ||
|
|
39
|
+
!Object.hasOwnProperty.call(requestTypes, requestType)
|
|
40
|
+
) {
|
|
41
|
+
throw new Error("Unknown CloudFormation Custom Response event format", {
|
|
42
|
+
cause: {
|
|
43
|
+
package: "@middy/cloudformation-router",
|
|
44
|
+
data: { requestType },
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
// Static
|
|
50
|
+
if (Object.hasOwnProperty.call(routesStatic, requestType)) {
|
|
51
|
+
const handler = routesStatic[requestType];
|
|
52
|
+
return handler(event, context, abort);
|
|
53
|
+
}
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
55
|
+
// Not Found
|
|
56
|
+
return notFoundResponse({ requestType });
|
|
57
|
+
};
|
|
58
|
+
};
|
|
56
59
|
|
|
57
|
-
export default cloudformationCustomResourceRouteHandler
|
|
60
|
+
export default cloudformationCustomResourceRouteHandler;
|
package/package.json
CHANGED
|
@@ -1,70 +1,67 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"@types/aws-lambda": "^8.10.100"
|
|
68
|
-
},
|
|
69
|
-
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
|
|
2
|
+
"name": "@middy/cloudformation-router",
|
|
3
|
+
"version": "6.2.0",
|
|
4
|
+
"description": "CloudFormation Custom Response event router for the middy framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20"
|
|
8
|
+
},
|
|
9
|
+
"engineStrict": true,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"module": "./index.js",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"default": "./index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"default": "./index.js"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"types": "index.d.ts",
|
|
26
|
+
"files": ["index.js", "index.d.ts"],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "npm run test:unit",
|
|
29
|
+
"test:unit": "node --test",
|
|
30
|
+
"test:perf": "node --test index.perf.js"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"Lambda",
|
|
35
|
+
"Middleware",
|
|
36
|
+
"Serverless",
|
|
37
|
+
"Framework",
|
|
38
|
+
"AWS",
|
|
39
|
+
"AWS Lambda",
|
|
40
|
+
"Middy",
|
|
41
|
+
"CloudFormation",
|
|
42
|
+
"Custom Response",
|
|
43
|
+
"router"
|
|
44
|
+
],
|
|
45
|
+
"author": {
|
|
46
|
+
"name": "Middy contributors",
|
|
47
|
+
"url": "https://github.com/middyjs/middy/graphs/contributors"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/middyjs/middy.git",
|
|
52
|
+
"directory": "packages/cloudformation-router"
|
|
53
|
+
},
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/middyjs/middy/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://middy.js.org",
|
|
58
|
+
"funding": {
|
|
59
|
+
"type": "github",
|
|
60
|
+
"url": "https://github.com/sponsors/willfarrell"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@middy/core": "6.2.0",
|
|
64
|
+
"@types/aws-lambda": "^8.10.100"
|
|
65
|
+
},
|
|
66
|
+
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
|
|
70
67
|
}
|