New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

middy-maintenance-mode

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middy-maintenance-mode - npm Package Compare versions

Comparing version

to
1.1.0

26

index.js

@@ -0,16 +1,26 @@

const DEFAULT_VARIABLE = 'MAINTENANCE_MODE'
const DEFAULT_VARIABLE_VALUE = 'on'
const defaults = {
envVariable: 'MAINTENANCE_MODE', // env variable to check for
envVariableValue: 'on', // value to check for maintainance mode
inMaintainanceMode: undefined,
envVariable: DEFAULT_VARIABLE, // env variable to check for
envVariableValue: DEFAULT_VARIABLE_VALUE, // value to check for maintainance mode
stageVariable: DEFAULT_VARIABLE,
stageVariableValue: DEFAULT_VARIABLE_VALUE,
isEnabled: undefined,
statusCode: 503, // service unavailable
headers: {
'Retry-After': 60 * 15 // 15 minutes
}
},
message: undefined
}
const inMaintainanceMode = options => {
if (typeof options.inMaintainanceMode === 'function') {
return options.inMaintainanceMode()
const isEnabled = (options, event) => {
if (typeof options.isEnabled === 'function') {
return options.isEnabled() === true
}
if (event && event[stageVariable] === options.stageVariableValue) {
return true
}
return process.env[options.envVariable] === options.envVariableValue

@@ -22,3 +32,3 @@ }

if (inMaintainanceMode(options)) {
if (isEnabled(options)) {
return handler.callback(null, {

@@ -25,0 +35,0 @@ statusCode: options.statusCode,

{
"name": "middy-maintenance-mode",
"version": "1.0.1",
"version": "1.1.0",
"description": "Middy Plugin for Maintenance Mode",

@@ -5,0 +5,0 @@ "engines": {

@@ -7,3 +7,11 @@ # Middy Maintance Mode

const maintenanceMode = require('middy-maintenance-mode')
middy(handler).use(maintenanceMode())
middy(handler).use(maintenanceMode({
envVariable: 'MAINTENANCE_MODE',
envVariableValue: 'on',
isEnabled: () => {
const isActive = true
return isActive
},
message: 'service in maintainance mode'
}))
```

@@ -14,9 +22,12 @@

```
envVariable: 'MAINTENANCE_MODE', // env variable to check for
envVariableValue: 'on', // value to check for maintainance mode
inMaintainanceMode: undefined,
envVariable: DEFAULT_VARIABLE, // env variable to check for
envVariableValue: DEFAULT_VARIABLE_VALUE, // value to check for maintainance mode
stageVariable: DEFAULT_VARIABLE,
stageVariableValue: DEFAULT_VARIABLE_VALUE,
isEnabled: undefined,
statusCode: 503, // service unavailable
headers: {
'Retry-After': 60 * 15 // 15 minutes
}
},
message: undefined
```