Socket
Socket
Sign inDemoInstall

@netlify/functions

Package Overview
Dependencies
Maintainers
14
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netlify/functions - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

7

CHANGELOG.md
# 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 @@

6

package.json
{
"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 }
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc