@webiny/handler-aws 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d

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 (102) 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 +19 -28
  6. package/dynamodb/index.js.map +1 -1
  7. package/dynamodb/plugins/DynamoDBEventHandler.d.ts +6 -5
  8. package/dynamodb/plugins/DynamoDBEventHandler.js +3 -12
  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 +21 -30
  15. package/eventBridge/index.js.map +1 -1
  16. package/eventBridge/plugins/EventBridgeEventHandler.d.ts +6 -5
  17. package/eventBridge/plugins/EventBridgeEventHandler.js +3 -12
  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.d.ts +1 -1
  23. package/execute.js +16 -14
  24. package/execute.js.map +1 -1
  25. package/gateway/index.d.ts +7 -11
  26. package/gateway/index.js +48 -22
  27. package/gateway/index.js.map +1 -1
  28. package/gateway/register.d.ts +1 -0
  29. package/gateway/register.js +21 -0
  30. package/gateway/register.js.map +1 -0
  31. package/index.d.ts +34 -5
  32. package/index.js +158 -29
  33. package/index.js.map +1 -1
  34. package/package.json +14 -20
  35. package/plugins/handlerClient.js +9 -18
  36. package/plugins/handlerClient.js.map +1 -1
  37. package/plugins/index.d.ts +1 -1
  38. package/plugins/index.js +2 -3
  39. package/plugins/index.js.map +1 -1
  40. package/raw/index.d.ts +3 -8
  41. package/raw/index.js +22 -29
  42. package/raw/index.js.map +1 -1
  43. package/raw/plugins/RawEventHandler.d.ts +17 -6
  44. package/raw/plugins/RawEventHandler.js +20 -9
  45. package/raw/plugins/RawEventHandler.js.map +1 -1
  46. package/registry.d.ts +17 -0
  47. package/registry.js +44 -0
  48. package/registry.js.map +1 -0
  49. package/s3/index.d.ts +6 -9
  50. package/s3/index.js +22 -31
  51. package/s3/index.js.map +1 -1
  52. package/s3/plugins/S3EventHandler.d.ts +6 -5
  53. package/s3/plugins/S3EventHandler.js +3 -12
  54. package/s3/plugins/S3EventHandler.js.map +1 -1
  55. package/s3/register.d.ts +4 -0
  56. package/s3/register.js +25 -0
  57. package/s3/register.js.map +1 -0
  58. package/sns/index.d.ts +8 -0
  59. package/sns/index.js +79 -0
  60. package/sns/index.js.map +1 -0
  61. package/sns/plugins/SNSEventHandler.d.ts +20 -0
  62. package/sns/plugins/SNSEventHandler.js +21 -0
  63. package/sns/plugins/SNSEventHandler.js.map +1 -0
  64. package/sns/register.d.ts +1 -0
  65. package/sns/register.js +25 -0
  66. package/sns/register.js.map +1 -0
  67. package/sourceHandler.d.ts +2 -0
  68. package/sourceHandler.js +12 -0
  69. package/sourceHandler.js.map +1 -0
  70. package/sqs/index.d.ts +6 -9
  71. package/sqs/index.js +26 -32
  72. package/sqs/index.js.map +1 -1
  73. package/sqs/plugins/SQSEventHandler.d.ts +6 -5
  74. package/sqs/plugins/SQSEventHandler.js +3 -12
  75. package/sqs/plugins/SQSEventHandler.js.map +1 -1
  76. package/sqs/register.d.ts +1 -0
  77. package/sqs/register.js +28 -0
  78. package/sqs/register.js.map +1 -0
  79. package/types.d.ts +27 -4
  80. package/types.js +14 -9
  81. package/types.js.map +1 -1
  82. package/utils/composedHandler.d.ts +6 -0
  83. package/utils/composedHandler.js +24 -0
  84. package/utils/composedHandler.js.map +1 -0
  85. package/utils/index.d.ts +2 -0
  86. package/utils/index.js +29 -0
  87. package/utils/index.js.map +1 -0
  88. package/utils/timer/CustomTimer.d.ts +5 -0
  89. package/utils/timer/CustomTimer.js +19 -0
  90. package/utils/timer/CustomTimer.js.map +1 -0
  91. package/utils/timer/Timer.d.ts +10 -0
  92. package/utils/timer/Timer.js +24 -0
  93. package/utils/timer/Timer.js.map +1 -0
  94. package/utils/timer/abstractions/ITimer.d.ts +10 -0
  95. package/utils/timer/abstractions/ITimer.js +7 -0
  96. package/utils/timer/abstractions/ITimer.js.map +1 -0
  97. package/utils/timer/factory.d.ts +4 -0
  98. package/utils/timer/factory.js +20 -0
  99. package/utils/timer/factory.js.map +1 -0
  100. package/utils/timer/index.d.ts +4 -0
  101. package/utils/timer/index.js +51 -0
  102. package/utils/timer/index.js.map +1 -0
