@webiny/handler-aws 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
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 +23 -0
- package/createHandler.js.map +1 -0
- package/dynamodb/index.d.ts +5 -8
- package/dynamodb/index.js +41 -87
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +8 -7
- package/dynamodb/plugins/DynamoDBEventHandler.js +12 -28
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.d.ts +1 -0
- package/dynamodb/register.js +16 -0
- package/dynamodb/register.js.map +1 -0
- package/eventBridge/index.d.ts +7 -10
- package/eventBridge/index.js +42 -88
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +8 -7
- package/eventBridge/plugins/EventBridgeEventHandler.js +12 -28
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +4 -0
- package/eventBridge/register.js +11 -0
- package/eventBridge/register.js.map +1 -0
- package/execute.d.ts +1 -1
- package/execute.js +54 -67
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +7 -11
- package/gateway/index.js +43 -102
- package/gateway/index.js.map +1 -1
- package/gateway/register.d.ts +1 -0
- package/gateway/register.js +11 -0
- package/gateway/register.js.map +1 -0
- package/index.d.ts +35 -6
- package/index.js +17 -245
- package/package.json +22 -25
- 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 +44 -95
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +17 -6
- package/raw/plugins/RawEventHandler.js +14 -21
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +17 -0
- package/registry.js +23 -0
- package/registry.js.map +1 -0
- package/s3/index.d.ts +6 -9
- package/s3/index.js +41 -87
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +8 -7
- package/s3/plugins/S3EventHandler.js +12 -28
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +4 -0
- package/s3/register.js +15 -0
- package/s3/register.js.map +1 -0
- package/sns/index.d.ts +8 -0
- package/sns/index.js +42 -0
- package/sns/index.js.map +1 -0
- package/sns/plugins/SNSEventHandler.d.ts +20 -0
- package/sns/plugins/SNSEventHandler.js +14 -0
- package/sns/plugins/SNSEventHandler.js.map +1 -0
- package/sns/register.d.ts +1 -0
- package/sns/register.js +15 -0
- package/sns/register.js.map +1 -0
- package/sourceHandler.d.ts +2 -0
- package/sourceHandler.js +4 -0
- package/sourceHandler.js.map +1 -0
- package/sqs/index.d.ts +6 -9
- package/sqs/index.js +42 -87
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +8 -7
- package/sqs/plugins/SQSEventHandler.js +12 -28
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.d.ts +1 -0
- package/sqs/register.js +16 -0
- package/sqs/register.js.map +1 -0
- package/types.d.ts +28 -5
- package/types.js +10 -32
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +6 -0
- package/utils/composedHandler.js +8 -0
- package/utils/composedHandler.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +2 -0
- package/utils/timer/CustomTimer.d.ts +5 -0
- package/utils/timer/CustomTimer.js +13 -0
- package/utils/timer/CustomTimer.js.map +1 -0
- package/utils/timer/Timer.d.ts +10 -0
- package/utils/timer/Timer.js +16 -0
- package/utils/timer/Timer.js.map +1 -0
- package/utils/timer/abstractions/ITimer.d.ts +10 -0
- package/utils/timer/abstractions/ITimer.js +0 -0
- package/utils/timer/factory.d.ts +4 -0
- package/utils/timer/factory.js +12 -0
- package/utils/timer/factory.js.map +1 -0
- package/utils/timer/index.d.ts +4 -0
- package/utils/timer/index.js +3 -0
- package/index.js.map +0 -1
- package/plugins/handlerClient.d.ts +0 -2
- package/plugins/handlerClient.js +0 -62
- package/plugins/handlerClient.js.map +0 -1
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,23 @@
|
|
|
1
|
+
import { AsyncPluginsContainer } from "@webiny/plugins";
|
|
2
|
+
import { registry } from "./registry.js";
|
|
3
|
+
import { lambdaRequestTracker } from "pino-lambda";
|
|
4
|
+
const withRequest = lambdaRequestTracker();
|
|
5
|
+
const createHandler = ({ plugins, ...params })=>{
|
|
6
|
+
const pluginsContainer = new AsyncPluginsContainer(plugins);
|
|
7
|
+
return async (event, context = {})=>{
|
|
8
|
+
withRequest(event, context);
|
|
9
|
+
const plugins = await pluginsContainer.init();
|
|
10
|
+
const handler = registry.getHandler(event, context);
|
|
11
|
+
return handler.handle({
|
|
12
|
+
params: {
|
|
13
|
+
...params,
|
|
14
|
+
plugins
|
|
15
|
+
},
|
|
16
|
+
event,
|
|
17
|
+
context
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export { createHandler };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=createHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHandler.js","sources":["../src/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"],"names":["withRequest","lambdaRequestTracker","createHandler","plugins","params","pluginsContainer","AsyncPluginsContainer","event","context","handler","registry"],"mappings":";;;AASA,MAAMA,cAAcC;AAEb,MAAMC,gBAAgC,CAAC,EAAEC,OAAO,EAAE,GAAGC,QAAQ;IAChE,MAAMC,mBAAmB,IAAIC,sBAAsBH;IAEnD,OAAO,OAAOI,OAAOC,UAAU,CAAC,CAAkB;QAC9CR,YAAYO,OAAOC;QAEnB,MAAML,UAAU,MAAME,iBAAiB,IAAI;QAC3C,MAAMI,UAAUC,SAAS,UAAU,CAACH,OAAOC;QAC3C,OAAOC,QAAQ,MAAM,CAAC;YAClB,QAAQ;gBACJ,GAAGL,MAAM;gBACTD;YACJ;YACAI;YACAC;QACJ;IACJ;AACJ"}
|
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,88 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _exportNames = {
|
|
9
|
-
createHandler: true
|
|
10
|
-
};
|
|
11
|
-
exports.createHandler = void 0;
|
|
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 } from "@webiny/handler";
|
|
2
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
|
+
import { DynamoDBEventHandler } from "./plugins/DynamoDBEventHandler.js";
|
|
4
|
+
import lib_reply from "fastify/lib/reply.js";
|
|
5
|
+
import { execute } from "../execute.js";
|
|
6
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
7
|
+
export * from "./plugins/DynamoDBEventHandler.js";
|
|
37
8
|
const url = "/webiny-dynamodb-event";
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (result instanceof Reply) {
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
app.__webiny_raw_result = result;
|
|
78
|
-
return reply.send({});
|
|
79
|
-
});
|
|
80
|
-
return (0, _execute.execute)({
|
|
81
|
-
app,
|
|
82
|
-
url,
|
|
83
|
-
payload
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
exports.createHandler = createHandler;
|
|
9
|
+
const dynamodb_createHandler = (params)=>(payload, context)=>{
|
|
10
|
+
const app = createHandler({
|
|
11
|
+
...params,
|
|
12
|
+
options: {
|
|
13
|
+
logger: true === params.debug,
|
|
14
|
+
...params.options || {}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
registerDefaultPlugins(app.webiny);
|
|
18
|
+
const plugins = app.webiny.plugins.byType(DynamoDBEventHandler.type).reverse();
|
|
19
|
+
if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.");
|
|
20
|
+
const handler = createComposedHandler(plugins);
|
|
21
|
+
app.post(url, async (request, reply)=>{
|
|
22
|
+
const params = {
|
|
23
|
+
request,
|
|
24
|
+
context: app.webiny,
|
|
25
|
+
event: payload,
|
|
26
|
+
lambdaContext: context,
|
|
27
|
+
reply
|
|
28
|
+
};
|
|
29
|
+
const result = await handler(params);
|
|
30
|
+
if (result instanceof lib_reply) return result;
|
|
31
|
+
app.__webiny_raw_result = result;
|
|
32
|
+
return reply.send({});
|
|
33
|
+
});
|
|
34
|
+
return execute({
|
|
35
|
+
app,
|
|
36
|
+
url: url,
|
|
37
|
+
payload
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export { dynamodb_createHandler as createHandler };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
package/dynamodb/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"dynamodb/index.js","sources":["../../src/dynamodb/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"],"names":["url","createHandler","params","payload","context","app","createBaseHandler","registerDefaultPlugins","plugins","DynamoDBEventHandler","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AAoBA,MAAMA,MAAM;AAQL,MAAMC,yBAAgB,CAACC,SACnB,CAACC,SAASC;QACb,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAC7B,MAAM,CAAuBI,qBAAqB,IAAI,EACtD,OAAO;QACZ,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIE,MACN;QAIR,MAAMC,UAAUC,sBAIdJ;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOa,SAASC;YAC1B,MAAMZ,SAGF;gBACAW;gBACA,SAASR,IAAI,MAAM;gBACnB,OAAOF;gBACP,eAAeC;gBACfU;YACJ;YACA,MAAMC,SAAS,MAAMJ,QACjBT;YAGJ,IAAIa,kBAAkBC,WAClB,OAAOD;YAGXV,IAAI,mBAAmB,GAAGU;YAC1B,OAAOD,MAAM,IAAI,CAAC,CAAC;QACvB;QACA,OAAOG,QAAQ;YACXZ;YACAL,KAAAA;YACAG;QACJ;IACJ"}
|
|
@@ -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,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 {
|
|
15
|
-
constructor(cb) {
|
|
16
|
-
super();
|
|
17
|
-
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
|
-
this.cb = cb;
|
|
19
|
-
}
|
|
20
|
-
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
class DynamoDBEventHandler extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.fastify.aws.dynamodb.eventHandler";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
21
10
|
}
|
|
11
|
+
const createEventHandler = (cb)=>new DynamoDBEventHandler(cb);
|
|
12
|
+
export { DynamoDBEventHandler, createEventHandler };
|
|
22
13
|
|
|
23
|
-
|
|
24
|
-
(0, _defineProperty2.default)(DynamoDBEventHandler, "type", "handler.fastify.aws.dynamodb.eventHandler");
|
|
25
|
-
|
|
26
|
-
const createEventHandler = cb => {
|
|
27
|
-
return new DynamoDBEventHandler(cb);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
exports.createEventHandler = createEventHandler;
|
|
14
|
+
//# sourceMappingURL=DynamoDBEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"dynamodb/plugins/DynamoDBEventHandler.js","sources":["../../../src/dynamodb/plugins/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"],"names":["DynamoDBEventHandler","Plugin","cb","createEventHandler"],"mappings":";AAiBO,MAAMA,6BAA6CC;;aAC/B,IAAI,GAAG;;IAI9B,YAAmBC,EAA0C,CAAE;QAC3D,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,qBAAqB,CAAWD,KAClC,IAAIF,qBAA+BE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
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) || 0 === event.Records.length) return false;
|
|
8
|
+
const [record] = event.Records;
|
|
9
|
+
if ("string" != typeof record.eventSource) return false;
|
|
10
|
+
return "aws:dynamodb" === record.eventSource.toLowerCase();
|
|
11
|
+
},
|
|
12
|
+
handle: async ({ params, event, context })=>createHandler(params)(event, context)
|
|
13
|
+
});
|
|
14
|
+
registry.register(handler);
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamodb/register.js","sources":["../../src/dynamodb/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"],"names":["handler","createSourceHandler","event","Array","record","params","context","createHandler","registry"],"mappings":";;;AAMA,MAAMA,UAAUC,oBAAwD;IACpE,MAAM;IACN,QAAQC,CAAAA;QACJ,IAAI,CAACC,MAAM,OAAO,CAACD,MAAM,OAAO,KAAKA,AAAyB,MAAzBA,MAAM,OAAO,CAAC,MAAM,EACrD,OAAO;QAEX,MAAM,CAACE,OAAO,GAAGF,MAAM,OAAO;QAC9B,IAAI,AAA8B,YAA9B,OAAOE,OAAO,WAAW,EACzB,OAAO;QAEX,OAAOA,AAAqC,mBAArCA,OAAO,WAAW,CAAC,WAAW;IACzC;IACA,QAAQ,OAAO,EAAEC,MAAM,EAAEH,KAAK,EAAEI,OAAO,EAAE,GAC9BC,cAAcF,QAAQH,OAAOI;AAE5C;AAEAE,SAAS,QAAQ,CAACR"}
|
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,88 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
options: (0, _objectSpread2.default)({
|
|
44
|
-
logger: params.debug === true
|
|
45
|
-
}, params.options || {})
|
|
46
|
-
});
|
|
47
|
-
/**
|
|
48
|
-
* We always must add our default plugins to the app.
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
52
|
-
/**
|
|
53
|
-
* There must be an event plugin for this handler to work.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
const plugins = app.webiny.plugins.byType(_EventBridgeEventHandler.EventBridgeEventHandler.type);
|
|
57
|
-
const handler = plugins.shift();
|
|
58
|
-
|
|
59
|
-
if (!handler) {
|
|
60
|
-
throw new Error(`To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
app.post(url, async (request, reply) => {
|
|
64
|
-
const params = {
|
|
65
|
-
request,
|
|
66
|
-
reply,
|
|
67
|
-
context: app.webiny,
|
|
68
|
-
payload,
|
|
69
|
-
lambdaContext: context
|
|
70
|
-
};
|
|
71
|
-
const result = await handler.cb(params);
|
|
72
|
-
|
|
73
|
-
if (result instanceof Reply) {
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
app.__webiny_raw_result = result;
|
|
78
|
-
return reply.send({});
|
|
79
|
-
});
|
|
80
|
-
return (0, _execute.execute)({
|
|
81
|
-
app,
|
|
82
|
-
url,
|
|
83
|
-
payload
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
exports.createHandler = createHandler;
|
|
1
|
+
import { createHandler } from "@webiny/handler";
|
|
2
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
|
+
import { EventBridgeEventHandler } from "./plugins/EventBridgeEventHandler.js";
|
|
4
|
+
import { execute } from "../execute.js";
|
|
5
|
+
import lib_reply from "fastify/lib/reply.js";
|
|
6
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
7
|
+
export * from "./plugins/EventBridgeEventHandler.js";
|
|
8
|
+
const url = "/webiny-eventBridge-event";
|
|
9
|
+
const eventBridge_createHandler = (params)=>(payload, context)=>{
|
|
10
|
+
const app = createHandler({
|
|
11
|
+
...params,
|
|
12
|
+
options: {
|
|
13
|
+
logger: true === params.debug,
|
|
14
|
+
...params.options || {}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
registerDefaultPlugins(app.webiny);
|
|
18
|
+
const plugins = app.webiny.plugins.byType(EventBridgeEventHandler.type).reverse();
|
|
19
|
+
if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.");
|
|
20
|
+
const handler = createComposedHandler(plugins);
|
|
21
|
+
app.post(url, async (request, reply)=>{
|
|
22
|
+
const params = {
|
|
23
|
+
request,
|
|
24
|
+
reply,
|
|
25
|
+
context: app.webiny,
|
|
26
|
+
payload,
|
|
27
|
+
lambdaContext: context
|
|
28
|
+
};
|
|
29
|
+
const result = await handler(params);
|
|
30
|
+
if (result instanceof lib_reply) return result;
|
|
31
|
+
app.__webiny_raw_result = result;
|
|
32
|
+
return reply.send({});
|
|
33
|
+
});
|
|
34
|
+
return execute({
|
|
35
|
+
app,
|
|
36
|
+
url: url,
|
|
37
|
+
payload
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export { eventBridge_createHandler as createHandler };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
package/eventBridge/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"eventBridge/index.js","sources":["../../src/eventBridge/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"],"names":["url","createHandler","params","payload","context","app","createBaseHandler","registerDefaultPlugins","plugins","EventBridgeEventHandler","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AA6BA,MAAMA,MAAM;AAEL,MAAMC,4BAAgB,CAACC,SACnB,CAACC,SAASC;QACb,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAC7B,MAAM,CAA0CI,wBAAwB,IAAI,EAC5E,OAAO;QACZ,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIE,MACN;QAIR,MAAMC,UAAUC,sBAIdJ;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOa,SAASC;YAC1B,MAAMZ,SAGF;gBACAW;gBACAC;gBACA,SAAST,IAAI,MAAM;gBACnBF;gBACA,eAAeC;YACnB;YACA,MAAMW,SAAS,MAAMJ,QACjBT;YAOJ,IAAIa,kBAAkBC,WAClB,OAAOD;YAGXV,IAAI,mBAAmB,GAAGU;YAC1B,OAAOD,MAAM,IAAI,CAAC,CAAC;QACvB;QACA,OAAOG,QAAQ;YACXZ;YACAL,KAAAA;YACAG;QACJ;IACJ"}
|
|
@@ -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,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 {
|
|
15
|
-
constructor(cb) {
|
|
16
|
-
super();
|
|
17
|
-
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
|
-
this.cb = cb;
|
|
19
|
-
}
|
|
20
|
-
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
class EventBridgeEventHandler extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.fastify.aws.eventBridge.eventHandler";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
21
10
|
}
|
|
11
|
+
const createEventHandler = (cb)=>new EventBridgeEventHandler(cb);
|
|
12
|
+
export { EventBridgeEventHandler, createEventHandler };
|
|
22
13
|
|
|
23
|
-
|
|
24
|
-
(0, _defineProperty2.default)(EventBridgeEventHandler, "type", "handler.fastify.aws.sqs.eventHandler");
|
|
25
|
-
|
|
26
|
-
const createEventHandler = cb => {
|
|
27
|
-
return new EventBridgeEventHandler(cb);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
exports.createEventHandler = createEventHandler;
|
|
14
|
+
//# sourceMappingURL=EventBridgeEventHandler.js.map
|