From 7f9252091f9bfc1036b0e84cbf17593a6265b594 Mon Sep 17 00:00:00 2001 From: Wojciech Iskra Date: Tue, 27 Jul 2021 14:52:41 +0200 Subject: [PATCH] feat(middy2): middy v2 version (#34) - updated deps - stopped breaking the middleware chain - updated the tests - bump version to 2.0.0 --- index.js | 2 - index.test.js | 98 +++++++++++++++++++---------------------------- package-lock.json | 24 ++++++------ package.json | 6 +-- 4 files changed, 56 insertions(+), 74 deletions(-) diff --git a/index.js b/index.js index 26b1ba9..f6eb016 100644 --- a/index.js +++ b/index.js @@ -60,8 +60,6 @@ const corsMiddleware = (opts) => ({ }, handler.response ); - - return handler; }, }); diff --git a/index.test.js b/index.test.js index ddb0c97..8c28aa8 100644 --- a/index.test.js +++ b/index.test.js @@ -176,19 +176,15 @@ test('Adds CORS headers on error from disallowed origin', async () => { }, {} ) - ).rejects.toEqual( - expect.objectContaining({ - response: { - headers: { - 'access-control-allow-credentials': true, - 'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For', - 'access-control-allow-methods': 'GET, POST', - 'access-control-expose-headers': 'x-my-header', - 'access-control-max-age': 2628000, - }, - }, - }) - ); + ).resolves.toMatchObject({ + headers: { + 'access-control-allow-credentials': true, + 'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For', + 'access-control-allow-methods': 'GET, POST', + 'access-control-expose-headers': 'x-my-header', + 'access-control-max-age': 2628000, + }, + }); }); test('Adds CORS headers on error from allowed origin', async () => { @@ -216,20 +212,16 @@ test('Adds CORS headers on error from allowed origin', async () => { }, {} ) - ).rejects.toEqual( - expect.objectContaining({ - response: { - headers: { - 'access-control-allow-credentials': true, - 'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For', - 'access-control-allow-methods': 'GET, POST', - 'access-control-allow-origin': 'https://www.tek.no', - 'access-control-expose-headers': 'x-my-header', - 'access-control-max-age': 2628000, - }, - }, - }) - ); + ).resolves.toMatchObject({ + headers: { + 'access-control-allow-credentials': true, + 'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For', + 'access-control-allow-methods': 'GET, POST', + 'access-control-allow-origin': 'https://www.tek.no', + 'access-control-expose-headers': 'x-my-header', + 'access-control-max-age': 2628000, + }, + }); }); test('Adds CORS headers on error when all origins allowed', async () => { @@ -257,20 +249,16 @@ test('Adds CORS headers on error when all origins allowed', async () => { }, {} ) - ).rejects.toEqual( - expect.objectContaining({ - response: { - headers: { - 'access-control-allow-credentials': true, - 'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For', - 'access-control-allow-methods': 'GET, POST', - 'access-control-allow-origin': 'https://www.tek.no', - 'access-control-expose-headers': 'x-my-header', - 'access-control-max-age': 2628000, - }, - }, - }) - ); + ).resolves.toMatchObject({ + headers: { + 'access-control-allow-credentials': true, + 'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For', + 'access-control-allow-methods': 'GET, POST', + 'access-control-allow-origin': 'https://www.tek.no', + 'access-control-expose-headers': 'x-my-header', + 'access-control-max-age': 2628000, + }, + }); }); test('Keep headers already present in the response on error from disallowed origin', async () => { @@ -286,8 +274,6 @@ test('Keep headers already present in the response on error from disallowed orig someHeader: 'someValue', }, }; - - return true; }); handler.use( @@ -310,19 +296,15 @@ test('Keep headers already present in the response on error from disallowed orig }, {} ) - ).rejects.toEqual( - expect.objectContaining({ - response: { - headers: { - 'access-control-allow-credentials': true, - 'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For', - 'access-control-allow-methods': 'GET, POST', - 'access-control-allow-origin': 'https://www.tek.no', - 'access-control-expose-headers': 'x-my-header', - 'access-control-max-age': 2628000, - someHeader: 'someValue', - }, - }, - }) - ); + ).resolves.toMatchObject({ + headers: { + 'access-control-allow-credentials': true, + 'access-control-allow-headers': 'Content-Type, Accept, X-Forwarded-For', + 'access-control-allow-methods': 'GET, POST', + 'access-control-allow-origin': 'https://www.tek.no', + 'access-control-expose-headers': 'x-my-header', + 'access-control-max-age': 2628000, + someHeader: 'someValue', + }, + }); }); diff --git a/package-lock.json b/package-lock.json index e68fb44..09fef00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@schibsted/middy-cors", - "version": "0.3.0", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -935,13 +935,10 @@ } }, "@middy/core": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@middy/core/-/core-1.4.0.tgz", - "integrity": "sha512-ek7sC1BVh11oPPoATrG44WDpqxws9dHnOY1Y2Kg/95+hCuIpH7mTWMf2ja3Hj5w81PVF9i/CmsIhK5RsOKNZVg==", - "dev": true, - "requires": { - "once": "^1.4.0" - } + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/@middy/core/-/core-2.4.3.tgz", + "integrity": "sha512-RrFtUdTz4wslGykSObLXzY1yL8ZBD/joZ0TTMVet2y19L1enIqfXABp0bv+LcbGP1NJNw8a9tXSAXk8ZNBoOwQ==", + "dev": true }, "@nodelib/fs.scandir": { "version": "2.1.3", @@ -3261,7 +3258,8 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=", - "dev": true + "dev": true, + "optional": true }, "har-schema": { "version": "2.0.0", @@ -3886,6 +3884,7 @@ "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", "dev": true, + "optional": true, "requires": { "is-docker": "^2.0.0" } @@ -5881,6 +5880,7 @@ "resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-8.0.1.tgz", "integrity": "sha512-BvEXF+UmsnAfYfoapKM9nGxnP+Wn7P91YfXmrKnfcYCx6VBeoN5Ez5Ogck6I8Bi5k4RlpqRYaw75pAwzX9OphA==", "dev": true, + "optional": true, "requires": { "growly": "^1.3.0", "is-wsl": "^2.2.0", @@ -6953,7 +6953,8 @@ "version": "0.1.1", "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==", - "dev": true + "dev": true, + "optional": true }, "signal-exit": { "version": "3.0.3", @@ -7692,7 +7693,8 @@ "version": "8.3.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.1.tgz", "integrity": "sha512-FOmRr+FmWEIG8uhZv6C2bTgEVXsHk08kE7mPlrBbEe+c3r9pjceVPgupIfNIhc4yx55H69OXANrUaSuu9eInKg==", - "dev": true + "dev": true, + "optional": true }, "v8-compile-cache": { "version": "2.1.1", diff --git a/package.json b/package.json index e91b2b4..f24070b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@schibsted/middy-cors", - "version": "0.3.0", + "version": "2.0.0", "description": "Middy middleware for adding CORS headers to success response and errors", "main": "index.js", "engines": { @@ -47,7 +47,7 @@ }, "homepage": "https://github.com/schibsted/middy-cors#readme", "devDependencies": { - "@middy/core": "^1.4.0", + "@middy/core": "^2.4.3", "babel-eslint": "^10.1.0", "eslint": "^7.11.0", "eslint-config-airbnb-base": "^14.2.0", @@ -66,6 +66,6 @@ "ramda": "^0.27.1" }, "peerDependencies": { - "@middy/core": ">=1.0.0" + "@middy/core": ">=2.0.0" } }