@webiny/handler-aws 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d
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/createHandler.d.ts +2 -0
- package/createHandler.js +29 -0
- package/createHandler.js.map +1 -0
- package/dynamodb/index.d.ts +5 -8
- package/dynamodb/index.js +19 -28
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +6 -5
- package/dynamodb/plugins/DynamoDBEventHandler.js +3 -12
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.d.ts +1 -0
- package/dynamodb/register.js +28 -0
- package/dynamodb/register.js.map +1 -0
- package/eventBridge/index.d.ts +7 -10
- package/eventBridge/index.js +21 -30
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +6 -5
- package/eventBridge/plugins/EventBridgeEventHandler.js +3 -12
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +4 -0
- package/eventBridge/register.js +21 -0
- package/eventBridge/register.js.map +1 -0
- package/execute.d.ts +1 -1
- package/execute.js +16 -14
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +7 -11
- package/gateway/index.js +48 -22
- package/gateway/index.js.map +1 -1
- package/gateway/register.d.ts +1 -0
- package/gateway/register.js +21 -0
- package/gateway/register.js.map +1 -0
- package/index.d.ts +34 -5
- package/index.js +158 -29
- package/index.js.map +1 -1
- package/package.json +14 -20
- package/plugins/handlerClient.js +9 -18
- package/plugins/handlerClient.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +2 -3
- package/plugins/index.js.map +1 -1
- package/raw/index.d.ts +3 -8
- package/raw/index.js +22 -29
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +17 -6
- package/raw/plugins/RawEventHandler.js +20 -9
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +17 -0
- package/registry.js +44 -0
- package/registry.js.map +1 -0
- package/s3/index.d.ts +6 -9
- package/s3/index.js +22 -31
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +6 -5
- package/s3/plugins/S3EventHandler.js +3 -12
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +4 -0
- package/s3/register.js +25 -0
- package/s3/register.js.map +1 -0
- package/sns/index.d.ts +8 -0
- package/sns/index.js +79 -0
- package/sns/index.js.map +1 -0
- package/sns/plugins/SNSEventHandler.d.ts +20 -0
- package/sns/plugins/SNSEventHandler.js +21 -0
- package/sns/plugins/SNSEventHandler.js.map +1 -0
- package/sns/register.d.ts +1 -0
- package/sns/register.js +25 -0
- package/sns/register.js.map +1 -0
- package/sourceHandler.d.ts +2 -0
- package/sourceHandler.js +12 -0
- package/sourceHandler.js.map +1 -0
- package/sqs/index.d.ts +6 -9
- package/sqs/index.js +26 -32
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +6 -5
- package/sqs/plugins/SQSEventHandler.js +3 -12
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.d.ts +1 -0
- package/sqs/register.js +28 -0
- package/sqs/register.js.map +1 -0
- package/types.d.ts +27 -4
- package/types.js +14 -9
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +6 -0
- package/utils/composedHandler.js +24 -0
- package/utils/composedHandler.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +29 -0
- package/utils/index.js.map +1 -0
- package/utils/timer/CustomTimer.d.ts +5 -0
- package/utils/timer/CustomTimer.js +19 -0
- package/utils/timer/CustomTimer.js.map +1 -0
- package/utils/timer/Timer.d.ts +10 -0
- package/utils/timer/Timer.js +24 -0
- package/utils/timer/Timer.js.map +1 -0
- package/utils/timer/abstractions/ITimer.d.ts +10 -0
- package/utils/timer/abstractions/ITimer.js +7 -0
- package/utils/timer/abstractions/ITimer.js.map +1 -0
- package/utils/timer/factory.d.ts +4 -0
- package/utils/timer/factory.js +20 -0
- package/utils/timer/factory.js.map +1 -0
- package/utils/timer/index.d.ts +4 -0
- package/utils/timer/index.js +51 -0
- package/utils/timer/index.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-aws",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.fdd9228b5d",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,32 +12,26 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@
|
|
16
|
-
"@
|
|
17
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
18
|
-
"@webiny/handler-client": "0.0.0-unstable.
|
|
19
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
20
|
-
"
|
|
21
|
-
"fastify": "4.
|
|
15
|
+
"@fastify/aws-lambda": "4.1.0",
|
|
16
|
+
"@webiny/aws-sdk": "0.0.0-unstable.fdd9228b5d",
|
|
17
|
+
"@webiny/handler": "0.0.0-unstable.fdd9228b5d",
|
|
18
|
+
"@webiny/handler-client": "0.0.0-unstable.fdd9228b5d",
|
|
19
|
+
"@webiny/plugins": "0.0.0-unstable.fdd9228b5d",
|
|
20
|
+
"@webiny/utils": "0.0.0-unstable.fdd9228b5d",
|
|
21
|
+
"fastify": "4.29.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"@babel/preset-typescript": "^7.18.6",
|
|
28
|
-
"@webiny/cli": "^0.0.0-unstable.fcdad0bc61",
|
|
29
|
-
"@webiny/project-utils": "^0.0.0-unstable.fcdad0bc61",
|
|
30
|
-
"rimraf": "^3.0.2",
|
|
31
|
-
"ttypescript": "^1.5.13",
|
|
32
|
-
"typescript": "4.7.4"
|
|
24
|
+
"@webiny/project-utils": "0.0.0-unstable.fdd9228b5d",
|
|
25
|
+
"rimraf": "6.0.1",
|
|
26
|
+
"typescript": "5.3.3"
|
|
33
27
|
},
|
|
34
28
|
"publishConfig": {
|
|
35
29
|
"access": "public",
|
|
36
30
|
"directory": "dist"
|
|
37
31
|
},
|
|
38
32
|
"scripts": {
|
|
39
|
-
"build": "
|
|
40
|
-
"watch": "
|
|
33
|
+
"build": "node ../cli/bin.js run build",
|
|
34
|
+
"watch": "node ../cli/bin.js run watch"
|
|
41
35
|
},
|
|
42
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "fdd9228b5d2636463e8a34b6e0d26eea1e29c01d"
|
|
43
37
|
}
|
package/plugins/handlerClient.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.createHandlerClientPlugin = void 0;
|
|
9
|
-
|
|
10
|
-
var _lambda = _interopRequireDefault(require("aws-sdk/clients/lambda"));
|
|
11
|
-
|
|
7
|
+
var _clientLambda = require("@webiny/aws-sdk/client-lambda");
|
|
12
8
|
var _handlerClient = require("@webiny/handler-client");
|
|
13
|
-
|
|
14
9
|
const createHandlerClientPlugin = () => {
|
|
15
10
|
const plugin = new _handlerClient.HandlerClientPlugin({
|
|
16
11
|
invoke: async params => {
|
|
@@ -19,27 +14,24 @@ const createHandlerClientPlugin = () => {
|
|
|
19
14
|
name,
|
|
20
15
|
payload
|
|
21
16
|
} = params;
|
|
22
|
-
const lambdaClient = new
|
|
17
|
+
const lambdaClient = new _clientLambda.LambdaClient({
|
|
23
18
|
region: process.env.AWS_REGION
|
|
24
19
|
});
|
|
25
|
-
const response = await lambdaClient.
|
|
20
|
+
const response = await lambdaClient.send(new _clientLambda.InvokeCommand({
|
|
26
21
|
FunctionName: name,
|
|
27
22
|
InvocationType: useAwait === false ? "Event" : "RequestResponse",
|
|
28
23
|
Payload: JSON.stringify(payload)
|
|
29
|
-
})
|
|
30
|
-
|
|
24
|
+
}));
|
|
31
25
|
if (useAwait === false) {
|
|
32
26
|
return null;
|
|
33
27
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return JSON.parse(Payload);
|
|
28
|
+
const decoder = new TextDecoder("utf-8");
|
|
29
|
+
return JSON.parse(decoder.decode(response.Payload));
|
|
37
30
|
},
|
|
38
31
|
canUse: params => {
|
|
39
|
-
if (!
|
|
32
|
+
if (!params?.name) {
|
|
40
33
|
return true;
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
const {
|
|
44
36
|
name
|
|
45
37
|
} = params;
|
|
@@ -47,16 +39,15 @@ const createHandlerClientPlugin = () => {
|
|
|
47
39
|
* In case we are invoking currently active lambda, let's use this plugin as well.
|
|
48
40
|
* When invoking some other lambda, name starts with arn.
|
|
49
41
|
*/
|
|
50
|
-
|
|
51
42
|
if (name === process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
52
43
|
return true;
|
|
53
44
|
}
|
|
54
|
-
|
|
55
45
|
return name.match("arn:") !== null;
|
|
56
46
|
}
|
|
57
47
|
});
|
|
58
48
|
plugin.name = "handler-client";
|
|
59
49
|
return plugin;
|
|
60
50
|
};
|
|
51
|
+
exports.createHandlerClientPlugin = createHandlerClientPlugin;
|
|
61
52
|
|
|
62
|
-
|
|
53
|
+
//# sourceMappingURL=handlerClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createHandlerClientPlugin","plugin","HandlerClientPlugin","invoke","params","await","useAwait","name","payload","lambdaClient","LambdaClient","region","process","env","AWS_REGION","response","FunctionName","InvocationType","Payload","JSON","stringify","
|
|
1
|
+
{"version":3,"names":["_clientLambda","require","_handlerClient","createHandlerClientPlugin","plugin","HandlerClientPlugin","invoke","params","await","useAwait","name","payload","lambdaClient","LambdaClient","region","process","env","AWS_REGION","response","send","InvokeCommand","FunctionName","InvocationType","Payload","JSON","stringify","decoder","TextDecoder","parse","decode","canUse","AWS_LAMBDA_FUNCTION_NAME","match","exports"],"sources":["handlerClient.ts"],"sourcesContent":["import { LambdaClient, InvokeCommand } from \"@webiny/aws-sdk/client-lambda\";\nimport { HandlerClientPlugin } from \"@webiny/handler-client\";\n\nexport const createHandlerClientPlugin = () => {\n const plugin = new HandlerClientPlugin({\n invoke: async params => {\n const { await: useAwait, name, payload } = params;\n const lambdaClient = new LambdaClient({\n region: process.env.AWS_REGION\n });\n const response = await lambdaClient.send(\n new InvokeCommand({\n FunctionName: name,\n InvocationType: useAwait === false ? \"Event\" : \"RequestResponse\",\n Payload: JSON.stringify(payload)\n })\n );\n\n if (useAwait === false) {\n return null;\n }\n\n const decoder = new TextDecoder(\"utf-8\");\n return JSON.parse(decoder.decode(response.Payload));\n },\n canUse: params => {\n if (!params?.name) {\n return true;\n }\n const { name } = params;\n /**\n * In case we are invoking currently active lambda, let's use this plugin as well.\n * When invoking some other lambda, name starts with arn.\n */\n if (name === process.env.AWS_LAMBDA_FUNCTION_NAME) {\n return true;\n }\n return name.match(\"arn:\") !== null;\n }\n });\n\n plugin.name = \"handler-client\";\n\n return plugin;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAEO,MAAME,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,MAAMC,MAAM,GAAG,IAAIC,kCAAmB,CAAC;IACnCC,MAAM,EAAE,MAAMC,MAAM,IAAI;MACpB,MAAM;QAAEC,KAAK,EAAEC,QAAQ;QAAEC,IAAI;QAAEC;MAAQ,CAAC,GAAGJ,MAAM;MACjD,MAAMK,YAAY,GAAG,IAAIC,0BAAY,CAAC;QAClCC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;MACxB,CAAC,CAAC;MACF,MAAMC,QAAQ,GAAG,MAAMN,YAAY,CAACO,IAAI,CACpC,IAAIC,2BAAa,CAAC;QACdC,YAAY,EAAEX,IAAI;QAClBY,cAAc,EAAEb,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,iBAAiB;QAChEc,OAAO,EAAEC,IAAI,CAACC,SAAS,CAACd,OAAO;MACnC,CAAC,CACL,CAAC;MAED,IAAIF,QAAQ,KAAK,KAAK,EAAE;QACpB,OAAO,IAAI;MACf;MAEA,MAAMiB,OAAO,GAAG,IAAIC,WAAW,CAAC,OAAO,CAAC;MACxC,OAAOH,IAAI,CAACI,KAAK,CAACF,OAAO,CAACG,MAAM,CAACX,QAAQ,CAACK,OAAO,CAAC,CAAC;IACvD,CAAC;IACDO,MAAM,EAAEvB,MAAM,IAAI;MACd,IAAI,CAACA,MAAM,EAAEG,IAAI,EAAE;QACf,OAAO,IAAI;MACf;MACA,MAAM;QAAEA;MAAK,CAAC,GAAGH,MAAM;MACvB;AACZ;AACA;AACA;MACY,IAAIG,IAAI,KAAKK,OAAO,CAACC,GAAG,CAACe,wBAAwB,EAAE;QAC/C,OAAO,IAAI;MACf;MACA,OAAOrB,IAAI,CAACsB,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI;IACtC;EACJ,CAAC,CAAC;EAEF5B,MAAM,CAACM,IAAI,GAAG,gBAAgB;EAE9B,OAAON,MAAM;AACjB,CAAC;AAAC6B,OAAA,CAAA9B,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
package/plugins/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Context } from "@webiny/handler/types";
|
|
1
|
+
import type { Context } from "@webiny/handler/types";
|
|
2
2
|
export declare const registerDefaultPlugins: (context: Context) => void;
|
package/plugins/index.js
CHANGED
|
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.registerDefaultPlugins = void 0;
|
|
7
|
-
|
|
8
7
|
var _handlerClient = require("./handlerClient");
|
|
9
|
-
|
|
10
8
|
const registerDefaultPlugins = context => {
|
|
11
9
|
context.plugins.register([(0, _handlerClient.createHandlerClientPlugin)()]);
|
|
12
10
|
};
|
|
11
|
+
exports.registerDefaultPlugins = registerDefaultPlugins;
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerDefaultPlugins","context","plugins","register","createHandlerClientPlugin"],"sources":["index.ts"],"sourcesContent":["import { createHandlerClientPlugin } from \"./handlerClient\";\nimport { Context } from \"@webiny/handler/types\";\n\nexport const registerDefaultPlugins = (context: Context): void => {\n context.plugins.register([createHandlerClientPlugin()]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_handlerClient","require","registerDefaultPlugins","context","plugins","register","createHandlerClientPlugin","exports"],"sources":["index.ts"],"sourcesContent":["import { createHandlerClientPlugin } from \"./handlerClient\";\nimport type { Context } from \"@webiny/handler/types\";\n\nexport const registerDefaultPlugins = (context: Context): void => {\n context.plugins.register([createHandlerClientPlugin()]);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAGO,MAAMC,sBAAsB,GAAIC,OAAgB,IAAW;EAC9DA,OAAO,CAACC,OAAO,CAACC,QAAQ,CAAC,CAAC,IAAAC,wCAAyB,EAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAACC,OAAA,CAAAL,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
package/raw/index.d.ts
CHANGED
|
@@ -4,16 +4,11 @@
|
|
|
4
4
|
*
|
|
5
5
|
* We should try to have some kind of standardized event type implementation at some point.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
|
|
7
|
+
import type { APIGatewayProxyResult, Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
8
|
+
import type { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
|
|
10
9
|
export interface HandlerCallable<Payload, Response = APIGatewayProxyResult> {
|
|
11
10
|
(payload: Payload, context: LambdaContext): Promise<Response>;
|
|
12
11
|
}
|
|
13
|
-
export
|
|
14
|
-
http?: {
|
|
15
|
-
debug?: boolean;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
12
|
+
export type CreateHandlerParams = BaseCreateHandlerParams;
|
|
18
13
|
export declare const createHandler: <Payload = any, Response_1 = APIGatewayProxyResult>(params: CreateHandlerParams) => HandlerCallable<Payload, Response_1>;
|
|
19
14
|
export * from "./plugins/RawEventHandler";
|
package/raw/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -9,13 +7,8 @@ var _exportNames = {
|
|
|
9
7
|
createHandler: true
|
|
10
8
|
};
|
|
11
9
|
exports.createHandler = void 0;
|
|
12
|
-
|
|
13
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
|
-
|
|
15
10
|
var _handler = require("@webiny/handler");
|
|
16
|
-
|
|
17
11
|
var _RawEventHandler = require("./plugins/RawEventHandler");
|
|
18
|
-
|
|
19
12
|
Object.keys(_RawEventHandler).forEach(function (key) {
|
|
20
13
|
if (key === "default" || key === "__esModule") return;
|
|
21
14
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -27,47 +20,48 @@ Object.keys(_RawEventHandler).forEach(function (key) {
|
|
|
27
20
|
}
|
|
28
21
|
});
|
|
29
22
|
});
|
|
30
|
-
|
|
31
23
|
var _plugins = require("../plugins");
|
|
32
|
-
|
|
33
24
|
var _execute = require("../execute");
|
|
34
|
-
|
|
25
|
+
var _composedHandler = require("../utils/composedHandler");
|
|
35
26
|
/**
|
|
36
27
|
* This is the handler implementation for @webiny/handler/plugins/EventPlugin.
|
|
37
28
|
* This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.
|
|
38
29
|
*
|
|
39
30
|
* We should try to have some kind of standardized event type implementation at some point.
|
|
40
31
|
*/
|
|
41
|
-
const Reply = require("fastify/lib/reply");
|
|
42
32
|
|
|
33
|
+
const Reply = require("fastify/lib/reply");
|
|
43
34
|
const url = "/webiny-raw-event";
|
|
44
|
-
|
|
45
35
|
const createHandler = params => {
|
|
46
36
|
return (payload, context) => {
|
|
47
|
-
var _params$http;
|
|
48
|
-
|
|
49
37
|
const app = (0, _handler.createHandler)({
|
|
50
|
-
|
|
51
|
-
options:
|
|
52
|
-
logger:
|
|
53
|
-
|
|
38
|
+
...params,
|
|
39
|
+
options: {
|
|
40
|
+
logger: params.debug === true,
|
|
41
|
+
...(params.options || {})
|
|
42
|
+
}
|
|
54
43
|
});
|
|
55
44
|
/**
|
|
56
45
|
* We always must add our default plugins to the app.
|
|
57
46
|
*/
|
|
58
|
-
|
|
59
47
|
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
60
48
|
/**
|
|
61
49
|
* There must be an event plugin for this handler to work.
|
|
62
50
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
const plugins = app.webiny.plugins.byType(_RawEventHandler.RawEventHandler.type).filter(plugin => {
|
|
52
|
+
/**
|
|
53
|
+
* Just in case check that the plugin contains canHandle method.
|
|
54
|
+
* If it does not, we assume it can handle any payload.
|
|
55
|
+
*/
|
|
56
|
+
if (typeof plugin.canHandle !== "function") {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return plugin.canHandle(payload);
|
|
60
|
+
}).reverse();
|
|
61
|
+
if (plugins.length === 0) {
|
|
68
62
|
throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);
|
|
69
63
|
}
|
|
70
|
-
|
|
64
|
+
const handler = (0, _composedHandler.createComposedHandler)(plugins);
|
|
71
65
|
app.post(url, async (request, reply) => {
|
|
72
66
|
const params = {
|
|
73
67
|
request,
|
|
@@ -76,12 +70,10 @@ const createHandler = params => {
|
|
|
76
70
|
payload,
|
|
77
71
|
lambdaContext: context
|
|
78
72
|
};
|
|
79
|
-
const result = await handler
|
|
80
|
-
|
|
73
|
+
const result = await handler(params);
|
|
81
74
|
if (result instanceof Reply) {
|
|
82
75
|
return result;
|
|
83
76
|
}
|
|
84
|
-
|
|
85
77
|
app.__webiny_raw_result = result;
|
|
86
78
|
return reply.send({});
|
|
87
79
|
});
|
|
@@ -92,5 +84,6 @@ const createHandler = params => {
|
|
|
92
84
|
});
|
|
93
85
|
};
|
|
94
86
|
};
|
|
87
|
+
exports.createHandler = createHandler;
|
|
95
88
|
|
|
96
|
-
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
package/raw/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_handler","require","_RawEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_plugins","_execute","_composedHandler","Reply","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","RawEventHandler","type","filter","plugin","canHandle","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["/**\n * This is the handler implementation for @webiny/handler/plugins/EventPlugin.\n * This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.\n *\n * We should try to have some kind of standardized event type implementation at some point.\n */\nimport type { APIGatewayProxyResult, Context as LambdaContext } from \"@webiny/aws-sdk/types\";\nimport type { CreateHandlerParams as BaseCreateHandlerParams } from \"@webiny/handler\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { RawEventHandler } from \"~/raw/plugins/RawEventHandler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { execute } from \"~/execute\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\nimport type { Context, Request } from \"@webiny/handler/types\";\n\nconst Reply = require(\"fastify/lib/reply\");\n\nconst url = \"/webiny-raw-event\";\n\nexport interface HandlerCallable<Payload, Response = APIGatewayProxyResult> {\n (payload: Payload, context: LambdaContext): Promise<Response>;\n}\n\nexport type CreateHandlerParams = BaseCreateHandlerParams;\n\ninterface HandlerParams<Payload = any> {\n request: Request;\n context: Context;\n payload: Payload;\n lambdaContext: LambdaContext;\n reply: Record<string, any>;\n next: () => Promise<Payload>;\n}\n\nexport const createHandler = <Payload = any, Response = APIGatewayProxyResult>(\n params: CreateHandlerParams\n): HandlerCallable<Payload, Response> => {\n return (payload, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins\n .byType<RawEventHandler<Payload, any, Response>>(RawEventHandler.type)\n .filter(plugin => {\n /**\n * Just in case check that the plugin contains canHandle method.\n * If it does not, we assume it can handle any payload.\n */\n if (typeof plugin.canHandle !== \"function\") {\n return true;\n }\n return plugin.canHandle(payload);\n })\n .reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n RawEventHandler<Payload, any, Response>,\n HandlerParams,\n Response\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<HandlerParams, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n payload,\n lambdaContext: context\n };\n const result = await handler(params as unknown as HandlerParams);\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload\n });\n };\n};\n\nexport * from \"./plugins/RawEventHandler\";\n"],"mappings":";;;;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AA2FAE,MAAA,CAAAC,IAAA,CAAAF,gBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,gBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,gBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AA1FA,IAAAS,QAAA,GAAAd,OAAA;AACA,IAAAe,QAAA,GAAAf,OAAA;AACA,IAAAgB,gBAAA,GAAAhB,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;;AAUA,MAAMiB,KAAK,GAAGjB,OAAO,CAAC,mBAAmB,CAAC;AAE1C,MAAMkB,GAAG,GAAG,mBAAmB;AAiBxB,MAAMC,aAAa,GACtBC,MAA2B,IACU;EACrC,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,EAAC;MAC1B,GAAGJ,MAAM;MACTK,OAAO,EAAE;QACLC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK,IAAI;QAC7B,IAAIP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAC7BC,MAAM,CAA0CC,gCAAe,CAACC,IAAI,CAAC,CACrEC,MAAM,CAACC,MAAM,IAAI;MACd;AAChB;AACA;AACA;MACgB,IAAI,OAAOA,MAAM,CAACC,SAAS,KAAK,UAAU,EAAE;QACxC,OAAO,IAAI;MACf;MACA,OAAOD,MAAM,CAACC,SAAS,CAACf,OAAO,CAAC;IACpC,CAAC,CAAC,CACDgB,OAAO,CAAC,CAAC;IACd,IAAIP,OAAO,CAACQ,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAG,IAAAC,sCAAqB,EAInCX,OAAO,CAAC;IAEVP,GAAG,CAACmB,IAAI,CAACxB,GAAG,EAAE,OAAOyB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMxB,MAAmC,GAAG;QACxCuB,OAAO;QACPC,KAAK;QACLtB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,OAAO;QACPwB,aAAa,EAAEvB;MACnB,CAAC;MACD,MAAMwB,MAAM,GAAG,MAAMN,OAAO,CAACpB,MAAkC,CAAC;MAEhE,IAAI0B,MAAM,YAAY7B,KAAK,EAAE;QACzB,OAAO6B,MAAM;MACjB;MAEAvB,GAAG,CAACwB,mBAAmB,GAAGD,MAAM;MAChC,OAAOF,KAAK,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACX1B,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context as
|
|
3
|
-
import {
|
|
1
|
+
import type { Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
2
|
+
import type { Context as BaseContext, Reply } from "@webiny/handler/types";
|
|
3
|
+
import type { EventPluginCallableParams } from "@webiny/handler";
|
|
4
|
+
import { EventPlugin } from "@webiny/handler";
|
|
4
5
|
export interface RawEventHandlerCallableParams<Event, Context extends BaseContext> extends EventPluginCallableParams<Event, Context> {
|
|
5
6
|
lambdaContext: LambdaContext;
|
|
6
7
|
}
|
|
7
8
|
export interface RawEventHandlerCallable<Event, Context extends BaseContext, Response> {
|
|
8
9
|
(params: RawEventHandlerCallableParams<Event, Context>): Promise<Response | Reply>;
|
|
9
10
|
}
|
|
10
|
-
export
|
|
11
|
-
|
|
11
|
+
export interface RawEventHandlerParamsConfig<Event = any, Context extends BaseContext = BaseContext, Response = any> {
|
|
12
|
+
canHandle(event: Event): boolean;
|
|
13
|
+
handle: RawEventHandlerCallable<Event, Context, Response>;
|
|
12
14
|
}
|
|
13
|
-
export
|
|
15
|
+
export type RawEventHandlerParams<Event = any, Context extends BaseContext = BaseContext, Response = any> = RawEventHandlerCallable<Event, Context, Response> | RawEventHandlerParamsConfig<Event, Context, Response>;
|
|
16
|
+
export declare class RawEventHandler<Event = any, Context extends BaseContext = BaseContext, Response = any> extends EventPlugin<Event, Context, Response> {
|
|
17
|
+
private readonly params;
|
|
18
|
+
constructor(params: RawEventHandlerParams<Event, Context, Response>);
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
canHandle(event: Event): boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare const createEventHandler: <Event_1 = any, Context extends BaseContext = BaseContext, Response_1 = any>(params: RawEventHandlerParams<Event_1, Context, Response_1>) => RawEventHandler<Event_1, Context, Response_1>;
|
|
@@ -4,20 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createEventHandler = exports.RawEventHandler = void 0;
|
|
7
|
-
|
|
8
7
|
var _handler = require("@webiny/handler");
|
|
9
|
-
|
|
10
8
|
class RawEventHandler extends _handler.EventPlugin {
|
|
11
|
-
constructor(
|
|
9
|
+
constructor(params) {
|
|
10
|
+
const cb = typeof params === "function" ? params : params.handle;
|
|
11
|
+
/**
|
|
12
|
+
* Callable is correct, TS is just having problems with the override.
|
|
13
|
+
*/
|
|
14
|
+
// @ts-expect-error
|
|
12
15
|
super(cb);
|
|
16
|
+
this.params = params;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
canHandle(event) {
|
|
22
|
+
if (typeof this.params === "function" || !this.params?.canHandle) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return this.params.canHandle(event);
|
|
13
26
|
}
|
|
14
|
-
|
|
15
27
|
}
|
|
16
|
-
|
|
17
28
|
exports.RawEventHandler = RawEventHandler;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return new RawEventHandler(cb);
|
|
29
|
+
const createEventHandler = params => {
|
|
30
|
+
return new RawEventHandler(params);
|
|
21
31
|
};
|
|
32
|
+
exports.createEventHandler = createEventHandler;
|
|
22
33
|
|
|
23
|
-
|
|
34
|
+
//# sourceMappingURL=RawEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RawEventHandler","EventPlugin","constructor","cb","createEventHandler"],"sources":["RawEventHandler.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":["_handler","require","RawEventHandler","EventPlugin","constructor","params","cb","handle","canHandle","event","exports","createEventHandler"],"sources":["RawEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext } from \"@webiny/aws-sdk/types\";\nimport type { Context as BaseContext, Reply } from \"@webiny/handler/types\";\nimport type { EventPluginCallableParams } from \"@webiny/handler\";\nimport { EventPlugin } from \"@webiny/handler\";\n\nexport interface RawEventHandlerCallableParams<Event, Context extends BaseContext>\n extends EventPluginCallableParams<Event, Context> {\n lambdaContext: LambdaContext;\n}\nexport interface RawEventHandlerCallable<Event, Context extends BaseContext, Response> {\n (params: RawEventHandlerCallableParams<Event, Context>): Promise<Response | Reply>;\n}\n\nexport interface RawEventHandlerParamsConfig<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> {\n canHandle(event: Event): boolean;\n handle: RawEventHandlerCallable<Event, Context, Response>;\n}\n\nexport type RawEventHandlerParams<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> =\n | RawEventHandlerCallable<Event, Context, Response>\n | RawEventHandlerParamsConfig<Event, Context, Response>;\n\nexport class RawEventHandler<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends EventPlugin<Event, Context, Response> {\n private readonly params: RawEventHandlerParams<Event, Context, Response>;\n\n public constructor(params: RawEventHandlerParams<Event, Context, Response>) {\n const cb = typeof params === \"function\" ? params : params.handle;\n /**\n * Callable is correct, TS is just having problems with the override.\n */\n // @ts-expect-error\n super(cb);\n this.params = params;\n }\n /**\n *\n */\n public canHandle(event: Event): boolean {\n if (typeof this.params === \"function\" || !this.params?.canHandle) {\n return true;\n }\n return this.params.canHandle(event);\n }\n}\n\nexport const createEventHandler = <\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n params: RawEventHandlerParams<Event, Context, Response>\n) => {\n return new RawEventHandler<Event, Context, Response>(params);\n};\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AA2BO,MAAMC,eAAe,SAIlBC,oBAAW,CAA2B;EAGrCC,WAAWA,CAACC,MAAuD,EAAE;IACxE,MAAMC,EAAE,GAAG,OAAOD,MAAM,KAAK,UAAU,GAAGA,MAAM,GAAGA,MAAM,CAACE,MAAM;IAChE;AACR;AACA;IACQ;IACA,KAAK,CAACD,EAAE,CAAC;IACT,IAAI,CAACD,MAAM,GAAGA,MAAM;EACxB;EACA;AACJ;AACA;EACWG,SAASA,CAACC,KAAY,EAAW;IACpC,IAAI,OAAO,IAAI,CAACJ,MAAM,KAAK,UAAU,IAAI,CAAC,IAAI,CAACA,MAAM,EAAEG,SAAS,EAAE;MAC9D,OAAO,IAAI;IACf;IACA,OAAO,IAAI,CAACH,MAAM,CAACG,SAAS,CAACC,KAAK,CAAC;EACvC;AACJ;AAACC,OAAA,CAAAR,eAAA,GAAAA,eAAA;AAEM,MAAMS,kBAAkB,GAK3BN,MAAuD,IACtD;EACD,OAAO,IAAIH,eAAe,CAA2BG,MAAM,CAAC;AAChE,CAAC;AAACK,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
package/registry.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: refactor this to use a proper DI container
|
|
3
|
+
*/
|
|
4
|
+
import type { HandlerEvent, SourceHandler } from "./types";
|
|
5
|
+
import type { Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
6
|
+
interface RegisterOptions {
|
|
7
|
+
silent?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare class HandlerRegistry {
|
|
10
|
+
private readonly handlers;
|
|
11
|
+
private constructor();
|
|
12
|
+
static create(): HandlerRegistry;
|
|
13
|
+
register(handler: SourceHandler<any>, options?: RegisterOptions): void;
|
|
14
|
+
getHandler(event: HandlerEvent, context: LambdaContext): SourceHandler;
|
|
15
|
+
}
|
|
16
|
+
export type { HandlerRegistry };
|
|
17
|
+
export declare const registry: HandlerRegistry;
|
package/registry.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.registry = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* TODO: refactor this to use a proper DI container
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
class HandlerRegistry {
|
|
12
|
+
handlers = new Map();
|
|
13
|
+
constructor() {
|
|
14
|
+
/**
|
|
15
|
+
* We don't want this class to be constructed outside the static create() method
|
|
16
|
+
*/
|
|
17
|
+
}
|
|
18
|
+
static create() {
|
|
19
|
+
return new HandlerRegistry();
|
|
20
|
+
}
|
|
21
|
+
register(handler, options) {
|
|
22
|
+
if (this.handlers.has(handler.name)) {
|
|
23
|
+
if (options?.silent) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* This should only happen during the development phase.
|
|
28
|
+
*/
|
|
29
|
+
throw new Error(`Handler "${handler.name}" is already registered.`);
|
|
30
|
+
}
|
|
31
|
+
this.handlers.set(handler.name, handler);
|
|
32
|
+
}
|
|
33
|
+
getHandler(event, context) {
|
|
34
|
+
for (const handler of this.handlers.values()) {
|
|
35
|
+
if (handler.canUse(event, context)) {
|
|
36
|
+
return handler;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const registry = exports.registry = HandlerRegistry.create();
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=registry.js.map
|
package/registry.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["HandlerRegistry","handlers","Map","constructor","create","register","handler","options","has","name","silent","Error","set","getHandler","event","context","values","canUse","JSON","stringify","registry","exports"],"sources":["registry.ts"],"sourcesContent":["/**\n * TODO: refactor this to use a proper DI container\n */\nimport type { HandlerEvent, SourceHandler } from \"~/types\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types\";\n\ninterface RegisterOptions {\n silent?: boolean;\n}\n\nclass HandlerRegistry {\n private readonly handlers = new Map<string, SourceHandler>();\n\n private constructor() {\n /**\n * We don't want this class to be constructed outside the static create() method\n */\n }\n\n public static create() {\n return new HandlerRegistry();\n }\n\n public register(handler: SourceHandler<any>, options?: RegisterOptions) {\n if (this.handlers.has(handler.name)) {\n if (options?.silent) {\n return;\n }\n /**\n * This should only happen during the development phase.\n */\n throw new Error(`Handler \"${handler.name}\" is already registered.`);\n }\n this.handlers.set(handler.name, handler);\n }\n\n public getHandler(event: HandlerEvent, context: LambdaContext): SourceHandler {\n for (const handler of this.handlers.values()) {\n if (handler.canUse(event, context)) {\n return handler;\n }\n }\n throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);\n }\n}\n\nexport type { HandlerRegistry };\n\nexport const registry = HandlerRegistry.create();\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAQA,MAAMA,eAAe,CAAC;EACDC,QAAQ,GAAG,IAAIC,GAAG,CAAwB,CAAC;EAEpDC,WAAWA,CAAA,EAAG;IAClB;AACR;AACA;EAFQ;EAKJ,OAAcC,MAAMA,CAAA,EAAG;IACnB,OAAO,IAAIJ,eAAe,CAAC,CAAC;EAChC;EAEOK,QAAQA,CAACC,OAA2B,EAAEC,OAAyB,EAAE;IACpE,IAAI,IAAI,CAACN,QAAQ,CAACO,GAAG,CAACF,OAAO,CAACG,IAAI,CAAC,EAAE;MACjC,IAAIF,OAAO,EAAEG,MAAM,EAAE;QACjB;MACJ;MACA;AACZ;AACA;MACY,MAAM,IAAIC,KAAK,CAAC,YAAYL,OAAO,CAACG,IAAI,0BAA0B,CAAC;IACvE;IACA,IAAI,CAACR,QAAQ,CAACW,GAAG,CAACN,OAAO,CAACG,IAAI,EAAEH,OAAO,CAAC;EAC5C;EAEOO,UAAUA,CAACC,KAAmB,EAAEC,OAAsB,EAAiB;IAC1E,KAAK,MAAMT,OAAO,IAAI,IAAI,CAACL,QAAQ,CAACe,MAAM,CAAC,CAAC,EAAE;MAC1C,IAAIV,OAAO,CAACW,MAAM,CAACH,KAAK,EAAEC,OAAO,CAAC,EAAE;QAChC,OAAOT,OAAO;MAClB;IACJ;IACA,MAAM,IAAIK,KAAK,CAAC,sCAAsCO,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC,EAAE,CAAC;EAClF;AACJ;AAIO,MAAMM,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAGpB,eAAe,CAACI,MAAM,CAAC,CAAC","ignoreList":[]}
|
package/s3/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { HandlerFactoryParams } from "../types";
|
|
2
|
+
import type { APIGatewayProxyResult, Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types";
|
|
3
|
+
export * from "./plugins/S3EventHandler";
|
|
4
4
|
export interface HandlerCallable {
|
|
5
|
-
(
|
|
6
|
-
}
|
|
7
|
-
export interface CreateHandlerParams extends BaseCreateHandlerParams {
|
|
8
|
-
debug?: boolean;
|
|
5
|
+
(event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
9
6
|
}
|
|
10
|
-
export
|
|
11
|
-
export
|
|
7
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
8
|
+
export declare const createHandler: (params: HandlerParams) => HandlerCallable;
|
package/s3/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -9,13 +8,9 @@ var _exportNames = {
|
|
|
9
8
|
createHandler: true
|
|
10
9
|
};
|
|
11
10
|
exports.createHandler = void 0;
|
|
12
|
-
|
|
13
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
|
-
|
|
15
11
|
var _handler = require("@webiny/handler");
|
|
16
|
-
|
|
12
|
+
var _plugins = require("../plugins");
|
|
17
13
|
var _S3EventHandler = require("./plugins/S3EventHandler");
|
|
18
|
-
|
|
19
14
|
Object.keys(_S3EventHandler).forEach(function (key) {
|
|
20
15
|
if (key === "default" || key === "__esModule") return;
|
|
21
16
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -27,62 +22,58 @@ Object.keys(_S3EventHandler).forEach(function (key) {
|
|
|
27
22
|
}
|
|
28
23
|
});
|
|
29
24
|
});
|
|
30
|
-
|
|
31
|
-
var _plugins = require("../plugins");
|
|
32
|
-
|
|
33
25
|
var _execute = require("../execute");
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
var _reply = _interopRequireDefault(require("fastify/lib/reply"));
|
|
27
|
+
var _composedHandler = require("../utils/composedHandler");
|
|
28
|
+
/**
|
|
29
|
+
* We need a class, not an interface exported from types.
|
|
30
|
+
*/
|
|
31
|
+
// @ts-expect-error
|
|
36
32
|
|
|
37
33
|
const url = "/webiny-s3-event";
|
|
38
|
-
|
|
39
34
|
const createHandler = params => {
|
|
40
|
-
return (
|
|
35
|
+
return async (event, context) => {
|
|
41
36
|
const app = (0, _handler.createHandler)({
|
|
42
|
-
|
|
43
|
-
options:
|
|
44
|
-
logger: params.debug === true
|
|
45
|
-
|
|
37
|
+
...params,
|
|
38
|
+
options: {
|
|
39
|
+
logger: params.debug === true,
|
|
40
|
+
...(params.options || {})
|
|
41
|
+
}
|
|
46
42
|
});
|
|
47
43
|
/**
|
|
48
44
|
* We always must add our default plugins to the app.
|
|
49
45
|
*/
|
|
50
|
-
|
|
51
46
|
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
52
47
|
/**
|
|
53
48
|
* There must be an event plugin for this handler to work.
|
|
54
49
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const handler = plugins.shift();
|
|
58
|
-
|
|
59
|
-
if (!handler) {
|
|
50
|
+
const plugins = app.webiny.plugins.byType(_S3EventHandler.S3EventHandler.type).reverse();
|
|
51
|
+
if (plugins.length === 0) {
|
|
60
52
|
throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);
|
|
61
53
|
}
|
|
62
|
-
|
|
54
|
+
const handler = (0, _composedHandler.createComposedHandler)(plugins);
|
|
63
55
|
app.post(url, async (request, reply) => {
|
|
64
56
|
const params = {
|
|
65
57
|
request,
|
|
66
58
|
reply,
|
|
67
59
|
context: app.webiny,
|
|
68
|
-
event
|
|
60
|
+
event,
|
|
69
61
|
lambdaContext: context
|
|
70
62
|
};
|
|
71
|
-
const result = await handler
|
|
72
|
-
|
|
73
|
-
if (result instanceof Reply) {
|
|
63
|
+
const result = await handler(params);
|
|
64
|
+
if (result instanceof _reply.default) {
|
|
74
65
|
return result;
|
|
75
66
|
}
|
|
76
|
-
|
|
77
67
|
app.__webiny_raw_result = result;
|
|
78
68
|
return reply.send({});
|
|
79
69
|
});
|
|
80
70
|
return (0, _execute.execute)({
|
|
81
71
|
app,
|
|
82
72
|
url,
|
|
83
|
-
payload
|
|
73
|
+
payload: event
|
|
84
74
|
});
|
|
85
75
|
};
|
|
86
76
|
};
|
|
77
|
+
exports.createHandler = createHandler;
|
|
87
78
|
|
|
88
|
-
|
|
79
|
+
//# sourceMappingURL=index.js.map
|