@middy/http-urlencode-path-parser 2.5.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.
- package/LICENSE +21 -0
- package/README.md +89 -0
- package/index.d.ts +5 -0
- package/index.js +17 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2021 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Middy http-urlencode-body-parser middleware
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.png"/>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<p><strong>HTTP URLencode body parser middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda</strong></p>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
<p>
|
|
13
|
+
<a href="http://badge.fury.io/js/%40middy%2Fhttp-urlencode-path-parser">
|
|
14
|
+
<img src="https://badge.fury.io/js/%40middy%2Fhttp-urlencode-path-parser.svg" alt="npm version" style="max-width:100%;">
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://snyk.io/test/github/middyjs/middy">
|
|
17
|
+
<img src="https://snyk.io/test/github/middyjs/middy/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/middyjs/middy" style="max-width:100%;">
|
|
18
|
+
</a>
|
|
19
|
+
<a href="https://standardjs.com/">
|
|
20
|
+
<img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard Code Style" style="max-width:100%;">
|
|
21
|
+
</a>
|
|
22
|
+
<a href="https://gitter.im/middyjs/Lobby">
|
|
23
|
+
<img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;">
|
|
24
|
+
</a>
|
|
25
|
+
</p>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
This middleware automatically parses HTTP requests with URL-encoded paths. This can happen when using path variables (ie `/{name}/`) for an endpoint and the UI `encodeURIComponent` the values before making the request.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
To install this middleware you can use NPM:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install --save @middy/http-urlencode-path-parser
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Options
|
|
41
|
+
|
|
42
|
+
None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Sample usage
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import middy from '@middy/core'
|
|
49
|
+
import httpUrlEncodePathParser from '@middy/http-urlencode-path-parser'
|
|
50
|
+
|
|
51
|
+
const handler = middy((event, context) => {
|
|
52
|
+
return event.body // propagates the body as response
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
handler.use(httpUrlEncodePathParser())
|
|
56
|
+
|
|
57
|
+
// When Lambda runs the handler with a sample event...
|
|
58
|
+
const event = {
|
|
59
|
+
|
|
60
|
+
pathParameters: {
|
|
61
|
+
name: encodeURIComponent('Mîddy')
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
handler(event, {}, (_, body) => {
|
|
66
|
+
t.deepEqual(body, {
|
|
67
|
+
name: 'Mîddy'
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Middy documentation and examples
|
|
74
|
+
|
|
75
|
+
For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
## Contributing
|
|
79
|
+
|
|
80
|
+
Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
|
86
|
+
|
|
87
|
+
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
88
|
+
<img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
|
|
89
|
+
</a>
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const httpUrlencodePathParserMiddlewareBefore = async request => {
|
|
4
|
+
var _request$event;
|
|
5
|
+
|
|
6
|
+
if (!((_request$event = request.event) !== null && _request$event !== void 0 && _request$event.pathParameters)) return;
|
|
7
|
+
|
|
8
|
+
for (const key in request.event.pathParameters) {
|
|
9
|
+
request.event.pathParameters[key] = decodeURIComponent(request.event.pathParameters[key]);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const httpUrlencodePathParserMiddleware = () => ({
|
|
14
|
+
before: httpUrlencodePathParserMiddlewareBefore
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
module.exports = httpUrlencodePathParserMiddleware;
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@middy/http-urlencode-path-parser",
|
|
3
|
+
"version": "2.5.2",
|
|
4
|
+
"description": "Urlencode path parser middleware for the middy framework",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=12"
|
|
8
|
+
},
|
|
9
|
+
"engineStrict": true,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"main": "index.js",
|
|
14
|
+
"types": "index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"index.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "npm run test:unit",
|
|
20
|
+
"test:unit": "ava"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"keywords": [
|
|
24
|
+
"Lambda",
|
|
25
|
+
"Middleware",
|
|
26
|
+
"Serverless",
|
|
27
|
+
"Framework",
|
|
28
|
+
"AWS",
|
|
29
|
+
"AWS Lambda",
|
|
30
|
+
"Middy",
|
|
31
|
+
"HTTP",
|
|
32
|
+
"API",
|
|
33
|
+
"Urlencode",
|
|
34
|
+
"Path Parser"
|
|
35
|
+
],
|
|
36
|
+
"author": {
|
|
37
|
+
"name": "Middy contributors",
|
|
38
|
+
"url": "https://github.com/middyjs/middy/graphs/contributors"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "github:middyjs/middy",
|
|
43
|
+
"directory": "packages/http-urlencode-path-parser"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/middyjs/middy/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/middyjs/middy#readme",
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@middy/core": "^2.5.2"
|
|
51
|
+
},
|
|
52
|
+
"gitHead": "a2bb757a7a13638ae64277f8eecfcf11c1af17d4"
|
|
53
|
+
}
|