@webiny/handler-aws 6.3.0 → 6.4.0-beta.0

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 (67) hide show
  1. package/createHandler.js +16 -22
  2. package/createHandler.js.map +1 -1
  3. package/dynamodb/index.js +34 -49
  4. package/dynamodb/index.js.map +1 -1
  5. package/dynamodb/plugins/DynamoDBEventHandler.js +10 -9
  6. package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
  7. package/dynamodb/register.js +8 -18
  8. package/dynamodb/register.js.map +1 -1
  9. package/eventBridge/index.js +34 -49
  10. package/eventBridge/index.js.map +1 -1
  11. package/eventBridge/plugins/EventBridgeEventHandler.js +10 -9
  12. package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
  13. package/eventBridge/register.js +3 -11
  14. package/eventBridge/register.js.map +1 -1
  15. package/execute.js +52 -60
  16. package/execute.js.map +1 -1
  17. package/gateway/index.js +39 -67
  18. package/gateway/index.js.map +1 -1
  19. package/gateway/register.js +3 -11
  20. package/gateway/register.js.map +1 -1
  21. package/index.js +8 -39
  22. package/package.json +8 -8
  23. package/plugins/index.js +3 -4
  24. package/plugins/index.js.map +1 -1
  25. package/raw/index.js +38 -63
  26. package/raw/index.js.map +1 -1
  27. package/raw/plugins/RawEventHandler.js +11 -21
  28. package/raw/plugins/RawEventHandler.js.map +1 -1
  29. package/registry.js +17 -32
  30. package/registry.js.map +1 -1
  31. package/s3/index.js +34 -49
  32. package/s3/index.js.map +1 -1
  33. package/s3/plugins/S3EventHandler.js +10 -9
  34. package/s3/plugins/S3EventHandler.js.map +1 -1
  35. package/s3/register.js +7 -15
  36. package/s3/register.js.map +1 -1
  37. package/sns/index.js +34 -49
  38. package/sns/index.js.map +1 -1
  39. package/sns/plugins/SNSEventHandler.js +10 -9
  40. package/sns/plugins/SNSEventHandler.js.map +1 -1
  41. package/sns/register.js +7 -15
  42. package/sns/register.js.map +1 -1
  43. package/sourceHandler.js +2 -3
  44. package/sourceHandler.js.map +1 -1
  45. package/sqs/index.js +35 -52
  46. package/sqs/index.js.map +1 -1
  47. package/sqs/plugins/SQSEventHandler.js +10 -9
  48. package/sqs/plugins/SQSEventHandler.js.map +1 -1
  49. package/sqs/register.js +8 -18
  50. package/sqs/register.js.map +1 -1
  51. package/types.js +5 -4
  52. package/types.js.map +1 -1
  53. package/utils/composedHandler.js +5 -14
  54. package/utils/composedHandler.js.map +1 -1
  55. package/utils/index.js +0 -2
  56. package/utils/timer/CustomTimer.js +9 -8
  57. package/utils/timer/CustomTimer.js.map +1 -1
  58. package/utils/timer/Timer.js +12 -13
  59. package/utils/timer/Timer.js.map +1 -1
  60. package/utils/timer/abstractions/ITimer.js +0 -3
  61. package/utils/timer/factory.js +7 -8
  62. package/utils/timer/factory.js.map +1 -1
  63. package/utils/timer/index.js +0 -2
  64. package/index.js.map +0 -1
  65. package/utils/index.js.map +0 -1
  66. package/utils/timer/abstractions/ITimer.js.map +0 -1
  67. package/utils/timer/index.js.map +0 -1
package/createHandler.js CHANGED
@@ -1,29 +1,23 @@
1
1
  import { AsyncPluginsContainer } from "@webiny/plugins";
2
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
3
  import { lambdaRequestTracker } from "pino-lambda";
8
4
  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
- };
5
+ const createHandler = ({ plugins, ...params })=>{
6
+ const pluginsContainer = new AsyncPluginsContainer(plugins);
7
+ return async (event, context = {})=>{
8
+ withRequest(event, context);
9
+ const plugins = await pluginsContainer.init();
10
+ const handler = registry.getHandler(event, context);
11
+ return handler.handle({
12
+ params: {
13
+ ...params,
14
+ plugins
15
+ },
16
+ event,
17
+ context
18
+ });
19
+ };
27
20
  };