package/s3/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","plugins","options","logger","debug","registerDefaultPlugins","webiny","byType","S3EventHandler","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 { S3Event, Context as LambdaContext } from \"aws-lambda\";\nimport { S3EventHandler, S3EventHandlerCallableParams } from \"./plugins/S3EventHandler\";\nimport { APIGatewayProxyResult } from \"aws-lambda/trigger/api-gateway-proxy\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { execute } from \"~/execute\";\n\nconst url = \"/webiny-s3-event\";\n\nexport interface HandlerCallable {\n (payload: S3Event, 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 plugins: params.plugins,\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<S3EventHandler>(S3EventHandler.type);\n const handler = plugins.shift();\n if (!handler) {\n throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);\n }\n\n app.post(url, async (request, reply) => {\n const params: S3EventHandlerCallableParams = {\n request,\n reply,\n context: app.webiny,\n event: 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/S3EventHandler\";\n"],"mappings":";;;;;;;;;;;;;;AAAA;;AAMA;;AA8DA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AA5DA;;AACA;;AALA,MAAMA,KAAK,GAAGC,OAAO,CAAC,mBAAD,CAArB;;AAOA,MAAMC,GAAG,GAAG,kBAAZ;;AAUO,MAAMC,aAAa,GAAIC,MAAD,IAAkD;EAC3E,OAAO,CAACC,OAAD,EAAUC,OAAV,KAAsB;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAA,EAAkB;MAC1BC,OAAO,EAAEL,MAAM,CAACK,OADU;MAE1BC,OAAO;QACHC,MAAM,EAAEP,MAAM,CAACQ,KAAP,KAAiB;MADtB,GAECR,MAAM,CAACM,OAAP,IAAkB,EAFnB;IAFmB,CAAlB,CAAZ;IAOA;AACR;AACA;;IACQ,IAAAG,+BAAA,EAAuBN,GAAG,CAACO,MAA3B;IACA;AACR;AACA;;IACQ,MAAML,OAAO,GAAGF,GAAG,CAACO,MAAJ,CAAWL,OAAX,CAAmBM,MAAnB,CAA0CC,8BAAA,CAAeC,IAAzD,CAAhB;IACA,MAAMC,OAAO,GAAGT,OAAO,CAACU,KAAR,EAAhB;;IACA,IAAI,CAACD,OAAL,EAAc;MACV,MAAM,IAAIE,KAAJ,CAAW,kEAAX,CAAN;IACH;;IAEDb,GAAG,CAACc,IAAJ,CAASnB,GAAT,EAAc,OAAOoB,OAAP,EAAgBC,KAAhB,KAA0B;MACpC,MAAMnB,MAAoC,GAAG;QACzCkB,OADyC;QAEzCC,KAFyC;QAGzCjB,OAAO,EAAEC,GAAG,CAACO,MAH4B;QAIzCU,KAAK,EAAEnB,OAJkC;QAKzCoB,aAAa,EAAEnB;MAL0B,CAA7C;MAOA,MAAMoB,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAR,CAAWvB,MAAX,CAArB;;MAEA,IAAIsB,MAAM,YAAY1B,KAAtB,EAA6B;QACzB,OAAO0B,MAAP;MACH;;MAEAnB,GAAD,CAAaqB,mBAAb,GAAmCF,MAAnC;MACA,OAAOH,KAAK,CAACM,IAAN,CAAW,EAAX,CAAP;IACH,CAhBD;IAiBA,OAAO,IAAAC,gBAAA,EAAQ;MACXvB,GADW;MAEXL,GAFW;MAGXG;IAHW,CAAR,CAAP;EAKH,CA3CD;AA4CH,CA7CM"}
1
+ {"version":3,"names":["_handler","require","_plugins","_S3EventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","event","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","S3EventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","send","execute","payload"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport type { S3EventHandlerCallableParams } from \"~/s3/plugins/S3EventHandler\";\nimport { S3EventHandler } from \"~/s3/plugins/S3EventHandler\";\nimport { execute } from \"~/execute\";\nimport type { HandlerFactoryParams } from \"~/types\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n S3Event\n} from \"@webiny/aws-sdk/types\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\n\nexport * from \"./plugins/S3EventHandler\";\n\nexport interface HandlerCallable {\n (event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-s3-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, 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<S3EventHandler>(S3EventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);\n }\n\n const handler = createComposedHandler<\n S3EventHandler,\n S3EventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<S3EventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n const result = await handler(\n params as unknown as S3EventHandlerCallableParams<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: event\n });\n };\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AAeAG,MAAA,CAAAC,IAAA,CAAAF,eAAA,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,eAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,eAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAdA,IAAAS,QAAA,GAAAf,OAAA;AAMA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AAMA,IAAAkB,gBAAA,GAAAlB,OAAA;AAVA;AACA;AACA;AACA;;AAiBA,MAAMmB,GAAG,GAAG,kBAAkB;AAEvB,MAAMC,aAAa,GAAIC,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,EAAC;MAC1B,GAAGJ,MAAM;MACTK,OAAO,EAAE;QACLC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK,IAAI;QAC7B,IAAIP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IACxF,IAAIJ,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,kEAAkE,CAAC;IACvF;IAEA,MAAMC,OAAO,GAAG,IAAAC,sCAAqB,EAInCR,OAAO,CAAC;IAEVP,GAAG,CAACgB,IAAI,CAACrB,GAAG,EAAE,OAAOsB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAAyE,GAAG;QAC9EoB,OAAO;QACPC,KAAK;QACLnB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,KAAK;QACLqB,aAAa,EAAEpB;MACnB,CAAC;MACD,MAAMqB,MAAM,GAAG,MAAMN,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIuB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEApB,GAAG,CAACsB,mBAAmB,GAAGF,MAAM;MAChC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXxB,GAAG;MACHL,GAAG;MACH8B,OAAO,EAAE3B;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -1,15 +1,16 @@
1
+ import type { Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types";
1
2
  import { Plugin } from "@webiny/plugins/Plugin";
2
- import { Request, Reply, Context } from "@webiny/handler/types";
3
- import { S3Event, Context as LambdaContext } from "aws-lambda";
4
- export interface S3EventHandlerCallableParams {
3
+ import type { Context, Reply, Request } from "@webiny/handler/types";
4
+ export interface S3EventHandlerCallableParams<Response = Reply> {
5
5
  request: Request;
6
6
  context: Context;
7
7
  event: S3Event;
8
8
  lambdaContext: LambdaContext;
9
9
  reply: Reply;
10
+ next: () => Promise<Response>;
10
11
  }
11
- export interface S3EventHandlerCallable<Response> {
12
- (params: S3EventHandlerCallableParams): Promise<Response | Reply>;
12
+ export interface S3EventHandlerCallable<Response = Reply> {
13
+ (params: S3EventHandlerCallableParams<Response>): Promise<Response>;
13
14
  }
14
15
  export declare class S3EventHandler<Response = any> extends Plugin {
15
16
  static type: string;
@@ -1,30 +1,21 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.createEventHandler = exports.S3EventHandler = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
7
  var _Plugin = require("@webiny/plugins/Plugin");
13
-
14
8
  class S3EventHandler extends _Plugin.Plugin {
9
+ static type = "handler.fastify.aws.s3.eventHandler";
15
10
  constructor(cb) {
16
11
  super();
17
- (0, _defineProperty2.default)(this, "cb", void 0);
18
12
  this.cb = cb;
19
13
  }
20
-
21
14
  }
22
-
23
15
  exports.S3EventHandler = S3EventHandler;
24
- (0, _defineProperty2.default)(S3EventHandler, "type", "handler.fastify.aws.s3.eventHandler");
25
-
26
16
  const createEventHandler = cb => {
27
17
  return new S3EventHandler(cb);
28
18
  };
19
+ exports.createEventHandler = createEventHandler;
29
20
 
30
- exports.createEventHandler = createEventHandler;
21
+ //# sourceMappingURL=S3EventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["S3EventHandler","Plugin","constructor","cb","createEventHandler"],"sources":["S3EventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { S3Event, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface S3EventHandlerCallableParams {\n request: Request;\n context: Context;\n event: S3Event;\n lambdaContext: LambdaContext;\n reply: Reply;\n}\nexport interface S3EventHandlerCallable<Response> {\n (params: S3EventHandlerCallableParams): Promise<Response | Reply>;\n}\n\nexport class S3EventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.s3.eventHandler\";\n\n public readonly cb: S3EventHandlerCallable<Response>;\n\n public constructor(cb: S3EventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: S3EventHandlerCallable<Response>) => {\n return new S3EventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAeO,MAAMA,cAAN,SAA6CC,cAA7C,CAAoD;EAKhDC,WAAW,CAACC,EAAD,EAAuC;IACrD;IADqD;IAErD,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARsD;;;8BAA9CH,c,UACqB,qC;;AAU3B,MAAMI,kBAAkB,GAAcD,EAAX,IAAoD;EAClF,OAAO,IAAIH,cAAJ,CAA6BG,EAA7B,CAAP;AACH,CAFM"}
1
+ {"version":3,"names":["_Plugin","require","S3EventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["S3EventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, S3Event } from \"@webiny/aws-sdk/types\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types\";\n\nexport interface S3EventHandlerCallableParams<Response = Reply> {\n request: Request;\n context: Context;\n event: S3Event;\n lambdaContext: LambdaContext;\n reply: Reply;\n next: () => Promise<Response>;\n}\n\nexport interface S3EventHandlerCallable<Response = Reply> {\n (params: S3EventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class S3EventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.s3.eventHandler\";\n\n public readonly cb: S3EventHandlerCallable<Response>;\n\n public constructor(cb: S3EventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: S3EventHandlerCallable<Response>) => {\n return new S3EventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAgBO,MAAMC,cAAc,SAAyBC,cAAM,CAAC;EACvD,OAAuBC,IAAI,GAAG,qCAAqC;EAI5DC,WAAWA,CAACC,EAAoC,EAAE;IACrD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,cAAA,GAAAA,cAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAAoC,IAAK;EAClF,OAAO,IAAIJ,cAAc,CAAWI,EAAE,CAAC;AAC3C,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { HandlerFactoryParams } from "../types";
2
+ export interface HandlerParams extends HandlerFactoryParams {
3
+ debug?: boolean;
4
+ }
package/s3/register.js ADDED
@@ -0,0 +1,25 @@
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-s3",
8
+ canUse: event => {
9
+ if (!Array.isArray(event.Records) || event.Records.length === 0) {
10
+ return false;
11
+ }
12
+ const [record] = event.Records;
13
+ return !!record.s3;
14
+ },
15
+ handle: async ({
16
+ params,
17
+ event,
18
+ context
19
+ }) => {
20
+ return (0, _index.createHandler)(params)(event, context);
21
+ }
22
+ });
23
+ _registry.registry.register(handler);
24
+
25
+ //# 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","s3","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import type { S3Event } from \"@webiny/aws-sdk/types\";\nimport { registry } from \"~/registry\";\nimport type { HandlerFactoryParams } from \"~/types\";\nimport { createSourceHandler } from \"~/sourceHandler\";\nimport { createHandler } from \"./index\";\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst handler = createSourceHandler<S3Event, HandlerParams>({\n name: \"handler-aws-s3\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.s3;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":";;AACA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAMA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAAyB;EACxDC,IAAI,EAAE,gBAAgB;EACtBC,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,OAAO,CAAC,CAACE,MAAM,CAACC,EAAE;EACtB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAER,KAAK;IAAES;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAAChB,OAAO,CAAC","ignoreList":[]}
package/sns/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { APIGatewayProxyResult, SNSEvent, Context as LambdaContext } from "@webiny/aws-sdk/types";
2
+ import type { HandlerFactoryParams } from "../types";
3
+ export * from "./plugins/SNSEventHandler";
4
+ export interface HandlerCallable {
5
+ (event: SNSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
6
+ }
7
+ export type HandlerParams = HandlerFactoryParams;
8
+ export declare const createHandler: (params: HandlerParams) => HandlerCallable;
package/sns/index.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ var _exportNames = {
8
+ createHandler: true
9
+ };
10
+ exports.createHandler = void 0;
11
+ var _handler = require("@webiny/handler");
12
+ var _plugins = require("../plugins");
13
+ var _SNSEventHandler = require("./plugins/SNSEventHandler");
14
+ Object.keys(_SNSEventHandler).forEach(function (key) {
15
+ if (key === "default" || key === "__esModule") return;
16
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
17
+ if (key in exports && exports[key] === _SNSEventHandler[key]) return;
18
+ Object.defineProperty(exports, key, {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _SNSEventHandler[key];
22
+ }
23
+ });
24
+ });
25
+ var _execute = require("../execute");
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
+ */
31
+ // @ts-expect-error
32
+
33
+ const url = "/webiny-sns-event";
34
+ const createHandler = params => {
35
+ return async (event, context) => {
36
+ const app = (0, _handler.createHandler)({
37
+ ...params,
38
+ options: {
39
+ logger: params.debug === true,
40
+ ...(params.options || {})
41
+ }
42
+ });
43
+ /**
44
+ * We always must add our default plugins to the app.
45
+ */
46
+ (0, _plugins.registerDefaultPlugins)(app.webiny);
47
+ /**
48
+ * There must be an event plugin for this handler to work.
49
+ */
50
+ const plugins = app.webiny.plugins.byType(_SNSEventHandler.SNSEventHandler.type).reverse();
51
+ if (plugins.length === 0) {
52
+ throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);
53
+ }
54
+ const handler = (0, _composedHandler.createComposedHandler)(plugins);
55
+ app.post(url, async (request, reply) => {
56
+ const params = {
57
+ request,
58
+ reply,
59
+ context: app.webiny,
60
+ event,
61
+ lambdaContext: context
62
+ };
63
+ const result = await handler(params);
64
+ if (result instanceof _reply.default) {
65
+ return result;
66
+ }
67
+ app.__webiny_raw_result = result;
68
+ return reply.send({});
69
+ });
70
+ return (0, _execute.execute)({
71
+ app,
72
+ url,
73
+ payload: event
74
+ });
75
+ };
76
+ };
77
+ exports.createHandler = createHandler;
78
+
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_handler","require","_plugins","_SNSEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","event","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","SNSEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","send","execute","payload"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n SNSEvent,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport type { SNSEventHandlerCallableParams } from \"./plugins/SNSEventHandler\";\nimport { SNSEventHandler } from \"./plugins/SNSEventHandler\";\nimport { execute } from \"~/execute\";\nimport type { HandlerFactoryParams } from \"~/types\";\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/SNSEventHandler\";\n\nexport interface HandlerCallable {\n (event: SNSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-sns-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, 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<SNSEventHandler>(SNSEventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n SNSEventHandler,\n SNSEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<SNSEventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n\n const result = await handler(\n params as unknown as SNSEventHandlerCallableParams<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: event\n });\n };\n};\n"],"mappings":";;;;;;;;;;AAKA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAF,OAAA;AAUAG,MAAA,CAAAC,IAAA,CAAAF,gBAAA,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,gBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,gBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AATA,IAAAS,QAAA,GAAAf,OAAA;AAMA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AACA,IAAAkB,gBAAA,GAAAlB,OAAA;AALA;AACA;AACA;AACA;;AAYA,MAAMmB,GAAG,GAAG,mBAAmB;AAExB,MAAMC,aAAa,GAAIC,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,EAAC;MAC1B,GAAGJ,MAAM;MACTK,OAAO,EAAE;QACLC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK,IAAI;QAC7B,IAAIP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBC,gCAAe,CAACC,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IAC1F,IAAIJ,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAG,IAAAC,sCAAqB,EAInCR,OAAO,CAAC;IAEVP,GAAG,CAACgB,IAAI,CAACrB,GAAG,EAAE,OAAOsB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAA0E,GAAG;QAC/EoB,OAAO;QACPC,KAAK;QACLnB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,KAAK;QACLqB,aAAa,EAAEpB;MACnB,CAAC;MAED,MAAMqB,MAAM,GAAG,MAAMN,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIuB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEApB,GAAG,CAACsB,mBAAmB,GAAGF,MAAM;MAChC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXxB,GAAG;MACHL,GAAG;MACH8B,OAAO,EAAE3B;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -0,0 +1,20 @@
1
+ import type { Context as LambdaContext, SNSEvent } from "@webiny/aws-sdk/types";
2
+ import { Plugin } from "@webiny/plugins/Plugin";
3
+ import type { Context, Reply, Request } from "@webiny/handler/types";
4
+ export interface SNSEventHandlerCallableParams<Response = Reply> {
5
+ request: Request;
6
+ reply: Reply;
7
+ context: Context;
8
+ event: SNSEvent;
9
+ lambdaContext: LambdaContext;
10
+ next: () => Promise<Response>;
11
+ }
12
+ export interface SNSEventHandlerCallable<Response = Reply> {
13
+ (params: SNSEventHandlerCallableParams<Response>): Promise<Response>;
14
+ }
15
+ export declare class SNSEventHandler<Response = any> extends Plugin {
16
+ static type: string;
17
+ readonly cb: SNSEventHandlerCallable<Response>;
18
+ constructor(cb: SNSEventHandlerCallable<Response>);
19
+ }
20
+ export declare const createEventHandler: <Response_1>(cb: SNSEventHandlerCallable<Response_1>) => SNSEventHandler<Response_1>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createEventHandler = exports.SNSEventHandler = void 0;
7
+ var _Plugin = require("@webiny/plugins/Plugin");
8
+ class SNSEventHandler extends _Plugin.Plugin {
9
+ static type = "handler.fastify.aws.sns.eventHandler";
10
+ constructor(cb) {
11
+ super();
12
+ this.cb = cb;
13
+ }
14
+ }
15
+ exports.SNSEventHandler = SNSEventHandler;
16
+ const createEventHandler = cb => {
17
+ return new SNSEventHandler(cb);
18
+ };
19
+ exports.createEventHandler = createEventHandler;
20
+
21
+ //# sourceMappingURL=SNSEventHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_Plugin","require","SNSEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["SNSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SNSEvent } from \"@webiny/aws-sdk/types\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types\";\n\nexport interface SNSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SNSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SNSEventHandlerCallable<Response = Reply> {\n (params: SNSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SNSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sns.eventHandler\";\n\n public readonly cb: SNSEventHandlerCallable<Response>;\n\n public constructor(cb: SNSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SNSEventHandlerCallable<Response>) => {\n return new SNSEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAgBO,MAAMC,eAAe,SAAyBC,cAAM,CAAC;EACxD,OAAuBC,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,eAAA,GAAAA,eAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAAqC,IAAK;EACnF,OAAO,IAAIJ,eAAe,CAAWI,EAAE,CAAC;AAC5C,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _registry = require("../registry");
4
+ var _index = require("./index");
5
+ var _sourceHandler = require("../sourceHandler");
6
+ const handler = (0, _sourceHandler.createSourceHandler)({
7
+ name: "handler-aws-sns",
8
+ canUse: event => {
9
+ if (!Array.isArray(event.Records) || event.Records.length === 0) {
10
+ return false;
11
+ }
12
+ const [record] = event.Records;
13
+ return !!record.Sns;
14
+ },
15
+ handle: async ({
16
+ params,
17
+ event,
18
+ context
19
+ }) => {
20
+ return (0, _index.createHandler)(params)(event, context);
21
+ }
22
+ });
23
+ _registry.registry.register(handler);
24
+
25
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_registry","require","_index","_sourceHandler","handler","createSourceHandler","name","canUse","event","Array","isArray","Records","length","record","Sns","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import type { SNSEvent } from \"@webiny/aws-sdk/types\";\nimport { registry } from \"~/registry\";\nimport type { HandlerParams } from \"./index\";\nimport { createHandler } from \"./index\";\nimport { createSourceHandler } from \"~/sourceHandler\";\n\nconst handler = createSourceHandler<SNSEvent, HandlerParams>({\n name: \"handler-aws-sns\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.Sns;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":";;AACA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAEA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAA0B;EACzDC,IAAI,EAAE,iBAAiB;EACvBC,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,OAAO,CAAC,CAACE,MAAM,CAACC,GAAG;EACvB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAER,KAAK;IAAES;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAAChB,OAAO,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from "./types";
2
+ export declare const createSourceHandler: <TEvent = HandlerEvent, TParams extends HandlerFactoryParams = HandlerFactoryParams>(handler: SourceHandler<TEvent, TParams, any>) => SourceHandler<TEvent, TParams, any>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createSourceHandler = void 0;
7
+ const createSourceHandler = handler => {
8
+ return handler;
9
+ };
10
+ exports.createSourceHandler = createSourceHandler;
11
+
12
+ //# sourceMappingURL=sourceHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createSourceHandler","handler","exports"],"sources":["sourceHandler.ts"],"sourcesContent":["import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from \"~/types\";\n\nexport const createSourceHandler = <\n TEvent = HandlerEvent,\n TParams extends HandlerFactoryParams = HandlerFactoryParams\n>(\n handler: SourceHandler<TEvent, TParams>\n) => {\n return handler;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,mBAAmB,GAI5BC,OAAuC,IACtC;EACD,OAAOA,OAAO;AAClB,CAAC;AAACC,OAAA,CAAAF,mBAAA,GAAAA,mBAAA","ignoreList":[]}
package/sqs/index.d.ts CHANGED
@@ -1,11 +1,8 @@
1
- import { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
2
- import { SQSEvent, Context as LambdaContext } from "aws-lambda";
3
- import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
1
+ import type { APIGatewayProxyResult, Context as LambdaContext, SQSEvent } from "@webiny/aws-sdk/types";
2
+ import type { HandlerFactoryParams } from "../types";
3
+ export * from "./plugins/SQSEventHandler";
4
4
  export interface HandlerCallable {
5
- (payload: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
6
- }
7
- export interface CreateHandlerParams extends BaseCreateHandlerParams {
8
- debug?: boolean;
5
+ (event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
9
6
  }
10
- export declare const createHandler: (params: CreateHandlerParams) => HandlerCallable;
11
- export * from "./plugins/SQSEventHandler";
7
+ export type HandlerParams = HandlerFactoryParams;
8
+ export declare const createHandler: (params: HandlerParams) => HandlerCallable;
package/sqs/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -9,13 +8,9 @@ var _exportNames = {
9
8
  createHandler: true
10
9
  };
11
10
  exports.createHandler = void 0;
12
-
13
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
14
-
15
11
  var _handler = require("@webiny/handler");
16
-
12
+ var _plugins = require("../plugins");
17
13
  var _SQSEventHandler = require("./plugins/SQSEventHandler");
18
-
19
14
  Object.keys(_SQSEventHandler).forEach(function (key) {
20
15
  if (key === "default" || key === "__esModule") return;
21
16
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -27,62 +22,61 @@ Object.keys(_SQSEventHandler).forEach(function (key) {
27
22
  }
28
23
  });
29
24
  });
30
-
31
- var _plugins = require("../plugins");
32
-
33
25
  var _execute = require("../execute");
34
-
35
- const Reply = require("fastify/lib/reply");
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
+ */
31
+ // @ts-expect-error
36
32
 
37
33
  const url = "/webiny-sqs-event";
38
-
39
34
  const createHandler = params => {
40
- return (payload, context) => {
35
+ return async (event, context) => {
41
36
  const app = (0, _handler.createHandler)({
42
- plugins: params.plugins,
43
- options: (0, _objectSpread2.default)({
44
- logger: params.debug === true
45
- }, params.options || {})
37
+ ...params,
38
+ options: {
39
+ logger: params.debug === true,
40
+ ...(params.options || {})
41
+ }
46
42
  });
47
43
  /**
48
44
  * We always must add our default plugins to the app.
49
45
  */
50
-
51
46
  (0, _plugins.registerDefaultPlugins)(app.webiny);
52
47
  /**
53
48
  * There must be an event plugin for this handler to work.
54
49
  */
55
-
56
- const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type);
57
- const handler = plugins.shift();
58
-
59
- if (!handler) {
50
+ const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type).reverse();
51
+ if (plugins.length === 0) {
60
52
  throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);
61
53
  }
62
-
54
+ const handler = (0, _composedHandler.createComposedHandler)(plugins);
63
55
  app.post(url, async (request, reply) => {
64
56
  const params = {
65
57
  request,
66
58
  reply,
67
59
  context: app.webiny,
68
- event: payload,
60
+ event,
69
61
  lambdaContext: context
70
62
  };
71
- const result = await handler.cb(params);
72
-
73
- if (result instanceof Reply) {
63
+ const result = await handler(params);
64
+ if (result instanceof _reply.default) {
74
65
  return result;
75
66
  }
76
-
77
67
  app.__webiny_raw_result = result;
78
- return reply.send({});
68
+ if (!reply.sent) {
69
+ reply.send({});
70
+ }
71
+ return reply;
79
72
  });
80
73
  return (0, _execute.execute)({
81
74
  app,
82
75
  url,
83
- payload
76
+ payload: event
84
77
  });
85
78
  };
86
79
  };
80
+ exports.createHandler = createHandler;
87
81
 
88
- exports.createHandler = createHandler;
82
+ //# sourceMappingURL=index.js.map
package/sqs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","plugins","options","logger","debug","registerDefaultPlugins","webiny","byType","SQSEventHandler","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 { SQSEvent, Context as LambdaContext } from \"aws-lambda\";\nimport { SQSEventHandler, SQSEventHandlerCallableParams } from \"./plugins/SQSEventHandler\";\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 {\n (payload: SQSEvent, 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 plugins: params.plugins,\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<SQSEventHandler>(SQSEventHandler.type);\n const handler = plugins.shift();\n if (!handler) {\n throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);\n }\n\n app.post(url, async (request, reply) => {\n const params: SQSEventHandlerCallableParams = {\n request,\n reply,\n context: app.webiny,\n event: 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/SQSEventHandler\";\n"],"mappings":";;;;;;;;;;;;;;AAAA;;AAMA;;AA8DA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AA5DA;;AACA;;AALA,MAAMA,KAAK,GAAGC,OAAO,CAAC,mBAAD,CAArB;;AAOA,MAAMC,GAAG,GAAG,mBAAZ;;AAUO,MAAMC,aAAa,GAAIC,MAAD,IAAkD;EAC3E,OAAO,CAACC,OAAD,EAAUC,OAAV,KAAsB;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAA,EAAkB;MAC1BC,OAAO,EAAEL,MAAM,CAACK,OADU;MAE1BC,OAAO;QACHC,MAAM,EAAEP,MAAM,CAACQ,KAAP,KAAiB;MADtB,GAECR,MAAM,CAACM,OAAP,IAAkB,EAFnB;IAFmB,CAAlB,CAAZ;IAOA;AACR;AACA;;IACQ,IAAAG,+BAAA,EAAuBN,GAAG,CAACO,MAA3B;IACA;AACR;AACA;;IACQ,MAAML,OAAO,GAAGF,GAAG,CAACO,MAAJ,CAAWL,OAAX,CAAmBM,MAAnB,CAA2CC,gCAAA,CAAgBC,IAA3D,CAAhB;IACA,MAAMC,OAAO,GAAGT,OAAO,CAACU,KAAR,EAAhB;;IACA,IAAI,CAACD,OAAL,EAAc;MACV,MAAM,IAAIE,KAAJ,CAAW,oEAAX,CAAN;IACH;;IAEDb,GAAG,CAACc,IAAJ,CAASnB,GAAT,EAAc,OAAOoB,OAAP,EAAgBC,KAAhB,KAA0B;MACpC,MAAMnB,MAAqC,GAAG;QAC1CkB,OAD0C;QAE1CC,KAF0C;QAG1CjB,OAAO,EAAEC,GAAG,CAACO,MAH6B;QAI1CU,KAAK,EAAEnB,OAJmC;QAK1CoB,aAAa,EAAEnB;MAL2B,CAA9C;MAOA,MAAMoB,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAR,CAAWvB,MAAX,CAArB;;MAEA,IAAIsB,MAAM,YAAY1B,KAAtB,EAA6B;QACzB,OAAO0B,MAAP;MACH;;MAEAnB,GAAD,CAAaqB,mBAAb,GAAmCF,MAAnC;MACA,OAAOH,KAAK,CAACM,IAAN,CAAW,EAAX,CAAP;IACH,CAhBD;IAiBA,OAAO,IAAAC,gBAAA,EAAQ;MACXvB,GADW;MAEXL,GAFW;MAGXG;IAHW,CAAR,CAAP;EAKH,CA3CD;AA4CH,CA7CM"}
1
+ {"version":3,"names":["_handler","require","_plugins","_SQSEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","event","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","SQSEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","sent","send","execute","payload"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n SQSEvent\n} from \"@webiny/aws-sdk/types\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport type { SQSEventHandlerCallableParams } from \"~/sqs/plugins/SQSEventHandler\";\nimport { SQSEventHandler } from \"~/sqs/plugins/SQSEventHandler\";\nimport { execute } from \"~/execute\";\nimport type { HandlerFactoryParams } from \"~/types\";\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/SQSEventHandler\";\n\nexport interface HandlerCallable {\n (event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-sqs-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, 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<SQSEventHandler>(SQSEventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n SQSEventHandler,\n SQSEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<SQSEventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n\n const result = await handler(\n params as unknown as SQSEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n if (!reply.sent) {\n reply.send({});\n }\n return reply;\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"mappings":";;;;;;;;;;AAKA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAF,OAAA;AAUAG,MAAA,CAAAC,IAAA,CAAAF,gBAAA,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,gBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,gBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AATA,IAAAS,QAAA,GAAAf,OAAA;AAMA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AACA,IAAAkB,gBAAA,GAAAlB,OAAA;AALA;AACA;AACA;AACA;;AAYA,MAAMmB,GAAG,GAAG,mBAAmB;AAExB,MAAMC,aAAa,GAAIC,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,EAAC;MAC1B,GAAGJ,MAAM;MACTK,OAAO,EAAE;QACLC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK,IAAI;QAC7B,IAAIP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBC,gCAAe,CAACC,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IAC1F,IAAIJ,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAG,IAAAC,sCAAqB,EAInCR,OAAO,CAAC;IAEVP,GAAG,CAACgB,IAAI,CAACrB,GAAG,EAAE,OAAOsB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAA0E,GAAG;QAC/EoB,OAAO;QACPC,KAAK;QACLnB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,KAAK;QACLqB,aAAa,EAAEpB;MACnB,CAAC;MAED,MAAMqB,MAAM,GAAG,MAAMN,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIuB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEApB,GAAG,CAACsB,mBAAmB,GAAGF,MAAM;MAChC,IAAI,CAACF,KAAK,CAACK,IAAI,EAAE;QACbL,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;MAClB;MACA,OAAON,KAAK;IAChB,CAAC,CAAC;IACF,OAAO,IAAAO,gBAAO,EAAC;MACXzB,GAAG;MACHL,GAAG;MACH+B,OAAO,EAAE5B;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -1,15 +1,16 @@
1
+ import type { Context as LambdaContext, SQSEvent } from "@webiny/aws-sdk/types";
1
2
  import { Plugin } from "@webiny/plugins/Plugin";
2
- import { Request, Reply, Context } from "@webiny/handler/types";
3
- import { SQSEvent, Context as LambdaContext } from "aws-lambda";
4
- export interface SQSEventHandlerCallableParams {
3
+ import type { Context, Reply, Request } from "@webiny/handler/types";
4
+ export interface SQSEventHandlerCallableParams<Response = Reply> {
5
5
  request: Request;
6
6
  reply: Reply;
7
7
  context: Context;
8
8
  event: SQSEvent;
9
9
  lambdaContext: LambdaContext;
10
+ next: () => Promise<Response>;
10
11
  }
11
- export interface SQSEventHandlerCallable<Response> {
12
- (params: SQSEventHandlerCallableParams): Promise<Response | Reply>;
12
+ export interface SQSEventHandlerCallable<Response = Reply> {
13
+ (params: SQSEventHandlerCallableParams<Response>): Promise<Response>;
13
14
  }
14
15
  export declare class SQSEventHandler<Response = any> extends Plugin {
15
16
  static type: string;
@@ -1,30 +1,21 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.createEventHandler = exports.SQSEventHandler = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
7
  var _Plugin = require("@webiny/plugins/Plugin");
13
-
14
8
  class SQSEventHandler extends _Plugin.Plugin {
9
+ static type = "handler.fastify.aws.sqs.eventHandler";
15
10
  constructor(cb) {
16
11
  super();
17
- (0, _defineProperty2.default)(this, "cb", void 0);
18
12
  this.cb = cb;
19
13
  }
20
-
21
14
  }
22
-
23
15
  exports.SQSEventHandler = SQSEventHandler;
24
- (0, _defineProperty2.default)(SQSEventHandler, "type", "handler.fastify.aws.sqs.eventHandler");
25
-
26
16
  const createEventHandler = cb => {
27
17
  return new SQSEventHandler(cb);
28
18
  };
19
+ exports.createEventHandler = createEventHandler;
29
20
 
30
- exports.createEventHandler = createEventHandler;
21
+ //# sourceMappingURL=SQSEventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["SQSEventHandler","Plugin","constructor","cb","createEventHandler"],"sources":["SQSEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Reply, Context } from \"@webiny/handler/types\";\nimport { SQSEvent, Context as LambdaContext } from \"aws-lambda\";\n\nexport interface SQSEventHandlerCallableParams {\n request: Request;\n reply: Reply;\n context: Context;\n event: SQSEvent;\n lambdaContext: LambdaContext;\n}\nexport interface SQSEventHandlerCallable<Response> {\n (params: SQSEventHandlerCallableParams): Promise<Response | Reply>;\n}\n\nexport class SQSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: SQSEventHandlerCallable<Response>;\n\n public constructor(cb: SQSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SQSEventHandlerCallable<Response>) => {\n return new SQSEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAeO,MAAMA,eAAN,SAA8CC,cAA9C,CAAqD;EAKjDC,WAAW,CAACC,EAAD,EAAwC;IACtD;IADsD;IAEtD,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARuD;;;8BAA/CH,e,UACqB,sC;;AAU3B,MAAMI,kBAAkB,GAAcD,EAAX,IAAqD;EACnF,OAAO,IAAIH,eAAJ,CAA8BG,EAA9B,CAAP;AACH,CAFM"}
1
+ {"version":3,"names":["_Plugin","require","SQSEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["SQSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SQSEvent } from \"@webiny/aws-sdk/types\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types\";\n\nexport interface SQSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SQSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SQSEventHandlerCallable<Response = Reply> {\n (params: SQSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SQSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: SQSEventHandlerCallable<Response>;\n\n public constructor(cb: SQSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SQSEventHandlerCallable<Response>) => {\n return new SQSEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAgBO,MAAMC,eAAe,SAAyBC,cAAM,CAAC;EACxD,OAAuBC,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,eAAA,GAAAA,eAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAAqC,IAAK;EACnF,OAAO,IAAIJ,eAAe,CAAWI,EAAE,CAAC;AAC5C,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _registry = require("../registry");
4
+ var _index = require("./index");
5
+ var _sourceHandler = require("../sourceHandler");
6
+ const handler = (0, _sourceHandler.createSourceHandler)({
7
+ name: "handler-aws-sqs",
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:sqs";
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