@webiny/handler-aws 0.0.0-mt-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/index.d.ts +19 -0
- package/index.js +40 -0
- package/package.json +45 -0
- package/plugins/handlerArgs.d.ts +7 -0
- package/plugins/handlerArgs.js +16 -0
- package/plugins/handlerClient.d.ts +3 -0
- package/plugins/handlerClient.js +40 -0
- package/plugins/handlerHttp.d.ts +5 -0
- package/plugins/handlerHttp.js +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @webiny/handler-aws
|
|
2
|
+
[](https://www.npmjs.com/package/@webiny/handler-aws)
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/handler-aws)
|
|
4
|
+
[](https://github.com/prettier/prettier)
|
|
5
|
+
[](http://makeapullrequest.com)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
```
|
|
9
|
+
npm install --save @webiny/handler-aws
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Or if you prefer yarn:
|
|
13
|
+
```
|
|
14
|
+
yarn add @webiny/handler-aws
|
|
15
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HandlerHttpOptions } from "@webiny/handler-http/types";
|
|
2
|
+
import { PluginCollection } from "@webiny/plugins/types";
|
|
3
|
+
declare type CreateAwsHandlerOptions = {
|
|
4
|
+
plugins: PluginCollection;
|
|
5
|
+
http?: HandlerHttpOptions;
|
|
6
|
+
};
|
|
7
|
+
interface CreateAwsHandler {
|
|
8
|
+
(...plugins: PluginCollection): Function;
|
|
9
|
+
(params: CreateAwsHandlerOptions): Function;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* To avoid braking changes, the "createHandler" function supports two signature:
|
|
13
|
+
* 1. A list of plugins. (backwards-compatible)
|
|
14
|
+
* 2. A single argument of type `CreateHandlerOptions`.
|
|
15
|
+
*
|
|
16
|
+
* @param {Array | CreateAwsHandlerOptions} args - The list of plugins or object of type `CreateHandlerOptions`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const createHandler: CreateAwsHandler;
|
|
19
|
+
export {};
|
package/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createHandler = void 0;
|
|
9
|
+
|
|
10
|
+
var _handlerClient = _interopRequireDefault(require("@webiny/handler-client"));
|
|
11
|
+
|
|
12
|
+
var _handlerHttp = _interopRequireDefault(require("@webiny/handler-http"));
|
|
13
|
+
|
|
14
|
+
var _handlerArgs = _interopRequireDefault(require("@webiny/handler-args"));
|
|
15
|
+
|
|
16
|
+
var _handler = require("@webiny/handler");
|
|
17
|
+
|
|
18
|
+
var _handlerClient2 = _interopRequireDefault(require("./plugins/handlerClient"));
|
|
19
|
+
|
|
20
|
+
var _handlerHttp2 = _interopRequireDefault(require("./plugins/handlerHttp"));
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* To avoid braking changes, the "createHandler" function supports two signature:
|
|
24
|
+
* 1. A list of plugins. (backwards-compatible)
|
|
25
|
+
* 2. A single argument of type `CreateHandlerOptions`.
|
|
26
|
+
*
|
|
27
|
+
* @param {Array | CreateAwsHandlerOptions} args - The list of plugins or object of type `CreateHandlerOptions`.
|
|
28
|
+
*/
|
|
29
|
+
const createHandler = (...args) => {
|
|
30
|
+
let plugins = args;
|
|
31
|
+
const createHandlerOptions = args[0];
|
|
32
|
+
|
|
33
|
+
if (createHandlerOptions && Array.isArray(createHandlerOptions.plugins)) {
|
|
34
|
+
plugins = createHandlerOptions.plugins;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (0, _handler.createHandler)((0, _handlerClient.default)(), (0, _handlerArgs.default)(), (0, _handlerHttp.default)(createHandlerOptions && createHandlerOptions.http), _handlerClient2.default, _handlerHttp2.default, ...plugins);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.createHandler = createHandler;
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/handler-aws",
|
|
3
|
+
"version": "0.0.0-mt-1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
8
|
+
},
|
|
9
|
+
"description": "A package that contains plugins for developing Webiny API in the AWS cloud.",
|
|
10
|
+
"contributors": [
|
|
11
|
+
"Pavel Denisjuk <pavel@webiny.com>",
|
|
12
|
+
"Sven Al Hamad <sven@webiny.com>",
|
|
13
|
+
"Adrian Smijulj <adrian@webiny.com>"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@babel/runtime": "7.15.4",
|
|
18
|
+
"@webiny/handler": "0.0.0-mt-1",
|
|
19
|
+
"@webiny/handler-args": "0.0.0-mt-1",
|
|
20
|
+
"@webiny/handler-client": "0.0.0-mt-1",
|
|
21
|
+
"@webiny/handler-http": "0.0.0-mt-1",
|
|
22
|
+
"@webiny/plugins": "0.0.0-mt-1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@babel/cli": "^7.5.5",
|
|
26
|
+
"@babel/core": "^7.5.5",
|
|
27
|
+
"@babel/preset-env": "^7.5.5",
|
|
28
|
+
"@babel/preset-typescript": "^7.8.3",
|
|
29
|
+
"@webiny/cli": "^0.0.0-mt-1",
|
|
30
|
+
"@webiny/project-utils": "^0.0.0-mt-1",
|
|
31
|
+
"babel-plugin-lodash": "^3.3.4",
|
|
32
|
+
"merge": "^1.2.1",
|
|
33
|
+
"rimraf": "^3.0.2",
|
|
34
|
+
"typescript": "^4.1.3"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"directory": "dist"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "yarn webiny run build",
|
|
42
|
+
"watch": "yarn webiny run watch"
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "37736d8456a6ecb342a6c3645060bd9a3f2d4bb0"
|
|
45
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = {
|
|
8
|
+
type: "context",
|
|
9
|
+
|
|
10
|
+
apply(context) {
|
|
11
|
+
const [event] = context.args;
|
|
12
|
+
context.invocationArgs = event;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
};
|
|
16
|
+
exports.default = _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _lambda = _interopRequireDefault(require("aws-sdk/clients/lambda"));
|
|
11
|
+
|
|
12
|
+
const plugin = {
|
|
13
|
+
type: "handler-client",
|
|
14
|
+
name: "handler-client",
|
|
15
|
+
|
|
16
|
+
async invoke({
|
|
17
|
+
name,
|
|
18
|
+
payload,
|
|
19
|
+
await: useAwait
|
|
20
|
+
}) {
|
|
21
|
+
const lambdaClient = new _lambda.default({
|
|
22
|
+
region: process.env.AWS_REGION
|
|
23
|
+
});
|
|
24
|
+
const response = await lambdaClient.invoke({
|
|
25
|
+
FunctionName: name,
|
|
26
|
+
InvocationType: useAwait === false ? "Event" : "RequestResponse",
|
|
27
|
+
Payload: JSON.stringify(payload)
|
|
28
|
+
}).promise();
|
|
29
|
+
|
|
30
|
+
if (useAwait === false) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const Payload = response.Payload;
|
|
35
|
+
return JSON.parse(Payload);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
};
|
|
39
|
+
var _default = plugin;
|
|
40
|
+
exports.default = _default;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HttpContext } from "@webiny/handler-http/types";
|
|
2
|
+
import { ContextPlugin } from "@webiny/handler/types";
|
|
3
|
+
import { ArgsContext } from "@webiny/handler-args/types";
|
|
4
|
+
declare const _default: ContextPlugin<HttpContext & ArgsContext<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("@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>>>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
const lowercaseKeys = obj => {
|
|
9
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
10
|
+
acc[key.toLowerCase()] = obj[key];
|
|
11
|
+
return acc;
|
|
12
|
+
}, {});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
var _default = {
|
|
16
|
+
type: "context",
|
|
17
|
+
|
|
18
|
+
apply(context) {
|
|
19
|
+
const {
|
|
20
|
+
invocationArgs
|
|
21
|
+
} = context;
|
|
22
|
+
|
|
23
|
+
if (!invocationArgs || !invocationArgs.httpMethod) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
isBase64Encoded
|
|
29
|
+
} = invocationArgs;
|
|
30
|
+
const request = {
|
|
31
|
+
method: invocationArgs.httpMethod,
|
|
32
|
+
body: invocationArgs.body,
|
|
33
|
+
headers: lowercaseKeys(invocationArgs.headers || {}),
|
|
34
|
+
cookies: invocationArgs.cookies,
|
|
35
|
+
path: {
|
|
36
|
+
base: invocationArgs.rawPath,
|
|
37
|
+
parameters: invocationArgs.pathParameters,
|
|
38
|
+
query: invocationArgs.queryStringParameters
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
context.http = {
|
|
42
|
+
request,
|
|
43
|
+
|
|
44
|
+
response({
|
|
45
|
+
statusCode = 200,
|
|
46
|
+
body = "",
|
|
47
|
+
headers = {}
|
|
48
|
+
}) {
|
|
49
|
+
return {
|
|
50
|
+
statusCode,
|
|
51
|
+
body: isBase64Encoded ? Buffer.from(body).toString("base64") : body,
|
|
52
|
+
headers,
|
|
53
|
+
isBase64Encoded
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (isBase64Encoded) {
|
|
60
|
+
context.http.request.body = Buffer.from(context.http.request.body, "base64").toString("utf-8");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
};
|
|
65
|
+
exports.default = _default;
|