@webiny/handler-aws 0.0.0-unstable.d7f521b032 → 0.0.0-unstable.dbdf5d6258

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.
Files changed (103) hide show
  1. package/README.md +10 -14
  2. package/createHandler.d.ts +2 -0
  3. package/createHandler.js +29 -0
  4. package/createHandler.js.map +1 -0
  5. package/dynamodb/index.d.ts +5 -8
  6. package/dynamodb/index.js +26 -56
  7. package/dynamodb/index.js.map +1 -1
  8. package/dynamodb/plugins/DynamoDBEventHandler.d.ts +8 -7
  9. package/dynamodb/plugins/DynamoDBEventHandler.js +5 -22
  10. package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
  11. package/dynamodb/register.d.ts +1 -0
  12. package/dynamodb/register.js +26 -0
  13. package/dynamodb/register.js.map +1 -0
  14. package/eventBridge/index.d.ts +7 -10
  15. package/eventBridge/index.js +27 -57
  16. package/eventBridge/index.js.map +1 -1
  17. package/eventBridge/plugins/EventBridgeEventHandler.d.ts +8 -7
  18. package/eventBridge/plugins/EventBridgeEventHandler.js +5 -22
  19. package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
  20. package/eventBridge/register.d.ts +4 -0
  21. package/eventBridge/register.js +19 -0
  22. package/eventBridge/register.js.map +1 -0
  23. package/execute.d.ts +1 -1
  24. package/execute.js +18 -23
  25. package/execute.js.map +1 -1
  26. package/gateway/index.d.ts +7 -11
  27. package/gateway/index.js +27 -57
  28. package/gateway/index.js.map +1 -1
  29. package/gateway/register.d.ts +1 -0
  30. package/gateway/register.js +19 -0
  31. package/gateway/register.js.map +1 -0
  32. package/index.d.ts +35 -6
  33. package/index.js +41 -238
  34. package/index.js.map +1 -1
  35. package/package.json +15 -22
  36. package/plugins/handlerClient.js +11 -27
  37. package/plugins/handlerClient.js.map +1 -1
  38. package/plugins/index.d.ts +1 -1
  39. package/plugins/index.js +4 -12
  40. package/plugins/index.js.map +1 -1
  41. package/raw/index.d.ts +5 -10
  42. package/raw/index.js +32 -57
  43. package/raw/index.js.map +1 -1
  44. package/raw/plugins/RawEventHandler.d.ts +17 -6
  45. package/raw/plugins/RawEventHandler.js +21 -18
  46. package/raw/plugins/RawEventHandler.js.map +1 -1
  47. package/registry.d.ts +17 -0
  48. package/registry.js +38 -0
  49. package/registry.js.map +1 -0
  50. package/s3/index.d.ts +6 -9
  51. package/s3/index.js +29 -59
  52. package/s3/index.js.map +1 -1
  53. package/s3/plugins/S3EventHandler.d.ts +8 -7
  54. package/s3/plugins/S3EventHandler.js +5 -22
  55. package/s3/plugins/S3EventHandler.js.map +1 -1
  56. package/s3/register.d.ts +4 -0
  57. package/s3/register.js +23 -0
  58. package/s3/register.js.map +1 -0
  59. package/sns/index.d.ts +8 -0
  60. package/sns/index.js +57 -0
  61. package/sns/index.js.map +1 -0
  62. package/sns/plugins/SNSEventHandler.d.ts +20 -0
  63. package/sns/plugins/SNSEventHandler.js +13 -0
  64. package/sns/plugins/SNSEventHandler.js.map +1 -0
  65. package/sns/register.d.ts +1 -0
  66. package/sns/register.js +23 -0
  67. package/sns/register.js.map +1 -0
  68. package/sourceHandler.d.ts +2 -0
  69. package/sourceHandler.js +5 -0
  70. package/sourceHandler.js.map +1 -0
  71. package/sqs/index.d.ts +6 -9
  72. package/sqs/index.js +33 -60
  73. package/sqs/index.js.map +1 -1
  74. package/sqs/plugins/SQSEventHandler.d.ts +8 -7
  75. package/sqs/plugins/SQSEventHandler.js +5 -22
  76. package/sqs/plugins/SQSEventHandler.js.map +1 -1
  77. package/sqs/register.d.ts +1 -0
  78. package/sqs/register.js +26 -0
  79. package/sqs/register.js.map +1 -0
  80. package/types.d.ts +28 -5
  81. package/types.js +7 -30
  82. package/types.js.map +1 -1
  83. package/utils/composedHandler.d.ts +6 -0
  84. package/utils/composedHandler.js +17 -0
  85. package/utils/composedHandler.js.map +1 -0
  86. package/utils/index.d.ts +2 -0
  87. package/utils/index.js +4 -0
  88. package/utils/index.js.map +1 -0
  89. package/utils/timer/CustomTimer.d.ts +5 -0
  90. package/utils/timer/CustomTimer.js +12 -0
  91. package/utils/timer/CustomTimer.js.map +1 -0
  92. package/utils/timer/Timer.d.ts +10 -0
  93. package/utils/timer/Timer.js +17 -0
  94. package/utils/timer/Timer.js.map +1 -0
  95. package/utils/timer/abstractions/ITimer.d.ts +10 -0
  96. package/utils/timer/abstractions/ITimer.js +3 -0
  97. package/utils/timer/abstractions/ITimer.js.map +1 -0
  98. package/utils/timer/factory.d.ts +4 -0
  99. package/utils/timer/factory.js +13 -0
  100. package/utils/timer/factory.js.map +1 -0
  101. package/utils/timer/index.d.ts +4 -0
  102. package/utils/timer/index.js +5 -0
  103. package/utils/timer/index.js.map +1 -0
