@webiny/handler-aws 0.0.0-unstable.df6d94b531 → 0.0.0-unstable.df7a8bb475
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -14
- package/createHandler.d.ts +2 -0
- package/createHandler.js +29 -0
- package/createHandler.js.map +1 -0
- package/dynamodb/index.d.ts +5 -8
- package/dynamodb/index.js +26 -56
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +8 -7
- package/dynamodb/plugins/DynamoDBEventHandler.js +5 -22
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.d.ts +1 -0
- package/dynamodb/register.js +26 -0
- package/dynamodb/register.js.map +1 -0
- package/eventBridge/index.d.ts +7 -10
- package/eventBridge/index.js +27 -57
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +8 -7
- package/eventBridge/plugins/EventBridgeEventHandler.js +5 -22
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +4 -0
- package/eventBridge/register.js +19 -0
- package/eventBridge/register.js.map +1 -0
- package/execute.d.ts +1 -1
- package/execute.js +18 -23
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +7 -11
- package/gateway/index.js +27 -57
- package/gateway/index.js.map +1 -1
- package/gateway/register.d.ts +1 -0
- package/gateway/register.js +19 -0
- package/gateway/register.js.map +1 -0
- package/index.d.ts +35 -6
- package/index.js +41 -238
- package/index.js.map +1 -1
- package/package.json +15 -22
- package/plugins/handlerClient.js +11 -27
- package/plugins/handlerClient.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +4 -12
- package/plugins/index.js.map +1 -1
- package/raw/index.d.ts +5 -10
- package/raw/index.js +32 -57
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +17 -6
- package/raw/plugins/RawEventHandler.js +21 -18
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +17 -0
- package/registry.js +38 -0
- package/registry.js.map +1 -0
- package/s3/index.d.ts +6 -9
- package/s3/index.js +29 -59
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +8 -7
- package/s3/plugins/S3EventHandler.js +5 -22
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +4 -0
- package/s3/register.js +23 -0
- package/s3/register.js.map +1 -0
- package/sns/index.d.ts +8 -0
- package/sns/index.js +57 -0
- package/sns/index.js.map +1 -0
- package/sns/plugins/SNSEventHandler.d.ts +20 -0
- package/sns/plugins/SNSEventHandler.js +13 -0
- package/sns/plugins/SNSEventHandler.js.map +1 -0
- package/sns/register.d.ts +1 -0
- package/sns/register.js +23 -0
- package/sns/register.js.map +1 -0
- package/sourceHandler.d.ts +2 -0
- package/sourceHandler.js +5 -0
- package/sourceHandler.js.map +1 -0
- package/sqs/index.d.ts +6 -9
- package/sqs/index.js +33 -60
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +8 -7
- package/sqs/plugins/SQSEventHandler.js +5 -22
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.d.ts +1 -0
- package/sqs/register.js +26 -0
- package/sqs/register.js.map +1 -0
- package/types.d.ts +28 -5
- package/types.js +7 -30
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +6 -0
- package/utils/composedHandler.js +17 -0
- package/utils/composedHandler.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +4 -0
- package/utils/index.js.map +1 -0
- package/utils/timer/CustomTimer.d.ts +5 -0
- package/utils/timer/CustomTimer.js +12 -0
- package/utils/timer/CustomTimer.js.map +1 -0
- package/utils/timer/Timer.d.ts +10 -0
- package/utils/timer/Timer.js +17 -0
- package/utils/timer/Timer.js.map +1 -0
- package/utils/timer/abstractions/ITimer.d.ts +10 -0
- package/utils/timer/abstractions/ITimer.js +3 -0
- package/utils/timer/abstractions/ITimer.js.map +1 -0
- package/utils/timer/factory.d.ts +4 -0
- package/utils/timer/factory.js +13 -0
- package/utils/timer/factory.js.map +1 -0
- package/utils/timer/index.d.ts +4 -0
- package/utils/timer/index.js +5 -0
- package/utils/timer/index.js.map +1 -0
package/README.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
# @webiny/handler-aws
|
|
2
|
-
|
|
3
|
-
[!
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Or if you prefer yarn:
|
|
13
|
-
```
|
|
14
|
-
yarn add @webiny/handler-aws
|
|
15
|
-
```
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
package/createHandler.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AsyncPluginsContainer } from "@webiny/plugins";
|
|
2
|
+
import { registry } from "./registry.js";
|
|
3
|
+
|
|
4
|
+
// TODO: Once we have a better infrastructure for handling such cases, we should refactor this.
|
|
5
|
+
// Ideally, the DI container should already be ready to be used in these `handler` packages.
|
|
6
|
+
// At the moment, that is not the case, so we have to hardcode `pino-lambda` here.
|
|
7
|
+
import { lambdaRequestTracker } from "pino-lambda";
|
|
8
|
+
const withRequest = lambdaRequestTracker();
|
|
9
|
+
export const createHandler = ({
|
|
10
|
+
plugins,
|
|
11
|
+
...params
|
|
12
|
+
}) => {
|
|
13
|
+
const pluginsContainer = new AsyncPluginsContainer(plugins);
|
|
14
|
+
return async (event, context = {}) => {
|
|
15
|
+
withRequest(event, context);
|
|
16
|
+
const plugins = await pluginsContainer.init();
|
|
17
|
+
const handler = registry.getHandler(event, context);
|
|
18
|
+
return handler.handle({
|
|
19
|
+
params: {
|
|
20
|
+
...params,
|
|
21
|
+
plugins
|
|
22
|
+
},
|
|
23
|
+
event,
|
|
24
|
+
context
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=createHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["AsyncPluginsContainer","registry","lambdaRequestTracker","withRequest","createHandler","plugins","params","pluginsContainer","event","context","init","handler","getHandler","handle"],"sources":["createHandler.ts"],"sourcesContent":["import { AsyncPluginsContainer } from \"@webiny/plugins\";\nimport type { HandlerFactory, LambdaContext } from \"~/types.js\";\nimport { registry } from \"./registry.js\";\n\n// TODO: Once we have a better infrastructure for handling such cases, we should refactor this.\n// Ideally, the DI container should already be ready to be used in these `handler` packages.\n// At the moment, that is not the case, so we have to hardcode `pino-lambda` here.\nimport { lambdaRequestTracker } from \"pino-lambda\";\n\nconst withRequest = lambdaRequestTracker();\n\nexport const createHandler: HandlerFactory = ({ plugins, ...params }) => {\n const pluginsContainer = new AsyncPluginsContainer(plugins);\n\n return async (event, context = {} as LambdaContext) => {\n withRequest(event, context);\n\n const plugins = await pluginsContainer.init();\n const handler = registry.getHandler(event, context);\n return handler.handle({\n params: {\n ...params,\n plugins\n },\n event,\n context\n });\n };\n};\n"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,iBAAiB;AAEvD,SAASC,QAAQ;;AAEjB;AACA;AACA;AACA,SAASC,oBAAoB,QAAQ,aAAa;AAElD,MAAMC,WAAW,GAAGD,oBAAoB,CAAC,CAAC;AAE1C,OAAO,MAAME,aAA6B,GAAGA,CAAC;EAAEC,OAAO;EAAE,GAAGC;AAAO,CAAC,KAAK;EACrE,MAAMC,gBAAgB,GAAG,IAAIP,qBAAqB,CAACK,OAAO,CAAC;EAE3D,OAAO,OAAOG,KAAK,EAAEC,OAAO,GAAG,CAAC,CAAkB,KAAK;IACnDN,WAAW,CAACK,KAAK,EAAEC,OAAO,CAAC;IAE3B,MAAMJ,OAAO,GAAG,MAAME,gBAAgB,CAACG,IAAI,CAAC,CAAC;IAC7C,MAAMC,OAAO,GAAGV,QAAQ,CAACW,UAAU,CAACJ,KAAK,EAAEC,OAAO,CAAC;IACnD,OAAOE,OAAO,CAACE,MAAM,CAAC;MAClBP,MAAM,EAAE;QACJ,GAAGA,MAAM;QACTD;MACJ,CAAC;MACDG,KAAK;MACLC;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
|
package/dynamodb/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { APIGatewayProxyResult, Context as LambdaContext, DynamoDBStreamEvent } from "@webiny/aws-sdk/types/index.js";
|
|
2
|
+
import type { HandlerFactoryParams } from "../types.js";
|
|
3
|
+
export * from "./plugins/DynamoDBEventHandler.js";
|
|
4
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
4
5
|
export interface HandlerCallable {
|
|
5
6
|
(event: DynamoDBStreamEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
6
7
|
}
|
|
7
|
-
export
|
|
8
|
-
debug?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare const createHandler: (params: CreateHandlerParams) => HandlerCallable;
|
|
11
|
-
export * from "./plugins/DynamoDBEventHandler";
|
|
8
|
+
export declare const createHandler: (params: HandlerParams) => HandlerCallable;
|
package/dynamodb/index.js
CHANGED
|
@@ -1,64 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
|
-
|
|
15
|
-
var _handler = require("@webiny/handler");
|
|
16
|
-
|
|
17
|
-
var _DynamoDBEventHandler = require("./plugins/DynamoDBEventHandler");
|
|
18
|
-
|
|
19
|
-
Object.keys(_DynamoDBEventHandler).forEach(function (key) {
|
|
20
|
-
if (key === "default" || key === "__esModule") return;
|
|
21
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
22
|
-
if (key in exports && exports[key] === _DynamoDBEventHandler[key]) return;
|
|
23
|
-
Object.defineProperty(exports, key, {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function () {
|
|
26
|
-
return _DynamoDBEventHandler[key];
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
var _plugins = require("../plugins");
|
|
32
|
-
|
|
33
|
-
var _execute = require("../execute");
|
|
34
|
-
|
|
35
|
-
const Reply = require("fastify/lib/reply");
|
|
36
|
-
|
|
1
|
+
import { createHandler as createBaseHandler } from "@webiny/handler";
|
|
2
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
|
+
import { DynamoDBEventHandler } from "./plugins/DynamoDBEventHandler.js";
|
|
4
|
+
/**
|
|
5
|
+
* We need a class, not an interface exported from types.
|
|
6
|
+
*/
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
import Reply from "fastify/lib/reply.js";
|
|
9
|
+
import { execute } from "../execute.js";
|
|
10
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
11
|
+
export * from "./plugins/DynamoDBEventHandler.js";
|
|
37
12
|
const url = "/webiny-dynamodb-event";
|
|
38
|
-
|
|
39
|
-
const createHandler = params => {
|
|
13
|
+
export const createHandler = params => {
|
|
40
14
|
return (payload, context) => {
|
|
41
|
-
const app = (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
const app = createBaseHandler({
|
|
16
|
+
...params,
|
|
17
|
+
options: {
|
|
18
|
+
logger: params.debug === true,
|
|
19
|
+
...(params.options || {})
|
|
20
|
+
}
|
|
21
|
+
});
|
|
46
22
|
/**
|
|
47
23
|
* We always must add our default plugins to the app.
|
|
48
24
|
*/
|
|
49
|
-
|
|
50
|
-
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
25
|
+
registerDefaultPlugins(app.webiny);
|
|
51
26
|
/**
|
|
52
27
|
* There must be an event plugin for this handler to work.
|
|
53
28
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const handler = plugins.shift();
|
|
57
|
-
|
|
58
|
-
if (!handler) {
|
|
29
|
+
const plugins = app.webiny.plugins.byType(DynamoDBEventHandler.type).reverse();
|
|
30
|
+
if (plugins.length === 0) {
|
|
59
31
|
throw new Error(`To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.`);
|
|
60
32
|
}
|
|
61
|
-
|
|
33
|
+
const handler = createComposedHandler(plugins);
|
|
62
34
|
app.post(url, async (request, reply) => {
|
|
63
35
|
const params = {
|
|
64
36
|
request,
|
|
@@ -67,16 +39,14 @@ const createHandler = params => {
|
|
|
67
39
|
lambdaContext: context,
|
|
68
40
|
reply
|
|
69
41
|
};
|
|
70
|
-
const result = await handler
|
|
71
|
-
|
|
42
|
+
const result = await handler(params);
|
|
72
43
|
if (result instanceof Reply) {
|
|
73
44
|
return result;
|
|
74
45
|
}
|
|
75
|
-
|
|
76
46
|
app.__webiny_raw_result = result;
|
|
77
47
|
return reply.send({});
|
|
78
48
|
});
|
|
79
|
-
return
|
|
49
|
+
return execute({
|
|
80
50
|
app,
|
|
81
51
|
url,
|
|
82
52
|
payload
|
|
@@ -84,4 +54,4 @@ const createHandler = params => {
|
|
|
84
54
|
};
|
|
85
55
|
};
|
|
86
56
|
|
|
87
|
-
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
package/dynamodb/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Reply","
|
|
1
|
+
{"version":3,"names":["createHandler","createBaseHandler","registerDefaultPlugins","DynamoDBEventHandler","Reply","execute","createComposedHandler","url","params","payload","context","app","options","logger","debug","webiny","plugins","byType","type","reverse","length","Error","handler","post","request","reply","event","lambdaContext","result","__webiny_raw_result","send"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n DynamoDBStreamEvent\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { DynamoDBEventHandlerCallableParams } from \"./plugins/DynamoDBEventHandler.js\";\nimport { DynamoDBEventHandler } from \"./plugins/DynamoDBEventHandler.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { execute } from \"~/execute.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/DynamoDBEventHandler.js\";\n\nconst url = \"/webiny-dynamodb-event\";\n\nexport type HandlerParams = HandlerFactoryParams;\n\nexport interface HandlerCallable {\n (event: DynamoDBStreamEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport const createHandler = (params: HandlerParams): 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\n .byType<DynamoDBEventHandler>(DynamoDBEventHandler.type)\n .reverse();\n if (plugins.length === 0) {\n throw new Error(\n `To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.`\n );\n }\n\n const handler = createComposedHandler<\n DynamoDBEventHandler,\n DynamoDBEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<\n DynamoDBEventHandlerCallableParams<APIGatewayProxyResult>,\n \"next\"\n > = {\n request,\n context: app.webiny,\n event: payload,\n lambdaContext: context,\n reply\n };\n const result = await handler(\n params as unknown as DynamoDBEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload\n });\n };\n};\n"],"mappings":"AAMA,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,sBAAsB;AAE/B,SAASC,oBAAoB;AAC7B;AACA;AACA;AACA;AACA,OAAOC,KAAK,MAAM,sBAAsB;AACxC,SAASC,OAAO;AAChB,SAASC,qBAAqB;AAE9B;AAEA,MAAMC,GAAG,GAAG,wBAAwB;AAQpC,OAAO,MAAMP,aAAa,GAAIQ,MAAqB,IAAsB;EACrE,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQV,sBAAsB,CAACS,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAC7BC,MAAM,CAAuBd,oBAAoB,CAACe,IAAI,CAAC,CACvDC,OAAO,CAAC,CAAC;IACd,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CACX,yEACJ,CAAC;IACL;IAEA,MAAMC,OAAO,GAAGhB,qBAAqB,CAInCU,OAAO,CAAC;IAEVL,GAAG,CAACY,IAAI,CAAChB,GAAG,EAAE,OAAOiB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMjB,MAGL,GAAG;QACAgB,OAAO;QACPd,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBW,KAAK,EAAEjB,OAAO;QACdkB,aAAa,EAAEjB,OAAO;QACtBe;MACJ,CAAC;MACD,MAAMG,MAAM,GAAG,MAAMN,OAAO,CACxBd,MACJ,CAAC;MAED,IAAIoB,MAAM,YAAYxB,KAAK,EAAE;QACzB,OAAOwB,MAAM;MACjB;MAEAjB,GAAG,CAACkB,mBAAmB,GAAGD,MAAM;MAChC,OAAOH,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAOzB,OAAO,CAAC;MACXM,GAAG;MACHJ,GAAG;MACHE;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export interface DynamoDBEventHandlerCallableParams {
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
import type { Context, Reply, Request } from "@webiny/handler/types.js";
|
|
3
|
+
import type { Context as LambdaContext, DynamoDBStreamEvent } from "@webiny/aws-sdk/types/index.js";
|
|
4
|
+
export interface DynamoDBEventHandlerCallableParams<Response = Reply> {
|
|
5
5
|
request: Request;
|
|
6
6
|
context: Context;
|
|
7
7
|
event: DynamoDBStreamEvent;
|
|
8
8
|
lambdaContext: LambdaContext;
|
|
9
9
|
reply: Reply;
|
|
10
|
+
next: () => Promise<Response>;
|
|
10
11
|
}
|
|
11
|
-
export interface DynamoDBEventHandlerCallable<Response> {
|
|
12
|
-
(params: DynamoDBEventHandlerCallableParams): Promise<Response
|
|
12
|
+
export interface DynamoDBEventHandlerCallable<Response = Reply> {
|
|
13
|
+
(params: DynamoDBEventHandlerCallableParams<Response>): Promise<Response>;
|
|
13
14
|
}
|
|
14
15
|
export declare class DynamoDBEventHandler<Response = any> extends Plugin {
|
|
15
16
|
static type: string;
|
|
16
17
|
readonly cb: DynamoDBEventHandlerCallable<Response>;
|
|
17
18
|
constructor(cb: DynamoDBEventHandlerCallable<Response>);
|
|
18
19
|
}
|
|
19
|
-
export declare const createEventHandler: <
|
|
20
|
+
export declare const createEventHandler: <Response>(cb: DynamoDBEventHandlerCallable<Response>) => DynamoDBEventHandler<Response>;
|
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.createEventHandler = exports.DynamoDBEventHandler = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _Plugin = require("@webiny/plugins/Plugin");
|
|
13
|
-
|
|
14
|
-
class DynamoDBEventHandler extends _Plugin.Plugin {
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
export class DynamoDBEventHandler extends Plugin {
|
|
3
|
+
static type = "handler.fastify.aws.dynamodb.eventHandler";
|
|
15
4
|
constructor(cb) {
|
|
16
5
|
super();
|
|
17
|
-
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
6
|
this.cb = cb;
|
|
19
7
|
}
|
|
20
|
-
|
|
21
8
|
}
|
|
22
|
-
|
|
23
|
-
exports.DynamoDBEventHandler = DynamoDBEventHandler;
|
|
24
|
-
(0, _defineProperty2.default)(DynamoDBEventHandler, "type", "handler.fastify.aws.dynamodb.eventHandler");
|
|
25
|
-
|
|
26
|
-
const createEventHandler = cb => {
|
|
9
|
+
export const createEventHandler = cb => {
|
|
27
10
|
return new DynamoDBEventHandler(cb);
|
|
28
11
|
};
|
|
29
12
|
|
|
30
|
-
|
|
13
|
+
//# sourceMappingURL=DynamoDBEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DynamoDBEventHandler","
|
|
1
|
+
{"version":3,"names":["Plugin","DynamoDBEventHandler","type","constructor","cb","createEventHandler"],"sources":["DynamoDBEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\nimport type { Context as LambdaContext, DynamoDBStreamEvent } from \"@webiny/aws-sdk/types/index.js\";\n\nexport interface DynamoDBEventHandlerCallableParams<Response = Reply> {\n request: Request;\n context: Context;\n event: DynamoDBStreamEvent;\n lambdaContext: LambdaContext;\n reply: Reply;\n next: () => Promise<Response>;\n}\n\nexport interface DynamoDBEventHandlerCallable<Response = Reply> {\n (params: DynamoDBEventHandlerCallableParams<Response>): Promise<Response>;\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,SAASA,MAAM,QAAQ,2BAA2B;AAiBlD,OAAO,MAAMC,oBAAoB,SAAyBD,MAAM,CAAC;EAC7D,OAAuBE,IAAI,GAAG,2CAA2C;EAIlEC,WAAWA,CAACC,EAA0C,EAAE;IAC3D,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAcD,EAA0C,IAAK;EACxF,OAAO,IAAIH,oBAAoB,CAAWG,EAAE,CAAC;AACjD,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { registry } from "../registry.js";
|
|
2
|
+
import { createSourceHandler } from "../sourceHandler.js";
|
|
3
|
+
import { createHandler } from "./index.js";
|
|
4
|
+
const handler = createSourceHandler({
|
|
5
|
+
name: "handler-aws-dynamodb-stream",
|
|
6
|
+
canUse: event => {
|
|
7
|
+
if (!Array.isArray(event.Records) || event.Records.length === 0) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const [record] = event.Records;
|
|
11
|
+
if (typeof record.eventSource !== "string") {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return record.eventSource.toLowerCase() === "aws:dynamodb";
|
|
15
|
+
},
|
|
16
|
+
handle: async ({
|
|
17
|
+
params,
|
|
18
|
+
event,
|
|
19
|
+
context
|
|
20
|
+
}) => {
|
|
21
|
+
return createHandler(params)(event, context);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
registry.register(handler);
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["registry","createSourceHandler","createHandler","handler","name","canUse","event","Array","isArray","Records","length","record","eventSource","toLowerCase","handle","params","context","register"],"sources":["register.ts"],"sourcesContent":["import { registry } from \"~/registry.js\";\nimport type { DynamoDBStreamEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\nimport type { HandlerParams } from \"~/dynamodb/index.js\";\nimport { createHandler } from \"~/dynamodb/index.js\";\n\nconst handler = createSourceHandler<DynamoDBStreamEvent, HandlerParams>({\n name: \"handler-aws-dynamodb-stream\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n if (typeof record.eventSource !== \"string\") {\n return false;\n }\n return record.eventSource.toLowerCase() === \"aws:dynamodb\";\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":"AAAA,SAASA,QAAQ;AAEjB,SAASC,mBAAmB;AAE5B,SAASC,aAAa;AAEtB,MAAMC,OAAO,GAAGF,mBAAmB,CAAqC;EACpEG,IAAI,EAAE,6BAA6B;EACnCC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,IAAI,OAAOE,MAAM,CAACC,WAAW,KAAK,QAAQ,EAAE;MACxC,OAAO,KAAK;IAChB;IACA,OAAOD,MAAM,CAACC,WAAW,CAACC,WAAW,CAAC,CAAC,KAAK,cAAc;EAC9D,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAET,KAAK;IAAEU;EAAQ,CAAC,KAAK;IAC1C,OAAOd,aAAa,CAACa,MAAM,CAAC,CAACT,KAAK,EAAEU,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFhB,QAAQ,CAACiB,QAAQ,CAACd,OAAO,CAAC","ignoreList":[]}
|
package/eventBridge/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
1
|
+
import type { HandlerFactoryParams } from "../types.js";
|
|
2
|
+
import type { APIGatewayProxyResult, Context as LambdaContext, EventBridgeEvent } from "@webiny/aws-sdk/types/index.js";
|
|
3
|
+
export * from "./plugins/EventBridgeEventHandler.js";
|
|
4
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
5
|
+
export interface HandlerCallable {
|
|
6
|
+
(event: EventBridgeEvent<string, string>, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
6
7
|
}
|
|
7
|
-
export
|
|
8
|
-
debug?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare const createHandler: <DetailType extends string, Detail>(params: CreateHandlerParams) => HandlerCallable<DetailType, Detail>;
|
|
11
|
-
export * from "./plugins/EventBridgeEventHandler";
|
|
8
|
+
export declare const createHandler: (params: HandlerParams) => HandlerCallable;
|
package/eventBridge/index.js
CHANGED
|
@@ -1,64 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _handler = require("@webiny/handler");
|
|
16
|
-
|
|
17
|
-
var _EventBridgeEventHandler = require("./plugins/EventBridgeEventHandler");
|
|
18
|
-
|
|
19
|
-
Object.keys(_EventBridgeEventHandler).forEach(function (key) {
|
|
20
|
-
if (key === "default" || key === "__esModule") return;
|
|
21
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
22
|
-
if (key in exports && exports[key] === _EventBridgeEventHandler[key]) return;
|
|
23
|
-
Object.defineProperty(exports, key, {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function () {
|
|
26
|
-
return _EventBridgeEventHandler[key];
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
var _plugins = require("../plugins");
|
|
32
|
-
|
|
33
|
-
var _execute = require("../execute");
|
|
34
|
-
|
|
35
|
-
const Reply = require("fastify/lib/reply");
|
|
36
|
-
|
|
37
|
-
const url = "/webiny-sqs-event";
|
|
38
|
-
|
|
39
|
-
const createHandler = params => {
|
|
1
|
+
import { createHandler as createBaseHandler } from "@webiny/handler";
|
|
2
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
|
+
import { EventBridgeEventHandler } from "./plugins/EventBridgeEventHandler.js";
|
|
4
|
+
import { execute } from "../execute.js";
|
|
5
|
+
/**
|
|
6
|
+
* We need a class, not an interface exported from types.
|
|
7
|
+
*/
|
|
8
|
+
// @ts-expect-error
|
|
9
|
+
import Reply from "fastify/lib/reply.js";
|
|
10
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
11
|
+
export * from "./plugins/EventBridgeEventHandler.js";
|
|
12
|
+
const url = "/webiny-eventBridge-event";
|
|
13
|
+
export const createHandler = params => {
|
|
40
14
|
return (payload, context) => {
|
|
41
|
-
const app = (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
const app = createBaseHandler({
|
|
16
|
+
...params,
|
|
17
|
+
options: {
|
|
18
|
+
logger: params.debug === true,
|
|
19
|
+
...(params.options || {})
|
|
20
|
+
}
|
|
21
|
+
});
|
|
46
22
|
/**
|
|
47
23
|
* We always must add our default plugins to the app.
|
|
48
24
|
*/
|
|
49
|
-
|
|
50
|
-
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
25
|
+
registerDefaultPlugins(app.webiny);
|
|
51
26
|
/**
|
|
52
27
|
* There must be an event plugin for this handler to work.
|
|
53
28
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const handler = plugins.shift();
|
|
57
|
-
|
|
58
|
-
if (!handler) {
|
|
29
|
+
const plugins = app.webiny.plugins.byType(EventBridgeEventHandler.type).reverse();
|
|
30
|
+
if (plugins.length === 0) {
|
|
59
31
|
throw new Error(`To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.`);
|
|
60
32
|
}
|
|
61
|
-
|
|
33
|
+
const handler = createComposedHandler(plugins);
|
|
62
34
|
app.post(url, async (request, reply) => {
|
|
63
35
|
const params = {
|
|
64
36
|
request,
|
|
@@ -67,16 +39,14 @@ const createHandler = params => {
|
|
|
67
39
|
payload,
|
|
68
40
|
lambdaContext: context
|
|
69
41
|
};
|
|
70
|
-
const result = await handler
|
|
71
|
-
|
|
42
|
+
const result = await handler(params);
|
|
72
43
|
if (result instanceof Reply) {
|
|
73
44
|
return result;
|
|
74
45
|
}
|
|
75
|
-
|
|
76
46
|
app.__webiny_raw_result = result;
|
|
77
47
|
return reply.send({});
|
|
78
48
|
});
|
|
79
|
-
return
|
|
49
|
+
return execute({
|
|
80
50
|
app,
|
|
81
51
|
url,
|
|
82
52
|
payload
|
|
@@ -84,4 +54,4 @@ const createHandler = params => {
|
|
|
84
54
|
};
|
|
85
55
|
};
|
|
86
56
|
|
|
87
|
-
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
package/eventBridge/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createHandler","createBaseHandler","registerDefaultPlugins","EventBridgeEventHandler","execute","Reply","createComposedHandler","url","params","payload","context","app","options","logger","debug","webiny","plugins","byType","type","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","send"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { EventBridgeEventHandlerCallableParams } from \"~/eventBridge/plugins/EventBridgeEventHandler.js\";\nimport { EventBridgeEventHandler } from \"~/eventBridge/plugins/EventBridgeEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n EventBridgeEvent\n} from \"@webiny/aws-sdk/types/index.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/EventBridgeEventHandler.js\";\n\nexport type HandlerParams = HandlerFactoryParams;\n\nexport interface HandlerCallable {\n (\n event: EventBridgeEvent<string, string>,\n context: LambdaContext\n ): Promise<APIGatewayProxyResult>;\n}\n\nconst url = \"/webiny-eventBridge-event\";\n\nexport const createHandler = (params: HandlerParams): 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\n .byType<EventBridgeEventHandler<string, string>>(EventBridgeEventHandler.type)\n .reverse();\n if (plugins.length === 0) {\n throw new Error(\n `To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.`\n );\n }\n\n const handler = createComposedHandler<\n EventBridgeEventHandler<string, string>,\n EventBridgeEventHandlerCallableParams<string, string, APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<\n EventBridgeEventHandlerCallableParams<string, string, APIGatewayProxyResult>,\n \"next\"\n > = {\n request,\n reply,\n context: app.webiny,\n payload,\n lambdaContext: context\n };\n const result = await handler(\n params as unknown as EventBridgeEventHandlerCallableParams<\n string,\n string,\n APIGatewayProxyResult\n >\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload\n });\n };\n};\n"],"mappings":"AAAA,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,sBAAsB;AAE/B,SAASC,uBAAuB;AAChC,SAASC,OAAO;AAOhB;AACA;AACA;AACA;AACA,OAAOC,KAAK,MAAM,sBAAsB;AACxC,SAASC,qBAAqB;AAE9B;AAWA,MAAMC,GAAG,GAAG,2BAA2B;AAEvC,OAAO,MAAMP,aAAa,GAAIQ,MAAqB,IAAsB;EACrE,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQV,sBAAsB,CAACS,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAC7BC,MAAM,CAA0Cd,uBAAuB,CAACe,IAAI,CAAC,CAC7EC,OAAO,CAAC,CAAC;IACd,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CACX,oFACJ,CAAC;IACL;IAEA,MAAMC,OAAO,GAAGhB,qBAAqB,CAInCU,OAAO,CAAC;IAEVL,GAAG,CAACY,IAAI,CAAChB,GAAG,EAAE,OAAOiB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMjB,MAGL,GAAG;QACAgB,OAAO;QACPC,KAAK;QACLf,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,OAAO;QACPiB,aAAa,EAAEhB;MACnB,CAAC;MACD,MAAMiB,MAAM,GAAG,MAAML,OAAO,CACxBd,MAKJ,CAAC;MAED,IAAImB,MAAM,YAAYtB,KAAK,EAAE;QACzB,OAAOsB,MAAM;MACjB;MAEAhB,GAAG,CAACiB,mBAAmB,GAAGD,MAAM;MAChC,OAAOF,KAAK,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAOzB,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHE;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export interface EventBridgeEventHandlerCallableParams<DetailType extends string, Detail> {
|
|
1
|
+
import type { Context as LambdaContext, EventBridgeEvent } from "@webiny/aws-sdk/types/index.js";
|
|
2
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
3
|
+
import type { Context, Reply, Request } from "@webiny/handler/types.js";
|
|
4
|
+
export interface EventBridgeEventHandlerCallableParams<DetailType extends string, Detail, Response = Reply> {
|
|
5
5
|
request: Request;
|
|
6
6
|
reply: Reply;
|
|
7
7
|
context: Context;
|
|
8
8
|
payload: EventBridgeEvent<DetailType, Detail>;
|
|
9
9
|
lambdaContext: LambdaContext;
|
|
10
|
+
next: () => Promise<Response>;
|
|
10
11
|
}
|
|
11
|
-
export interface EventBridgeEventHandlerCallable<DetailType extends string, Detail, Response> {
|
|
12
|
-
(params: EventBridgeEventHandlerCallableParams<DetailType, Detail>): Promise<Response
|
|
12
|
+
export interface EventBridgeEventHandlerCallable<DetailType extends string, Detail, Response = Reply> {
|
|
13
|
+
(params: EventBridgeEventHandlerCallableParams<DetailType, Detail, Response>): Promise<Response>;
|
|
13
14
|
}
|
|
14
15
|
export declare class EventBridgeEventHandler<DetailType extends string, Detail, Response = any> extends Plugin {
|
|
15
16
|
static type: string;
|
|
16
17
|
readonly cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>;
|
|
17
18
|
constructor(cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>);
|
|
18
19
|
}
|
|
19
|
-
export declare const createEventHandler: <DetailType extends string, Detail,
|
|
20
|
+
export declare const createEventHandler: <DetailType extends string, Detail, Response = any>(cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>) => EventBridgeEventHandler<DetailType, Detail, Response>;
|
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.createEventHandler = exports.EventBridgeEventHandler = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _Plugin = require("@webiny/plugins/Plugin");
|
|
13
|
-
|
|
14
|
-
class EventBridgeEventHandler extends _Plugin.Plugin {
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
export class EventBridgeEventHandler extends Plugin {
|
|
3
|
+
static type = "handler.fastify.aws.eventBridge.eventHandler";
|
|
15
4
|
constructor(cb) {
|
|
16
5
|
super();
|
|
17
|
-
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
6
|
this.cb = cb;
|
|
19
7
|
}
|
|
20
|
-
|
|
21
8
|
}
|
|
22
|
-
|
|
23
|
-
exports.EventBridgeEventHandler = EventBridgeEventHandler;
|
|
24
|
-
(0, _defineProperty2.default)(EventBridgeEventHandler, "type", "handler.fastify.aws.sqs.eventHandler");
|
|
25
|
-
|
|
26
|
-
const createEventHandler = cb => {
|
|
9
|
+
export const createEventHandler = cb => {
|
|
27
10
|
return new EventBridgeEventHandler(cb);
|
|
28
11
|
};
|
|
29
12
|
|
|
30
|
-
|
|
13
|
+
//# sourceMappingURL=EventBridgeEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["EventBridgeEventHandler","
|
|
1
|
+
{"version":3,"names":["Plugin","EventBridgeEventHandler","type","constructor","cb","createEventHandler"],"sources":["EventBridgeEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, EventBridgeEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface EventBridgeEventHandlerCallableParams<\n DetailType extends string,\n Detail,\n Response = Reply\n> {\n request: Request;\n reply: Reply;\n context: Context;\n payload: EventBridgeEvent<DetailType, Detail>;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\nexport interface EventBridgeEventHandlerCallable<\n DetailType extends string,\n Detail,\n Response = Reply\n> {\n (\n params: EventBridgeEventHandlerCallableParams<DetailType, Detail, Response>\n ): Promise<Response>;\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.eventBridge.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":"AACA,SAASA,MAAM,QAAQ,2BAA2B;AAyBlD,OAAO,MAAMC,uBAAuB,SAI1BD,MAAM,CAAC;EACb,OAAuBE,IAAI,GAAG,8CAA8C;EAIrEC,WAAWA,CAACC,EAAiE,EAAE;IAClF,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAC3BD,EAAiE,IAChE;EACD,OAAO,IAAIH,uBAAuB,CAA+BG,EAAE,CAAC;AACxE,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { registry } from "../registry.js";
|
|
2
|
+
import { createSourceHandler } from "../sourceHandler.js";
|
|
3
|
+
import { createHandler } from "./index.js";
|
|
4
|
+
const handler = createSourceHandler({
|
|
5
|
+
name: "handler-aws-event-bridge",
|
|
6
|
+
canUse: event => {
|
|
7
|
+
return !!event.source;
|
|
8
|
+
},
|
|
9
|
+
handle: async ({
|
|
10
|
+
params,
|
|
11
|
+
event,
|
|
12
|
+
context
|
|
13
|
+
}) => {
|
|
14
|
+
return createHandler(params)(event, context);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
registry.register(handler);
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=register.js.map
|