21
+ export { createHandler };
28
22
 
29
23
  //# sourceMappingURL=createHandler.js.map
@@ -1 +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
+ {"version":3,"file":"createHandler.js","sources":["../src/createHandler.ts"],"sourcesContent":["import { AsyncPluginsContainer } from \"@webiny/plugins\";\nimport type { HandlerFactory, LambdaContext } from \"~/types.js\";\nimport { registry } from \"./registry.js\";\n\n// TODO: Once we have a better infrastructure for handling such cases, we should refactor this.\n// Ideally, the DI container should already be ready to be used in these `handler` packages.\n// At the moment, that is not the case, so we have to hardcode `pino-lambda` here.\nimport { lambdaRequestTracker } from \"pino-lambda\";\n\nconst withRequest = lambdaRequestTracker();\n\nexport const createHandler: HandlerFactory = ({ plugins, ...params }) => {\n const pluginsContainer = new AsyncPluginsContainer(plugins);\n\n return async (event, context = {} as LambdaContext) => {\n withRequest(event, context);\n\n const plugins = await pluginsContainer.init();\n const handler = registry.getHandler(event, context);\n return handler.handle({\n params: {\n ...params,\n plugins\n },\n event,\n context\n });\n };\n};\n"],"names":["withRequest","lambdaRequestTracker","createHandler","plugins","params","pluginsContainer","AsyncPluginsContainer","event","context","handler","registry"],"mappings":";;;AASA,MAAMA,cAAcC;AAEb,MAAMC,gBAAgC,CAAC,EAAEC,OAAO,EAAE,GAAGC,QAAQ;IAChE,MAAMC,mBAAmB,IAAIC,sBAAsBH;IAEnD,OAAO,OAAOI,OAAOC,UAAU,CAAC,CAAkB;QAC9CR,YAAYO,OAAOC;QAEnB,MAAML,UAAU,MAAME,iBAAiB,IAAI;QAC3C,MAAMI,UAAUC,SAAS,UAAU,CAACH,OAAOC;QAC3C,OAAOC,QAAQ,MAAM,CAAC;YAClB,QAAQ;gBACJ,GAAGL,MAAM;gBACTD;YACJ;YACAI;YACAC;QACJ;IACJ;AACJ"}
package/dynamodb/index.js CHANGED
@@ -1,57 +1,42 @@
1
- import { createHandler as createBaseHandler } from "@webiny/handler";
1
+ import { createHandler } from "@webiny/handler";
2
2
  import { registerDefaultPlugins } from "../plugins/index.js";
3
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";
4
+ import lib_reply from "fastify/lib/reply.js";
9
5
  import { execute } from "../execute.js";
10
6
  import { createComposedHandler } from "../utils/composedHandler.js";
11
7
  export * from "./plugins/DynamoDBEventHandler.js";
12
8
  const url = "/webiny-dynamodb-event";
13
- export const createHandler = params => {
14
- return (payload, context) => {
15
- const app = createBaseHandler({
16
- ...params,
17
- options: {
18
- logger: params.debug === true,
19
- ...(params.options || {})
20
- }
21
- });
22
- /**
23
- * We always must add our default plugins to the app.
24
- */
25
- registerDefaultPlugins(app.webiny);
26
- /**
27
- * There must be an event plugin for this handler to work.
28
- */
29
- const plugins = app.webiny.plugins.byType(DynamoDBEventHandler.type).reverse();
30
- if (plugins.length === 0) {
31
- throw new Error(`To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.`);
32
- }
33
- const handler = createComposedHandler(plugins);
34
- app.post(url, async (request, reply) => {
35
- const params = {
36
- request,
37
- context: app.webiny,
38
- event: payload,
39
- lambdaContext: context,
40
- reply
41
- };
42
- const result = await handler(params);
43
- if (result instanceof Reply) {
44
- return result;
45
- }
46
- app.__webiny_raw_result = result;
47
- return reply.send({});
48
- });
49
- return execute({
50
- app,
51
- url,
52
- payload
53
- });
54
- };
55
- };
9
+ const dynamodb_createHandler = (params)=>(payload, context)=>{
10
+ const app = createHandler({
11
+ ...params,
12
+ options: {
13
+ logger: true === params.debug,
14
+ ...params.options || {}
15
+ }
16
+ });
17
+ registerDefaultPlugins(app.webiny);
18
+ const plugins = app.webiny.plugins.byType(DynamoDBEventHandler.type).reverse();
19
+ if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.");
20
+ const handler = createComposedHandler(plugins);
21
+ app.post(url, async (request, reply)=>{
22
+ const params = {
23
+ request,
24
+ context: app.webiny,
25
+ event: payload,
26
+ lambdaContext: context,
27
+ reply
28
+ };
29
+ const result = await handler(params);
30
+ if (result instanceof lib_reply) return result;
31
+ app.__webiny_raw_result = result;
32
+ return reply.send({});
33
+ });
34
+ return execute({
35
+ app,
36
+ url: url,
37
+ payload
38
+ });
39
+ };
40
+ export { dynamodb_createHandler as createHandler };
56
41
 
