@webiny/handler-aws 0.0.0-unstable.97a151f74d → 0.0.0-unstable.98511f29f1
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/dynamodb/index.js +2 -20
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.js +0 -8
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/eventBridge/index.js +2 -20
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.js +0 -8
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/execute.js +0 -10
- package/execute.js.map +1 -1
- package/gateway/index.js +2 -22
- package/gateway/index.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +20 -7
- package/index.js.map +1 -1
- package/package.json +15 -15
- package/plugins/handlerClient.js +0 -10
- package/plugins/handlerClient.js.map +1 -1
- package/plugins/index.js +0 -3
- package/plugins/index.js.map +1 -1
- package/raw/index.js +3 -21
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.js +0 -6
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/s3/index.js +2 -20
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.js +0 -8
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/sqs/index.js +2 -20
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.js +0 -8
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/types.js +4 -8
- package/types.js.map +1 -1
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.98511f29f1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,23 +12,23 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@babel/runtime": "7.
|
|
15
|
+
"@babel/runtime": "7.22.6",
|
|
16
16
|
"@fastify/aws-lambda": "3.1.3",
|
|
17
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
18
|
-
"@webiny/handler-client": "0.0.0-unstable.
|
|
19
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
17
|
+
"@webiny/handler": "0.0.0-unstable.98511f29f1",
|
|
18
|
+
"@webiny/handler-client": "0.0.0-unstable.98511f29f1",
|
|
19
|
+
"@webiny/plugins": "0.0.0-unstable.98511f29f1",
|
|
20
20
|
"aws-lambda": "1.0.7",
|
|
21
|
-
"fastify": "4.
|
|
21
|
+
"fastify": "4.11.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@babel/cli": "
|
|
25
|
-
"@babel/core": "
|
|
26
|
-
"@babel/preset-env": "
|
|
27
|
-
"@babel/preset-typescript": "
|
|
28
|
-
"@webiny/cli": "
|
|
29
|
-
"@webiny/project-utils": "
|
|
30
|
-
"rimraf": "
|
|
31
|
-
"ttypescript": "
|
|
24
|
+
"@babel/cli": "7.22.6",
|
|
25
|
+
"@babel/core": "7.22.8",
|
|
26
|
+
"@babel/preset-env": "7.22.7",
|
|
27
|
+
"@babel/preset-typescript": "7.22.5",
|
|
28
|
+
"@webiny/cli": "0.0.0-unstable.98511f29f1",
|
|
29
|
+
"@webiny/project-utils": "0.0.0-unstable.98511f29f1",
|
|
30
|
+
"rimraf": "3.0.2",
|
|
31
|
+
"ttypescript": "1.5.15",
|
|
32
32
|
"typescript": "4.7.4"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"build": "yarn webiny run build",
|
|
40
40
|
"watch": "yarn webiny run watch"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "98511f29f1e1fc7d03ed0d1379d0a0aeff6dae84"
|
|
43
43
|
}
|
package/plugins/handlerClient.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
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
|
});
|
|
8
7
|
exports.createHandlerClientPlugin = void 0;
|
|
9
|
-
|
|
10
8
|
var _lambda = _interopRequireDefault(require("aws-sdk/clients/lambda"));
|
|
11
|
-
|
|
12
9
|
var _handlerClient = require("@webiny/handler-client");
|
|
13
|
-
|
|
14
10
|
const createHandlerClientPlugin = () => {
|
|
15
11
|
const plugin = new _handlerClient.HandlerClientPlugin({
|
|
16
12
|
invoke: async params => {
|
|
@@ -27,11 +23,9 @@ const createHandlerClientPlugin = () => {
|
|
|
27
23
|
InvocationType: useAwait === false ? "Event" : "RequestResponse",
|
|
28
24
|
Payload: JSON.stringify(payload)
|
|
29
25
|
}).promise();
|
|
30
|
-
|
|
31
26
|
if (useAwait === false) {
|
|
32
27
|
return null;
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
const Payload = response.Payload;
|
|
36
30
|
return JSON.parse(Payload);
|
|
37
31
|
},
|
|
@@ -39,7 +33,6 @@ const createHandlerClientPlugin = () => {
|
|
|
39
33
|
if (!(params !== null && params !== void 0 && params.name)) {
|
|
40
34
|
return true;
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
const {
|
|
44
37
|
name
|
|
45
38
|
} = params;
|
|
@@ -47,16 +40,13 @@ const createHandlerClientPlugin = () => {
|
|
|
47
40
|
* In case we are invoking currently active lambda, let's use this plugin as well.
|
|
48
41
|
* When invoking some other lambda, name starts with arn.
|
|
49
42
|
*/
|
|
50
|
-
|
|
51
43
|
if (name === process.env.AWS_LAMBDA_FUNCTION_NAME) {
|
|
52
44
|
return true;
|
|
53
45
|
}
|
|
54
|
-
|
|
55
46
|
return name.match("arn:") !== null;
|
|
56
47
|
}
|
|
57
48
|
});
|
|
58
49
|
plugin.name = "handler-client";
|
|
59
50
|
return plugin;
|
|
60
51
|
};
|
|
61
|
-
|
|
62
52
|
exports.createHandlerClientPlugin = createHandlerClientPlugin;
|
|
@@ -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","promise","parse","canUse","AWS_LAMBDA_FUNCTION_NAME","match"],"sources":["handlerClient.ts"],"sourcesContent":["import LambdaClient from \"aws-sdk/clients/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\n .invoke({\n FunctionName: name,\n InvocationType: useAwait === false ? \"Event\" : \"RequestResponse\",\n Payload: JSON.stringify(payload)\n })\n .promise();\n\n if (useAwait === false) {\n return null;\n }\n\n const Payload = response.Payload as string;\n return JSON.parse(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":"
|
|
1
|
+
{"version":3,"names":["_lambda","_interopRequireDefault","require","_handlerClient","createHandlerClientPlugin","plugin","HandlerClientPlugin","invoke","params","await","useAwait","name","payload","lambdaClient","LambdaClient","region","process","env","AWS_REGION","response","FunctionName","InvocationType","Payload","JSON","stringify","promise","parse","canUse","AWS_LAMBDA_FUNCTION_NAME","match","exports"],"sources":["handlerClient.ts"],"sourcesContent":["import LambdaClient from \"aws-sdk/clients/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\n .invoke({\n FunctionName: name,\n InvocationType: useAwait === false ? \"Event\" : \"RequestResponse\",\n Payload: JSON.stringify(payload)\n })\n .promise();\n\n if (useAwait === false) {\n return null;\n }\n\n const Payload = response.Payload as string;\n return JSON.parse(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,OAAA,GAAAC,sBAAA,CAAAC,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,eAAY,CAAC;QAClCC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;MACxB,CAAC,CAAC;MACF,MAAMC,QAAQ,GAAG,MAAMN,YAAY,CAC9BN,MAAM,CAAC;QACJa,YAAY,EAAET,IAAI;QAClBU,cAAc,EAAEX,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,iBAAiB;QAChEY,OAAO,EAAEC,IAAI,CAACC,SAAS,CAACZ,OAAO;MACnC,CAAC,CAAC,CACDa,OAAO,CAAC,CAAC;MAEd,IAAIf,QAAQ,KAAK,KAAK,EAAE;QACpB,OAAO,IAAI;MACf;MAEA,MAAMY,OAAO,GAAGH,QAAQ,CAACG,OAAiB;MAC1C,OAAOC,IAAI,CAACG,KAAK,CAACJ,OAAO,CAAC;IAC9B,CAAC;IACDK,MAAM,EAAEnB,MAAM,IAAI;MACd,IAAI,EAACA,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEG,IAAI,GAAE;QACf,OAAO,IAAI;MACf;MACA,MAAM;QAAEA;MAAK,CAAC,GAAGH,MAAM;MACvB;AACZ;AACA;AACA;MACY,IAAIG,IAAI,KAAKK,OAAO,CAACC,GAAG,CAACW,wBAAwB,EAAE;QAC/C,OAAO,IAAI;MACf;MACA,OAAOjB,IAAI,CAACkB,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI;IACtC;EACJ,CAAC,CAAC;EAEFxB,MAAM,CAACM,IAAI,GAAG,gBAAgB;EAE9B,OAAON,MAAM;AACjB,CAAC;AAACyB,OAAA,CAAA1B,yBAAA,GAAAA,yBAAA"}
|
package/plugins/index.js
CHANGED
|
@@ -4,11 +4,8 @@ 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
|
};
|
|
13
|
-
|
|
14
11
|
exports.registerDefaultPlugins = registerDefaultPlugins;
|
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 { 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"}
|
package/raw/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
11
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
|
-
|
|
15
12
|
var _handler = require("@webiny/handler");
|
|
16
|
-
|
|
17
13
|
var _RawEventHandler = require("./plugins/RawEventHandler");
|
|
18
|
-
|
|
19
14
|
Object.keys(_RawEventHandler).forEach(function (key) {
|
|
20
15
|
if (key === "default" || key === "__esModule") return;
|
|
21
16
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -27,47 +22,37 @@ Object.keys(_RawEventHandler).forEach(function (key) {
|
|
|
27
22
|
}
|
|
28
23
|
});
|
|
29
24
|
});
|
|
30
|
-
|
|
31
25
|
var _plugins = require("../plugins");
|
|
32
|
-
|
|
33
26
|
var _execute = require("../execute");
|
|
34
|
-
|
|
35
27
|
/**
|
|
36
28
|
* This is the handler implementation for @webiny/handler/plugins/EventPlugin.
|
|
37
29
|
* This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.
|
|
38
30
|
*
|
|
39
31
|
* We should try to have some kind of standardized event type implementation at some point.
|
|
40
32
|
*/
|
|
41
|
-
const Reply = require("fastify/lib/reply");
|
|
42
33
|
|
|
34
|
+
const Reply = require("fastify/lib/reply");
|
|
43
35
|
const url = "/webiny-raw-event";
|
|
44
|
-
|
|
45
36
|
const createHandler = params => {
|
|
46
37
|
return (payload, context) => {
|
|
47
38
|
var _params$http;
|
|
48
|
-
|
|
49
|
-
const app = (0, _handler.createHandler)({
|
|
50
|
-
plugins: params.plugins,
|
|
39
|
+
const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
51
40
|
options: (0, _objectSpread2.default)({
|
|
52
41
|
logger: ((_params$http = params.http) === null || _params$http === void 0 ? void 0 : _params$http.debug) === true
|
|
53
42
|
}, params.options || {})
|
|
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
51
|
const plugins = app.webiny.plugins.byType(_RawEventHandler.RawEventHandler.type);
|
|
65
52
|
const handler = plugins.shift();
|
|
66
|
-
|
|
67
53
|
if (!handler) {
|
|
68
54
|
throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);
|
|
69
55
|
}
|
|
70
|
-
|
|
71
56
|
app.post(url, async (request, reply) => {
|
|
72
57
|
const params = {
|
|
73
58
|
request,
|
|
@@ -77,11 +62,9 @@ const createHandler = params => {
|
|
|
77
62
|
lambdaContext: context
|
|
78
63
|
};
|
|
79
64
|
const result = await handler.cb(params);
|
|
80
|
-
|
|
81
65
|
if (result instanceof Reply) {
|
|
82
66
|
return result;
|
|
83
67
|
}
|
|
84
|
-
|
|
85
68
|
app.__webiny_raw_result = result;
|
|
86
69
|
return reply.send({});
|
|
87
70
|
});
|
|
@@ -92,5 +75,4 @@ const createHandler = params => {
|
|
|
92
75
|
});
|
|
93
76
|
};
|
|
94
77
|
};
|
|
95
|
-
|
|
96
78
|
exports.createHandler = createHandler;
|
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","Reply","url","createHandler","params","payload","context","_params$http","app","createBaseHandler","_objectSpread2","default","options","logger","http","debug","registerDefaultPlugins","webiny","plugins","byType","RawEventHandler","type","handler","shift","Error","post","request","reply","lambdaContext","result","cb","__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 {\n createHandler as createBaseHandler,\n CreateHandlerParams as BaseCreateHandlerParams\n} from \"@webiny/handler\";\nconst Reply = require(\"fastify/lib/reply\");\nimport { Context as LambdaContext } from \"aws-lambda\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { RawEventHandler } from \"~/raw/plugins/RawEventHandler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { execute } from \"~/execute\";\n\nconst url = \"/webiny-raw-event\";\n\nexport interface HandlerCallable<Payload, Response = APIGatewayProxyResult> {\n (payload: Payload, context: LambdaContext): Promise<Response>;\n}\n\nexport interface CreateHandlerParams extends BaseCreateHandlerParams {\n http?: {\n debug?: boolean;\n };\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.http?.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.byType<RawEventHandler<Payload, any, Response>>(\n RawEventHandler.type\n );\n const handler = plugins.shift();\n if (!handler) {\n throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);\n }\n\n app.post(url, async (request, reply) => {\n const params = {\n request,\n reply,\n context: app.webiny,\n payload,\n lambdaContext: context\n };\n const result = await handler.cb(params);\n\n if (result instanceof Reply) {\n return result;\n }\n\n (app as any).__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":";;;;;;;;;;;AAMA,IAAAA,QAAA,GAAAC,OAAA;AAOA,IAAAC,gBAAA,GAAAD,OAAA;AAmEAE,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;AAlEA,IAAAS,QAAA,GAAAd,OAAA;AACA,IAAAe,QAAA,GAAAf,OAAA;AAfA;AACA;AACA;AACA;AACA;AACA;;AAKA,MAAMgB,KAAK,GAAGhB,OAAO,CAAC,mBAAmB,CAAC;AAO1C,MAAMiB,GAAG,GAAG,mBAAmB;AAYxB,MAAMC,aAAa,GACtBC,MAA2B,IACU;EACrC,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IAAA,IAAAC,YAAA;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,MAAAC,cAAA,CAAAC,OAAA,MAAAD,cAAA,CAAAC,OAAA,MACtBP,MAAM;MACTQ,OAAO,MAAAF,cAAA,CAAAC,OAAA;QACHE,MAAM,EAAE,EAAAN,YAAA,GAAAH,MAAM,CAACU,IAAI,cAAAP,YAAA,uBAAXA,YAAA,CAAaQ,KAAK,MAAK;MAAI,GAC/BX,MAAM,CAACQ,OAAO,IAAI,CAAC,CAAC;IAC3B,EACJ,CAAC;IACF;AACR;AACA;IACQ,IAAAI,+BAAsB,EAACR,GAAG,CAACS,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGV,GAAG,CAACS,MAAM,CAACC,OAAO,CAACC,MAAM,CACrCC,gCAAe,CAACC,IACpB,CAAC;IACD,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAK,CAAC,CAAC;IAC/B,IAAI,CAACD,OAAO,EAAE;MACV,MAAM,IAAIE,KAAK,CAAE,oEAAmE,CAAC;IACzF;IAEAhB,GAAG,CAACiB,IAAI,CAACvB,GAAG,EAAE,OAAOwB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMvB,MAAM,GAAG;QACXsB,OAAO;QACPC,KAAK;QACLrB,OAAO,EAAEE,GAAG,CAACS,MAAM;QACnBZ,OAAO;QACPuB,aAAa,EAAEtB;MACnB,CAAC;MACD,MAAMuB,MAAM,GAAG,MAAMP,OAAO,CAACQ,EAAE,CAAC1B,MAAM,CAAC;MAEvC,IAAIyB,MAAM,YAAY5B,KAAK,EAAE;QACzB,OAAO4B,MAAM;MACjB;MAECrB,GAAG,CAASuB,mBAAmB,GAAGF,MAAM;MACzC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXzB,GAAG;MACHN,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACV,OAAA,CAAAQ,aAAA,GAAAA,aAAA"}
|
|
@@ -4,20 +4,14 @@ 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
9
|
constructor(cb) {
|
|
12
10
|
super(cb);
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
exports.RawEventHandler = RawEventHandler;
|
|
18
|
-
|
|
19
14
|
const createEventHandler = cb => {
|
|
20
15
|
return new RawEventHandler(cb);
|
|
21
16
|
};
|
|
22
|
-
|
|
23
17
|
exports.createEventHandler = createEventHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["RawEventHandler","EventPlugin","constructor","cb","createEventHandler"],"sources":["RawEventHandler.ts"],"sourcesContent":["import { Reply, Context as BaseContext } from \"@webiny/handler/types\";\nimport { Context as LambdaContext } from \"aws-lambda\";\nimport { EventPlugin, EventPluginCallableParams } 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 class RawEventHandler<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends EventPlugin {\n public constructor(cb: RawEventHandlerCallable<Event, Context, Response>) {\n super(cb as any);\n }\n}\n\nexport const createEventHandler = <\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n cb: RawEventHandlerCallable<Event, Context, Response>\n) => {\n return new RawEventHandler<Event, Context, Response>(cb);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_handler","require","RawEventHandler","EventPlugin","constructor","cb","exports","createEventHandler"],"sources":["RawEventHandler.ts"],"sourcesContent":["import { Reply, Context as BaseContext } from \"@webiny/handler/types\";\nimport { Context as LambdaContext } from \"aws-lambda\";\nimport { EventPlugin, EventPluginCallableParams } 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 class RawEventHandler<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends EventPlugin {\n public constructor(cb: RawEventHandlerCallable<Event, Context, Response>) {\n super(cb as any);\n }\n}\n\nexport const createEventHandler = <\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n cb: RawEventHandlerCallable<Event, Context, Response>\n) => {\n return new RawEventHandler<Event, Context, Response>(cb);\n};\n"],"mappings":";;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AAUO,MAAMC,eAAe,SAIlBC,oBAAW,CAAC;EACXC,WAAWA,CAACC,EAAqD,EAAE;IACtE,KAAK,CAACA,EAAS,CAAC;EACpB;AACJ;AAACC,OAAA,CAAAJ,eAAA,GAAAA,eAAA;AAEM,MAAMK,kBAAkB,GAK3BF,EAAqD,IACpD;EACD,OAAO,IAAIH,eAAe,CAA2BG,EAAE,CAAC;AAC5D,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA"}
|
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
11
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
|
-
|
|
15
12
|
var _handler = require("@webiny/handler");
|
|
16
|
-
|
|
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,39 +22,29 @@ Object.keys(_S3EventHandler).forEach(function (key) {
|
|
|
27
22
|
}
|
|
28
23
|
});
|
|
29
24
|
});
|
|
30
|
-
|
|
31
25
|
var _plugins = require("../plugins");
|
|
32
|
-
|
|
33
26
|
var _execute = require("../execute");
|
|
34
|
-
|
|
35
27
|
const Reply = require("fastify/lib/reply");
|
|
36
|
-
|
|
37
28
|
const url = "/webiny-s3-event";
|
|
38
|
-
|
|
39
29
|
const createHandler = params => {
|
|
40
30
|
return (payload, context) => {
|
|
41
|
-
const app = (0, _handler.createHandler)({
|
|
42
|
-
plugins: params.plugins,
|
|
31
|
+
const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
43
32
|
options: (0, _objectSpread2.default)({
|
|
44
33
|
logger: params.debug === true
|
|
45
34
|
}, params.options || {})
|
|
46
|
-
});
|
|
35
|
+
}));
|
|
47
36
|
/**
|
|
48
37
|
* We always must add our default plugins to the app.
|
|
49
38
|
*/
|
|
50
|
-
|
|
51
39
|
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
52
40
|
/**
|
|
53
41
|
* There must be an event plugin for this handler to work.
|
|
54
42
|
*/
|
|
55
|
-
|
|
56
43
|
const plugins = app.webiny.plugins.byType(_S3EventHandler.S3EventHandler.type);
|
|
57
44
|
const handler = plugins.shift();
|
|
58
|
-
|
|
59
45
|
if (!handler) {
|
|
60
46
|
throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);
|
|
61
47
|
}
|
|
62
|
-
|
|
63
48
|
app.post(url, async (request, reply) => {
|
|
64
49
|
const params = {
|
|
65
50
|
request,
|
|
@@ -69,11 +54,9 @@ const createHandler = params => {
|
|
|
69
54
|
lambdaContext: context
|
|
70
55
|
};
|
|
71
56
|
const result = await handler.cb(params);
|
|
72
|
-
|
|
73
57
|
if (result instanceof Reply) {
|
|
74
58
|
return result;
|
|
75
59
|
}
|
|
76
|
-
|
|
77
60
|
app.__webiny_raw_result = result;
|
|
78
61
|
return reply.send({});
|
|
79
62
|
});
|
|
@@ -84,5 +67,4 @@ const createHandler = params => {
|
|
|
84
67
|
});
|
|
85
68
|
};
|
|
86
69
|
};
|
|
87
|
-
|
|
88
70
|
exports.createHandler = createHandler;
|
package/s3/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_handler","require","_S3EventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_plugins","_execute","Reply","url","createHandler","params","payload","context","app","createBaseHandler","_objectSpread2","default","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","S3EventHandler","type","handler","shift","Error","post","request","reply","event","lambdaContext","result","cb","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["import {\n createHandler as createBaseHandler,\n CreateHandlerParams as BaseCreateHandlerParams\n} from \"@webiny/handler\";\nconst Reply = require(\"fastify/lib/reply\");\nimport { S3Event, Context as LambdaContext } from \"aws-lambda\";\nimport { S3EventHandler, S3EventHandlerCallableParams } from \"./plugins/S3EventHandler\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { execute } from \"~/execute\";\n\nconst url = \"/webiny-s3-event\";\n\nexport interface HandlerCallable {\n (payload: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport interface CreateHandlerParams extends BaseCreateHandlerParams {\n debug?: boolean;\n}\n\nexport const createHandler = (params: CreateHandlerParams): HandlerCallable => {\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.byType<S3EventHandler>(S3EventHandler.type);\n const handler = plugins.shift();\n if (!handler) {\n throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);\n }\n\n app.post(url, async (request, reply) => {\n const params: S3EventHandlerCallableParams = {\n request,\n reply,\n context: app.webiny,\n event: payload,\n lambdaContext: context\n };\n const result = await handler.cb(params);\n\n if (result instanceof Reply) {\n return result;\n }\n\n (app as any).__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/S3EventHandler\";\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAMA,IAAAC,eAAA,GAAAD,OAAA;AA8DAE,MAAA,CAAAC,IAAA,CAAAF,eAAA,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,eAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,eAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AA5DA,IAAAS,QAAA,GAAAd,OAAA;AACA,IAAAe,QAAA,GAAAf,OAAA;AALA,MAAMgB,KAAK,GAAGhB,OAAO,CAAC,mBAAmB,CAAC;AAO1C,MAAMiB,GAAG,GAAG,kBAAkB;AAUvB,MAAMC,aAAa,GAAIC,MAA2B,IAAsB;EAC3E,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,MAAAC,cAAA,CAAAC,OAAA,MAAAD,cAAA,CAAAC,OAAA,MACtBN,MAAM;MACTO,OAAO,MAAAF,cAAA,CAAAC,OAAA;QACHE,MAAM,EAAER,MAAM,CAACS,KAAK,KAAK;MAAI,GACzBT,MAAM,CAACO,OAAO,IAAI,CAAC,CAAC;IAC3B,EACJ,CAAC;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACP,GAAG,CAACQ,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGT,GAAG,CAACQ,MAAM,CAACC,OAAO,CAACC,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC;IAC9E,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAK,CAAC,CAAC;IAC/B,IAAI,CAACD,OAAO,EAAE;MACV,MAAM,IAAIE,KAAK,CAAE,kEAAiE,CAAC;IACvF;IAEAf,GAAG,CAACgB,IAAI,CAACrB,GAAG,EAAE,OAAOsB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAAoC,GAAG;QACzCoB,OAAO;QACPC,KAAK;QACLnB,OAAO,EAAEC,GAAG,CAACQ,MAAM;QACnBW,KAAK,EAAErB,OAAO;QACdsB,aAAa,EAAErB;MACnB,CAAC;MACD,MAAMsB,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAE,CAACzB,MAAM,CAAC;MAEvC,IAAIwB,MAAM,YAAY3B,KAAK,EAAE;QACzB,OAAO2B,MAAM;MACjB;MAECrB,GAAG,CAASuB,mBAAmB,GAAGF,MAAM;MACzC,OAAOH,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXzB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACV,OAAA,CAAAQ,aAAA,GAAAA,aAAA"}
|
|
@@ -1,30 +1,22 @@
|
|
|
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
|
});
|
|
8
7
|
exports.createEventHandler = exports.S3EventHandler = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _Plugin = require("@webiny/plugins/Plugin");
|
|
13
|
-
|
|
14
10
|
class S3EventHandler extends _Plugin.Plugin {
|
|
15
11
|
constructor(cb) {
|
|
16
12
|
super();
|
|
17
13
|
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
14
|
this.cb = cb;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
exports.S3EventHandler = S3EventHandler;
|
|
24
18
|
(0, _defineProperty2.default)(S3EventHandler, "type", "handler.fastify.aws.s3.eventHandler");
|
|
25
|
-
|
|
26
19
|
const createEventHandler = cb => {
|
|
27
20
|
return new S3EventHandler(cb);
|
|
28
21
|
};
|
|
29
|
-
|
|
30
22
|
exports.createEventHandler = createEventHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["S3EventHandler","Plugin","constructor","cb","createEventHandler"],"sources":["S3EventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { S3Event, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface S3EventHandlerCallableParams {\n request: Request;\n context: Context;\n event: S3Event;\n lambdaContext: LambdaContext;\n reply: Reply;\n}\nexport interface S3EventHandlerCallable<Response> {\n (params: S3EventHandlerCallableParams): Promise<Response | Reply>;\n}\n\nexport class S3EventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.s3.eventHandler\";\n\n public readonly cb: S3EventHandlerCallable<Response>;\n\n public constructor(cb: S3EventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: S3EventHandlerCallable<Response>) => {\n return new S3EventHandler<Response>(cb);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_Plugin","require","S3EventHandler","Plugin","constructor","cb","_defineProperty2","default","exports","createEventHandler"],"sources":["S3EventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { S3Event, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface S3EventHandlerCallableParams {\n request: Request;\n context: Context;\n event: S3Event;\n lambdaContext: LambdaContext;\n reply: Reply;\n}\nexport interface S3EventHandlerCallable<Response> {\n (params: S3EventHandlerCallableParams): Promise<Response | Reply>;\n}\n\nexport class S3EventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.s3.eventHandler\";\n\n public readonly cb: S3EventHandlerCallable<Response>;\n\n public constructor(cb: S3EventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: S3EventHandlerCallable<Response>) => {\n return new S3EventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAeO,MAAMC,cAAc,SAAyBC,cAAM,CAAC;EAKhDC,WAAWA,CAACC,EAAoC,EAAE;IACrD,KAAK,CAAC,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA;IACR,IAAI,CAACF,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACG,OAAA,CAAAN,cAAA,GAAAA,cAAA;AAAA,IAAAI,gBAAA,CAAAC,OAAA,EATYL,cAAc,UACO,qCAAqC;AAUhE,MAAMO,kBAAkB,GAAcJ,EAAoC,IAAK;EAClF,OAAO,IAAIH,cAAc,CAAWG,EAAE,CAAC;AAC3C,CAAC;AAACG,OAAA,CAAAC,kBAAA,GAAAA,kBAAA"}
|
package/sqs/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
11
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
|
-
|
|
15
12
|
var _handler = require("@webiny/handler");
|
|
16
|
-
|
|
17
13
|
var _SQSEventHandler = require("./plugins/SQSEventHandler");
|
|
18
|
-
|
|
19
14
|
Object.keys(_SQSEventHandler).forEach(function (key) {
|
|
20
15
|
if (key === "default" || key === "__esModule") return;
|
|
21
16
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -27,39 +22,29 @@ Object.keys(_SQSEventHandler).forEach(function (key) {
|
|
|
27
22
|
}
|
|
28
23
|
});
|
|
29
24
|
});
|
|
30
|
-
|
|
31
25
|
var _plugins = require("../plugins");
|
|
32
|
-
|
|
33
26
|
var _execute = require("../execute");
|
|
34
|
-
|
|
35
27
|
const Reply = require("fastify/lib/reply");
|
|
36
|
-
|
|
37
28
|
const url = "/webiny-sqs-event";
|
|
38
|
-
|
|
39
29
|
const createHandler = params => {
|
|
40
30
|
return (payload, context) => {
|
|
41
|
-
const app = (0, _handler.createHandler)({
|
|
42
|
-
plugins: params.plugins,
|
|
31
|
+
const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
43
32
|
options: (0, _objectSpread2.default)({
|
|
44
33
|
logger: params.debug === true
|
|
45
34
|
}, params.options || {})
|
|
46
|
-
});
|
|
35
|
+
}));
|
|
47
36
|
/**
|
|
48
37
|
* We always must add our default plugins to the app.
|
|
49
38
|
*/
|
|
50
|
-
|
|
51
39
|
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
52
40
|
/**
|
|
53
41
|
* There must be an event plugin for this handler to work.
|
|
54
42
|
*/
|
|
55
|
-
|
|
56
43
|
const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type);
|
|
57
44
|
const handler = plugins.shift();
|
|
58
|
-
|
|
59
45
|
if (!handler) {
|
|
60
46
|
throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);
|
|
61
47
|
}
|
|
62
|
-
|
|
63
48
|
app.post(url, async (request, reply) => {
|
|
64
49
|
const params = {
|
|
65
50
|
request,
|
|
@@ -69,11 +54,9 @@ const createHandler = params => {
|
|
|
69
54
|
lambdaContext: context
|
|
70
55
|
};
|
|
71
56
|
const result = await handler.cb(params);
|
|
72
|
-
|
|
73
57
|
if (result instanceof Reply) {
|
|
74
58
|
return result;
|
|
75
59
|
}
|
|
76
|
-
|
|
77
60
|
app.__webiny_raw_result = result;
|
|
78
61
|
return reply.send({});
|
|
79
62
|
});
|
|
@@ -84,5 +67,4 @@ const createHandler = params => {
|
|
|
84
67
|
});
|
|
85
68
|
};
|
|
86
69
|
};
|
|
87
|
-
|
|
88
70
|
exports.createHandler = createHandler;
|
package/sqs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_handler","require","_SQSEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_plugins","_execute","Reply","url","createHandler","params","payload","context","app","createBaseHandler","_objectSpread2","default","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","SQSEventHandler","type","handler","shift","Error","post","request","reply","event","lambdaContext","result","cb","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["import {\n createHandler as createBaseHandler,\n CreateHandlerParams as BaseCreateHandlerParams\n} from \"@webiny/handler\";\nconst Reply = require(\"fastify/lib/reply\");\nimport { SQSEvent, Context as LambdaContext } from \"aws-lambda\";\nimport { SQSEventHandler, SQSEventHandlerCallableParams } from \"./plugins/SQSEventHandler\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { execute } from \"~/execute\";\n\nconst url = \"/webiny-sqs-event\";\n\nexport interface HandlerCallable {\n (payload: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport interface CreateHandlerParams extends BaseCreateHandlerParams {\n debug?: boolean;\n}\n\nexport const createHandler = (params: CreateHandlerParams): HandlerCallable => {\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.byType<SQSEventHandler>(SQSEventHandler.type);\n const handler = plugins.shift();\n if (!handler) {\n throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);\n }\n\n app.post(url, async (request, reply) => {\n const params: SQSEventHandlerCallableParams = {\n request,\n reply,\n context: app.webiny,\n event: payload,\n lambdaContext: context\n };\n const result = await handler.cb(params);\n\n if (result instanceof Reply) {\n return result;\n }\n\n (app as any).__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/SQSEventHandler\";\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAMA,IAAAC,gBAAA,GAAAD,OAAA;AA8DAE,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;AA5DA,IAAAS,QAAA,GAAAd,OAAA;AACA,IAAAe,QAAA,GAAAf,OAAA;AALA,MAAMgB,KAAK,GAAGhB,OAAO,CAAC,mBAAmB,CAAC;AAO1C,MAAMiB,GAAG,GAAG,mBAAmB;AAUxB,MAAMC,aAAa,GAAIC,MAA2B,IAAsB;EAC3E,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,MAAAC,cAAA,CAAAC,OAAA,MAAAD,cAAA,CAAAC,OAAA,MACtBN,MAAM;MACTO,OAAO,MAAAF,cAAA,CAAAC,OAAA;QACHE,MAAM,EAAER,MAAM,CAACS,KAAK,KAAK;MAAI,GACzBT,MAAM,CAACO,OAAO,IAAI,CAAC,CAAC;IAC3B,EACJ,CAAC;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACP,GAAG,CAACQ,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGT,GAAG,CAACQ,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBC,gCAAe,CAACC,IAAI,CAAC;IAChF,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAK,CAAC,CAAC;IAC/B,IAAI,CAACD,OAAO,EAAE;MACV,MAAM,IAAIE,KAAK,CAAE,oEAAmE,CAAC;IACzF;IAEAf,GAAG,CAACgB,IAAI,CAACrB,GAAG,EAAE,OAAOsB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAAqC,GAAG;QAC1CoB,OAAO;QACPC,KAAK;QACLnB,OAAO,EAAEC,GAAG,CAACQ,MAAM;QACnBW,KAAK,EAAErB,OAAO;QACdsB,aAAa,EAAErB;MACnB,CAAC;MACD,MAAMsB,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAE,CAACzB,MAAM,CAAC;MAEvC,IAAIwB,MAAM,YAAY3B,KAAK,EAAE;QACzB,OAAO2B,MAAM;MACjB;MAECrB,GAAG,CAASuB,mBAAmB,GAAGF,MAAM;MACzC,OAAOH,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXzB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACV,OAAA,CAAAQ,aAAA,GAAAA,aAAA"}
|
|
@@ -1,30 +1,22 @@
|
|
|
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
|
});
|
|
8
7
|
exports.createEventHandler = exports.SQSEventHandler = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
var _Plugin = require("@webiny/plugins/Plugin");
|
|
13
|
-
|
|
14
10
|
class SQSEventHandler extends _Plugin.Plugin {
|
|
15
11
|
constructor(cb) {
|
|
16
12
|
super();
|
|
17
13
|
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
14
|
this.cb = cb;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
exports.SQSEventHandler = SQSEventHandler;
|
|
24
18
|
(0, _defineProperty2.default)(SQSEventHandler, "type", "handler.fastify.aws.sqs.eventHandler");
|
|
25
|
-
|
|
26
19
|
const createEventHandler = cb => {
|
|
27
20
|
return new SQSEventHandler(cb);
|
|
28
21
|
};
|
|
29
|
-
|
|
30
22
|
exports.createEventHandler = createEventHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SQSEventHandler","Plugin","constructor","cb","createEventHandler"],"sources":["SQSEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { SQSEvent, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface SQSEventHandlerCallableParams {\n request: Request;\n reply: Reply;\n context: Context;\n event: SQSEvent;\n lambdaContext: LambdaContext;\n}\nexport interface SQSEventHandlerCallable<Response> {\n (params: SQSEventHandlerCallableParams): Promise<Response | Reply>;\n}\n\nexport class SQSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: SQSEventHandlerCallable<Response>;\n\n public constructor(cb: SQSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SQSEventHandlerCallable<Response>) => {\n return new SQSEventHandler<Response>(cb);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_Plugin","require","SQSEventHandler","Plugin","constructor","cb","_defineProperty2","default","exports","createEventHandler"],"sources":["SQSEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { SQSEvent, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface SQSEventHandlerCallableParams {\n request: Request;\n reply: Reply;\n context: Context;\n event: SQSEvent;\n lambdaContext: LambdaContext;\n}\nexport interface SQSEventHandlerCallable<Response> {\n (params: SQSEventHandlerCallableParams): Promise<Response | Reply>;\n}\n\nexport class SQSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: SQSEventHandlerCallable<Response>;\n\n public constructor(cb: SQSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SQSEventHandlerCallable<Response>) => {\n return new SQSEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAeO,MAAMC,eAAe,SAAyBC,cAAM,CAAC;EAKjDC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA;IACR,IAAI,CAACF,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACG,OAAA,CAAAN,eAAA,GAAAA,eAAA;AAAA,IAAAI,gBAAA,CAAAC,OAAA,EATYL,eAAe,UACM,sCAAsC;AAUjE,MAAMO,kBAAkB,GAAcJ,EAAqC,IAAK;EACnF,OAAO,IAAIH,eAAe,CAAWG,EAAE,CAAC;AAC5C,CAAC;AAACG,OAAA,CAAAC,kBAAA,GAAAA,kBAAA"}
|
package/types.js
CHANGED
|
@@ -7,11 +7,8 @@ var _exportNames = {
|
|
|
7
7
|
Base64EncodeHeader: true
|
|
8
8
|
};
|
|
9
9
|
exports.Base64EncodeHeader = void 0;
|
|
10
|
-
|
|
11
10
|
require("fastify");
|
|
12
|
-
|
|
13
11
|
var _types = require("@webiny/handler/types");
|
|
14
|
-
|
|
15
12
|
Object.keys(_types).forEach(function (key) {
|
|
16
13
|
if (key === "default" || key === "__esModule") return;
|
|
17
14
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -23,10 +20,9 @@ Object.keys(_types).forEach(function (key) {
|
|
|
23
20
|
}
|
|
24
21
|
});
|
|
25
22
|
});
|
|
26
|
-
let Base64EncodeHeader
|
|
27
|
-
exports.Base64EncodeHeader = Base64EncodeHeader;
|
|
28
|
-
|
|
29
|
-
(function (Base64EncodeHeader) {
|
|
23
|
+
let Base64EncodeHeader = /*#__PURE__*/function (Base64EncodeHeader) {
|
|
30
24
|
Base64EncodeHeader["encoded"] = "x-webiny-base64-encoded";
|
|
31
25
|
Base64EncodeHeader["binary"] = "x-webiny-binary";
|
|
32
|
-
|
|
26
|
+
return Base64EncodeHeader;
|
|
27
|
+
}({});
|
|
28
|
+
exports.Base64EncodeHeader = Base64EncodeHeader;
|