@webiny/handler-aws 5.39.0-beta.0 → 5.39.0-beta.2

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 (80) hide show
  1. package/createHandler.d.ts +2 -0
  2. package/createHandler.js +29 -0
  3. package/createHandler.js.map +1 -0
  4. package/dynamodb/index.d.ts +5 -8
  5. package/dynamodb/index.js +18 -13
  6. package/dynamodb/index.js.map +1 -1
  7. package/dynamodb/plugins/DynamoDBEventHandler.d.ts +6 -5
  8. package/dynamodb/plugins/DynamoDBEventHandler.js +1 -4
  9. package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
  10. package/dynamodb/register.d.ts +1 -0
  11. package/dynamodb/register.js +28 -0
  12. package/dynamodb/register.js.map +1 -0
  13. package/eventBridge/index.d.ts +7 -10
  14. package/eventBridge/index.js +19 -14
  15. package/eventBridge/index.js.map +1 -1
  16. package/eventBridge/plugins/EventBridgeEventHandler.d.ts +6 -5
  17. package/eventBridge/plugins/EventBridgeEventHandler.js +1 -4
  18. package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
  19. package/eventBridge/register.d.ts +4 -0
  20. package/eventBridge/register.js +21 -0
  21. package/eventBridge/register.js.map +1 -0
  22. package/execute.js +5 -4
  23. package/execute.js.map +1 -1
  24. package/gateway/index.d.ts +6 -10
  25. package/gateway/index.js +12 -11
  26. package/gateway/index.js.map +1 -1
  27. package/gateway/register.d.ts +1 -0
  28. package/gateway/register.js +21 -0
  29. package/gateway/register.js.map +1 -0
  30. package/index.d.ts +32 -5
  31. package/index.js +125 -23
  32. package/index.js.map +1 -1
  33. package/package.json +10 -8
  34. package/plugins/handlerClient.js +7 -8
  35. package/plugins/handlerClient.js.map +1 -1
  36. package/raw/index.d.ts +1 -5
  37. package/raw/index.js +12 -12
  38. package/raw/index.js.map +1 -1
  39. package/raw/plugins/RawEventHandler.d.ts +2 -2
  40. package/raw/plugins/RawEventHandler.js +4 -0
  41. package/raw/plugins/RawEventHandler.js.map +1 -1
  42. package/registry.d.ts +11 -0
  43. package/registry.js +38 -0
  44. package/registry.js.map +1 -0
  45. package/s3/index.d.ts +7 -9
  46. package/s3/index.js +21 -16
  47. package/s3/index.js.map +1 -1
  48. package/s3/plugins/S3EventHandler.d.ts +6 -5
  49. package/s3/plugins/S3EventHandler.js +1 -4
  50. package/s3/plugins/S3EventHandler.js.map +1 -1
  51. package/s3/register.d.ts +4 -0
  52. package/s3/register.js +25 -0
  53. package/s3/register.js.map +1 -0
  54. package/sns/index.d.ts +9 -0
  55. package/sns/index.js +77 -0
  56. package/sns/index.js.map +1 -0
  57. package/sns/plugins/SNSEventHandler.d.ts +20 -0
  58. package/sns/plugins/SNSEventHandler.js +21 -0
  59. package/sns/plugins/SNSEventHandler.js.map +1 -0
  60. package/sns/register.d.ts +1 -0
  61. package/sns/register.js +25 -0
  62. package/sns/register.js.map +1 -0
  63. package/sourceHandler.d.ts +2 -0
  64. package/sourceHandler.js +12 -0
  65. package/sourceHandler.js.map +1 -0
  66. package/sqs/index.d.ts +7 -9
  67. package/sqs/index.js +21 -16
  68. package/sqs/index.js.map +1 -1
  69. package/sqs/plugins/SQSEventHandler.d.ts +6 -5
  70. package/sqs/plugins/SQSEventHandler.js +1 -4
  71. package/sqs/plugins/SQSEventHandler.js.map +1 -1
  72. package/sqs/register.d.ts +1 -0
  73. package/sqs/register.js +28 -0
  74. package/sqs/register.js.map +1 -0
  75. package/types.d.ts +25 -1
  76. package/types.js +31 -1
  77. package/types.js.map +1 -1
  78. package/utils/composedHandler.d.ts +6 -0
  79. package/utils/composedHandler.js +24 -0
  80. package/utils/composedHandler.js.map +1 -0