57
42
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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
+ {"version":3,"file":"dynamodb/index.js","sources":["../../src/dynamodb/index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n DynamoDBStreamEvent\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { DynamoDBEventHandlerCallableParams } from \"./plugins/DynamoDBEventHandler.js\";\nimport { DynamoDBEventHandler } from \"./plugins/DynamoDBEventHandler.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { execute } from \"~/execute.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/DynamoDBEventHandler.js\";\n\nconst url = \"/webiny-dynamodb-event\";\n\nexport type HandlerParams = HandlerFactoryParams;\n\nexport interface HandlerCallable {\n (event: DynamoDBStreamEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return (payload, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins\n .byType<DynamoDBEventHandler>(DynamoDBEventHandler.type)\n .reverse();\n if (plugins.length === 0) {\n throw new Error(\n `To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.`\n );\n }\n\n const handler = createComposedHandler<\n DynamoDBEventHandler,\n DynamoDBEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<\n DynamoDBEventHandlerCallableParams<APIGatewayProxyResult>,\n \"next\"\n > = {\n request,\n context: app.webiny,\n event: payload,\n lambdaContext: context,\n reply\n };\n const result = await handler(\n params as unknown as DynamoDBEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload\n });\n };\n};\n"],"names":["url","createHandler","params","payload","context","app","createBaseHandler","registerDefaultPlugins","plugins","DynamoDBEventHandler","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AAoBA,MAAMA,MAAM;AAQL,MAAMC,yBAAgB,CAACC,SACnB,CAACC,SAASC;QACb,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAC7B,MAAM,CAAuBI,qBAAqB,IAAI,EACtD,OAAO;QACZ,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIE,MACN;QAIR,MAAMC,UAAUC,sBAIdJ;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOa,SAASC;YAC1B,MAAMZ,SAGF;gBACAW;gBACA,SAASR,IAAI,MAAM;gBACnB,OAAOF;gBACP,eAAeC;gBACfU;YACJ;YACA,MAAMC,SAAS,MAAMJ,QACjBT;YAGJ,IAAIa,kBAAkBC,WAClB,OAAOD;YAGXV,IAAI,mBAAmB,GAAGU;YAC1B,OAAOD,MAAM,IAAI,CAAC,CAAC;QACvB;QACA,OAAOG,QAAQ;YACXZ;YACAL,KAAAA;YACAG;QACJ;IACJ"}
@@ -1,13 +1,14 @@
1
1
  import { Plugin } from "@webiny/plugins/Plugin.js";
2
- export class DynamoDBEventHandler extends Plugin {
3
- static type = "handler.fastify.aws.dynamodb.eventHandler";
4
- constructor(cb) {
5
- super();
6
- this.cb = cb;
7
- }
2
+ class DynamoDBEventHandler extends Plugin {
3
+ static{
4
+ this.type = "handler.fastify.aws.dynamodb.eventHandler";
5
+ }
6
+ constructor(cb){
7
+ super();
8
+ this.cb = cb;
9
+ }
8
10
  }
9
- export const createEventHandler = cb => {
10
- return new DynamoDBEventHandler(cb);
11
- };
11
+ const createEventHandler = (cb)=>new DynamoDBEventHandler(cb);
12
+ export { DynamoDBEventHandler, createEventHandler };
12
13
 
13
14
  //# sourceMappingURL=DynamoDBEventHandler.js.map
@@ -1 +1 @@
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":[]}
1
+ {"version":3,"file":"dynamodb/plugins/DynamoDBEventHandler.js","sources":["../../../src/dynamodb/plugins/DynamoDBEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\nimport type { Context as LambdaContext, DynamoDBStreamEvent } from \"@webiny/aws-sdk/types/index.js\";\n\nexport interface DynamoDBEventHandlerCallableParams<Response = Reply> {\n request: Request;\n context: Context;\n event: DynamoDBStreamEvent;\n lambdaContext: LambdaContext;\n reply: Reply;\n next: () => Promise<Response>;\n}\n\nexport interface DynamoDBEventHandlerCallable<Response = Reply> {\n (params: DynamoDBEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class DynamoDBEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.dynamodb.eventHandler\";\n\n public readonly cb: DynamoDBEventHandlerCallable<Response>;\n\n public constructor(cb: DynamoDBEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: DynamoDBEventHandlerCallable<Response>) => {\n return new DynamoDBEventHandler<Response>(cb);\n};\n"],"names":["DynamoDBEventHandler","Plugin","cb","createEventHandler"],"mappings":";AAiBO,MAAMA,6BAA6CC;;aAC/B,IAAI,GAAG;;IAI9B,YAAmBC,EAA0C,CAAE;QAC3D,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,qBAAqB,CAAWD,KAClC,IAAIF,qBAA+BE"}
@@ -2,24 +2,14 @@ import { registry } from "../registry.js";
2
2
  import { createSourceHandler } from "../sourceHandler.js";
3
3
  import { createHandler } from "./index.js";
4
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
- }
5
+ name: "handler-aws-dynamodb-stream",
6
+ canUse: (event)=>{
7
+ if (!Array.isArray(event.Records) || 0 === event.Records.length) return false;
8
+ const [record] = event.Records;
9
+ if ("string" != typeof record.eventSource) return false;
10
+ return "aws:dynamodb" === record.eventSource.toLowerCase();
11
+ },
12
+ handle: async ({ params, event, context })=>createHandler(params)(event, context)
23
13
  });