package/README.md CHANGED
@@ -1,15 +1,11 @@
1
1
  # @webiny/handler-aws
2
- [![](https://img.shields.io/npm/dw/@webiny/handler-aws.svg)](https://www.npmjs.com/package/@webiny/handler-aws)
3
- [![](https://img.shields.io/npm/v/@webiny/handler-aws.svg)](https://www.npmjs.com/package/@webiny/handler-aws)
4
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
-
7
- ## Install
8
- ```
9
- npm install --save @webiny/handler-aws
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._
@@ -0,0 +1,2 @@
1
+ import type { HandlerFactory } from "./types.js";
2
+ export declare const createHandler: HandlerFactory;
@@ -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":[]}
@@ -1,11 +1,8 @@
1
- import { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
2
- import { DynamoDBStreamEvent, Context as LambdaContext } from "aws-lambda";
3
- import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
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 interface CreateHandlerParams extends BaseCreateHandlerParams {
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
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
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 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 = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
42
- options: (0, _objectSpread2.default)({
43
- logger: params.debug === true
44
- }, params.options || {})
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
- const plugins = app.webiny.plugins.byType(_DynamoDBEventHandler.DynamoDBEventHandler.type);
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.cb(params);
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 (0, _execute.execute)({
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
- exports.createHandler = createHandler;
57
+ //# sourceMappingURL=index.js.map
@@ -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":";;;;;;;;;;;;;;AAAA;;AAMA;;AAmEA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AA9DA;;AACA;;AARA,MAAMA,KAAK,GAAGC,OAAO,CAAC,mBAAD,CAArB;;AAUA,MAAMC,GAAG,GAAG,wBAAZ;;AAUO,MAAMC,aAAa,GAAIC,MAAD,IAAkD;EAC3E,OAAO,CAACC,OAAD,EAAUC,OAAV,KAAsB;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAA,8DACLJ,MADK;MAERK,OAAO;QACHC,MAAM,EAAEN,MAAM,CAACO,KAAP,KAAiB;MADtB,GAECP,MAAM,CAACK,OAAP,IAAkB,EAFnB;IAFC,GAAZ;IAOA;AACR;AACA;;IACQ,IAAAG,+BAAA,EAAuBL,GAAG,CAACM,MAA3B;IACA;AACR;AACA;;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAJ,CAAWC,OAAX,CAAmBC,MAAnB,CAAgDC,0CAAA,CAAqBC,IAArE,CAAhB;IACA,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAR,EAAhB;;IACA,IAAI,CAACD,OAAL,EAAc;MACV,MAAM,IAAIE,KAAJ,CACD,yEADC,CAAN;IAGH;;IAEDb,GAAG,CAACc,IAAJ,CAASnB,GAAT,EAAc,OAAOoB,OAAP,EAAgBC,KAAhB,KAA0B;MACpC,MAAMnB,MAA0C,GAAG;QAC/CkB,OAD+C;QAE/ChB,OAAO,EAAEC,GAAG,CAACM,MAFkC;QAG/CW,KAAK,EAAEnB,OAHwC;QAI/CoB,aAAa,EAAEnB,OAJgC;QAK/CiB;MAL+C,CAAnD;MAOA,MAAMG,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAR,CAAWvB,MAAX,CAArB;;MAEA,IAAIsB,MAAM,YAAY1B,KAAtB,EAA6B;QACzB,OAAO0B,MAAP;MACH;;MAEAnB,GAAD,CAAaqB,mBAAb,GAAmCF,MAAnC;MACA,OAAOH,KAAK,CAACM,IAAN,CAAW,EAAX,CAAP;IACH,CAhBD;IAiBA,OAAO,IAAAC,gBAAA,EAAQ;MACXvB,GADW;MAEXL,GAFW;MAGXG;IAHW,CAAR,CAAP;EAKH,CA7CD;AA8CH,CA/CM"}
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 { Request, Reply, Context } from "@webiny/handler/types";
3
- import { DynamoDBStreamEvent, Context as LambdaContext } from "aws-lambda";
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 | Reply>;
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: <Response_1>(cb: DynamoDBEventHandlerCallable<Response_1>) => DynamoDBEventHandler<Response_1>;
20
+ export declare const createEventHandler: <Response>(cb: DynamoDBEventHandlerCallable<Response>) => DynamoDBEventHandler<Response>;
@@ -1,30 +1,13 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
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
- exports.createEventHandler = createEventHandler;
13
+ //# sourceMappingURL=DynamoDBEventHandler.js.map
@@ -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":";;;;;;;;;;;AAAA;;AAeO,MAAMA,oBAAN,SAAmDC,cAAnD,CAA0D;EAKtDC,WAAW,CAACC,EAAD,EAA6C;IAC3D;IAD2D;IAE3D,KAAKA,EAAL,GAAUA,EAAV;EACH;;AAR4D;;;8BAApDH,oB,UACqB,2C;;AAU3B,MAAMI,kBAAkB,GAAcD,EAAX,IAA0D;EACxF,OAAO,IAAIH,oBAAJ,CAAmCG,EAAnC,CAAP;AACH,CAFM"}
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":[]}
@@ -1,11 +1,8 @@
1
- import { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
2
- import { EventBridgeEvent, Context as LambdaContext } from "aws-lambda";
3
- import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
4
- export interface HandlerCallable<DetailType extends string, Detail> {
5
- (event: EventBridgeEvent<DetailType, Detail>, context: LambdaContext): Promise<APIGatewayProxyResult>;
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 interface CreateHandlerParams extends BaseCreateHandlerParams {
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;
@@ -1,64 +1,36 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
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 _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 = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
42
- options: (0, _objectSpread2.default)({
43
- logger: params.debug === true
44
- }, params.options || {})
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
- const plugins = app.webiny.plugins.byType(_EventBridgeEventHandler.EventBridgeEventHandler.type);
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.cb(params);
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 (0, _execute.execute)({
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
- exports.createHandler = createHandler;
57
+ //# sourceMappingURL=index.js.map
@@ -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":";;;;;;;;;;;;;;AAAA;;AAMA;;AA0EA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AArEA;;AACA;;AARA,MAAMA,KAAK,GAAGC,OAAO,CAAC,mBAAD,CAArB;;AAUA,MAAMC,GAAG,GAAG,mBAAZ;;AAaO,MAAMC,aAAa,GACtBC,MADyB,IAEa;EACtC,OAAO,CAACC,OAAD,EAAUC,OAAV,KAAsB;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAA,8DACLJ,MADK;MAERK,OAAO;QACHC,MAAM,EAAEN,MAAM,CAACO,KAAP,KAAiB;MADtB,GAECP,MAAM,CAACK,OAAP,IAAkB,EAFnB;IAFC,GAAZ;IAOA;AACR;AACA;;IACQ,IAAAG,+BAAA,EAAuBL,GAAG,CAACM,MAA3B;IACA;AACR;AACA;;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAJ,CAAWC,OAAX,CAAmBC,MAAnB,CACZC,gDAAA,CAAwBC,IADZ,CAAhB;IAGA,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAR,EAAhB;;IACA,IAAI,CAACD,OAAL,EAAc;MACV,MAAM,IAAIE,KAAJ,CACD,oFADC,CAAN;IAGH;;IAEDb,GAAG,CAACc,IAAJ,CAASnB,GAAT,EAAc,OAAOoB,OAAP,EAAgBC,KAAhB,KAA0B;MACpC,MAAMnB,MAAiE,GAAG;QACtEkB,OADsE;QAEtEC,KAFsE;QAGtEjB,OAAO,EAAEC,GAAG,CAACM,MAHyD;QAItER,OAJsE;QAKtEmB,aAAa,EAAElB;MALuD,CAA1E;MAOA,MAAMmB,MAAM,GAAG,MAAMP,OAAO,CAACQ,EAAR,CAAWtB,MAAX,CAArB;;MAEA,IAAIqB,MAAM,YAAYzB,KAAtB,EAA6B;QACzB,OAAOyB,MAAP;MACH;;MAEAlB,GAAD,CAAaoB,mBAAb,GAAmCF,MAAnC;MACA,OAAOF,KAAK,CAACK,IAAN,CAAW,EAAX,CAAP;IACH,CAhBD;IAiBA,OAAO,IAAAC,gBAAA,EAAQ;MACXtB,GADW;MAEXL,GAFW;MAGXG;IAHW,CAAR,CAAP;EAKH,CA/CD;AAgDH,CAnDM"}
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 { Plugin } from "@webiny/plugins/Plugin";
2
- import { Request, Reply, Context } from "@webiny/handler/types";
3
- import { EventBridgeEvent, Context as LambdaContext } from "aws-lambda";
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 | Reply>;
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, Response_1 = any>(cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response_1>) => EventBridgeEventHandler<DetailType, Detail, Response_1>;
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
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
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
- exports.createEventHandler = createEventHandler;
13
+ //# sourceMappingURL=EventBridgeEventHandler.js.map
@@ -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":";;;;;;;;;;;AAAA;;AAeO,MAAMA,uBAAN,SAIGC,cAJH,CAIU;EAKNC,WAAW,CAACC,EAAD,EAAoE;IAClF;IADkF;IAElF,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARY;;;8BAJJH,uB,UAKqB,sC;;AAU3B,MAAMI,kBAAkB,GAC3BD,EAD8B,IAE7B;EACD,OAAO,IAAIH,uBAAJ,CAA0DG,EAA1D,CAAP;AACH,CAJM"}
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,4 @@
1
+ import type { HandlerFactoryParams } from "../types.js";
2
+ export interface HandlerParams extends HandlerFactoryParams {
3
+ debug?: boolean;
4
+ }
@@ -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