@webiny/handler-http
Advanced tools
Comparing version 5.21.0 to 5.22.0-beta.0
import { HttpContext, HandlerHttpOptions } from "./types"; | ||
import { ContextPlugin, HandlerErrorPlugin } from "@webiny/handler/types"; | ||
declare const _default: (options?: HandlerHttpOptions) => (ContextPlugin<HttpContext, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>> | HandlerErrorPlugin<HttpContext, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>, import("@webiny/handler/types").Context<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>>)[]; | ||
import { HandlerErrorPlugin } from "@webiny/handler/types"; | ||
import { ContextPlugin } from "@webiny/handler"; | ||
declare const _default: (options?: HandlerHttpOptions) => (ContextPlugin<HttpContext> | HandlerErrorPlugin<HttpContext, import("@webiny/handler/types").Context, import("@webiny/handler/types").Context, import("@webiny/handler/types").Context, import("@webiny/handler/types").Context, import("@webiny/handler/types").Context, import("@webiny/handler/types").Context, import("@webiny/handler/types").Context, import("@webiny/handler/types").Context, import("@webiny/handler/types").Context>)[]; | ||
export default _default; |
94
index.js
@@ -16,6 +16,8 @@ "use strict"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } | ||
var _handler = require("@webiny/handler"); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
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({ | ||
@@ -29,2 +31,8 @@ "Cache-Control": "no-store", | ||
const OPTIONS_HEADERS = { | ||
"Access-Control-Max-Age": "86400", | ||
"Cache-Control": "public, max-age=86400" | ||
}; | ||
const OPTION_STATUS_CODE = 204; | ||
const lowercaseKeys = obj => { | ||
@@ -37,47 +45,51 @@ return Object.keys(obj).reduce((acc, key) => { | ||
var _default = (options = {}) => [{ | ||
type: "context", | ||
var _default = (options = {}) => [new _handler.ContextPlugin(async context => { | ||
var _invocationArgs$path; | ||
apply(context) { | ||
var _invocationArgs$path; | ||
const { | ||
invocationArgs | ||
} = context; | ||
const { | ||
invocationArgs | ||
} = context; | ||
if (!invocationArgs || !invocationArgs.method) { | ||
return; | ||
} | ||
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 = invocationArgs.path) !== null && _invocationArgs$path !== void 0 ? _invocationArgs$path : {}; | ||
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, | ||
const path = (_invocationArgs$path = invocationArgs.path) !== null && _invocationArgs$path !== void 0 ? _invocationArgs$path : {}; | ||
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 | ||
}; | ||
} | ||
response({ | ||
statusCode = 200, | ||
body = "", | ||
headers = {} | ||
}) { | ||
return { | ||
statusCode, | ||
body, | ||
headers | ||
}; | ||
} | ||
}; | ||
} | ||
}, { | ||
}; | ||
}), { | ||
type: "handler-error", | ||
@@ -84,0 +96,0 @@ handle: (context, error) => { |
{ | ||
"name": "@webiny/handler-http", | ||
"version": "5.21.0", | ||
"version": "5.22.0-beta.0", | ||
"main": "index.js", | ||
@@ -17,12 +17,13 @@ "repository": { | ||
"dependencies": { | ||
"@babel/runtime": "7.16.3", | ||
"@webiny/handler": "5.21.0", | ||
"@babel/runtime": "7.16.7", | ||
"@webiny/handler": "5.22.0-beta.0", | ||
"@webiny/handler-args": "5.22.0-beta.0", | ||
"boolean": "3.1.4" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.5.5", | ||
"@babel/core": "^7.5.5", | ||
"@webiny/cli": "^5.21.0", | ||
"@webiny/project-utils": "^5.21.0", | ||
"@webiny/utils": "^5.21.0", | ||
"@babel/cli": "^7.16.0", | ||
"@babel/core": "^7.16.0", | ||
"@webiny/cli": "^5.22.0-beta.0", | ||
"@webiny/project-utils": "^5.22.0-beta.0", | ||
"@webiny/utils": "^5.22.0-beta.0", | ||
"merge": "^1.2.1", | ||
@@ -40,3 +41,3 @@ "rimraf": "^3.0.2", | ||
}, | ||
"gitHead": "c3d4955bf74e7ffdb9628867e3b23cdfe64ea8dc" | ||
"gitHead": "487330472a07000c4845340f3b3dfa6b3ae98944" | ||
} |
@@ -1,7 +0,9 @@ | ||
declare type ResponseArgs = { | ||
import { ArgsContext } from "@webiny/handler-args/types"; | ||
import { Context } from "@webiny/handler/types"; | ||
interface ResponseArgs { | ||
statusCode?: number; | ||
headers?: {}; | ||
body?: string; | ||
}; | ||
export declare type HttpRequestObject = { | ||
} | ||
export interface HttpRequestObject { | ||
method: "POST" | "GET" | "PUT" | "DELETE" | "OPTIONS" | string; | ||
@@ -22,4 +24,4 @@ body: string; | ||
}; | ||
}; | ||
export declare type HttpObject = { | ||
} | ||
export interface HttpObject { | ||
response: (args: ResponseArgs) => { | ||
@@ -29,9 +31,9 @@ [key: string]: any; | ||
request: HttpRequestObject; | ||
}; | ||
export declare type HttpContext = { | ||
} | ||
export interface HttpContext extends Context, ArgsContext { | ||
http: HttpObject; | ||
}; | ||
export declare type HandlerHttpOptions = { | ||
} | ||
export interface HandlerHttpOptions { | ||
debug?: boolean; | ||
}; | ||
} | ||
export {}; |
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
8287
4
152
2
+ Added@babel/runtime@7.16.7(transitive)
+ Added@webiny/handler@5.22.0-beta.0(transitive)
+ Added@webiny/handler-args@5.22.0-beta.0(transitive)
+ Added@webiny/plugins@5.22.0-beta.0(transitive)
- Removed@babel/runtime@7.16.3(transitive)
- Removed@webiny/handler@5.21.0(transitive)
- Removed@webiny/plugins@5.21.0(transitive)
Updated@babel/runtime@7.16.7