@webiny/handler-http
Advanced tools
Comparing version 5.30.0 to 5.31.0-beta.0
@@ -1,4 +0,5 @@ | ||
import { HandlerHttpOptions } from "./types"; | ||
import { Plugin } from "@webiny/plugins"; | ||
declare const _default: (options?: HandlerHttpOptions) => Plugin[]; | ||
/** | ||
* Dummy file | ||
*/ | ||
declare const _default: (_: any) => never[]; | ||
export default _default; |
122
index.js
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,118 +8,10 @@ value: true | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _handler = require("@webiny/handler"); | ||
var _boolean = require("boolean"); | ||
var _utils = require("@webiny/utils"); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
const DEFAULT_HEADERS = _objectSpread({ | ||
"Cache-Control": "no-store", | ||
"Content-Type": "application/json", | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Headers": "*", | ||
"Access-Control-Allow-Methods": "OPTIONS,POST" | ||
}, (0, _utils.getWebinyVersionHeaders)()); | ||
const OPTIONS_HEADERS = { | ||
"Access-Control-Max-Age": "86400", | ||
"Cache-Control": "public, max-age=86400" | ||
/** | ||
* Dummy file | ||
*/ | ||
// eslint-disable-next-line | ||
var _default = _ => { | ||
return []; | ||
}; | ||
const OPTION_STATUS_CODE = 204; | ||
const lowercaseKeys = obj => { | ||
return Object.keys(obj).reduce((acc, key) => { | ||
acc[key.toLowerCase()] = obj[key]; | ||
return acc; | ||
}, {}); | ||
}; | ||
var _default = (options = {}) => [new _handler.ContextPlugin(async context => { | ||
const { | ||
invocationArgs | ||
} = context; | ||
if (!invocationArgs || !invocationArgs.method) { | ||
return; | ||
} | ||
if (invocationArgs.method.toLowerCase() === "options") { | ||
context.setResult({ | ||
statusCode: OPTION_STATUS_CODE, | ||
body: "", | ||
headers: _objectSpread(_objectSpread({}, DEFAULT_HEADERS), OPTIONS_HEADERS) | ||
}); | ||
return; | ||
} | ||
const path = invocationArgs.path ?? { | ||
base: "", | ||
parameters: {}, | ||
query: "" | ||
}; | ||
const request = { | ||
method: invocationArgs.method, | ||
body: invocationArgs.body, | ||
headers: lowercaseKeys(invocationArgs.headers || {}), | ||
cookies: invocationArgs.cookies, | ||
path: { | ||
base: path.base, | ||
parameters: path.parameters, | ||
query: path.query | ||
} | ||
}; | ||
context.http = { | ||
request, | ||
response({ | ||
statusCode = 200, | ||
body = "", | ||
headers = {} | ||
}) { | ||
return { | ||
statusCode, | ||
body, | ||
headers | ||
}; | ||
} | ||
}; | ||
}), new _handler.HandlerErrorPlugin(async (context, error) => { | ||
if (!context.http || typeof context.http.response !== "function") { | ||
return error; | ||
} | ||
const debug = (0, _boolean.boolean)(options.debug); | ||
if (debug) { | ||
return context.http.response({ | ||
statusCode: 500, | ||
body: JSON.stringify({ | ||
error: { | ||
name: error.constructor.name, | ||
message: error.message, | ||
stack: error.stack | ||
} | ||
}), | ||
headers: DEFAULT_HEADERS | ||
}); | ||
} | ||
return context.http.response({ | ||
statusCode: 500, | ||
body: JSON.stringify({ | ||
error: { | ||
name: "Error", | ||
message: "Internal Server Error" | ||
} | ||
}), | ||
headers: DEFAULT_HEADERS | ||
}); | ||
})]; | ||
exports.default = _default; |
{ | ||
"name": "@webiny/handler-http", | ||
"version": "5.30.0", | ||
"version": "5.31.0-beta.0", | ||
"main": "index.js", | ||
@@ -17,8 +17,3 @@ "repository": { | ||
"dependencies": { | ||
"@babel/runtime": "7.18.6", | ||
"@webiny/handler": "5.30.0", | ||
"@webiny/handler-args": "5.30.0", | ||
"@webiny/plugins": "5.30.0", | ||
"@webiny/utils": "5.30.0", | ||
"boolean": "3.2.0" | ||
"@babel/runtime": "7.18.9" | ||
}, | ||
@@ -28,4 +23,4 @@ "devDependencies": { | ||
"@babel/core": "^7.16.0", | ||
"@webiny/cli": "^5.30.0", | ||
"@webiny/project-utils": "^5.30.0", | ||
"@webiny/cli": "^5.31.0-beta.0", | ||
"@webiny/project-utils": "^5.31.0-beta.0", | ||
"merge": "^1.2.1", | ||
@@ -43,3 +38,3 @@ "rimraf": "^3.0.2", | ||
}, | ||
"gitHead": "3cadc5d26e565586b28772afbc18ae554ce7b782" | ||
"gitHead": "dea7c56325ff140ef0e2d761f3e65708d46d401e" | ||
} |
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
1
3364
6
17
2
+ Added@babel/runtime@7.18.9(transitive)
- Removed@webiny/handler@5.30.0
- Removed@webiny/handler-args@5.30.0
- Removed@webiny/plugins@5.30.0
- Removed@webiny/utils@5.30.0
- Removedboolean@3.2.0
- Removed@babel/runtime@7.18.6(transitive)
- Removed@webiny/error@5.30.0(transitive)
- Removed@webiny/handler@5.30.0(transitive)
- Removed@webiny/handler-args@5.30.0(transitive)
- Removed@webiny/plugins@5.30.0(transitive)
- Removed@webiny/utils@5.30.0(transitive)
- Removedboolean@3.2.0(transitive)
- Removeduniqid@5.4.0(transitive)
Updated@babel/runtime@7.18.9