@webiny/handler-aws 0.0.0-unstable.aa00eecd97 → 0.0.0-unstable.ac6ebf63c6
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/README.md +10 -14
- 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 +27 -40
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +8 -7
- package/dynamodb/plugins/DynamoDBEventHandler.js +6 -15
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.d.ts +1 -0
- package/dynamodb/register.js +26 -0
- package/dynamodb/register.js.map +1 -0
- package/eventBridge/index.d.ts +7 -10
- package/eventBridge/index.js +28 -41
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +8 -7
- package/eventBridge/plugins/EventBridgeEventHandler.js +6 -15
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +4 -0
- package/eventBridge/register.js +19 -0
- package/eventBridge/register.js.map +1 -0
- package/execute.d.ts +1 -1
- package/execute.js +19 -14
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +7 -11
- package/gateway/index.js +28 -39
- package/gateway/index.js.map +1 -1
- package/gateway/register.d.ts +1 -0
- package/gateway/register.js +19 -0
- package/gateway/register.js.map +1 -0
- package/index.d.ts +35 -7
- package/index.js +47 -257
- package/index.js.map +1 -1
- package/package.json +15 -22
- package/plugins/handlerClient.js +12 -18
- package/plugins/handlerClient.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +5 -10
- package/plugins/index.js.map +1 -1
- package/raw/index.d.ts +5 -10
- package/raw/index.js +33 -41
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +17 -6
- package/raw/plugins/RawEventHandler.js +22 -13
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +17 -0
- package/registry.js +38 -0
- package/registry.js.map +1 -0
- package/s3/index.d.ts +6 -9
- package/s3/index.js +30 -43
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +8 -7
- package/s3/plugins/S3EventHandler.js +6 -15
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +4 -0
- package/s3/register.js +23 -0
- package/s3/register.js.map +1 -0
- package/sns/index.d.ts +8 -0
- package/sns/index.js +57 -0
- package/sns/index.js.map +1 -0
- package/sns/plugins/SNSEventHandler.d.ts +20 -0
- package/sns/plugins/SNSEventHandler.js +13 -0
- package/sns/plugins/SNSEventHandler.js.map +1 -0
- package/sns/register.d.ts +1 -0
- package/sns/register.js +23 -0
- package/sns/register.js.map +1 -0
- package/sourceHandler.d.ts +2 -0
- package/sourceHandler.js +5 -0
- package/sourceHandler.js.map +1 -0
- package/sqs/index.d.ts +6 -9
- package/sqs/index.js +34 -44
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +8 -7
- package/sqs/plugins/SQSEventHandler.js +6 -15
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.d.ts +1 -0
- package/sqs/register.js +26 -0
- package/sqs/register.js.map +1 -0
- package/types.d.ts +28 -5
- package/types.js +7 -26
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +6 -0
- package/utils/composedHandler.js +17 -0
- package/utils/composedHandler.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +4 -0
- package/utils/index.js.map +1 -0
- package/utils/timer/CustomTimer.d.ts +5 -0
- package/utils/timer/CustomTimer.js +12 -0
- package/utils/timer/CustomTimer.js.map +1 -0
- package/utils/timer/Timer.d.ts +10 -0
- package/utils/timer/Timer.js +17 -0
- package/utils/timer/Timer.js.map +1 -0
- package/utils/timer/abstractions/ITimer.d.ts +10 -0
- package/utils/timer/abstractions/ITimer.js +3 -0
- package/utils/timer/abstractions/ITimer.js.map +1 -0
- package/utils/timer/factory.d.ts +4 -0
- package/utils/timer/factory.js +13 -0
- package/utils/timer/factory.js.map +1 -0
- package/utils/timer/index.d.ts +4 -0
- package/utils/timer/index.js +5 -0
- package/utils/timer/index.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-aws",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.ac6ebf63c6",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
@@ -12,32 +13,24 @@
|
|
|
12
13
|
],
|
|
13
14
|
"license": "MIT",
|
|
14
15
|
"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": "
|
|
16
|
+
"@fastify/aws-lambda": "6.4.0",
|
|
17
|
+
"@webiny/aws-sdk": "0.0.0-unstable.ac6ebf63c6",
|
|
18
|
+
"@webiny/handler": "0.0.0-unstable.ac6ebf63c6",
|
|
19
|
+
"@webiny/handler-client": "0.0.0-unstable.ac6ebf63c6",
|
|
20
|
+
"@webiny/plugins": "0.0.0-unstable.ac6ebf63c6",
|
|
21
|
+
"@webiny/utils": "0.0.0-unstable.ac6ebf63c6",
|
|
22
|
+
"fastify": "5.7.4",
|
|
23
|
+
"pino-lambda": "4.4.1"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"@webiny/cli": "0.0.0-unstable.aa00eecd97",
|
|
29
|
-
"@webiny/project-utils": "0.0.0-unstable.aa00eecd97",
|
|
30
|
-
"rimraf": "3.0.2",
|
|
31
|
-
"ttypescript": "1.5.15",
|
|
32
|
-
"typescript": "4.7.4"
|
|
26
|
+
"@webiny/build-tools": "0.0.0-unstable.ac6ebf63c6",
|
|
27
|
+
"rimraf": "6.1.3",
|
|
28
|
+
"typescript": "5.9.3",
|
|
29
|
+
"vitest": "3.2.4"
|
|
33
30
|
},
|
|
34
31
|
"publishConfig": {
|
|
35
32
|
"access": "public",
|
|
36
33
|
"directory": "dist"
|
|
37
34
|
},
|
|
38
|
-
"
|
|
39
|
-
"build": "yarn webiny run build",
|
|
40
|
-
"watch": "yarn webiny run watch"
|
|
41
|
-
},
|
|
42
|
-
"gitHead": "aa00eecd97d16da9bdb0581f33d491487ce43ce9"
|
|
35
|
+
"gitHead": "ac6ebf63c6de308703d41f2c1b375e03cd96b813"
|
|
43
36
|
}
|
package/plugins/handlerClient.js
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createHandlerClientPlugin = void 0;
|
|
8
|
-
var _lambda = _interopRequireDefault(require("aws-sdk/clients/lambda"));
|
|
9
|
-
var _handlerClient = require("@webiny/handler-client");
|
|
10
|
-
const createHandlerClientPlugin = () => {
|
|
11
|
-
const plugin = new _handlerClient.HandlerClientPlugin({
|
|
1
|
+
import { LambdaClient, InvokeCommand } from "@webiny/aws-sdk/client-lambda/index.js";
|
|
2
|
+
import { HandlerClientPlugin } from "@webiny/handler-client";
|
|
3
|
+
export const createHandlerClientPlugin = () => {
|
|
4
|
+
const plugin = new HandlerClientPlugin({
|
|
12
5
|
invoke: async params => {
|
|
13
6
|
const {
|
|
14
7
|
await: useAwait,
|
|
15
8
|
name,
|
|
16
9
|
payload
|
|
17
10
|
} = params;
|
|
18
|
-
const lambdaClient = new
|
|
11
|
+
const lambdaClient = new LambdaClient({
|
|
19
12
|
region: process.env.AWS_REGION
|
|
20
13
|
});
|
|
21
|
-
const response = await lambdaClient.
|
|
14
|
+
const response = await lambdaClient.send(new InvokeCommand({
|
|
22
15
|
FunctionName: name,
|
|
23
16
|
InvocationType: useAwait === false ? "Event" : "RequestResponse",
|
|
24
17
|
Payload: JSON.stringify(payload)
|
|
25
|
-
})
|
|
18
|
+
}));
|
|
26
19
|
if (useAwait === false) {
|
|
27
20
|
return null;
|
|
28
21
|
}
|
|
29
|
-
const
|
|
30
|
-
return JSON.parse(Payload);
|
|
22
|
+
const decoder = new TextDecoder("utf-8");
|
|
23
|
+
return JSON.parse(decoder.decode(response.Payload));
|
|
31
24
|
},
|
|
32
25
|
canUse: params => {
|
|
33
|
-
if (!
|
|
26
|
+
if (!params?.name) {
|
|
34
27
|
return true;
|
|
35
28
|
}
|
|
36
29
|
const {
|
|
@@ -49,4 +42,5 @@ const createHandlerClientPlugin = () => {
|
|
|
49
42
|
plugin.name = "handler-client";
|
|
50
43
|
return plugin;
|
|
51
44
|
};
|
|
52
|
-
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=handlerClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["LambdaClient","InvokeCommand","HandlerClientPlugin","createHandlerClientPlugin","plugin","invoke","params","await","useAwait","name","payload","lambdaClient","region","process","env","AWS_REGION","response","send","FunctionName","InvocationType","Payload","JSON","stringify","decoder","TextDecoder","parse","decode","canUse","AWS_LAMBDA_FUNCTION_NAME","match"],"sources":["handlerClient.ts"],"sourcesContent":["import { LambdaClient, InvokeCommand } from \"@webiny/aws-sdk/client-lambda/index.js\";\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,SAASA,YAAY,EAAEC,aAAa,QAAQ,wCAAwC;AACpF,SAASC,mBAAmB,QAAQ,wBAAwB;AAE5D,OAAO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,MAAMC,MAAM,GAAG,IAAIF,mBAAmB,CAAC;IACnCG,MAAM,EAAE,MAAMC,MAAM,IAAI;MACpB,MAAM;QAAEC,KAAK,EAAEC,QAAQ;QAAEC,IAAI;QAAEC;MAAQ,CAAC,GAAGJ,MAAM;MACjD,MAAMK,YAAY,GAAG,IAAIX,YAAY,CAAC;QAClCY,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;MACxB,CAAC,CAAC;MACF,MAAMC,QAAQ,GAAG,MAAML,YAAY,CAACM,IAAI,CACpC,IAAIhB,aAAa,CAAC;QACdiB,YAAY,EAAET,IAAI;QAClBU,cAAc,EAAEX,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,iBAAiB;QAChEY,OAAO,EAAEC,IAAI,CAACC,SAAS,CAACZ,OAAO;MACnC,CAAC,CACL,CAAC;MAED,IAAIF,QAAQ,KAAK,KAAK,EAAE;QACpB,OAAO,IAAI;MACf;MAEA,MAAMe,OAAO,GAAG,IAAIC,WAAW,CAAC,OAAO,CAAC;MACxC,OAAOH,IAAI,CAACI,KAAK,CAACF,OAAO,CAACG,MAAM,CAACV,QAAQ,CAACI,OAAO,CAAC,CAAC;IACvD,CAAC;IACDO,MAAM,EAAErB,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,KAAKI,OAAO,CAACC,GAAG,CAACc,wBAAwB,EAAE;QAC/C,OAAO,IAAI;MACf;MACA,OAAOnB,IAAI,CAACoB,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI;IACtC;EACJ,CAAC,CAAC;EAEFzB,MAAM,CAACK,IAAI,GAAG,gBAAgB;EAE9B,OAAOL,MAAM;AACjB,CAAC","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.js";
|
|
2
2
|
export declare const registerDefaultPlugins: (context: Context) => void;
|
package/plugins/index.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.registerDefaultPlugins = void 0;
|
|
7
|
-
var _handlerClient = require("./handlerClient");
|
|
8
|
-
const registerDefaultPlugins = context => {
|
|
9
|
-
context.plugins.register([(0, _handlerClient.createHandlerClientPlugin)()]);
|
|
1
|
+
import { createHandlerClientPlugin } from "./handlerClient.js";
|
|
2
|
+
export const registerDefaultPlugins = context => {
|
|
3
|
+
context.plugins.register([createHandlerClientPlugin()]);
|
|
10
4
|
};
|
|
11
|
-
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
package/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerDefaultPlugins","context","plugins","register"
|
|
1
|
+
{"version":3,"names":["createHandlerClientPlugin","registerDefaultPlugins","context","plugins","register"],"sources":["index.ts"],"sourcesContent":["import { createHandlerClientPlugin } from \"./handlerClient.js\";\nimport type { Context } from \"@webiny/handler/types.js\";\n\nexport const registerDefaultPlugins = (context: Context): void => {\n context.plugins.register([createHandlerClientPlugin()]);\n};\n"],"mappings":"AAAA,SAASA,yBAAyB;AAGlC,OAAO,MAAMC,sBAAsB,GAAIC,OAAgB,IAAW;EAC9DA,OAAO,CAACC,OAAO,CAACC,QAAQ,CAAC,CAACJ,yBAAyB,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC","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/index.js";
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export declare const createHandler: <Payload = any, Response_1 = APIGatewayProxyResult>(params: CreateHandlerParams) => HandlerCallable<Payload, Response_1>;
|
|
19
|
-
export * from "./plugins/RawEventHandler";
|
|
12
|
+
export type CreateHandlerParams = BaseCreateHandlerParams;
|
|
13
|
+
export declare const createHandler: <Payload = any, Response = APIGatewayProxyResult>(params: CreateHandlerParams) => HandlerCallable<Payload, Response>;
|
|
14
|
+
export * from "./plugins/RawEventHandler.js";
|
package/raw/index.js
CHANGED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
var _exportNames = {
|
|
8
|
-
createHandler: true
|
|
9
|
-
};
|
|
10
|
-
exports.createHandler = void 0;
|
|
11
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
|
-
var _handler = require("@webiny/handler");
|
|
13
|
-
var _RawEventHandler = require("./plugins/RawEventHandler");
|
|
14
|
-
Object.keys(_RawEventHandler).forEach(function (key) {
|
|
15
|
-
if (key === "default" || key === "__esModule") return;
|
|
16
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
17
|
-
if (key in exports && exports[key] === _RawEventHandler[key]) return;
|
|
18
|
-
Object.defineProperty(exports, key, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _RawEventHandler[key];
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
var _plugins = require("../plugins");
|
|
26
|
-
var _execute = require("../execute");
|
|
27
1
|
/**
|
|
28
2
|
* This is the handler implementation for @webiny/handler/plugins/EventPlugin.
|
|
29
3
|
* This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.
|
|
@@ -31,28 +5,44 @@ var _execute = require("../execute");
|
|
|
31
5
|
* We should try to have some kind of standardized event type implementation at some point.
|
|
32
6
|
*/
|
|
33
7
|
|
|
34
|
-
|
|
8
|
+
import { createHandler as createBaseHandler } from "@webiny/handler";
|
|
9
|
+
import { RawEventHandler } from "./plugins/RawEventHandler.js";
|
|
10
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
11
|
+
import { execute } from "../execute.js";
|
|
12
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
import Reply from "fastify/lib/reply.js";
|
|
35
15
|
const url = "/webiny-raw-event";
|
|
36
|
-
const createHandler = params => {
|
|
16
|
+
export const createHandler = params => {
|
|
37
17
|
return (payload, context) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
options:
|
|
41
|
-
logger:
|
|
42
|
-
|
|
43
|
-
|
|
18
|
+
const app = createBaseHandler({
|
|
19
|
+
...params,
|
|
20
|
+
options: {
|
|
21
|
+
logger: params.debug === true,
|
|
22
|
+
...(params.options || {})
|
|
23
|
+
}
|
|
24
|
+
});
|
|
44
25
|
/**
|
|
45
26
|
* We always must add our default plugins to the app.
|
|
46
27
|
*/
|
|
47
|
-
|
|
28
|
+
registerDefaultPlugins(app.webiny);
|
|
48
29
|
/**
|
|
49
30
|
* There must be an event plugin for this handler to work.
|
|
50
31
|
*/
|
|
51
|
-
const plugins = app.webiny.plugins.byType(
|
|
52
|
-
|
|
53
|
-
|
|
32
|
+
const plugins = app.webiny.plugins.byType(RawEventHandler.type).filter(plugin => {
|
|
33
|
+
/**
|
|
34
|
+
* Just in case check that the plugin contains canHandle method.
|
|
35
|
+
* If it does not, we assume it can handle any payload.
|
|
36
|
+
*/
|
|
37
|
+
if (typeof plugin.canHandle !== "function") {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return plugin.canHandle(payload);
|
|
41
|
+
}).reverse();
|
|
42
|
+
if (plugins.length === 0) {
|
|
54
43
|
throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);
|
|
55
44
|
}
|
|
45
|
+
const handler = createComposedHandler(plugins);
|
|
56
46
|
app.post(url, async (request, reply) => {
|
|
57
47
|
const params = {
|
|
58
48
|
request,
|
|
@@ -61,18 +51,20 @@ const createHandler = params => {
|
|
|
61
51
|
payload,
|
|
62
52
|
lambdaContext: context
|
|
63
53
|
};
|
|
64
|
-
const result = await handler
|
|
54
|
+
const result = await handler(params);
|
|
65
55
|
if (result instanceof Reply) {
|
|
66
56
|
return result;
|
|
67
57
|
}
|
|
68
58
|
app.__webiny_raw_result = result;
|
|
69
59
|
return reply.send({});
|
|
70
60
|
});
|
|
71
|
-
return
|
|
61
|
+
return execute({
|
|
72
62
|
app,
|
|
73
63
|
url,
|
|
74
64
|
payload
|
|
75
65
|
});
|
|
76
66
|
};
|
|
77
67
|
};
|
|
78
|
-
|
|
68
|
+
export * from "./plugins/RawEventHandler.js";
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
package/raw/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createHandler","createBaseHandler","RawEventHandler","registerDefaultPlugins","execute","createComposedHandler","Reply","url","params","payload","context","app","options","logger","debug","webiny","plugins","byType","type","filter","plugin","canHandle","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","send"],"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 {\n APIGatewayProxyResult,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { CreateHandlerParams as BaseCreateHandlerParams } from \"@webiny/handler\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { RawEventHandler } from \"~/raw/plugins/RawEventHandler.js\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport { execute } from \"~/execute.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\nimport type { Context, Request } from \"@webiny/handler/types.js\";\n\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\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.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;;AAMA,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,eAAe;AACxB,SAASC,sBAAsB;AAC/B,SAASC,OAAO;AAChB,SAASC,qBAAqB;AAG9B;AACA,OAAOC,KAAK,MAAM,sBAAsB;AAExC,MAAMC,GAAG,GAAG,mBAAmB;AAiB/B,OAAO,MAAMP,aAAa,GACtBQ,MAA2B,IACU;EACrC,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQT,sBAAsB,CAACQ,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAC7BC,MAAM,CAA0Cf,eAAe,CAACgB,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,CAACZ,OAAO,CAAC;IACpC,CAAC,CAAC,CACDa,OAAO,CAAC,CAAC;IACd,IAAIN,OAAO,CAACO,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAGpB,qBAAqB,CAInCW,OAAO,CAAC;IAEVL,GAAG,CAACe,IAAI,CAACnB,GAAG,EAAE,OAAOoB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMpB,MAAmC,GAAG;QACxCmB,OAAO;QACPC,KAAK;QACLlB,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,OAAO;QACPoB,aAAa,EAAEnB;MACnB,CAAC;MACD,MAAMoB,MAAM,GAAG,MAAML,OAAO,CAACjB,MAAkC,CAAC;MAEhE,IAAIsB,MAAM,YAAYxB,KAAK,EAAE;QACzB,OAAOwB,MAAM;MACjB;MAEAnB,GAAG,CAACoB,mBAAmB,GAAGD,MAAM;MAChC,OAAOF,KAAK,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO5B,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHE;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAED","ignoreList":[]}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context as
|
|
3
|
-
import {
|
|
1
|
+
import type { Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
|
|
2
|
+
import type { Context as BaseContext, Reply } from "@webiny/handler/types.js";
|
|
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 = any, Context extends BaseContext = BaseContext, Response = any>(params: RawEventHandlerParams<Event, Context, Response>) => RawEventHandler<Event, Context, Response>;
|
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(cb) {
|
|
1
|
+
import { EventPlugin } from "@webiny/handler";
|
|
2
|
+
export class RawEventHandler extends EventPlugin {
|
|
3
|
+
constructor(params) {
|
|
4
|
+
const cb = typeof params === "function" ? params : params.handle;
|
|
5
|
+
/**
|
|
6
|
+
* Callable is correct, TS is just having problems with the override.
|
|
7
|
+
*/
|
|
8
|
+
// @ts-expect-error
|
|
10
9
|
super(cb);
|
|
10
|
+
this.params = params;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
canHandle(event) {
|
|
16
|
+
if (typeof this.params === "function" || !this.params?.canHandle) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return this.params.canHandle(event);
|
|
11
20
|
}
|
|
12
21
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return new RawEventHandler(cb);
|
|
22
|
+
export const createEventHandler = params => {
|
|
23
|
+
return new RawEventHandler(params);
|
|
16
24
|
};
|
|
17
|
-
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=RawEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["EventPlugin","RawEventHandler","constructor","params","cb","handle","canHandle","event","createEventHandler"],"sources":["RawEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\nimport type { Context as BaseContext, Reply } from \"@webiny/handler/types.js\";\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,SAASA,WAAW,QAAQ,iBAAiB;AA2B7C,OAAO,MAAMC,eAAe,SAIlBD,WAAW,CAA2B;EAGrCE,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;AAEA,OAAO,MAAMC,kBAAkB,GAK3BL,MAAuD,IACtD;EACD,OAAO,IAAIF,eAAe,CAA2BE,MAAM,CAAC;AAChE,CAAC","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.js";
|
|
5
|
+
import type { Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
|
|
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,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: refactor this to use a proper DI container
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
class HandlerRegistry {
|
|
6
|
+
handlers = new Map();
|
|
7
|
+
constructor() {
|
|
8
|
+
/**
|
|
9
|
+
* We don't want this class to be constructed outside the static create() method
|
|
10
|
+
*/
|
|
11
|
+
}
|
|
12
|
+
static create() {
|
|
13
|
+
return new HandlerRegistry();
|
|
14
|
+
}
|
|
15
|
+
register(handler, options) {
|
|
16
|
+
if (this.handlers.has(handler.name)) {
|
|
17
|
+
if (options?.silent) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* This should only happen during the development phase.
|
|
22
|
+
*/
|
|
23
|
+
throw new Error(`Handler "${handler.name}" is already registered.`);
|
|
24
|
+
}
|
|
25
|
+
this.handlers.set(handler.name, handler);
|
|
26
|
+
}
|
|
27
|
+
getHandler(event, context) {
|
|
28
|
+
for (const handler of this.handlers.values()) {
|
|
29
|
+
if (handler.canUse(event, context)) {
|
|
30
|
+
return handler;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export const registry = HandlerRegistry.create();
|
|
37
|
+
|
|
38
|
+
//# 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"],"sources":["registry.ts"],"sourcesContent":["/**\n * TODO: refactor this to use a proper DI container\n */\nimport type { HandlerEvent, SourceHandler } from \"~/types.js\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\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;AAIA,OAAO,MAAMM,QAAQ,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.js";
|
|
2
|
+
import type { APIGatewayProxyResult, Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types/index.js";
|
|
3
|
+
export * from "./plugins/S3EventHandler.js";
|
|
4
4
|
export interface HandlerCallable {
|
|
5
|
-
(
|
|
5
|
+
(event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
export declare const createHandler: (params: CreateHandlerParams) => HandlerCallable;
|
|
11
|
-
export * from "./plugins/S3EventHandler";
|
|
7
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
8
|
+
export declare const createHandler: (params: HandlerParams) => HandlerCallable;
|
package/s3/index.js
CHANGED
|
@@ -1,70 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _handler = require("@webiny/handler");
|
|
13
|
-
var _S3EventHandler = require("./plugins/S3EventHandler");
|
|
14
|
-
Object.keys(_S3EventHandler).forEach(function (key) {
|
|
15
|
-
if (key === "default" || key === "__esModule") return;
|
|
16
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
17
|
-
if (key in exports && exports[key] === _S3EventHandler[key]) return;
|
|
18
|
-
Object.defineProperty(exports, key, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _S3EventHandler[key];
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
var _plugins = require("../plugins");
|
|
26
|
-
var _execute = require("../execute");
|
|
27
|
-
const Reply = require("fastify/lib/reply");
|
|
1
|
+
import { createHandler as createBaseHandler } from "@webiny/handler";
|
|
2
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
|
+
import { S3EventHandler } from "./plugins/S3EventHandler.js";
|
|
4
|
+
import { execute } from "../execute.js";
|
|
5
|
+
/**
|
|
6
|
+
* We need a class, not an interface exported from types.
|
|
7
|
+
*/
|
|
8
|
+
// @ts-expect-error
|
|
9
|
+
import Reply from "fastify/lib/reply.js";
|
|
10
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
11
|
+
export * from "./plugins/S3EventHandler.js";
|
|
28
12
|
const url = "/webiny-s3-event";
|
|
29
|
-
const createHandler = params => {
|
|
30
|
-
return (
|
|
31
|
-
const app = (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
export const createHandler = params => {
|
|
14
|
+
return async (event, context) => {
|
|
15
|
+
const app = createBaseHandler({
|
|
16
|
+
...params,
|
|
17
|
+
options: {
|
|
18
|
+
logger: params.debug === true,
|
|
19
|
+
...(params.options || {})
|
|
20
|
+
}
|
|
21
|
+
});
|
|
36
22
|
/**
|
|
37
23
|
* We always must add our default plugins to the app.
|
|
38
24
|
*/
|
|
39
|
-
|
|
25
|
+
registerDefaultPlugins(app.webiny);
|
|
40
26
|
/**
|
|
41
27
|
* There must be an event plugin for this handler to work.
|
|
42
28
|
*/
|
|
43
|
-
const plugins = app.webiny.plugins.byType(
|
|
44
|
-
|
|
45
|
-
if (!handler) {
|
|
29
|
+
const plugins = app.webiny.plugins.byType(S3EventHandler.type).reverse();
|
|
30
|
+
if (plugins.length === 0) {
|
|
46
31
|
throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);
|
|
47
32
|
}
|
|
33
|
+
const handler = createComposedHandler(plugins);
|
|
48
34
|
app.post(url, async (request, reply) => {
|
|
49
35
|
const params = {
|
|
50
36
|
request,
|
|
51
37
|
reply,
|
|
52
38
|
context: app.webiny,
|
|
53
|
-
event
|
|
39
|
+
event,
|
|
54
40
|
lambdaContext: context
|
|
55
41
|
};
|
|
56
|
-
const result = await handler
|
|
42
|
+
const result = await handler(params);
|
|
57
43
|
if (result instanceof Reply) {
|
|
58
44
|
return result;
|
|
59
45
|
}
|
|
60
46
|
app.__webiny_raw_result = result;
|
|
61
47
|
return reply.send({});
|
|
62
48
|
});
|
|
63
|
-
return
|
|
49
|
+
return execute({
|
|
64
50
|
app,
|
|
65
51
|
url,
|
|
66
|
-
payload
|
|
52
|
+
payload: event
|
|
67
53
|
});
|
|
68
54
|
};
|
|
69
55
|
};
|
|
70
|
-
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=index.js.map
|