@@ -0,0 +1,2 @@
1
+ import { HandlerFactory } from "./types";
2
+ export declare const createHandler: HandlerFactory;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createHandler = void 0;
7
+ var _plugins = require("@webiny/plugins");
8
+ var _registry = require("./registry");
9
+ const createHandler = ({
10
+ plugins,
11
+ ...params
12
+ }) => {
13
+ const pluginsContainer = new _plugins.AsyncPluginsContainer(plugins);
14
+ return async (event, context) => {
15
+ const plugins = await pluginsContainer.init();
16
+ const handler = _registry.registry.getHandler(event, context);
17
+ return handler.handle({
18
+ params: {
19
+ ...params,
20
+ plugins
21
+ },
22
+ event,
23
+ context
24
+ });
25
+ };
26
+ };
27
+ exports.createHandler = createHandler;
28
+
29
+ //# sourceMappingURL=createHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_plugins","require","_registry","createHandler","plugins","params","pluginsContainer","AsyncPluginsContainer","event","context","init","handler","registry","getHandler","handle","exports"],"sources":["createHandler.ts"],"sourcesContent":["import { AsyncPluginsContainer } from \"@webiny/plugins\";\nimport { HandlerFactory } from \"~/types\";\nimport { registry } from \"./registry\";\n\nexport const createHandler: HandlerFactory = ({ plugins, ...params }) => {\n const pluginsContainer = new AsyncPluginsContainer(plugins);\n\n return async (event, context) => {\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,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AAEO,MAAME,aAA6B,GAAGA,CAAC;EAAEC,OAAO;EAAE,GAAGC;AAAO,CAAC,KAAK;EACrE,MAAMC,gBAAgB,GAAG,IAAIC,8BAAqB,CAACH,OAAO,CAAC;EAE3D,OAAO,OAAOI,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAML,OAAO,GAAG,MAAME,gBAAgB,CAACI,IAAI,CAAC,CAAC;IAC7C,MAAMC,OAAO,GAAGC,kBAAQ,CAACC,UAAU,CAACL,KAAK,EAAEC,OAAO,CAAC;IACnD,OAAOE,OAAO,CAACG,MAAM,CAAC;MAClBT,MAAM,EAAE;QACJ,GAAGA,MAAM;QACTD;MACJ,CAAC;MACDI,KAAK;MACLC;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACM,OAAA,CAAAZ,aAAA,GAAAA,aAAA"}
@@ -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 { APIGatewayProxyResult, Context as LambdaContext, DynamoDBStreamEvent } from "aws-lambda";
2
+ import { HandlerFactoryParams } from "../types";
3
+ export * from "./plugins/DynamoDBEventHandler";
4
+ export declare 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
@@ -8,8 +8,8 @@ var _exportNames = {
8
8
  createHandler: true
9
9
  };
10
10
  exports.createHandler = void 0;
11
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
11
  var _handler = require("@webiny/handler");
12
+ var _plugins = require("../plugins");
13
13
  var _DynamoDBEventHandler = require("./plugins/DynamoDBEventHandler");
14
14
  Object.keys(_DynamoDBEventHandler).forEach(function (key) {
15
15
  if (key === "default" || key === "__esModule") return;
@@ -22,17 +22,22 @@ Object.keys(_DynamoDBEventHandler).forEach(function (key) {
22
22
  }
23
23
  });
24
24
  });
25
- var _plugins = require("../plugins");
25
+ var _reply = _interopRequireDefault(require("fastify/lib/reply"));
26
26
  var _execute = require("../execute");
27
- const Reply = require("fastify/lib/reply");
27
+ var _composedHandler = require("../utils/composedHandler");
28
+ /**
29
+ * We need a class, not an interface exported from types.
30
+ */ // @ts-expect-error
28
31
  const url = "/webiny-dynamodb-event";
29
32
  const createHandler = params => {
30
33
  return (payload, context) => {
31
- const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
32
- options: (0, _objectSpread2.default)({
33
- logger: params.debug === true
34
- }, params.options || {})
35
- }));
34
+ const app = (0, _handler.createHandler)({
35
+ ...params,
36
+ options: {
37
+ logger: params.debug === true,
38
+ ...(params.options || {})
39
+ }
40
+ });
36
41
  /**
37
42
  * We always must add our default plugins to the app.
38
43
  */
