@webiny/handler-aws 5.34.8 → 5.35.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dynamodb/index.js +0 -17
- 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 +0 -17
- 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 +0 -19
- 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 +8 -8
- 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 +1 -18
- 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 +0 -17
- 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 +0 -17
- 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 +0 -4
- package/types.js.map +1 -1
package/dynamodb/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 _DynamoDBEventHandler = require("./plugins/DynamoDBEventHandler");
|
|
18
|
-
|
|
19
14
|
Object.keys(_DynamoDBEventHandler).forEach(function (key) {
|
|
20
15
|
if (key === "default" || key === "__esModule") return;
|
|
21
16
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -27,15 +22,10 @@ Object.keys(_DynamoDBEventHandler).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-dynamodb-event";
|
|
38
|
-
|
|
39
29
|
const createHandler = params => {
|
|
40
30
|
return (payload, context) => {
|
|
41
31
|
const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
@@ -46,19 +36,15 @@ const createHandler = params => {
|
|
|
46
36
|
/**
|
|
47
37
|
* We always must add our default plugins to the app.
|
|
48
38
|
*/
|
|
49
|
-
|
|
50
39
|
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
51
40
|
/**
|
|
52
41
|
* There must be an event plugin for this handler to work.
|
|
53
42
|
*/
|
|
54
|
-
|
|
55
43
|
const plugins = app.webiny.plugins.byType(_DynamoDBEventHandler.DynamoDBEventHandler.type);
|
|
56
44
|
const handler = plugins.shift();
|
|
57
|
-
|
|
58
45
|
if (!handler) {
|
|
59
46
|
throw new Error(`To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.`);
|
|
60
47
|
}
|
|
61
|
-
|
|
62
48
|
app.post(url, async (request, reply) => {
|
|
63
49
|
const params = {
|
|
64
50
|
request,
|
|
@@ -68,11 +54,9 @@ const createHandler = params => {
|
|
|
68
54
|
reply
|
|
69
55
|
};
|
|
70
56
|
const result = await handler.cb(params);
|
|
71
|
-
|
|
72
57
|
if (result instanceof Reply) {
|
|
73
58
|
return result;
|
|
74
59
|
}
|
|
75
|
-
|
|
76
60
|
app.__webiny_raw_result = result;
|
|
77
61
|
return reply.send({});
|
|
78
62
|
});
|
|
@@ -83,5 +67,4 @@ const createHandler = params => {
|
|
|
83
67
|
});
|
|
84
68
|
};
|
|
85
69
|
};
|
|
86
|
-
|
|
87
70
|
exports.createHandler = createHandler;
|
package/dynamodb/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","DynamoDBEventHandler","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 { DynamoDBStreamEvent, Context as LambdaContext } from \"aws-lambda\";\nimport {\n DynamoDBEventHandler,\n DynamoDBEventHandlerCallableParams\n} from \"./plugins/DynamoDBEventHandler\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { execute } from \"~/execute\";\n\nconst url = \"/webiny-dynamodb-event\";\n\nexport interface HandlerCallable {\n (event: DynamoDBStreamEvent, 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<DynamoDBEventHandler>(DynamoDBEventHandler.type);\n const handler = plugins.shift();\n if (!handler) {\n throw new Error(\n `To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.`\n );\n }\n\n app.post(url, async (request, reply) => {\n const params: DynamoDBEventHandlerCallableParams = {\n request,\n context: app.webiny,\n event: payload,\n lambdaContext: context,\n reply\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/DynamoDBEventHandler\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","DynamoDBEventHandler","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 { DynamoDBStreamEvent, Context as LambdaContext } from \"aws-lambda\";\nimport {\n DynamoDBEventHandler,\n DynamoDBEventHandlerCallableParams\n} from \"./plugins/DynamoDBEventHandler\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { execute } from \"~/execute\";\n\nconst url = \"/webiny-dynamodb-event\";\n\nexport interface HandlerCallable {\n (event: DynamoDBStreamEvent, 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<DynamoDBEventHandler>(DynamoDBEventHandler.type);\n const handler = plugins.shift();\n if (!handler) {\n throw new Error(\n `To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.`\n );\n }\n\n app.post(url, async (request, reply) => {\n const params: DynamoDBEventHandlerCallableParams = {\n request,\n context: app.webiny,\n event: payload,\n lambdaContext: context,\n reply\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/DynamoDBEventHandler\";\n"],"mappings":";;;;;;;;;;;AAAA;AAMA;AAmEA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AA9DA;AACA;AARA,MAAMA,KAAK,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAU1C,MAAMC,GAAG,GAAG,wBAAwB;AAU7B,MAAMC,aAAa,GAAIC,MAA2B,IAAsB;EAC3E,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,8DACtBJ,MAAM;MACTK,OAAO;QACHC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK;MAAI,GACzBP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;IAC3B,GACH;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CAAuBC,0CAAoB,CAACC,IAAI,CAAC;IAC1F,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAK,EAAE;IAC/B,IAAI,CAACD,OAAO,EAAE;MACV,MAAM,IAAIE,KAAK,CACV,yEAAwE,CAC5E;IACL;IAEAb,GAAG,CAACc,IAAI,CAACnB,GAAG,EAAE,OAAOoB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMnB,MAA0C,GAAG;QAC/CkB,OAAO;QACPhB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBW,KAAK,EAAEnB,OAAO;QACdoB,aAAa,EAAEnB,OAAO;QACtBiB;MACJ,CAAC;MACD,MAAMG,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAE,CAACvB,MAAM,CAAC;MAEvC,IAAIsB,MAAM,YAAY1B,KAAK,EAAE;QACzB,OAAO0B,MAAM;MACjB;MAECnB,GAAG,CAASqB,mBAAmB,GAAGF,MAAM;MACzC,OAAOH,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXvB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -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.DynamoDBEventHandler = 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 DynamoDBEventHandler 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.DynamoDBEventHandler = DynamoDBEventHandler;
|
|
24
18
|
(0, _defineProperty2.default)(DynamoDBEventHandler, "type", "handler.fastify.aws.dynamodb.eventHandler");
|
|
25
|
-
|
|
26
19
|
const createEventHandler = cb => {
|
|
27
20
|
return new DynamoDBEventHandler(cb);
|
|
28
21
|
};
|
|
29
|
-
|
|
30
22
|
exports.createEventHandler = createEventHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DynamoDBEventHandler","Plugin","constructor","cb","createEventHandler"],"sources":["DynamoDBEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { DynamoDBStreamEvent, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface DynamoDBEventHandlerCallableParams {\n request: Request;\n context: Context;\n event: DynamoDBStreamEvent;\n lambdaContext: LambdaContext;\n reply: Reply;\n}\nexport interface DynamoDBEventHandlerCallable<Response> {\n (params: DynamoDBEventHandlerCallableParams): Promise<Response | Reply>;\n}\n\nexport class DynamoDBEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.dynamodb.eventHandler\";\n\n public readonly cb: DynamoDBEventHandlerCallable<Response>;\n\n public constructor(cb: DynamoDBEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: DynamoDBEventHandlerCallable<Response>) => {\n return new DynamoDBEventHandler<Response>(cb);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["DynamoDBEventHandler","Plugin","constructor","cb","createEventHandler"],"sources":["DynamoDBEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { DynamoDBStreamEvent, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface DynamoDBEventHandlerCallableParams {\n request: Request;\n context: Context;\n event: DynamoDBStreamEvent;\n lambdaContext: LambdaContext;\n reply: Reply;\n}\nexport interface DynamoDBEventHandlerCallable<Response> {\n (params: DynamoDBEventHandlerCallableParams): Promise<Response | Reply>;\n}\n\nexport class DynamoDBEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.dynamodb.eventHandler\";\n\n public readonly cb: DynamoDBEventHandlerCallable<Response>;\n\n public constructor(cb: DynamoDBEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: DynamoDBEventHandlerCallable<Response>) => {\n return new DynamoDBEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;;;AAAA;AAeO,MAAMA,oBAAoB,SAAyBC,cAAM,CAAC;EAKtDC,WAAW,CAACC,EAA0C,EAAE;IAC3D,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAAC;AAAA,8BATYH,oBAAoB,UACC,2CAA2C;AAUtE,MAAMI,kBAAkB,GAAcD,EAA0C,IAAK;EACxF,OAAO,IAAIH,oBAAoB,CAAWG,EAAE,CAAC;AACjD,CAAC;AAAC"}
|
package/eventBridge/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 _EventBridgeEventHandler = require("./plugins/EventBridgeEventHandler");
|
|
18
|
-
|
|
19
14
|
Object.keys(_EventBridgeEventHandler).forEach(function (key) {
|
|
20
15
|
if (key === "default" || key === "__esModule") return;
|
|
21
16
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -27,15 +22,10 @@ Object.keys(_EventBridgeEventHandler).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
31
|
const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
@@ -46,19 +36,15 @@ const createHandler = params => {
|
|
|
46
36
|
/**
|
|
47
37
|
* We always must add our default plugins to the app.
|
|
48
38
|
*/
|
|
49
|
-
|
|
50
39
|
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
51
40
|
/**
|
|
52
41
|
* There must be an event plugin for this handler to work.
|
|
53
42
|
*/
|
|
54
|
-
|
|
55
43
|
const plugins = app.webiny.plugins.byType(_EventBridgeEventHandler.EventBridgeEventHandler.type);
|
|
56
44
|
const handler = plugins.shift();
|
|
57
|
-
|
|
58
45
|
if (!handler) {
|
|
59
46
|
throw new Error(`To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.`);
|
|
60
47
|
}
|
|
61
|
-
|
|
62
48
|
app.post(url, async (request, reply) => {
|
|
63
49
|
const params = {
|
|
64
50
|
request,
|
|
@@ -68,11 +54,9 @@ const createHandler = params => {
|
|
|
68
54
|
lambdaContext: context
|
|
69
55
|
};
|
|
70
56
|
const result = await handler.cb(params);
|
|
71
|
-
|
|
72
57
|
if (result instanceof Reply) {
|
|
73
58
|
return result;
|
|
74
59
|
}
|
|
75
|
-
|
|
76
60
|
app.__webiny_raw_result = result;
|
|
77
61
|
return reply.send({});
|
|
78
62
|
});
|
|
@@ -83,5 +67,4 @@ const createHandler = params => {
|
|
|
83
67
|
});
|
|
84
68
|
};
|
|
85
69
|
};
|
|
86
|
-
|
|
87
70
|
exports.createHandler = createHandler;
|
package/eventBridge/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","EventBridgeEventHandler","type","handler","shift","Error","post","request","reply","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 { EventBridgeEvent, Context as LambdaContext } from \"aws-lambda\";\nimport {\n EventBridgeEventHandler,\n EventBridgeEventHandlerCallableParams\n} from \"./plugins/EventBridgeEventHandler\";\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<DetailType extends string, Detail> {\n (\n event: EventBridgeEvent<DetailType, Detail>,\n context: LambdaContext\n ): Promise<APIGatewayProxyResult>;\n}\n\nexport interface CreateHandlerParams extends BaseCreateHandlerParams {\n debug?: boolean;\n}\n\nexport const createHandler = <DetailType extends string, Detail>(\n params: CreateHandlerParams\n): HandlerCallable<DetailType, Detail> => {\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<EventBridgeEventHandler<DetailType, Detail>>(\n EventBridgeEventHandler.type\n );\n const handler = plugins.shift();\n if (!handler) {\n throw new Error(\n `To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.`\n );\n }\n\n app.post(url, async (request, reply) => {\n const params: EventBridgeEventHandlerCallableParams<DetailType, Detail> = {\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/EventBridgeEventHandler\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","EventBridgeEventHandler","type","handler","shift","Error","post","request","reply","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 { EventBridgeEvent, Context as LambdaContext } from \"aws-lambda\";\nimport {\n EventBridgeEventHandler,\n EventBridgeEventHandlerCallableParams\n} from \"./plugins/EventBridgeEventHandler\";\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<DetailType extends string, Detail> {\n (\n event: EventBridgeEvent<DetailType, Detail>,\n context: LambdaContext\n ): Promise<APIGatewayProxyResult>;\n}\n\nexport interface CreateHandlerParams extends BaseCreateHandlerParams {\n debug?: boolean;\n}\n\nexport const createHandler = <DetailType extends string, Detail>(\n params: CreateHandlerParams\n): HandlerCallable<DetailType, Detail> => {\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<EventBridgeEventHandler<DetailType, Detail>>(\n EventBridgeEventHandler.type\n );\n const handler = plugins.shift();\n if (!handler) {\n throw new Error(\n `To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.`\n );\n }\n\n app.post(url, async (request, reply) => {\n const params: EventBridgeEventHandlerCallableParams<DetailType, Detail> = {\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/EventBridgeEventHandler\";\n"],"mappings":";;;;;;;;;;;AAAA;AAMA;AA0EA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AArEA;AACA;AARA,MAAMA,KAAK,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAU1C,MAAMC,GAAG,GAAG,mBAAmB;AAaxB,MAAMC,aAAa,GACtBC,MAA2B,IACW;EACtC,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,8DACtBJ,MAAM;MACTK,OAAO;QACHC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK;MAAI,GACzBP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;IAC3B,GACH;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CACrCC,gDAAuB,CAACC,IAAI,CAC/B;IACD,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAK,EAAE;IAC/B,IAAI,CAACD,OAAO,EAAE;MACV,MAAM,IAAIE,KAAK,CACV,oFAAmF,CACvF;IACL;IAEAb,GAAG,CAACc,IAAI,CAACnB,GAAG,EAAE,OAAOoB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMnB,MAAiE,GAAG;QACtEkB,OAAO;QACPC,KAAK;QACLjB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,OAAO;QACPmB,aAAa,EAAElB;MACnB,CAAC;MACD,MAAMmB,MAAM,GAAG,MAAMP,OAAO,CAACQ,EAAE,CAACtB,MAAM,CAAC;MAEvC,IAAIqB,MAAM,YAAYzB,KAAK,EAAE;QACzB,OAAOyB,MAAM;MACjB;MAEClB,GAAG,CAASoB,mBAAmB,GAAGF,MAAM;MACzC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXtB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -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.EventBridgeEventHandler = 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 EventBridgeEventHandler 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.EventBridgeEventHandler = EventBridgeEventHandler;
|
|
24
18
|
(0, _defineProperty2.default)(EventBridgeEventHandler, "type", "handler.fastify.aws.sqs.eventHandler");
|
|
25
|
-
|
|
26
19
|
const createEventHandler = cb => {
|
|
27
20
|
return new EventBridgeEventHandler(cb);
|
|
28
21
|
};
|
|
29
|
-
|
|
30
22
|
exports.createEventHandler = createEventHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["EventBridgeEventHandler","Plugin","constructor","cb","createEventHandler"],"sources":["EventBridgeEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { EventBridgeEvent, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface EventBridgeEventHandlerCallableParams<DetailType extends string, Detail> {\n request: Request;\n reply: Reply;\n context: Context;\n payload: EventBridgeEvent<DetailType, Detail>;\n lambdaContext: LambdaContext;\n}\nexport interface EventBridgeEventHandlerCallable<DetailType extends string, Detail, Response> {\n (params: EventBridgeEventHandlerCallableParams<DetailType, Detail>): Promise<Response | Reply>;\n}\n\nexport class EventBridgeEventHandler<\n DetailType extends string,\n Detail,\n Response = any\n> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>;\n\n public constructor(cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <DetailType extends string, Detail, Response = any>(\n cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>\n) => {\n return new EventBridgeEventHandler<DetailType, Detail, Response>(cb);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["EventBridgeEventHandler","Plugin","constructor","cb","createEventHandler"],"sources":["EventBridgeEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { EventBridgeEvent, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface EventBridgeEventHandlerCallableParams<DetailType extends string, Detail> {\n request: Request;\n reply: Reply;\n context: Context;\n payload: EventBridgeEvent<DetailType, Detail>;\n lambdaContext: LambdaContext;\n}\nexport interface EventBridgeEventHandlerCallable<DetailType extends string, Detail, Response> {\n (params: EventBridgeEventHandlerCallableParams<DetailType, Detail>): Promise<Response | Reply>;\n}\n\nexport class EventBridgeEventHandler<\n DetailType extends string,\n Detail,\n Response = any\n> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>;\n\n public constructor(cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <DetailType extends string, Detail, Response = any>(\n cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>\n) => {\n return new EventBridgeEventHandler<DetailType, Detail, Response>(cb);\n};\n"],"mappings":";;;;;;;;AAAA;AAeO,MAAMA,uBAAuB,SAI1BC,cAAM,CAAC;EAKNC,WAAW,CAACC,EAAiE,EAAE;IAClF,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAAC;AAAA,8BAbYH,uBAAuB,UAKF,sCAAsC;AAUjE,MAAMI,kBAAkB,GAC3BD,EAAiE,IAChE;EACD,OAAO,IAAIH,uBAAuB,CAA+BG,EAAE,CAAC;AACxE,CAAC;AAAC"}
|
package/execute.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.execute = void 0;
|
|
9
|
-
|
|
10
8
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
9
|
var _types = require("./types");
|
|
13
|
-
|
|
14
10
|
const createHandleResponse = (app, resolve) => {
|
|
15
11
|
return (err, result) => {
|
|
16
12
|
if (err) {
|
|
@@ -20,11 +16,9 @@ const createHandleResponse = (app, resolve) => {
|
|
|
20
16
|
headers: {}
|
|
21
17
|
});
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
if (app.__webiny_raw_result) {
|
|
25
20
|
return resolve(app.__webiny_raw_result);
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
const isBase64Encoded = !!result.headers[_types.Base64EncodeHeader.encoded] || !!result.headers[_types.Base64EncodeHeader.binary];
|
|
29
23
|
const response = {
|
|
30
24
|
statusCode: result.statusCode,
|
|
@@ -35,16 +29,13 @@ const createHandleResponse = (app, resolve) => {
|
|
|
35
29
|
return resolve(response);
|
|
36
30
|
};
|
|
37
31
|
};
|
|
38
|
-
|
|
39
32
|
const getPayloadProperty = (payload, prop, defaults = {}) => {
|
|
40
33
|
if (typeof payload === "object") {
|
|
41
34
|
const value = payload[prop] ? payload[prop] : {};
|
|
42
35
|
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, defaults), value);
|
|
43
36
|
}
|
|
44
|
-
|
|
45
37
|
return defaults;
|
|
46
38
|
};
|
|
47
|
-
|
|
48
39
|
const execute = params => {
|
|
49
40
|
const {
|
|
50
41
|
app,
|
|
@@ -67,5 +58,4 @@ const execute = params => {
|
|
|
67
58
|
}, createHandleResponse(app, resolve));
|
|
68
59
|
});
|
|
69
60
|
};
|
|
70
|
-
|
|
71
61
|
exports.execute = execute;
|
package/execute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createHandleResponse","app","resolve","err","result","statusCode","body","JSON","stringify","headers","__webiny_raw_result","isBase64Encoded","Base64EncodeHeader","encoded","binary","response","rawPayload","toString","payload","getPayloadProperty","prop","defaults","value","execute","params","url","query","cookies","Promise","inject","method"],"sources":["execute.ts"],"sourcesContent":["import { FastifyInstance } from \"@webiny/handler/types\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { LightMyRequestCallback } from \"fastify\";\nimport { Base64EncodeHeader } from \"~/types\";\n\ninterface Resolve {\n (response: APIGatewayProxyResult | any): void;\n}\nconst createHandleResponse = (app: FastifyInstance, resolve: Resolve): LightMyRequestCallback => {\n return (err, result) => {\n if (err) {\n return resolve({\n statusCode: 500,\n body: JSON.stringify(err),\n headers: {}\n });\n }\n if (app.__webiny_raw_result) {\n return resolve(app.__webiny_raw_result);\n }\n const isBase64Encoded =\n !!result.headers[Base64EncodeHeader.encoded] ||\n !!result.headers[Base64EncodeHeader.binary];\n const response: APIGatewayProxyResult = {\n statusCode: result.statusCode,\n body: isBase64Encoded ? result.rawPayload.toString(\"base64\") : result.payload,\n headers: result.headers as APIGatewayProxyResult[\"headers\"],\n isBase64Encoded\n };\n return resolve(response);\n };\n};\n\nconst getPayloadProperty = (\n payload: any,\n prop: string,\n defaults: Record<string, any> = {}\n): Record<string, any> => {\n if (typeof payload === \"object\") {\n const value = payload[prop] ? payload[prop] : {};\n\n return {\n ...defaults,\n ...value\n };\n }\n return defaults;\n};\n\nexport interface ExecuteParams {\n app: FastifyInstance;\n url: string;\n payload: any;\n}\n\nexport const execute = (params: ExecuteParams): Promise<any> => {\n const { app, url, payload } = params;\n\n const query = getPayloadProperty(payload, \"query\", {});\n const headers = getPayloadProperty(payload, \"headers\", {\n [\"content-type\"]: \"application/json\"\n });\n const cookies = getPayloadProperty(payload, \"cookies\", {});\n\n return new Promise(resolve => {\n app.inject(\n {\n method: \"POST\",\n url,\n payload: payload || {},\n query,\n headers,\n cookies\n },\n createHandleResponse(app, resolve)\n );\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["createHandleResponse","app","resolve","err","result","statusCode","body","JSON","stringify","headers","__webiny_raw_result","isBase64Encoded","Base64EncodeHeader","encoded","binary","response","rawPayload","toString","payload","getPayloadProperty","prop","defaults","value","execute","params","url","query","cookies","Promise","inject","method"],"sources":["execute.ts"],"sourcesContent":["import { FastifyInstance } from \"@webiny/handler/types\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { LightMyRequestCallback } from \"fastify\";\nimport { Base64EncodeHeader } from \"~/types\";\n\ninterface Resolve {\n (response: APIGatewayProxyResult | any): void;\n}\nconst createHandleResponse = (app: FastifyInstance, resolve: Resolve): LightMyRequestCallback => {\n return (err, result) => {\n if (err) {\n return resolve({\n statusCode: 500,\n body: JSON.stringify(err),\n headers: {}\n });\n }\n if (app.__webiny_raw_result) {\n return resolve(app.__webiny_raw_result);\n }\n const isBase64Encoded =\n !!result.headers[Base64EncodeHeader.encoded] ||\n !!result.headers[Base64EncodeHeader.binary];\n const response: APIGatewayProxyResult = {\n statusCode: result.statusCode,\n body: isBase64Encoded ? result.rawPayload.toString(\"base64\") : result.payload,\n headers: result.headers as APIGatewayProxyResult[\"headers\"],\n isBase64Encoded\n };\n return resolve(response);\n };\n};\n\nconst getPayloadProperty = (\n payload: any,\n prop: string,\n defaults: Record<string, any> = {}\n): Record<string, any> => {\n if (typeof payload === \"object\") {\n const value = payload[prop] ? payload[prop] : {};\n\n return {\n ...defaults,\n ...value\n };\n }\n return defaults;\n};\n\nexport interface ExecuteParams {\n app: FastifyInstance;\n url: string;\n payload: any;\n}\n\nexport const execute = (params: ExecuteParams): Promise<any> => {\n const { app, url, payload } = params;\n\n const query = getPayloadProperty(payload, \"query\", {});\n const headers = getPayloadProperty(payload, \"headers\", {\n [\"content-type\"]: \"application/json\"\n });\n const cookies = getPayloadProperty(payload, \"cookies\", {});\n\n return new Promise(resolve => {\n app.inject(\n {\n method: \"POST\",\n url,\n payload: payload || {},\n query,\n headers,\n cookies\n },\n createHandleResponse(app, resolve)\n );\n });\n};\n"],"mappings":";;;;;;;;AAGA;AAKA,MAAMA,oBAAoB,GAAG,CAACC,GAAoB,EAAEC,OAAgB,KAA6B;EAC7F,OAAO,CAACC,GAAG,EAAEC,MAAM,KAAK;IACpB,IAAID,GAAG,EAAE;MACL,OAAOD,OAAO,CAAC;QACXG,UAAU,EAAE,GAAG;QACfC,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACL,GAAG,CAAC;QACzBM,OAAO,EAAE,CAAC;MACd,CAAC,CAAC;IACN;IACA,IAAIR,GAAG,CAACS,mBAAmB,EAAE;MACzB,OAAOR,OAAO,CAACD,GAAG,CAACS,mBAAmB,CAAC;IAC3C;IACA,MAAMC,eAAe,GACjB,CAAC,CAACP,MAAM,CAACK,OAAO,CAACG,yBAAkB,CAACC,OAAO,CAAC,IAC5C,CAAC,CAACT,MAAM,CAACK,OAAO,CAACG,yBAAkB,CAACE,MAAM,CAAC;IAC/C,MAAMC,QAA+B,GAAG;MACpCV,UAAU,EAAED,MAAM,CAACC,UAAU;MAC7BC,IAAI,EAAEK,eAAe,GAAGP,MAAM,CAACY,UAAU,CAACC,QAAQ,CAAC,QAAQ,CAAC,GAAGb,MAAM,CAACc,OAAO;MAC7ET,OAAO,EAAEL,MAAM,CAACK,OAA2C;MAC3DE;IACJ,CAAC;IACD,OAAOT,OAAO,CAACa,QAAQ,CAAC;EAC5B,CAAC;AACL,CAAC;AAED,MAAMI,kBAAkB,GAAG,CACvBD,OAAY,EACZE,IAAY,EACZC,QAA6B,GAAG,CAAC,CAAC,KACZ;EACtB,IAAI,OAAOH,OAAO,KAAK,QAAQ,EAAE;IAC7B,MAAMI,KAAK,GAAGJ,OAAO,CAACE,IAAI,CAAC,GAAGF,OAAO,CAACE,IAAI,CAAC,GAAG,CAAC,CAAC;IAEhD,mEACOC,QAAQ,GACRC,KAAK;EAEhB;EACA,OAAOD,QAAQ;AACnB,CAAC;AAQM,MAAME,OAAO,GAAIC,MAAqB,IAAmB;EAC5D,MAAM;IAAEvB,GAAG;IAAEwB,GAAG;IAAEP;EAAQ,CAAC,GAAGM,MAAM;EAEpC,MAAME,KAAK,GAAGP,kBAAkB,CAACD,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;EACtD,MAAMT,OAAO,GAAGU,kBAAkB,CAACD,OAAO,EAAE,SAAS,EAAE;IACnD,CAAC,cAAc,GAAG;EACtB,CAAC,CAAC;EACF,MAAMS,OAAO,GAAGR,kBAAkB,CAACD,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;EAE1D,OAAO,IAAIU,OAAO,CAAC1B,OAAO,IAAI;IAC1BD,GAAG,CAAC4B,MAAM,CACN;MACIC,MAAM,EAAE,MAAM;MACdL,GAAG;MACHP,OAAO,EAAEA,OAAO,IAAI,CAAC,CAAC;MACtBQ,KAAK;MACLjB,OAAO;MACPkB;IACJ,CAAC,EACD3B,oBAAoB,CAACC,GAAG,EAAEC,OAAO,CAAC,CACrC;EACL,CAAC,CAAC;AACN,CAAC;AAAC"}
|
package/gateway/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
|
});
|
|
@@ -18,35 +17,25 @@ Object.defineProperty(exports, "createRoute", {
|
|
|
18
17
|
return _handler.createRoute;
|
|
19
18
|
}
|
|
20
19
|
});
|
|
21
|
-
|
|
22
20
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
23
|
-
|
|
24
21
|
var _awsLambda = _interopRequireDefault(require("@fastify/aws-lambda"));
|
|
25
|
-
|
|
26
22
|
var _handler = require("@webiny/handler");
|
|
27
|
-
|
|
28
23
|
var _plugins = require("../plugins");
|
|
29
|
-
|
|
30
24
|
var _types = require("../types");
|
|
31
|
-
|
|
32
25
|
const getHeader = (headers, header) => {
|
|
33
26
|
for (const key in headers) {
|
|
34
27
|
if (key.toLowerCase() !== header) {
|
|
35
28
|
continue;
|
|
36
29
|
}
|
|
37
|
-
|
|
38
30
|
return headers[key];
|
|
39
31
|
}
|
|
40
|
-
|
|
41
32
|
return undefined;
|
|
42
33
|
};
|
|
43
|
-
|
|
44
34
|
const defaultContentType = "application/json";
|
|
45
35
|
const defaultCharset = "utf-8";
|
|
46
36
|
/**
|
|
47
37
|
* We need to attach default headers to the request, so it does not break if there is none sent.
|
|
48
38
|
*/
|
|
49
|
-
|
|
50
39
|
const attachRequiredProperties = event => {
|
|
51
40
|
/**
|
|
52
41
|
* A possibility that headers are not defined?
|
|
@@ -55,14 +44,12 @@ const attachRequiredProperties = event => {
|
|
|
55
44
|
if (!event.headers) {
|
|
56
45
|
event.headers = {};
|
|
57
46
|
}
|
|
58
|
-
|
|
59
47
|
const contentType = getHeader(event.headers, "content-type");
|
|
60
48
|
/**
|
|
61
49
|
* We check the existing content type and add the default one if it does not exist.
|
|
62
50
|
*
|
|
63
51
|
* Also, if the content-type is the application/json, and the body is not sent, we add it.
|
|
64
52
|
*/
|
|
65
|
-
|
|
66
53
|
if (!contentType) {
|
|
67
54
|
event.headers["content-type"] = [defaultContentType, `charset=${defaultCharset}`].join(";");
|
|
68
55
|
event.body = "{}";
|
|
@@ -70,11 +57,9 @@ const attachRequiredProperties = event => {
|
|
|
70
57
|
event.body = "{}";
|
|
71
58
|
}
|
|
72
59
|
};
|
|
73
|
-
|
|
74
60
|
const createHandler = params => {
|
|
75
61
|
return (event, context) => {
|
|
76
62
|
var _params$http;
|
|
77
|
-
|
|
78
63
|
const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
79
64
|
options: (0, _objectSpread2.default)({
|
|
80
65
|
logger: ((_params$http = params.http) === null || _params$http === void 0 ? void 0 : _params$http.debug) === true
|
|
@@ -83,13 +68,10 @@ const createHandler = params => {
|
|
|
83
68
|
/**
|
|
84
69
|
* We always must add our default plugins to the app.
|
|
85
70
|
*/
|
|
86
|
-
|
|
87
71
|
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
88
|
-
|
|
89
72
|
if (app.webiny.plugins.byType(_handler.RoutePlugin.type).length === 0) {
|
|
90
73
|
throw new Error(`To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.`);
|
|
91
74
|
}
|
|
92
|
-
|
|
93
75
|
attachRequiredProperties(event);
|
|
94
76
|
const appLambda = (0, _awsLambda.default)(app, (0, _objectSpread2.default)({
|
|
95
77
|
decorateRequest: true,
|
|
@@ -102,5 +84,4 @@ const createHandler = params => {
|
|
|
102
84
|
return appLambda(event, context);
|
|
103
85
|
};
|
|
104
86
|
};
|
|
105
|
-
|
|
106
87
|
exports.createHandler = createHandler;
|
package/gateway/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getHeader","headers","header","key","toLowerCase","undefined","defaultContentType","defaultCharset","attachRequiredProperties","event","contentType","join","body","startsWith","createHandler","params","context","app","createBaseHandler","options","logger","http","debug","registerDefaultPlugins","webiny","plugins","byType","RoutePlugin","type","length","Error","appLambda","awsLambdaFastify","decorateRequest","serializeLambdaArguments","decorationPropertyName","enforceBase64","response","Base64EncodeHeader","encoded","binary","lambdaOptions"],"sources":["index.ts"],"sourcesContent":["import awsLambdaFastify, {\n LambdaFastifyOptions as LambdaOptions,\n LambdaResponse\n} from \"@fastify/aws-lambda\";\nimport { APIGatewayEvent, Context as LambdaContext } from \"aws-lambda\";\nimport {\n createHandler as createBaseHandler,\n CreateHandlerParams as BaseCreateHandlerParams,\n RoutePlugin,\n createRoute\n} from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { Base64EncodeHeader } from \"~/types\";\nimport { APIGatewayProxyEventHeaders } from \"aws-lambda/trigger/api-gateway-proxy\";\n\nexport interface HandlerCallable {\n (event: APIGatewayEvent, ctx: LambdaContext): Promise<LambdaResponse>;\n}\n\nexport interface CreateHandlerParams extends BaseCreateHandlerParams {\n http?: {\n debug?: boolean;\n };\n lambdaOptions?: LambdaOptions;\n}\n\nconst getHeader = (headers: APIGatewayProxyEventHeaders, header: string): string | undefined => {\n for (const key in headers) {\n if (key.toLowerCase() !== header) {\n continue;\n }\n return headers[key];\n }\n return undefined;\n};\n\nconst defaultContentType = \"application/json\";\nconst defaultCharset = \"utf-8\";\n/**\n * We need to attach default headers to the request, so it does not break if there is none sent.\n */\nconst attachRequiredProperties = (event: APIGatewayEvent): void => {\n /**\n * A possibility that headers are not defined?\n * Maybe during testing?\n */\n if (!event.headers) {\n event.headers = {};\n }\n const contentType = getHeader(event.headers, \"content-type\");\n /**\n * We check the existing content type and add the default one if it does not exist.\n *\n * Also, if the content-type is the application/json, and the body is not sent, we add it.\n */\n if (!contentType) {\n event.headers[\"content-type\"] = [defaultContentType, `charset=${defaultCharset}`].join(\";\");\n event.body = \"{}\";\n } else if (!event.body && contentType.startsWith(defaultContentType)) {\n event.body = \"{}\";\n }\n};\n\nexport const createHandler = (params: CreateHandlerParams): HandlerCallable => {\n return (event, 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 if (app.webiny.plugins.byType<RoutePlugin>(RoutePlugin.type).length === 0) {\n throw new Error(\n `To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.`\n );\n }\n attachRequiredProperties(event);\n\n const appLambda = awsLambdaFastify(app, {\n decorateRequest: true,\n serializeLambdaArguments: true,\n decorationPropertyName: \"awsLambda\",\n enforceBase64: response => {\n return (\n !!response.headers[Base64EncodeHeader.encoded] ||\n !!response.headers[Base64EncodeHeader.binary]\n );\n },\n ...(params.lambdaOptions || {})\n });\n return appLambda(event, context);\n };\n};\n\nexport { RoutePlugin, createRoute };\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["getHeader","headers","header","key","toLowerCase","undefined","defaultContentType","defaultCharset","attachRequiredProperties","event","contentType","join","body","startsWith","createHandler","params","context","app","createBaseHandler","options","logger","http","debug","registerDefaultPlugins","webiny","plugins","byType","RoutePlugin","type","length","Error","appLambda","awsLambdaFastify","decorateRequest","serializeLambdaArguments","decorationPropertyName","enforceBase64","response","Base64EncodeHeader","encoded","binary","lambdaOptions"],"sources":["index.ts"],"sourcesContent":["import awsLambdaFastify, {\n LambdaFastifyOptions as LambdaOptions,\n LambdaResponse\n} from \"@fastify/aws-lambda\";\nimport { APIGatewayEvent, Context as LambdaContext } from \"aws-lambda\";\nimport {\n createHandler as createBaseHandler,\n CreateHandlerParams as BaseCreateHandlerParams,\n RoutePlugin,\n createRoute\n} from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { Base64EncodeHeader } from \"~/types\";\nimport { APIGatewayProxyEventHeaders } from \"aws-lambda/trigger/api-gateway-proxy\";\n\nexport interface HandlerCallable {\n (event: APIGatewayEvent, ctx: LambdaContext): Promise<LambdaResponse>;\n}\n\nexport interface CreateHandlerParams extends BaseCreateHandlerParams {\n http?: {\n debug?: boolean;\n };\n lambdaOptions?: LambdaOptions;\n}\n\nconst getHeader = (headers: APIGatewayProxyEventHeaders, header: string): string | undefined => {\n for (const key in headers) {\n if (key.toLowerCase() !== header) {\n continue;\n }\n return headers[key];\n }\n return undefined;\n};\n\nconst defaultContentType = \"application/json\";\nconst defaultCharset = \"utf-8\";\n/**\n * We need to attach default headers to the request, so it does not break if there is none sent.\n */\nconst attachRequiredProperties = (event: APIGatewayEvent): void => {\n /**\n * A possibility that headers are not defined?\n * Maybe during testing?\n */\n if (!event.headers) {\n event.headers = {};\n }\n const contentType = getHeader(event.headers, \"content-type\");\n /**\n * We check the existing content type and add the default one if it does not exist.\n *\n * Also, if the content-type is the application/json, and the body is not sent, we add it.\n */\n if (!contentType) {\n event.headers[\"content-type\"] = [defaultContentType, `charset=${defaultCharset}`].join(\";\");\n event.body = \"{}\";\n } else if (!event.body && contentType.startsWith(defaultContentType)) {\n event.body = \"{}\";\n }\n};\n\nexport const createHandler = (params: CreateHandlerParams): HandlerCallable => {\n return (event, 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 if (app.webiny.plugins.byType<RoutePlugin>(RoutePlugin.type).length === 0) {\n throw new Error(\n `To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.`\n );\n }\n attachRequiredProperties(event);\n\n const appLambda = awsLambdaFastify(app, {\n decorateRequest: true,\n serializeLambdaArguments: true,\n decorationPropertyName: \"awsLambda\",\n enforceBase64: response => {\n return (\n !!response.headers[Base64EncodeHeader.encoded] ||\n !!response.headers[Base64EncodeHeader.binary]\n );\n },\n ...(params.lambdaOptions || {})\n });\n return appLambda(event, context);\n };\n};\n\nexport { RoutePlugin, createRoute };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAKA;AAMA;AACA;AAcA,MAAMA,SAAS,GAAG,CAACC,OAAoC,EAAEC,MAAc,KAAyB;EAC5F,KAAK,MAAMC,GAAG,IAAIF,OAAO,EAAE;IACvB,IAAIE,GAAG,CAACC,WAAW,EAAE,KAAKF,MAAM,EAAE;MAC9B;IACJ;IACA,OAAOD,OAAO,CAACE,GAAG,CAAC;EACvB;EACA,OAAOE,SAAS;AACpB,CAAC;AAED,MAAMC,kBAAkB,GAAG,kBAAkB;AAC7C,MAAMC,cAAc,GAAG,OAAO;AAC9B;AACA;AACA;AACA,MAAMC,wBAAwB,GAAIC,KAAsB,IAAW;EAC/D;AACJ;AACA;AACA;EACI,IAAI,CAACA,KAAK,CAACR,OAAO,EAAE;IAChBQ,KAAK,CAACR,OAAO,GAAG,CAAC,CAAC;EACtB;EACA,MAAMS,WAAW,GAAGV,SAAS,CAACS,KAAK,CAACR,OAAO,EAAE,cAAc,CAAC;EAC5D;AACJ;AACA;AACA;AACA;EACI,IAAI,CAACS,WAAW,EAAE;IACdD,KAAK,CAACR,OAAO,CAAC,cAAc,CAAC,GAAG,CAACK,kBAAkB,EAAG,WAAUC,cAAe,EAAC,CAAC,CAACI,IAAI,CAAC,GAAG,CAAC;IAC3FF,KAAK,CAACG,IAAI,GAAG,IAAI;EACrB,CAAC,MAAM,IAAI,CAACH,KAAK,CAACG,IAAI,IAAIF,WAAW,CAACG,UAAU,CAACP,kBAAkB,CAAC,EAAE;IAClEG,KAAK,CAACG,IAAI,GAAG,IAAI;EACrB;AACJ,CAAC;AAEM,MAAME,aAAa,GAAIC,MAA2B,IAAsB;EAC3E,OAAO,CAACN,KAAK,EAAEO,OAAO,KAAK;IAAA;IACvB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,8DACtBH,MAAM;MACTI,OAAO;QACHC,MAAM,EAAE,iBAAAL,MAAM,CAACM,IAAI,iDAAX,aAAaC,KAAK,MAAK;MAAI,GAC/BP,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;IAC3B,GACH;IACF;AACR;AACA;IACQ,IAAAI,+BAAsB,EAACN,GAAG,CAACO,MAAM,CAAC;IAElC,IAAIP,GAAG,CAACO,MAAM,CAACC,OAAO,CAACC,MAAM,CAAcC,oBAAW,CAACC,IAAI,CAAC,CAACC,MAAM,KAAK,CAAC,EAAE;MACvE,MAAM,IAAIC,KAAK,CACV,iFAAgF,CACpF;IACL;IACAtB,wBAAwB,CAACC,KAAK,CAAC;IAE/B,MAAMsB,SAAS,GAAG,IAAAC,kBAAgB,EAACf,GAAG;MAClCgB,eAAe,EAAE,IAAI;MACrBC,wBAAwB,EAAE,IAAI;MAC9BC,sBAAsB,EAAE,WAAW;MACnCC,aAAa,EAAEC,QAAQ,IAAI;QACvB,OACI,CAAC,CAACA,QAAQ,CAACpC,OAAO,CAACqC,yBAAkB,CAACC,OAAO,CAAC,IAC9C,CAAC,CAACF,QAAQ,CAACpC,OAAO,CAACqC,yBAAkB,CAACE,MAAM,CAAC;MAErD;IAAC,GACGzB,MAAM,CAAC0B,aAAa,IAAI,CAAC,CAAC,EAChC;IACF,OAAOV,SAAS,CAACtB,KAAK,EAAEO,OAAO,CAAC;EACpC,CAAC;AACL,CAAC;AAAC"}
|
package/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export { createHandler as createDynamoDBHandler, CreateHandlerParams as CreateDy
|
|
|
4
4
|
export { createHandler as createSQSHandler, CreateHandlerParams as CreateSQSHandlerParams, SQSEventHandler, SQSEventHandlerCallable, SQSEventHandlerCallableParams, createEventHandler as createSQSEventHandler, HandlerCallable as SQSHandlerCallable } from "./sqs";
|
|
5
5
|
export { createHandler as createEventBridgeHandler, CreateHandlerParams as CreateEventBridgeHandlerParams, EventBridgeEventHandler, EventBridgeEventHandlerCallable, EventBridgeEventHandlerCallableParams, createEventHandler as createEventBridgeEventHandler, HandlerCallable as EventBridgeHandlerCallable } from "./eventBridge";
|
|
6
6
|
export { createHandler as createRawHandler, CreateHandlerParams as CreateRawHandlerParams, HandlerCallable as RawHandlerCallable, createEventHandler as createRawEventHandler, RawEventHandlerCallableParams, RawEventHandlerCallable, RawEventHandler } from "./raw";
|
|
7
|
+
export { ContextPlugin, createContextPlugin, ContextPluginCallable } from "@webiny/handler";
|
package/index.js
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "ContextPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _handler.ContextPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ContextPluginCallable", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _handler.ContextPluginCallable;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
6
18
|
Object.defineProperty(exports, "CreateApiGatewayHandlerParams", {
|
|
7
19
|
enumerable: true,
|
|
8
20
|
get: function () {
|
|
@@ -171,6 +183,12 @@ Object.defineProperty(exports, "createApiGatewayRoute", {
|
|
|
171
183
|
return _gateway.createRoute;
|
|
172
184
|
}
|
|
173
185
|
});
|
|
186
|
+
Object.defineProperty(exports, "createContextPlugin", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function () {
|
|
189
|
+
return _handler.createContextPlugin;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
174
192
|
Object.defineProperty(exports, "createDynamoDBEventHandler", {
|
|
175
193
|
enumerable: true,
|
|
176
194
|
get: function () {
|
|
@@ -231,15 +249,10 @@ Object.defineProperty(exports, "createSQSHandler", {
|
|
|
231
249
|
return _sqs.createHandler;
|
|
232
250
|
}
|
|
233
251
|
});
|
|
234
|
-
|
|
235
252
|
var _gateway = require("./gateway");
|
|
236
|
-
|
|
237
253
|
var _s = require("./s3");
|
|
238
|
-
|
|
239
254
|
var _dynamodb = require("./dynamodb");
|
|
240
|
-
|
|
241
255
|
var _sqs = require("./sqs");
|
|
242
|
-
|
|
243
256
|
var _eventBridge = require("./eventBridge");
|
|
244
|
-
|
|
245
|
-
var
|
|
257
|
+
var _raw = require("./raw");
|
|
258
|
+
var _handler = require("@webiny/handler");
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export {\n createHandler as createApiGatewayHandler,\n CreateHandlerParams as CreateApiGatewayHandlerParams,\n RoutePlugin,\n createRoute as createApiGatewayRoute\n} from \"~/gateway\";\n\nexport {\n createHandler as createS3Handler,\n CreateHandlerParams as CreateS3HandlerParams,\n S3EventHandler,\n S3EventHandlerCallable,\n S3EventHandlerCallableParams,\n createEventHandler as createS3EventHandler\n} from \"~/s3\";\n\nexport {\n createHandler as createDynamoDBHandler,\n CreateHandlerParams as CreateDynamoDBHandlerParams,\n DynamoDBEventHandler,\n DynamoDBEventHandlerCallable,\n DynamoDBEventHandlerCallableParams,\n createEventHandler as createDynamoDBEventHandler,\n HandlerCallable as DynamoDBHandlerCallable\n} from \"~/dynamodb\";\n\nexport {\n createHandler as createSQSHandler,\n CreateHandlerParams as CreateSQSHandlerParams,\n SQSEventHandler,\n SQSEventHandlerCallable,\n SQSEventHandlerCallableParams,\n createEventHandler as createSQSEventHandler,\n HandlerCallable as SQSHandlerCallable\n} from \"~/sqs\";\n\nexport {\n createHandler as createEventBridgeHandler,\n CreateHandlerParams as CreateEventBridgeHandlerParams,\n EventBridgeEventHandler,\n EventBridgeEventHandlerCallable,\n EventBridgeEventHandlerCallableParams,\n createEventHandler as createEventBridgeEventHandler,\n HandlerCallable as EventBridgeHandlerCallable\n} from \"~/eventBridge\";\n\nexport {\n createHandler as createRawHandler,\n CreateHandlerParams as CreateRawHandlerParams,\n HandlerCallable as RawHandlerCallable,\n createEventHandler as createRawEventHandler,\n RawEventHandlerCallableParams,\n RawEventHandlerCallable,\n RawEventHandler\n} from \"~/raw\";\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export {\n createHandler as createApiGatewayHandler,\n CreateHandlerParams as CreateApiGatewayHandlerParams,\n RoutePlugin,\n createRoute as createApiGatewayRoute\n} from \"~/gateway\";\n\nexport {\n createHandler as createS3Handler,\n CreateHandlerParams as CreateS3HandlerParams,\n S3EventHandler,\n S3EventHandlerCallable,\n S3EventHandlerCallableParams,\n createEventHandler as createS3EventHandler\n} from \"~/s3\";\n\nexport {\n createHandler as createDynamoDBHandler,\n CreateHandlerParams as CreateDynamoDBHandlerParams,\n DynamoDBEventHandler,\n DynamoDBEventHandlerCallable,\n DynamoDBEventHandlerCallableParams,\n createEventHandler as createDynamoDBEventHandler,\n HandlerCallable as DynamoDBHandlerCallable\n} from \"~/dynamodb\";\n\nexport {\n createHandler as createSQSHandler,\n CreateHandlerParams as CreateSQSHandlerParams,\n SQSEventHandler,\n SQSEventHandlerCallable,\n SQSEventHandlerCallableParams,\n createEventHandler as createSQSEventHandler,\n HandlerCallable as SQSHandlerCallable\n} from \"~/sqs\";\n\nexport {\n createHandler as createEventBridgeHandler,\n CreateHandlerParams as CreateEventBridgeHandlerParams,\n EventBridgeEventHandler,\n EventBridgeEventHandlerCallable,\n EventBridgeEventHandlerCallableParams,\n createEventHandler as createEventBridgeEventHandler,\n HandlerCallable as EventBridgeHandlerCallable\n} from \"~/eventBridge\";\n\nexport {\n createHandler as createRawHandler,\n CreateHandlerParams as CreateRawHandlerParams,\n HandlerCallable as RawHandlerCallable,\n createEventHandler as createRawEventHandler,\n RawEventHandlerCallableParams,\n RawEventHandlerCallable,\n RawEventHandler\n} from \"~/raw\";\n\nexport { ContextPlugin, createContextPlugin, ContextPluginCallable } from \"@webiny/handler\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAOA;AASA;AAUA;AAUA;AAUA;AAUA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-aws",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.35.0-beta.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@babel/runtime": "7.
|
|
15
|
+
"@babel/runtime": "7.20.13",
|
|
16
16
|
"@fastify/aws-lambda": "3.1.3",
|
|
17
|
-
"@webiny/handler": "5.
|
|
18
|
-
"@webiny/handler-client": "5.
|
|
19
|
-
"@webiny/plugins": "5.
|
|
17
|
+
"@webiny/handler": "5.35.0-beta.1",
|
|
18
|
+
"@webiny/handler-client": "5.35.0-beta.1",
|
|
19
|
+
"@webiny/plugins": "5.35.0-beta.1",
|
|
20
20
|
"aws-lambda": "1.0.7",
|
|
21
21
|
"fastify": "4.11.0"
|
|
22
22
|
},
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@babel/core": "^7.19.3",
|
|
26
26
|
"@babel/preset-env": "^7.19.4",
|
|
27
27
|
"@babel/preset-typescript": "^7.18.6",
|
|
28
|
-
"@webiny/cli": "^5.
|
|
29
|
-
"@webiny/project-utils": "^5.
|
|
28
|
+
"@webiny/cli": "^5.35.0-beta.1",
|
|
29
|
+
"@webiny/project-utils": "^5.35.0-beta.1",
|
|
30
30
|
"rimraf": "^3.0.2",
|
|
31
31
|
"ttypescript": "^1.5.13",
|
|
32
32
|
"typescript": "4.7.4"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"build": "yarn webiny run build",
|
|
40
40
|
"watch": "yarn webiny run watch"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "6b376faedf02e056efbbf1e4d46d537850773ce0"
|
|
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":["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":";;;;;;;AAAA;AACA;AAEO,MAAMA,yBAAyB,GAAG,MAAM;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,EAAE;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;AAAC"}
|
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":["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":";;;;;;AAAA;AAGO,MAAMA,sBAAsB,GAAIC,OAAgB,IAAW;EAC9DA,OAAO,CAACC,OAAO,CAACC,QAAQ,CAAC,CAAC,IAAAC,wCAAyB,GAAE,CAAC,CAAC;AAC3D,CAAC;AAAC"}
|
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,25 +22,20 @@ 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
39
|
const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
50
40
|
options: (0, _objectSpread2.default)({
|
|
51
41
|
logger: ((_params$http = params.http) === null || _params$http === void 0 ? void 0 : _params$http.debug) === true
|
|
@@ -54,19 +44,15 @@ const createHandler = params => {
|
|
|
54
44
|
/**
|
|
55
45
|
* We always must add our default plugins to the app.
|
|
56
46
|
*/
|
|
57
|
-
|
|
58
47
|
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
59
48
|
/**
|
|
60
49
|
* There must be an event plugin for this handler to work.
|
|
61
50
|
*/
|
|
62
|
-
|
|
63
51
|
const plugins = app.webiny.plugins.byType(_RawEventHandler.RawEventHandler.type);
|
|
64
52
|
const handler = plugins.shift();
|
|
65
|
-
|
|
66
53
|
if (!handler) {
|
|
67
54
|
throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);
|
|
68
55
|
}
|
|
69
|
-
|
|
70
56
|
app.post(url, async (request, reply) => {
|
|
71
57
|
const params = {
|
|
72
58
|
request,
|
|
@@ -76,11 +62,9 @@ const createHandler = params => {
|
|
|
76
62
|
lambdaContext: context
|
|
77
63
|
};
|
|
78
64
|
const result = await handler.cb(params);
|
|
79
|
-
|
|
80
65
|
if (result instanceof Reply) {
|
|
81
66
|
return result;
|
|
82
67
|
}
|
|
83
|
-
|
|
84
68
|
app.__webiny_raw_result = result;
|
|
85
69
|
return reply.send({});
|
|
86
70
|
});
|
|
@@ -91,5 +75,4 @@ const createHandler = params => {
|
|
|
91
75
|
});
|
|
92
76
|
};
|
|
93
77
|
};
|
|
94
|
-
|
|
95
78
|
exports.createHandler = createHandler;
|
package/raw/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","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":"
|
|
1
|
+
{"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","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;AAOA;AAmEA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAlEA;AACA;AAfA;AACA;AACA;AACA;AACA;AACA;;AAKA,MAAMA,KAAK,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAO1C,MAAMC,GAAG,GAAG,mBAAmB;AAYxB,MAAMC,aAAa,GACtBC,MAA2B,IACU;EACrC,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IAAA;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,8DACtBJ,MAAM;MACTK,OAAO;QACHC,MAAM,EAAE,iBAAAN,MAAM,CAACO,IAAI,iDAAX,aAAaC,KAAK,MAAK;MAAI,GAC/BR,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;IAC3B,GACH;IACF;AACR;AACA;IACQ,IAAAI,+BAAsB,EAACN,GAAG,CAACO,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGR,GAAG,CAACO,MAAM,CAACC,OAAO,CAACC,MAAM,CACrCC,gCAAe,CAACC,IAAI,CACvB;IACD,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAK,EAAE;IAC/B,IAAI,CAACD,OAAO,EAAE;MACV,MAAM,IAAIE,KAAK,CAAE,oEAAmE,CAAC;IACzF;IAEAd,GAAG,CAACe,IAAI,CAACpB,GAAG,EAAE,OAAOqB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMpB,MAAM,GAAG;QACXmB,OAAO;QACPC,KAAK;QACLlB,OAAO,EAAEC,GAAG,CAACO,MAAM;QACnBT,OAAO;QACPoB,aAAa,EAAEnB;MACnB,CAAC;MACD,MAAMoB,MAAM,GAAG,MAAMP,OAAO,CAACQ,EAAE,CAACvB,MAAM,CAAC;MAEvC,IAAIsB,MAAM,YAAY1B,KAAK,EAAE;QACzB,OAAO0B,MAAM;MACjB;MAECnB,GAAG,CAASqB,mBAAmB,GAAGF,MAAM;MACzC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXvB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -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":["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":";;;;;;AAEA;AAUO,MAAMA,eAAe,SAIlBC,oBAAW,CAAC;EACXC,WAAW,CAACC,EAAqD,EAAE;IACtE,KAAK,CAACA,EAAE,CAAQ;EACpB;AACJ;AAAC;AAEM,MAAMC,kBAAkB,GAK3BD,EAAqD,IACpD;EACD,OAAO,IAAIH,eAAe,CAA2BG,EAAE,CAAC;AAC5D,CAAC;AAAC"}
|
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,15 +22,10 @@ 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
31
|
const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
@@ -46,19 +36,15 @@ const createHandler = params => {
|
|
|
46
36
|
/**
|
|
47
37
|
* We always must add our default plugins to the app.
|
|
48
38
|
*/
|
|
49
|
-
|
|
50
39
|
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
51
40
|
/**
|
|
52
41
|
* There must be an event plugin for this handler to work.
|
|
53
42
|
*/
|
|
54
|
-
|
|
55
43
|
const plugins = app.webiny.plugins.byType(_S3EventHandler.S3EventHandler.type);
|
|
56
44
|
const handler = plugins.shift();
|
|
57
|
-
|
|
58
45
|
if (!handler) {
|
|
59
46
|
throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);
|
|
60
47
|
}
|
|
61
|
-
|
|
62
48
|
app.post(url, async (request, reply) => {
|
|
63
49
|
const params = {
|
|
64
50
|
request,
|
|
@@ -68,11 +54,9 @@ const createHandler = params => {
|
|
|
68
54
|
lambdaContext: context
|
|
69
55
|
};
|
|
70
56
|
const result = await handler.cb(params);
|
|
71
|
-
|
|
72
57
|
if (result instanceof Reply) {
|
|
73
58
|
return result;
|
|
74
59
|
}
|
|
75
|
-
|
|
76
60
|
app.__webiny_raw_result = result;
|
|
77
61
|
return reply.send({});
|
|
78
62
|
});
|
|
@@ -83,5 +67,4 @@ const createHandler = params => {
|
|
|
83
67
|
});
|
|
84
68
|
};
|
|
85
69
|
};
|
|
86
|
-
|
|
87
70
|
exports.createHandler = createHandler;
|
package/s3/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","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":"
|
|
1
|
+
{"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","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;AAMA;AA8DA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AA5DA;AACA;AALA,MAAMA,KAAK,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAO1C,MAAMC,GAAG,GAAG,kBAAkB;AAUvB,MAAMC,aAAa,GAAIC,MAA2B,IAAsB;EAC3E,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,8DACtBJ,MAAM;MACTK,OAAO;QACHC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK;MAAI,GACzBP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;IAC3B,GACH;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC;IAC9E,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAK,EAAE;IAC/B,IAAI,CAACD,OAAO,EAAE;MACV,MAAM,IAAIE,KAAK,CAAE,kEAAiE,CAAC;IACvF;IAEAb,GAAG,CAACc,IAAI,CAACnB,GAAG,EAAE,OAAOoB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMnB,MAAoC,GAAG;QACzCkB,OAAO;QACPC,KAAK;QACLjB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBW,KAAK,EAAEnB,OAAO;QACdoB,aAAa,EAAEnB;MACnB,CAAC;MACD,MAAMoB,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAE,CAACvB,MAAM,CAAC;MAEvC,IAAIsB,MAAM,YAAY1B,KAAK,EAAE;QACzB,OAAO0B,MAAM;MACjB;MAECnB,GAAG,CAASqB,mBAAmB,GAAGF,MAAM;MACzC,OAAOH,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXvB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -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":["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":";;;;;;;;AAAA;AAeO,MAAMA,cAAc,SAAyBC,cAAM,CAAC;EAKhDC,WAAW,CAACC,EAAoC,EAAE;IACrD,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAAC;AAAA,8BATYH,cAAc,UACO,qCAAqC;AAUhE,MAAMI,kBAAkB,GAAcD,EAAoC,IAAK;EAClF,OAAO,IAAIH,cAAc,CAAWG,EAAE,CAAC;AAC3C,CAAC;AAAC"}
|
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,15 +22,10 @@ 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
31
|
const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
@@ -46,19 +36,15 @@ const createHandler = params => {
|
|
|
46
36
|
/**
|
|
47
37
|
* We always must add our default plugins to the app.
|
|
48
38
|
*/
|
|
49
|
-
|
|
50
39
|
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
51
40
|
/**
|
|
52
41
|
* There must be an event plugin for this handler to work.
|
|
53
42
|
*/
|
|
54
|
-
|
|
55
43
|
const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type);
|
|
56
44
|
const handler = plugins.shift();
|
|
57
|
-
|
|
58
45
|
if (!handler) {
|
|
59
46
|
throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);
|
|
60
47
|
}
|
|
61
|
-
|
|
62
48
|
app.post(url, async (request, reply) => {
|
|
63
49
|
const params = {
|
|
64
50
|
request,
|
|
@@ -68,11 +54,9 @@ const createHandler = params => {
|
|
|
68
54
|
lambdaContext: context
|
|
69
55
|
};
|
|
70
56
|
const result = await handler.cb(params);
|
|
71
|
-
|
|
72
57
|
if (result instanceof Reply) {
|
|
73
58
|
return result;
|
|
74
59
|
}
|
|
75
|
-
|
|
76
60
|
app.__webiny_raw_result = result;
|
|
77
61
|
return reply.send({});
|
|
78
62
|
});
|
|
@@ -83,5 +67,4 @@ const createHandler = params => {
|
|
|
83
67
|
});
|
|
84
68
|
};
|
|
85
69
|
};
|
|
86
|
-
|
|
87
70
|
exports.createHandler = createHandler;
|
package/sqs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","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":"
|
|
1
|
+
{"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","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;AAMA;AA8DA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AA5DA;AACA;AALA,MAAMA,KAAK,GAAGC,OAAO,CAAC,mBAAmB,CAAC;AAO1C,MAAMC,GAAG,GAAG,mBAAmB;AAUxB,MAAMC,aAAa,GAAIC,MAA2B,IAAsB;EAC3E,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,8DACtBJ,MAAM;MACTK,OAAO;QACHC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK;MAAI,GACzBP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;IAC3B,GACH;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBC,gCAAe,CAACC,IAAI,CAAC;IAChF,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAK,EAAE;IAC/B,IAAI,CAACD,OAAO,EAAE;MACV,MAAM,IAAIE,KAAK,CAAE,oEAAmE,CAAC;IACzF;IAEAb,GAAG,CAACc,IAAI,CAACnB,GAAG,EAAE,OAAOoB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMnB,MAAqC,GAAG;QAC1CkB,OAAO;QACPC,KAAK;QACLjB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBW,KAAK,EAAEnB,OAAO;QACdoB,aAAa,EAAEnB;MACnB,CAAC;MACD,MAAMoB,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAE,CAACvB,MAAM,CAAC;MAEvC,IAAIsB,MAAM,YAAY1B,KAAK,EAAE;QACzB,OAAO0B,MAAM;MACjB;MAECnB,GAAG,CAASqB,mBAAmB,GAAGF,MAAM;MACzC,OAAOH,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXvB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -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":["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":";;;;;;;;AAAA;AAeO,MAAMA,eAAe,SAAyBC,cAAM,CAAC;EAKjDC,WAAW,CAACC,EAAqC,EAAE;IACtD,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAAC;AAAA,8BATYH,eAAe,UACM,sCAAsC;AAUjE,MAAMI,kBAAkB,GAAcD,EAAqC,IAAK;EACnF,OAAO,IAAIH,eAAe,CAAWG,EAAE,CAAC;AAC5C,CAAC;AAAC"}
|
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;
|
|
@@ -25,7 +22,6 @@ Object.keys(_types).forEach(function (key) {
|
|
|
25
22
|
});
|
|
26
23
|
let Base64EncodeHeader;
|
|
27
24
|
exports.Base64EncodeHeader = Base64EncodeHeader;
|
|
28
|
-
|
|
29
25
|
(function (Base64EncodeHeader) {
|
|
30
26
|
Base64EncodeHeader["encoded"] = "x-webiny-base64-encoded";
|
|
31
27
|
Base64EncodeHeader["binary"] = "x-webiny-binary";
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Base64EncodeHeader"],"sources":["types.ts"],"sourcesContent":["import { APIGatewayEvent, Context as LambdaContext } from \"aws-lambda\";\nimport \"fastify\";\nexport * from \"@webiny/handler/types\";\n\nexport enum Base64EncodeHeader {\n encoded = \"x-webiny-base64-encoded\",\n binary = \"x-webiny-binary\"\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n __webiny_raw_result: any;\n }\n interface FastifyRequest {\n awsLambda: {\n event: APIGatewayEvent;\n context: LambdaContext;\n };\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["Base64EncodeHeader"],"sources":["types.ts"],"sourcesContent":["import { APIGatewayEvent, Context as LambdaContext } from \"aws-lambda\";\nimport \"fastify\";\nexport * from \"@webiny/handler/types\";\n\nexport enum Base64EncodeHeader {\n encoded = \"x-webiny-base64-encoded\",\n binary = \"x-webiny-binary\"\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n __webiny_raw_result: any;\n }\n interface FastifyRequest {\n awsLambda: {\n event: APIGatewayEvent;\n context: LambdaContext;\n };\n }\n}\n"],"mappings":";;;;;;;;;AACA;AACA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAAsC,IAE1BA,kBAAkB;AAAA;AAAA,WAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;AAAA,GAAlBA,kBAAkB,kCAAlBA,kBAAkB"}
|