@netlify/functions
Advanced tools
Comparing version 0.1.0 to 0.2.0
# Changelog | ||
## [0.2.0](https://www.github.com/netlify/functions-js/compare/v0.1.0...v0.2.0) (2021-02-23) | ||
### Features | ||
* conform to handler function signature ([#10](https://www.github.com/netlify/functions-js/issues/10)) ([261d4d2](https://www.github.com/netlify/functions-js/commit/261d4d25b410f29c060f666d38153a822832dccd)) | ||
## 0.1.0 (2021-02-22) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "@netlify/functions", | ||
"main": "./src/main.js", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "JavaScript utilities for Netlify Functions", | ||
@@ -52,3 +52,5 @@ "files": [ | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"is-promise": "^2.2.2" | ||
}, | ||
"devDependencies": { | ||
@@ -55,0 +57,0 @@ "@commitlint/cli": "^11.0.0", |
@@ -0,1 +1,3 @@ | ||
const isPromise = require('is-promise') | ||
const { HTTP_STATUS_METHOD_NOT_ALLOWED, HTTP_STATUS_OK } = require('./consts') | ||
@@ -15,8 +17,8 @@ | ||
// eslint-disable-next-line promise/prefer-await-to-callbacks | ||
const wrapHandler = (handler) => async (event, context, callback) => { | ||
const wrapHandler = (handler) => (event, context, callback) => { | ||
if (event.httpMethod !== 'GET' && event.httpMethod !== 'HEAD') { | ||
return { | ||
return Promise.resolve({ | ||
body: 'Method Not Allowed', | ||
statusCode: HTTP_STATUS_METHOD_NOT_ALLOWED, | ||
} | ||
}) | ||
} | ||
@@ -26,7 +28,12 @@ | ||
const wrappedCallback = (error, response) => callback(error, augmentResponse(response)) | ||
const response = await handler(event, context, wrappedCallback) | ||
const execution = handler(event, context, wrappedCallback) | ||
return augmentResponse(response) | ||
if (isPromise(execution)) { | ||
// eslint-disable-next-line promise/prefer-await-to-then | ||
return execution.then(augmentResponse) | ||
} | ||
return execution | ||
} | ||
module.exports = { builderFunction: wrapHandler } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6305
34
1
+ Addedis-promise@^2.2.2
+ Addedis-promise@2.2.2(transitive)