@@ -40,11 +45,11 @@ const createHandler = params => {
40
45
  /**
41
46
  * There must be an event plugin for this handler to work.
42
47
  */
43
- const plugins = app.webiny.plugins.byType(_DynamoDBEventHandler.DynamoDBEventHandler.type);
44
- const handler = plugins.shift();
45
- if (!handler) {
48
+ const plugins = app.webiny.plugins.byType(_DynamoDBEventHandler.DynamoDBEventHandler.type).reverse();
49
+ if (plugins.length === 0) {
46
50
  throw new Error(`To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.`);
47
51
  }
52
+ const handler = (0, _composedHandler.createComposedHandler)(plugins);
48
53
  app.post(url, async (request, reply) => {
49
54
  const params = {
50
55
  request,
@@ -53,8 +58,8 @@ const createHandler = params => {
53
58
  lambdaContext: context,
54
59
  reply
55
60
  };
56
- const result = await handler.cb(params);
57
- if (result instanceof Reply) {
61
+ const result = await handler(params);
62
+ if (result instanceof _reply.default) {
58
63
  return result;
59
64
  }
60
65
  app.__webiny_raw_result = result;
@@ -1 +1 @@
1
- {"version":3,"names":["_handler","require","_DynamoDBEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_plugins","_execute","Reply","url","createHandler","params","payload","context","app","createBaseHandler","_objectSpread2","default","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","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,IAAAA,QAAA,GAAAC,OAAA;AAMA,IAAAC,qBAAA,GAAAD,OAAA;AAmEAE,MAAA,CAAAC,IAAA,CAAAF,qBAAA,EAAAG,OAAA,WAAAC,GA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,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAA0C,GAAG;QAC/CoB,OAAO;QACPlB,OAAO,EAAEC,GAAG,CAACQ,MAAM;QACnBW,KAAK,EAAErB,OAAO;QACdsB,aAAa,EAAErB,OAAO;QACtBmB;MACJ,CAAC;MACD,MAAMG,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAE,CAACzB,MAAM,CAAC;MAEvC,IAAIwB,MAAM,YAAY3B,KAAK,EAAE;QACzB,OAAO2B,MAAM;MACjB;MAECrB,GAAG,CAASuB,mBAAmB,GAAGF,MAAM;MACzC,OAAOH,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXzB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACV,OAAA,CAAAQ,aAAA,GAAAA,aAAA"}
1
+ {"version":3,"names":["_handler","require","_plugins","_DynamoDBEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_reply","_interopRequireDefault","_execute","_composedHandler","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","DynamoDBEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","event","lambdaContext","result","Reply","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["import { APIGatewayProxyResult, Context as LambdaContext, DynamoDBStreamEvent } from \"aws-lambda\";\nimport { HandlerFactoryParams } from \"~/types\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport {\n DynamoDBEventHandler,\n DynamoDBEventHandlerCallableParams\n} from \"./plugins/DynamoDBEventHandler\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply\";\nimport { execute } from \"~/execute\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\n\nexport * from \"./plugins/DynamoDBEventHandler\";\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":";;;;;;;;;;AAEA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,qBAAA,GAAAF,OAAA;AAYAG,MAAA,CAAAC,IAAA,CAAAF,qBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,G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AK,EAAErB,OAAO;QACdsB,aAAa,EAAErB,OAAO;QACtBmB;MACJ,CAAC;MACD,MAAMG,MAAM,GAAG,MAAMP,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIwB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEArB,GAAG,CAACuB,mBAAmB,GAAGF,MAAM;MAChC,OAAOH,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXzB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA"}
@@ -1,15 +1,16 @@
1
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 {
2
+ import { Context, Reply, Request } from "@webiny/handler/types";
3
+ import { Context as LambdaContext, DynamoDBStreamEvent } from "aws-lambda";
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;
@@ -1,21 +1,18 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.createEventHandler = exports.DynamoDBEventHandler = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _Plugin = require("@webiny/plugins/Plugin");
10
8
  class DynamoDBEventHandler extends _Plugin.Plugin {
9
+ static type = "handler.fastify.aws.dynamodb.eventHandler";
11
10
  constructor(cb) {
12
11
  super();
13
- (0, _defineProperty2.default)(this, "cb", void 0);
14
12
  this.cb = cb;
15
13
  }
16
14
  }
17
15
  exports.DynamoDBEventHandler = DynamoDBEventHandler;
18
- (0, _defineProperty2.default)(DynamoDBEventHandler, "type", "handler.fastify.aws.dynamodb.eventHandler");
19
16
  const createEventHandler = cb => {
20
17
  return new DynamoDBEventHandler(cb);
21
18
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_Plugin","require","DynamoDBEventHandler","Plugin","constructor","cb","_defineProperty2","default","exports","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,IAAAA,OAAA,GAAAC,OAAA;AAeO,MAAMC,oBAAoB,SAAyBC,cAAM,CAAC;EAKtDC,WAAWA,CAACC,EAA0C,EAAE;IAC3D,KAAK,CAAC,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA;IACR,IAAI,CAACF,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACG,OAAA,CAAAN,oBAAA,GAAAA,oBAAA;AAAA,IAAAI,gBAAA,CAAAC,OAAA,EATYL,oBAAoB,UACC,2CAA2C;AAUtE,MAAMO,kBAAkB,GAAcJ,EAA0C,IAAK;EACxF,OAAO,IAAIH,oBAAoB,CAAWG,EAAE,CAAC;AACjD,CAAC;AAACG,OAAA,CAAAC,kBAAA,GAAAA,kBAAA"}
1
+ {"version":3,"names":["_Plugin","require","DynamoDBEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["DynamoDBEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, Reply, Request } from \"@webiny/handler/types\";\nimport { Context as LambdaContext, DynamoDBStreamEvent } from \"aws-lambda\";\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,IAAAA,OAAA,GAAAC,OAAA;AAiBO,MAAMC,oBAAoB,SAAyBC,cAAM,CAAC;EAC7D,OAAuBC,IAAI,GAAG,2CAA2C;EAIlEC,WAAWA,CAACC,EAA0C,EAAE;IAC3D,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,oBAAA,GAAAA,oBAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAA0C,IAAK;EACxF,OAAO,IAAIJ,oBAAoB,CAAWI,EAAE,CAAC;AACjD,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _registry = require("../registry");
4
+ var _sourceHandler = require("../sourceHandler");
5
+ var _index = require("./index");
6
+ const handler = (0, _sourceHandler.createSourceHandler)({
7
+ name: "handler-aws-dynamodb-stream",
8
+ canUse: event => {
9
+ if (!Array.isArray(event.Records) || event.Records.length === 0) {
10
+ return false;
11
+ }
12
+ const [record] = event.Records;
13
+ if (typeof record.eventSource !== "string") {
14
+ return false;
15
+ }
16
+ return record.eventSource.toLowerCase() === "aws:dynamodb";
17
+ },
18
+ handle: async ({
19
+ params,
20
+ event,
21
+ context
22
+ }) => {
23
+ return (0, _index.createHandler)(params)(event, context);
24
+ }
25
+ });
26
+ _registry.registry.register(handler);
27
+
28
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_registry","require","_sourceHandler","_index","handler","createSourceHandler","name","canUse","event","Array","isArray","Records","length","record","eventSource","toLowerCase","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import { registry } from \"~/registry\";\nimport { DynamoDBStreamEvent } from \"aws-lambda\";\nimport { createSourceHandler } from \"~/sourceHandler\";\nimport { createHandler, HandlerParams } from \"~/dynamodb/index\";\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,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAAqC;EACpEC,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,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACT,KAAK,EAAEU,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAACjB,OAAO,CAAC"}
@@ -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>;
6
- }
7
- export interface CreateHandlerParams extends BaseCreateHandlerParams {
8
- debug?: boolean;
9
- }
10
- export declare const createHandler: <DetailType extends string, Detail>(params: CreateHandlerParams) => HandlerCallable<DetailType, Detail>;
1
+ import { HandlerFactoryParams } from "../types";
2
+ import { APIGatewayProxyResult, Context as LambdaContext, EventBridgeEvent } from "aws-lambda";
11
3
  export * from "./plugins/EventBridgeEventHandler";
4
+ export declare type HandlerParams = HandlerFactoryParams;
5
+ export interface HandlerCallable {
6
+ (event: EventBridgeEvent<string, string>, context: LambdaContext): Promise<APIGatewayProxyResult>;
7
+ }
8
+ export declare const createHandler: (params: HandlerParams) => HandlerCallable;
@@ -8,8 +8,8 @@ var _exportNames = {
8
8
  createHandler: true
9
9
  };
10
10
  exports.createHandler = void 0;
11
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
11
  var _handler = require("@webiny/handler");
12
+ var _plugins = require("../plugins");
13
13
  var _EventBridgeEventHandler = require("./plugins/EventBridgeEventHandler");
14
14
  Object.keys(_EventBridgeEventHandler).forEach(function (key) {
15
15
  if (key === "default" || key === "__esModule") return;
@@ -22,17 +22,22 @@ Object.keys(_EventBridgeEventHandler).forEach(function (key) {
22
22
  }
23
23
  });
24
24
  });
25
- var _plugins = require("../plugins");
26
25
  var _execute = require("../execute");
27
- const Reply = require("fastify/lib/reply");
28
- const url = "/webiny-sqs-event";
26
+ var _reply = _interopRequireDefault(require("fastify/lib/reply"));
27
+ var _composedHandler = require("../utils/composedHandler");
28
+ /**
29
+ * We need a class, not an interface exported from types.
30
+ */ // @ts-expect-error
31
+ const url = "/webiny-eventBridge-event";
29
32
  const createHandler = params => {
30
33
  return (payload, context) => {
31
- const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
32
- options: (0, _objectSpread2.default)({
33
- logger: params.debug === true
34
- }, params.options || {})
35
- }));
34
+ const app = (0, _handler.createHandler)({
35
+ ...params,
36
+ options: {
37
+ logger: params.debug === true,
38
+ ...(params.options || {})
39
+ }
40
+ });
36
41
  /**
37
42
  * We always must add our default plugins to the app.
38
43
  */
@@ -40,11 +45,11 @@ const createHandler = params => {
40
45
  /**
41
46
  * There must be an event plugin for this handler to work.
42
47
  */
43
- const plugins = app.webiny.plugins.byType(_EventBridgeEventHandler.EventBridgeEventHandler.type);
44
- const handler = plugins.shift();
45
- if (!handler) {
48
+ const plugins = app.webiny.plugins.byType(_EventBridgeEventHandler.EventBridgeEventHandler.type).reverse();
49
+ if (plugins.length === 0) {
46
50
  throw new Error(`To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.`);
47
51
  }
52
+ const handler = (0, _composedHandler.createComposedHandler)(plugins);
48
53
  app.post(url, async (request, reply) => {
49
54
  const params = {
50
55
  request,
@@ -53,8 +58,8 @@ const createHandler = params => {
53
58
  payload,
54
59
  lambdaContext: context
55
60
  };
56
- const result = await handler.cb(params);
57
- if (result instanceof Reply) {
61
+ const result = await handler(params);
62
+ if (result instanceof _reply.default) {
58
63
  return result;
59
64
  }
60
65
  app.__webiny_raw_result = result;
@@ -1 +1 @@
1
- {"version":3,"names":["_handler","require","_EventBridgeEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_plugins","_execute","Reply","url","createHandler","params","payload","context","app","createBaseHandler","_objectSpread2","default","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","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,IAAAA,QAAA,GAAAC,OAAA;AAMA,IAAAC,wBAAA,GAAAD,OAAA;AA0EAE,MAAA,CAAAC,IAAA,CAAAF,wBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,wBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,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IAAIuB,MAAM,YAAY1B,KAAK,EAAE;QACzB,OAAO0B,MAAM;MACjB;MAECpB,GAAG,CAASsB,mBAAmB,GAAGF,MAAM;MACzC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXxB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACV,OAAA,CAAAQ,aAAA,GAAAA,aAAA"}
1
+ {"version":3,"names":["_handler","require","_plugins","_EventBridgeEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","EventBridgeEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport {\n EventBridgeEventHandler,\n EventBridgeEventHandlerCallableParams\n} from \"~/eventBridge/plugins/EventBridgeEventHandler\";\nimport { execute } from \"~/execute\";\nimport { HandlerFactoryParams } from \"~/types\";\nimport { APIGatewayProxyResult, Context as LambdaContext, EventBridgeEvent } from \"aws-lambda\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\n\nexport * from \"./plugins/EventBridgeEventHandler\";\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,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,wBAAA,GAAAF,OAAA;AAcAG,MAAA,CAAAC,IAAA,CAAAF,wBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,wBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,wBAAA,CAAAI,GAAA;IAAA;EA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MAAM;MAChC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXxB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA"}
@@ -1,15 +1,16 @@
1
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> {
2
+ import { Context, Reply, Request } from "@webiny/handler/types";
3
+ import { Context as LambdaContext, EventBridgeEvent } from "aws-lambda";
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;
@@ -1,21 +1,18 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.createEventHandler = exports.EventBridgeEventHandler = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _Plugin = require("@webiny/plugins/Plugin");
10
8
  class EventBridgeEventHandler extends _Plugin.Plugin {
9
+ static type = "handler.fastify.aws.eventBridge.eventHandler";
11
10
  constructor(cb) {
12
11
  super();
13
- (0, _defineProperty2.default)(this, "cb", void 0);
14
12
  this.cb = cb;
15
13
  }
16
14
  }
17
15
  exports.EventBridgeEventHandler = EventBridgeEventHandler;
18
- (0, _defineProperty2.default)(EventBridgeEventHandler, "type", "handler.fastify.aws.sqs.eventHandler");
19
16
  const createEventHandler = cb => {
20
17
  return new EventBridgeEventHandler(cb);
21
18
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_Plugin","require","EventBridgeEventHandler","Plugin","constructor","cb","_defineProperty2","default","exports","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,IAAAA,OAAA,GAAAC,OAAA;AAeO,MAAMC,uBAAuB,SAI1BC,cAAM,CAAC;EAKNC,WAAWA,CAACC,EAAiE,EAAE;IAClF,KAAK,CAAC,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA;IACR,IAAI,CAACF,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACG,OAAA,CAAAN,uBAAA,GAAAA,uBAAA;AAAA,IAAAI,gBAAA,CAAAC,OAAA,EAbYL,uBAAuB,UAKF,sCAAsC;AAUjE,MAAMO,kBAAkB,GAC3BJ,EAAiE,IAChE;EACD,OAAO,IAAIH,uBAAuB,CAA+BG,EAAE,CAAC;AACxE,CAAC;AAACG,OAAA,CAAAC,kBAAA,GAAAA,kBAAA"}
1
+ {"version":3,"names":["_Plugin","require","EventBridgeEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["EventBridgeEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, Reply, Request } from \"@webiny/handler/types\";\nimport { Context as LambdaContext, EventBridgeEvent } from \"aws-lambda\";\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":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AA0BO,MAAMC,uBAAuB,SAI1BC,cAAM,CAAC;EACb,OAAuBC,IAAI,GAAG,8CAA8C;EAIrEC,WAAWA,CAACC,EAAiE,EAAE;IAClF,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,uBAAA,GAAAA,uBAAA;AAEM,MAAMM,kBAAkB,GAC3BF,EAAiE,IAChE;EACD,OAAO,IAAIJ,uBAAuB,CAA+BI,EAAE,CAAC;AACxE,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA"}
@@ -0,0 +1,4 @@
1
+ import { HandlerFactoryParams } from "../types";
2
+ export interface HandlerParams extends HandlerFactoryParams {
3
+ debug?: boolean;
4
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _registry = require("../registry");
4
+ var _sourceHandler = require("../sourceHandler");
5
+ var _index = require("./index");
6
+ const handler = (0, _sourceHandler.createSourceHandler)({
7
+ name: "handler-aws-event-bridge",
8
+ canUse: event => {
9
+ return !!event.source;
10
+ },
11
+ handle: async ({
12
+ params,
13
+ event,
14
+ context
15
+ }) => {
16
+ return (0, _index.createHandler)(params)(event, context);
17
+ }
18
+ });
19
+ _registry.registry.register(handler);
20
+
21
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_registry","require","_sourceHandler","_index","handler","createSourceHandler","name","canUse","event","source","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import { registry } from \"~/registry\";\nimport { HandlerFactoryParams } from \"~/types\";\nimport { EventBridgeEvent } from \"aws-lambda\";\nimport { createSourceHandler } from \"~/sourceHandler\";\nimport { createHandler } from \"~/eventBridge/index\";\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst handler = createSourceHandler<EventBridgeEvent<string, string>, HandlerParams>({\n name: \"handler-aws-event-bridge\",\n canUse: event => {\n return !!event.source;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":";;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAMA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAAkD;EACjFC,IAAI,EAAE,0BAA0B;EAChCC,MAAM,EAAEC,KAAK,IAAI;IACb,OAAO,CAAC,CAACA,KAAK,CAACC,MAAM;EACzB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAEH,KAAK;IAAEI;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACH,KAAK,EAAEI,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAACX,OAAO,CAAC"}
package/execute.js CHANGED
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.execute = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
7
  var _types = require("./types");
10
8
  const createHandleResponse = (app, resolve) => {
11
9
  return (err, result) => {
@@ -30,9 +28,12 @@ const createHandleResponse = (app, resolve) => {
30
28
  };
31
29
  };
32
30
  const getPayloadProperty = (payload, prop, defaults = {}) => {
33
- if (typeof payload === "object") {
31
+ if (payload && typeof payload === "object") {
34
32
  const value = payload[prop] ? payload[prop] : {};
35
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, defaults), value);
33
+ return {
34
+ ...defaults,
35
+ ...value
36
+ };
36
37
  }
37
38
  return defaults;
38
39
  };
package/execute.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_types","require","createHandleResponse","app","resolve","err","result","statusCode","body","JSON","stringify","headers","__webiny_raw_result","isBase64Encoded","Base64EncodeHeader","encoded","binary","response","rawPayload","toString","payload","getPayloadProperty","prop","defaults","value","_objectSpread2","default","execute","params","url","query","cookies","Promise","inject","method","exports"],"sources":["execute.ts"],"sourcesContent":["import { FastifyInstance } from \"@webiny/handler/types\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { LightMyRequestCallback } from \"fastify\";\nimport { Base64EncodeHeader } from \"~/types\";\n\ninterface Resolve {\n (response: APIGatewayProxyResult | any): void;\n}\nconst createHandleResponse = (app: FastifyInstance, resolve: Resolve): LightMyRequestCallback => {\n return (err, result) => {\n if (err) {\n return resolve({\n statusCode: 500,\n body: JSON.stringify(err),\n headers: {}\n });\n }\n if (app.__webiny_raw_result) {\n return resolve(app.__webiny_raw_result);\n }\n const isBase64Encoded =\n !!result.headers[Base64EncodeHeader.encoded] ||\n !!result.headers[Base64EncodeHeader.binary];\n const response: APIGatewayProxyResult = {\n statusCode: result.statusCode,\n body: isBase64Encoded ? result.rawPayload.toString(\"base64\") : result.payload,\n headers: result.headers as APIGatewayProxyResult[\"headers\"],\n isBase64Encoded\n };\n return resolve(response);\n };\n};\n\nconst getPayloadProperty = (\n payload: any,\n prop: string,\n defaults: Record<string, any> = {}\n): Record<string, any> => {\n if (typeof payload === \"object\") {\n const value = payload[prop] ? payload[prop] : {};\n\n return {\n ...defaults,\n ...value\n };\n }\n return defaults;\n};\n\nexport interface ExecuteParams {\n app: FastifyInstance;\n url: string;\n payload: any;\n}\n\nexport const execute = (params: ExecuteParams): Promise<any> => {\n const { app, url, payload } = params;\n\n const query = getPayloadProperty(payload, \"query\", {});\n const headers = getPayloadProperty(payload, \"headers\", {\n [\"content-type\"]: \"application/json\"\n });\n const cookies = getPayloadProperty(payload, \"cookies\", {});\n\n return new Promise(resolve => {\n app.inject(\n {\n method: \"POST\",\n url,\n payload: payload || {},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AA,MACOH,QAAQ,GACRC,KAAK;EAEhB;EACA,OAAOD,QAAQ;AACnB,CAAC;AAQM,MAAMI,OAAO,GAAIC,MAAqB,IAAmB;EAC5D,MAAM;IAAEzB,GAAG;IAAE0B,GAAG;IAAET;EAAQ,CAAC,GAAGQ,MAAM;EAEpC,MAAME,KAAK,GAAGT,kBAAkB,CAACD,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;EACtD,MAAMT,OAAO,GAAGU,kBAAkB,CAACD,OAAO,EAAE,SAAS,EAAE;IACnD,CAAC,cAAc,GAAG;EACtB,CAAC,CAAC;EACF,MAAMW,OAAO,GAAGV,kBAAkB,CAACD,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;EAE1D,OAAO,IAAIY,OAAO,CAAC5B,OAAO,IAAI;IAC1BD,GAAG,CAAC8B,MAAM,CACN;MACIC,MAAM,EAAE,MAAM;MACdL,GAAG;MACHT,OAAO,EAAEA,OAAO,IAAI,CAAC,CAAC;MACtBU,KAAK;MACLnB,OAAO;MACPoB;IACJ,CAAC,EACD7B,oBAAoB,CAACC,GAAG,EAAEC,OAAO,CACrC,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAAC+B,OAAA,CAAAR,OAAA,GAAAA,OAAA"}
1
+ {"version":3,"names":["_types","require","createHandleResponse","app","resolve","err","result","statusCode","body","JSON","stringify","headers","__webiny_raw_result","isBase64Encoded","Base64EncodeHeader","encoded","binary","response","rawPayload","toString","payload","getPayloadProperty","prop","defaults","value","execute","params","url","query","cookies","Promise","inject","method","exports"],"sources":["execute.ts"],"sourcesContent":["import { FastifyInstance } from \"@webiny/handler/types\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { LightMyRequestCallback } from \"fastify\";\nimport { Base64EncodeHeader } from \"~/types\";\n\ninterface Resolve {\n (response: APIGatewayProxyResult | any): void;\n}\nconst createHandleResponse = (app: FastifyInstance, resolve: Resolve): LightMyRequestCallback => {\n return (err, result) => {\n if (err) {\n return resolve({\n statusCode: 500,\n body: JSON.stringify(err),\n headers: {}\n });\n }\n if (app.__webiny_raw_result) {\n return resolve(app.__webiny_raw_result);\n }\n const isBase64Encoded =\n !!result.headers[Base64EncodeHeader.encoded] ||\n !!result.headers[Base64EncodeHeader.binary];\n const response: APIGatewayProxyResult = {\n statusCode: result.statusCode,\n body: isBase64Encoded ? result.rawPayload.toString(\"base64\") : result.payload,\n headers: result.headers as APIGatewayProxyResult[\"headers\"],\n isBase64Encoded\n };\n return resolve(response);\n };\n};\n\nconst getPayloadProperty = (\n payload: any,\n prop: string,\n defaults: Record<string, any> = {}\n): Record<string, any> => {\n if (payload && typeof payload === \"object\") {\n const value = payload[prop] ? payload[prop] : {};\n\n return {\n ...defaults,\n ...value\n };\n }\n return defaults;\n};\n\nexport interface ExecuteParams {\n app: FastifyInstance;\n url: string;\n payload: any;\n}\n\nexport const execute = (params: ExecuteParams): Promise<any> => {\n const { app, url, payload } = params;\n\n const query = getPayloadProperty(payload, \"query\", {});\n const headers = getPayloadProperty(payload, \"headers\", {\n [\"content-type\"]: \"application/json\"\n });\n const cookies = getPayloadProperty(payload, \"cookies\", {});\n\n return new Promise(resolve => {\n app.inject(\n {\n method: \"POST\",\n url,\n payload: payload || {},\n query,\n headers,\n cookies\n },\n createHandleResponse(app, resolve)\n );\n });\n};\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AAKA,MAAMC,oBAAoB,GAAGA,CAACC,GAAoB,EAAEC,OAAgB,KAA6B;EAC7F,OAAO,CAACC,GAAG,EAAEC,MAAM,KAAK;IACpB,IAAID,GAAG,EAAE;MACL,OAAOD,OAAO,CAAC;QACXG,UAAU,EAAE,GAAG;QACfC,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACL,GAAG,CAAC;QACzBM,OAAO,EAAE,CAAC;MACd,CAAC,CAAC;IACN;IACA,IAAIR,GAAG,CAACS,mBAAmB,EAAE;MACzB,OAAOR,OAAO,CAACD,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AIU,OAAO,CAAC1B,OAAO,IAAI;IAC1BD,GAAG,CAAC4B,MAAM,CACN;MACIC,MAAM,EAAE,MAAM;MACdL,GAAG;MACHP,OAAO,EAAEA,OAAO,IAAI,CAAC,CAAC;MACtBQ,KAAK;MACLjB,OAAO;MACPkB;IACJ,CAAC,EACD3B,oBAAoB,CAACC,GAAG,EAAEC,OAAO,CACrC,CAAC;EACL,CAAC,CAAC;AACN,CAAC;AAAC6B,OAAA,CAAAR,OAAA,GAAAA,OAAA"}
@@ -1,14 +1,10 @@
1
- import { LambdaFastifyOptions as LambdaOptions, LambdaResponse } from "@fastify/aws-lambda";
1
+ import { LambdaResponse } from "@fastify/aws-lambda";
2
+ import { createRoute, RoutePlugin } from "@webiny/handler";
2
3
  import { APIGatewayEvent, Context as LambdaContext } from "aws-lambda";
3
- import { CreateHandlerParams as BaseCreateHandlerParams, RoutePlugin, createRoute } from "@webiny/handler";
4
+ import { HandlerFactoryParams } from "../types";
5
+ export { RoutePlugin, createRoute };
6
+ export declare type HandlerParams = HandlerFactoryParams;
4
7
  export interface HandlerCallable {
5
8
  (event: APIGatewayEvent, ctx: LambdaContext): Promise<LambdaResponse>;
6
9
  }
7
- export interface CreateHandlerParams extends BaseCreateHandlerParams {
8
- http?: {
9
- debug?: boolean;
10
- };
11
- lambdaOptions?: LambdaOptions;
12
- }
13
- export declare const createHandler: (params: CreateHandlerParams) => HandlerCallable;
14
- export { RoutePlugin, createRoute };
10
+ export declare const createHandler: (params: HandlerParams) => HandlerCallable;
package/gateway/index.js CHANGED
@@ -17,7 +17,6 @@ Object.defineProperty(exports, "createRoute", {
17
17
  return _handler.createRoute;
18
18
  }
19
19
  });
20
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
21
20
  var _awsLambda = _interopRequireDefault(require("@fastify/aws-lambda"));
22
21
  var _handler = require("@webiny/handler");
23
22
  var _plugins = require("../plugins");
@@ -58,13 +57,14 @@ const attachRequiredProperties = event => {
58
57
  }
59
58
  };
60
59
  const createHandler = params => {
61
- return (event, context) => {
62
- var _params$http;
63
- const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
64
- options: (0, _objectSpread2.default)({
65
- logger: ((_params$http = params.http) === null || _params$http === void 0 ? void 0 : _params$http.debug) === true
66
- }, params.options || {})
67
- }));
60
+ return async (event, context) => {
61
+ const app = (0, _handler.createHandler)({
62
+ ...params,
63
+ options: {
64
+ logger: params.debug === true,
65
+ ...(params.options || {})
66
+ }
67
+ });
68
68
  /**
69
69
  * We always must add our default plugins to the app.
70
70
  */
@@ -73,14 +73,15 @@ const createHandler = params => {
73
73
  throw new Error(`To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.`);
74
74
  }
75
75
  attachRequiredProperties(event);
76
- const appLambda = (0, _awsLambda.default)(app, (0, _objectSpread2.default)({
76
+ const appLambda = (0, _awsLambda.default)(app, {
77
77
  decorateRequest: true,
78
78
  serializeLambdaArguments: true,
79
79
  decorationPropertyName: "awsLambda",
80
80
  enforceBase64: response => {
81
81
  return !!response.headers[_types.Base64EncodeHeader.encoded] || !!response.headers[_types.Base64EncodeHeader.binary];
82
- }
83
- }, params.lambdaOptions || {}));
82
+ },
83
+ ...(params.lambdaOptions || {})
84
+ });
84
85
  return appLambda(event, context);
85
86
  };
86
87
  };