@middy/http-content-encoding 3.0.0-alpha.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +94 -0
  3. package/index.d.ts +12 -0
  4. package/package.json +58 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-2022 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,94 @@
1
+ # Middy http-content-encoding 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 content encoding 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-content-encoding">
14
+ <img src="https://badge.fury.io/js/%40middy%2Fhttp-content-encoding.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 take the `preferredEncoding` output from `@middy/http-content-negotiation` and applies the encoding to `response.body` when a string.
29
+
30
+ ## Install
31
+
32
+ To install this middleware you can use NPM:
33
+
34
+ ```bash
35
+ npm install --save @middy/http-content-encoding
36
+ ```
37
+
38
+ ## Options
39
+ - `br` (object) (optional): `zlib.createBrotliCompress` [brotliOptions](https://nodejs.org/api/zlib.html#zlib_class_brotlioptions)
40
+ - `gzip` (object) (optional): `zlib.createGzip` [gzipOptions](https://nodejs.org/api/zlib.html#zlib_class_options)
41
+ - `deflate` (object) (optional): `zlib.createDeflate` [deflateOptions](https://nodejs.org/api/zlib.html#zlib_class_options)
42
+ - `overridePreferredEncoding` (array[string]) (optional): Override the preferred encoding order, most browsers prefer `gzip` over `br`, even though `br` has higher compression. Default: `[]`
43
+
44
+ NOTES:
45
+ - **Important** For `br` encoding NodeJS defaults to `11`. Levels `10` & `11` have been shown to have lower performance for the level of compression they apply. Testing is recommended to ensure the right balance of compression & performance.
46
+
47
+ ## Sample usage
48
+
49
+ ```javascript
50
+ import middy from '@middy/core'
51
+ import httpContentNegotiation from '@middy/http-content-negotiation'
52
+ import httpContentEncoding from '@middy/http-content-encoding'
53
+ import { constants } from 'zlib'
54
+
55
+ const handler = middy((event, context) => {
56
+ return {
57
+ statusCode: 200,
58
+ body: '{...}'
59
+ }
60
+ })
61
+
62
+ handler
63
+ .use(httpContentNegotiation())
64
+ .use(httpCompressMiddleware({
65
+ br: {
66
+ params: {
67
+ [constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT, // adjusted for UTF-8 text
68
+ [constants.BROTLI_PARAM_QUALITY]: 7
69
+ }
70
+ },
71
+ overridePreferredEncoding: ['br', 'gzip', 'deflate']
72
+ }))
73
+
74
+ export default { handler }
75
+ ```
76
+
77
+
78
+ ## Middy documentation and examples
79
+
80
+ 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).
81
+
82
+
83
+ ## Contributing
84
+
85
+ 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).
86
+
87
+
88
+ ## License
89
+
90
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
91
+
92
+ <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
93
+ <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
94
+ </a>
package/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import middy from '@middy/core'
2
+
3
+ interface Options {
4
+ br?: any
5
+ gzip?: any
6
+ deflate?: any
7
+ overridePreferredEncoding?: string[]
8
+ }
9
+
10
+ declare function httpContentEncoding (options?: Options): middy.MiddlewareObj
11
+
12
+ export default httpContentEncoding
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@middy/http-content-encoding",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "Http content encoding middleware for the middy framework",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=12"
8
+ },
9
+ "engineStrict": true,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "exports": "./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
+ "Content Encoding",
34
+ "gzip",
35
+ "brotli",
36
+ "deflate"
37
+ ],
38
+ "author": {
39
+ "name": "Middy contributors",
40
+ "url": "https://github.com/middyjs/middy/graphs/contributors"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "github:middyjs/middy",
45
+ "directory": "packages/http-content-encoding"
46
+ },
47
+ "bugs": {
48
+ "url": "https://github.com/middyjs/middy/issues"
49
+ },
50
+ "homepage": "https://github.com/middyjs/middy#readme",
51
+ "dependencies": {
52
+ "@middy/util": "^3.0.0-alpha.0"
53
+ },
54
+ "devDependencies": {
55
+ "@middy/core": "^3.0.0-alpha.0"
56
+ },
57
+ "gitHead": "c533f62841c8a39d061d7b94f30ba178f002c8db"
58
+ }