24
14
  registry.register(handler);
25
15
 
@@ -1 +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
+ {"version":3,"file":"dynamodb/register.js","sources":["../../src/dynamodb/register.ts"],"sourcesContent":["import { registry } from \"~/registry.js\";\nimport type { DynamoDBStreamEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\nimport type { HandlerParams } from \"~/dynamodb/index.js\";\nimport { createHandler } from \"~/dynamodb/index.js\";\n\nconst handler = createSourceHandler<DynamoDBStreamEvent, HandlerParams>({\n name: \"handler-aws-dynamodb-stream\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n if (typeof record.eventSource !== \"string\") {\n return false;\n }\n return record.eventSource.toLowerCase() === \"aws:dynamodb\";\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"names":["handler","createSourceHandler","event","Array","record","params","context","createHandler","registry"],"mappings":";;;AAMA,MAAMA,UAAUC,oBAAwD;IACpE,MAAM;IACN,QAAQC,CAAAA;QACJ,IAAI,CAACC,MAAM,OAAO,CAACD,MAAM,OAAO,KAAKA,AAAyB,MAAzBA,MAAM,OAAO,CAAC,MAAM,EACrD,OAAO;QAEX,MAAM,CAACE,OAAO,GAAGF,MAAM,OAAO;QAC9B,IAAI,AAA8B,YAA9B,OAAOE,OAAO,WAAW,EACzB,OAAO;QAEX,OAAOA,AAAqC,mBAArCA,OAAO,WAAW,CAAC,WAAW;IACzC;IACA,QAAQ,OAAO,EAAEC,MAAM,EAAEH,KAAK,EAAEI,OAAO,EAAE,GAC9BC,cAAcF,QAAQH,OAAOI;AAE5C;AAEAE,SAAS,QAAQ,CAACR"}
@@ -1,57 +1,42 @@
1
- import { createHandler as createBaseHandler } from "@webiny/handler";
1
+ import { createHandler } from "@webiny/handler";
2
2
  import { registerDefaultPlugins } from "../plugins/index.js";
3
3
  import { EventBridgeEventHandler } from "./plugins/EventBridgeEventHandler.js";
4
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";
5
+ import lib_reply from "fastify/lib/reply.js";
10
6
  import { createComposedHandler } from "../utils/composedHandler.js";
11
7
  export * from "./plugins/EventBridgeEventHandler.js";
12
8
  const url = "/webiny-eventBridge-event";
13
- export const createHandler = params => {
14
- return (payload, context) => {
15
- const app = createBaseHandler({
16
- ...params,
17
- options: {
18
- logger: params.debug === true,
19
- ...(params.options || {})
20
- }
21
- });
22
- /**
23
- * We always must add our default plugins to the app.
24
- */
25
- registerDefaultPlugins(app.webiny);
26
- /**
27
- * There must be an event plugin for this handler to work.
28
- */
29
- const plugins = app.webiny.plugins.byType(EventBridgeEventHandler.type).reverse();
30
- if (plugins.length === 0) {
31
- throw new Error(`To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.`);
32
- }
33
- const handler = createComposedHandler(plugins);
34
- app.post(url, async (request, reply) => {
35
- const params = {
36
- request,
37
- reply,
38
- context: app.webiny,
39
- payload,
40
- lambdaContext: context
41
- };
42
- const result = await handler(params);
43
- if (result instanceof Reply) {
44
- return result;
45
- }
46
- app.__webiny_raw_result = result;
47
- return reply.send({});
48
- });
49
- return execute({
50
- app,
51
- url,
52
- payload
53
- });
54
- };
55
- };
9
+ const eventBridge_createHandler = (params)=>(payload, context)=>{
10
+ const app = createHandler({
11
+ ...params,
12
+ options: {
13
+ logger: true === params.debug,
14
+ ...params.options || {}
15
+ }
16
+ });
17
+ registerDefaultPlugins(app.webiny);
18
+ const plugins = app.webiny.plugins.byType(EventBridgeEventHandler.type).reverse();
19
+ if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.");
20
+ const handler = createComposedHandler(plugins);
21
+ app.post(url, async (request, reply)=>{
22
+ const params = {
23
+ request,
24
+ reply,
25
+ context: app.webiny,
26
+ payload,
27
+ lambdaContext: context
28
+ };
29
+ const result = await handler(params);
30
+ if (result instanceof lib_reply) return result;
31
+ app.__webiny_raw_result = result;
32
+ return reply.send({});
33
+ });
34
+ return execute({
35
+ app,
36
+ url: url,
37
+ payload
38
+ });
39
+ };
40
+ export { eventBridge_createHandler as createHandler };
56
41
 
57
42
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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
+ {"version":3,"file":"eventBridge/index.js","sources":["../../src/eventBridge/index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { EventBridgeEventHandlerCallableParams } from \"~/eventBridge/plugins/EventBridgeEventHandler.js\";\nimport { EventBridgeEventHandler } from \"~/eventBridge/plugins/EventBridgeEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n EventBridgeEvent\n} from \"@webiny/aws-sdk/types/index.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/EventBridgeEventHandler.js\";\n\nexport type HandlerParams = HandlerFactoryParams;\n\nexport interface HandlerCallable {\n (\n event: EventBridgeEvent<string, string>,\n context: LambdaContext\n ): Promise<APIGatewayProxyResult>;\n}\n\nconst url = \"/webiny-eventBridge-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return (payload, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins\n .byType<EventBridgeEventHandler<string, string>>(EventBridgeEventHandler.type)\n .reverse();\n if (plugins.length === 0) {\n throw new Error(\n `To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.`\n );\n }\n\n const handler = createComposedHandler<\n EventBridgeEventHandler<string, string>,\n EventBridgeEventHandlerCallableParams<string, string, APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<\n EventBridgeEventHandlerCallableParams<string, string, APIGatewayProxyResult>,\n \"next\"\n > = {\n request,\n reply,\n context: app.webiny,\n payload,\n lambdaContext: context\n };\n const result = await handler(\n params as unknown as EventBridgeEventHandlerCallableParams<\n string,\n string,\n APIGatewayProxyResult\n >\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload\n });\n };\n};\n"],"names":["url","createHandler","params","payload","context","app","createBaseHandler","registerDefaultPlugins","plugins","EventBridgeEventHandler","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AA6BA,MAAMA,MAAM;AAEL,MAAMC,4BAAgB,CAACC,SACnB,CAACC,SAASC;QACb,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAC7B,MAAM,CAA0CI,wBAAwB,IAAI,EAC5E,OAAO;QACZ,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIE,MACN;QAIR,MAAMC,UAAUC,sBAIdJ;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOa,SAASC;YAC1B,MAAMZ,SAGF;gBACAW;gBACAC;gBACA,SAAST,IAAI,MAAM;gBACnBF;gBACA,eAAeC;YACnB;YACA,MAAMW,SAAS,MAAMJ,QACjBT;YAOJ,IAAIa,kBAAkBC,WAClB,OAAOD;YAGXV,IAAI,mBAAmB,GAAGU;YAC1B,OAAOD,MAAM,IAAI,CAAC,CAAC;QACvB;QACA,OAAOG,QAAQ;YACXZ;YACAL,KAAAA;YACAG;QACJ;IACJ"}
@@ -1,13 +1,14 @@
1
1
  import { Plugin } from "@webiny/plugins/Plugin.js";
2
- export class EventBridgeEventHandler extends Plugin {
3
- static type = "handler.fastify.aws.eventBridge.eventHandler";
4
- constructor(cb) {
5
- super();
6
- this.cb = cb;
7
- }
2
+ class EventBridgeEventHandler extends Plugin {
3
+ static{
4
+ this.type = "handler.fastify.aws.eventBridge.eventHandler";
5
+ }
6
+ constructor(cb){
7
+ super();
8
+ this.cb = cb;
9
+ }
8
10
  }
9
- export const createEventHandler = cb => {
10
- return new EventBridgeEventHandler(cb);
11
- };
11
+ const createEventHandler = (cb)=>new EventBridgeEventHandler(cb);
12
+ export { EventBridgeEventHandler, createEventHandler };
12
13
 
13
14
  //# sourceMappingURL=EventBridgeEventHandler.js.map
@@ -1 +1 @@
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":[]}
1
+ {"version":3,"file":"eventBridge/plugins/EventBridgeEventHandler.js","sources":["../../../src/eventBridge/plugins/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"],"names":["EventBridgeEventHandler","Plugin","cb","createEventHandler"],"mappings":";AA0BO,MAAMA,gCAIHC;;aACiB,IAAI,GAAG;;IAI9B,YAAmBC,EAAiE,CAAE;QAClF,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,qBAAqB,CAC9BD,KAEO,IAAIF,wBAAsDE"}
@@ -2,17 +2,9 @@ import { registry } from "../registry.js";
2
2
  import { createSourceHandler } from "../sourceHandler.js";
3
3
  import { createHandler } from "./index.js";
4
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
- }
5
+ name: "handler-aws-event-bridge",
6
+ canUse: (event)=>!!event.source,
7
+ handle: async ({ params, event, context })=>createHandler(params)(event, context)
16
8
  });
17
9
  registry.register(handler);
18
10
 
@@ -1 +1 @@
1
- {"version":3,"names":["registry","createSourceHandler","createHandler","handler","name","canUse","event","source","handle","params","context","register"],"sources":["register.ts"],"sourcesContent":["import type { EventBridgeEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\nimport { createHandler } from \"~/eventBridge/index.js\";\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":"AACA,SAASA,QAAQ;AAEjB,SAASC,mBAAmB;AAC5B,SAASC,aAAa;AAMtB,MAAMC,OAAO,GAAGF,mBAAmB,CAAkD;EACjFG,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,OAAOR,aAAa,CAACO,MAAM,CAAC,CAACH,KAAK,EAAEI,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFV,QAAQ,CAACW,QAAQ,CAACR,OAAO,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"eventBridge/register.js","sources":["../../src/eventBridge/register.ts"],"sourcesContent":["import type { EventBridgeEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\nimport { createHandler } from \"~/eventBridge/index.js\";\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"],"names":["handler","createSourceHandler","event","params","context","createHandler","registry"],"mappings":";;;AAUA,MAAMA,UAAUC,oBAAqE;IACjF,MAAM;IACN,QAAQC,CAAAA,QACG,CAAC,CAACA,MAAM,MAAM;IAEzB,QAAQ,OAAO,EAAEC,MAAM,EAAED,KAAK,EAAEE,OAAO,EAAE,GAC9BC,cAAcF,QAAQD,OAAOE;AAE5C;AAEAE,SAAS,QAAQ,CAACN"}
package/execute.js CHANGED
@@ -1,66 +1,58 @@
1
1
  import { Base64EncodeHeader } from "./types.js";
2
- const createHandleResponse = (app, resolve) => {
3
- return (err, result) => {
4
- if (err) {
5
- return resolve({
6
- statusCode: 500,
7
- body: JSON.stringify(err),
8
- headers: {}
9
- });
10
- }
11
- if (app.__webiny_raw_result) {
12
- return resolve(app.__webiny_raw_result);
13
- } else if (!result) {
14
- const response = {
15
- statusCode: 200,
16
- body: "",
17
- headers: {},
18
- isBase64Encoded: false
19
- };
20
- return resolve(response);
21
- }
22
- const isBase64Encoded = !!result.headers[Base64EncodeHeader.encoded] || !!result.headers[Base64EncodeHeader.binary];
23
- const response = {
24
- statusCode: result.statusCode,
25
- body: isBase64Encoded ? result.rawPayload.toString("base64") : result.payload,
26
- headers: result.headers,
27
- isBase64Encoded
2
+ const createHandleResponse = (app, resolve)=>(err, result)=>{
3
+ if (err) return resolve({
4
+ statusCode: 500,
5
+ body: JSON.stringify(err),
6
+ headers: {}
7
+ });
8
+ if (app.__webiny_raw_result) return resolve(app.__webiny_raw_result);
9
+ if (!result) {
10
+ const response = {
11
+ statusCode: 200,
12
+ body: "",
13
+ headers: {},
14
+ isBase64Encoded: false
15
+ };
16
+ return resolve(response);
17
+ }
18
+ const isBase64Encoded = !!result.headers[Base64EncodeHeader.encoded] || !!result.headers[Base64EncodeHeader.binary];
19
+ const response = {
20
+ statusCode: result.statusCode,
21
+ body: isBase64Encoded ? result.rawPayload.toString("base64") : result.payload,
22
+ headers: result.headers,
23
+ isBase64Encoded
24
+ };
25
+ return resolve(response);
28
26
  };
29
- return resolve(response);
30
- };
31
- };
32
- const getPayloadProperty = (payload, prop, defaults = {}) => {
33
- if (payload && typeof payload === "object") {
34
- const value = payload[prop] ? payload[prop] : {};
35
- return {
36
- ...defaults,
37
- ...value
38
- };
39
- }
40
- return defaults;
27
+ const getPayloadProperty = (payload, prop, defaults = {})=>{
28
+ if (payload && "object" == typeof payload) {
29
+ const value = payload[prop] ? payload[prop] : {};
30
+ return {
31
+ ...defaults,
32
+ ...value
33
+ };
34
+ }
35
+ return defaults;
41
36
  };
42
- export const execute = params => {
43
- const {
44
- app,
45
- url,
46
- payload
47
- } = params;
48
- const query = getPayloadProperty(payload, "query", {});
49
- const headers = getPayloadProperty(payload, "headers", {
50
- ["content-type"]: "application/json"
51
- });
52
- const cookies = getPayloadProperty(payload, "cookies", {});
53
- return new Promise(resolve => {
54
- app.inject({
55
- method: "POST",
56
- url,
57
- payload: payload || {},
58
- body: payload || {},
59
- query,
60
- headers,
61
- cookies
62
- }, createHandleResponse(app, resolve));
63
- });
37
+ const execute = (params)=>{
38
+ const { app, url, payload } = params;
39
+ const query = getPayloadProperty(payload, "query", {});
40
+ const headers = getPayloadProperty(payload, "headers", {
41
+ ["content-type"]: "application/json"
42
+ });
43
+ const cookies = getPayloadProperty(payload, "cookies", {});
44
+ return new Promise((resolve)=>{
45
+ app.inject({
46
+ method: "POST",
47
+ url,
48
+ payload: payload || {},
49
+ body: payload || {},
50
+ query,
51
+ headers,
52
+ cookies
53
+ }, createHandleResponse(app, resolve));
54
+ });
64
55
  };
56
+ export { execute };
65
57
 
66
58
  //# sourceMappingURL=execute.js.map