@webiny/handler-aws 0.0.0-unstable.1e66d121db → 0.0.0-unstable.2696f9d9e8

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 (82) hide show
  1. package/createHandler.d.ts +2 -0
  2. package/createHandler.js +29 -0
  3. package/createHandler.js.map +1 -0
  4. package/dynamodb/index.d.ts +5 -8
  5. package/dynamodb/index.js +18 -29
  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 +19 -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.js +7 -14
  23. package/execute.js.map +1 -1
  24. package/gateway/index.d.ts +6 -10
  25. package/gateway/index.js +48 -22
  26. package/gateway/index.js.map +1 -1
  27. package/gateway/register.d.ts +1 -0
  28. package/gateway/register.js +21 -0
  29. package/gateway/register.js.map +1 -0
  30. package/index.d.ts +33 -5
  31. package/index.js +146 -29
  32. package/index.js.map +1 -1
  33. package/package.json +18 -16
  34. package/plugins/handlerClient.js +9 -18
  35. package/plugins/handlerClient.js.map +1 -1
  36. package/plugins/index.js +2 -3
  37. package/plugins/index.js.map +1 -1
  38. package/raw/index.d.ts +1 -5
  39. package/raw/index.js +13 -29
  40. package/raw/index.js.map +1 -1
  41. package/raw/plugins/RawEventHandler.d.ts +2 -2
  42. package/raw/plugins/RawEventHandler.js +6 -6
  43. package/raw/plugins/RawEventHandler.js.map +1 -1
  44. package/registry.d.ts +11 -0
  45. package/registry.js +38 -0
  46. package/registry.js.map +1 -0
  47. package/s3/index.d.ts +7 -9
  48. package/s3/index.js +21 -32
  49. package/s3/index.js.map +1 -1
  50. package/s3/plugins/S3EventHandler.d.ts +6 -5
  51. package/s3/plugins/S3EventHandler.js +3 -12
  52. package/s3/plugins/S3EventHandler.js.map +1 -1
  53. package/s3/register.d.ts +4 -0
  54. package/s3/register.js +25 -0
  55. package/s3/register.js.map +1 -0
  56. package/sns/index.d.ts +9 -0
  57. package/sns/index.js +77 -0
  58. package/sns/index.js.map +1 -0
  59. package/sns/plugins/SNSEventHandler.d.ts +20 -0
  60. package/sns/plugins/SNSEventHandler.js +21 -0
  61. package/sns/plugins/SNSEventHandler.js.map +1 -0
  62. package/sns/register.d.ts +1 -0
  63. package/sns/register.js +25 -0
  64. package/sns/register.js.map +1 -0
  65. package/sourceHandler.d.ts +2 -0
  66. package/sourceHandler.js +12 -0
  67. package/sourceHandler.js.map +1 -0
  68. package/sqs/index.d.ts +7 -9
  69. package/sqs/index.js +21 -32
  70. package/sqs/index.js.map +1 -1
  71. package/sqs/plugins/SQSEventHandler.d.ts +6 -5
  72. package/sqs/plugins/SQSEventHandler.js +3 -12
  73. package/sqs/plugins/SQSEventHandler.js.map +1 -1
  74. package/sqs/register.d.ts +1 -0
  75. package/sqs/register.js +28 -0
  76. package/sqs/register.js.map +1 -0
  77. package/types.d.ts +25 -1
  78. package/types.js +37 -9
  79. package/types.js.map +1 -1
  80. package/utils/composedHandler.d.ts +6 -0
  81. package/utils/composedHandler.js +24 -0
  82. package/utils/composedHandler.js.map +1 -0
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 { registry } from \"~/registry\";\nimport { HandlerFactoryParams } from \"~/types\";\nimport { S3Event } from \"aws-lambda\";\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":";;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAGA,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"}
package/sns/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { HandlerFactoryParams } from "../types";
2
+ import { APIGatewayProxyResult, SNSEvent } from "aws-lambda";
3
+ import { Context as LambdaContext } from "aws-lambda/handler";
4
+ export * from "./plugins/SNSEventHandler";
5
+ export interface HandlerCallable {
6
+ (event: SNSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
7
+ }
8
+ export declare type HandlerParams = HandlerFactoryParams;
9
+ export declare const createHandler: (params: HandlerParams) => HandlerCallable;
package/sns/index.js ADDED
@@ -0,0 +1,77 @@
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
+ */ // @ts-expect-error
31
+ const url = "/webiny-sns-event";
32
+ const createHandler = params => {
33
+ return async (event, context) => {
34
+ const app = (0, _handler.createHandler)({
35
+ ...params,
36
+ options: {
37
+ logger: params.debug === true,
38
+ ...(params.options || {})
39
+ }
40
+ });
41
+ /**
42
+ * We always must add our default plugins to the app.
43
+ */
44
+ (0, _plugins.registerDefaultPlugins)(app.webiny);
45
+ /**
46
+ * There must be an event plugin for this handler to work.
47
+ */
48
+ const plugins = app.webiny.plugins.byType(_SNSEventHandler.SNSEventHandler.type).reverse();
49
+ if (plugins.length === 0) {
50
+ throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);
51
+ }
52
+ const handler = (0, _composedHandler.createComposedHandler)(plugins);
53
+ app.post(url, async (request, reply) => {
54
+ const params = {
55
+ request,
56
+ reply,
57
+ context: app.webiny,
58
+ event,
59
+ lambdaContext: context
60
+ };
61
+ const result = await handler(params);
62
+ if (result instanceof _reply.default) {
63
+ return result;
64
+ }
65
+ app.__webiny_raw_result = result;
66
+ return reply.send({});
67
+ });
68
+ return (0, _execute.execute)({
69
+ app,
70
+ url,
71
+ payload: event
72
+ });
73
+ };
74
+ };
75
+ exports.createHandler = createHandler;
76
+
77
+ //# 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 { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { SNSEventHandler, SNSEventHandlerCallableParams } from \"./plugins/SNSEventHandler\";\nimport { execute } from \"~/execute\";\nimport { HandlerFactoryParams } from \"~/types\";\nimport { APIGatewayProxyResult, SNSEvent } from \"aws-lambda\";\nimport { Context as LambdaContext } from \"aws-lambda/handler\";\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":";;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAYAG,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;AAXA,IAAAS,QAAA,GAAAf,OAAA;AAQA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AACA,IAAAkB,gBAAA,GAAAlB,OAAA;AALA;AACA;AACA,GAFA,CAGA;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,CAAE,oEAAmE,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"}
@@ -0,0 +1,20 @@
1
+ import { Plugin } from "@webiny/plugins/Plugin";
2
+ import { Context, Reply, Request } from "@webiny/handler/types";
3
+ import { Context as LambdaContext, SNSEvent } from "aws-lambda";
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 { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, Reply, Request } from \"@webiny/handler/types\";\nimport { Context as LambdaContext, SNSEvent } from \"aws-lambda\";\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":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAiBO,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"}
@@ -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 { registry } from \"~/registry\";\nimport { SNSEvent } from \"aws-lambda\";\nimport { createHandler, HandlerParams } 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":";;AAAA,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"}
@@ -0,0 +1,2 @@
1
+ import { 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 { 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"}
package/sqs/index.d.ts CHANGED
@@ -1,11 +1,9 @@
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 { HandlerFactoryParams } from "../types";
2
+ import { APIGatewayProxyResult, SQSEvent } from "aws-lambda";
3
+ import { Context as LambdaContext } from "aws-lambda/handler";
4
+ export * from "./plugins/SQSEventHandler";
4
5
  export interface HandlerCallable {
5
- (payload: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
6
- }
7
- export interface CreateHandlerParams extends BaseCreateHandlerParams {
8
- debug?: boolean;
6
+ (event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
9
7
  }
10
- export declare const createHandler: (params: CreateHandlerParams) => HandlerCallable;
11
- export * from "./plugins/SQSEventHandler";
8
+ export declare type HandlerParams = HandlerFactoryParams;
9
+ 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,56 @@ 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");
36
-
26
+ var _reply = _interopRequireDefault(require("fastify/lib/reply"));
27
+ var _composedHandler = require("../utils/composedHandler");
28
+ /**
29
+ * We need a class, not an interface exported from types.
30
+ */ // @ts-expect-error
37
31
  const url = "/webiny-sqs-event";
38
-
39
32
  const createHandler = params => {
40
- return (payload, context) => {
33
+ return async (event, context) => {
41
34
  const app = (0, _handler.createHandler)({
42
- plugins: params.plugins,
43
- options: (0, _objectSpread2.default)({
44
- logger: params.debug === true
45
- }, params.options || {})
35
+ ...params,
36
+ options: {
37
+ logger: params.debug === true,
38
+ ...(params.options || {})
39
+ }
46
40
  });
47
41
  /**
48
42
  * We always must add our default plugins to the app.
49
43
  */
50
-
51
44
  (0, _plugins.registerDefaultPlugins)(app.webiny);
52
45
  /**
53
46
  * There must be an event plugin for this handler to work.
54
47
  */
55
-
56
- const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type);
57
- const handler = plugins.shift();
58
-
59
- if (!handler) {
48
+ const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type).reverse();
49
+ if (plugins.length === 0) {
60
50
  throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);
61
51
  }
62
-
52
+ const handler = (0, _composedHandler.createComposedHandler)(plugins);
63
53
  app.post(url, async (request, reply) => {
64
54
  const params = {
65
55
  request,
66
56
  reply,
67
57
  context: app.webiny,
68
- event: payload,
58
+ event,
69
59
  lambdaContext: context
70
60
  };
71
- const result = await handler.cb(params);
72
-
73
- if (result instanceof Reply) {
61
+ const result = await handler(params);
62
+ if (result instanceof _reply.default) {
74
63
  return result;
75
64
  }
76
-
77
65
  app.__webiny_raw_result = result;
78
66
  return reply.send({});
79
67
  });
80
68
  return (0, _execute.execute)({
81
69
  app,
82
70
  url,
83
- payload
71
+ payload: event
84
72
  });
85
73
  };
86
74
  };
75
+ exports.createHandler = createHandler;
87
76
 
88
- exports.createHandler = createHandler;
77
+ //# 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","send","execute","payload"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { SQSEventHandler, SQSEventHandlerCallableParams } from \"~/sqs/plugins/SQSEventHandler\";\nimport { execute } from \"~/execute\";\nimport { HandlerFactoryParams } from \"~/types\";\nimport { APIGatewayProxyResult, SQSEvent } from \"aws-lambda\";\nimport { Context as LambdaContext } from \"aws-lambda/handler\";\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 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;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAYAG,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;AAXA,IAAAS,QAAA,GAAAf,OAAA;AAQA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AACA,IAAAkB,gBAAA,GAAAlB,OAAA;AALA;AACA;AACA,GAFA,CAGA;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,CAAE,oEAAmE,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"}
@@ -1,15 +1,16 @@
1
1
  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 {
2
+ import { Context, Reply, Request } from "@webiny/handler/types";
3
+ import { Context as LambdaContext, SQSEvent } from "aws-lambda";
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 { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, Reply, Request } from \"@webiny/handler/types\";\nimport { Context as LambdaContext, SQSEvent } from \"aws-lambda\";\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":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAiBO,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"}
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_registry","require","_index","_sourceHandler","handler","createSourceHandler","name","canUse","event","Array","isArray","Records","length","record","eventSource","toLowerCase","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import { registry } from \"~/registry\";\nimport { SQSEvent } from \"aws-lambda\";\nimport { createHandler, HandlerParams } from \"./index\";\nimport { createSourceHandler } from \"~/sourceHandler\";\n\nconst handler = createSourceHandler<SQSEvent, HandlerParams>({\n name: \"handler-aws-sqs\",\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:sqs\";\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":";;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,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,IAAI,OAAOE,MAAM,CAACC,WAAW,KAAK,QAAQ,EAAE;MACxC,OAAO,KAAK;IAChB;IACA,OAAOD,MAAM,CAACC,WAAW,CAACC,WAAW,CAAC,CAAC,KAAK,SAAS;EACzD,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAET,KAAK;IAAEU;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACT,KAAK,EAAEU,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAACjB,OAAO,CAAC"}
package/types.d.ts CHANGED
@@ -1,6 +1,30 @@
1
- import { APIGatewayEvent, Context as LambdaContext } from "aws-lambda";
1
+ import { APIGatewayEvent, Context as LambdaContext, APIGatewayEventRequestContextWithAuthorizer, DynamoDBStreamEvent, EventBridgeEvent, S3Event, SQSEvent, SNSEvent } from "aws-lambda";
2
2
  import "fastify";
3
+ import { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
4
+ import { LambdaFastifyOptions as LambdaOptions } from "@fastify/aws-lambda";
5
+ export { HandlerRegistry } from "./registry";
3
6
  export * from "@webiny/handler/types";
7
+ export { APIGatewayEvent, LambdaContext, APIGatewayEventRequestContextWithAuthorizer };
8
+ export declare type HandlerEvent = APIGatewayEvent | SNSEvent | SQSEvent | S3Event | EventBridgeEvent<string, string> | DynamoDBStreamEvent;
9
+ export interface EventResolver<T = any> {
10
+ (event: HandlerEvent, context: LambdaContext): T;
11
+ }
12
+ export interface HandlerFactoryParams extends BaseCreateHandlerParams {
13
+ lambdaOptions?: LambdaOptions;
14
+ }
15
+ export interface HandlerFactory<T extends HandlerFactoryParams = HandlerFactoryParams, R = any> {
16
+ (params: T): EventResolver<R>;
17
+ }
18
+ export interface HandlerParams<E, P extends HandlerFactoryParams> {
19
+ params: P;
20
+ event: E;
21
+ context: LambdaContext;
22
+ }
23
+ export interface SourceHandler<E = HandlerEvent, P extends HandlerFactoryParams = HandlerFactoryParams, T = any> {
24
+ name: string;
25
+ canUse: (event: Partial<E>, context: LambdaContext) => boolean;
26
+ handle: (params: HandlerParams<E, P>) => Promise<T>;
27
+ }
4
28
  export declare enum Base64EncodeHeader {
5
29
  encoded = "x-webiny-base64-encoded",
6
30
  binary = "x-webiny-binary"
package/types.js CHANGED
@@ -4,14 +4,41 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
- Base64EncodeHeader: true
7
+ Base64EncodeHeader: true,
8
+ APIGatewayEvent: true,
9
+ LambdaContext: true,
10
+ APIGatewayEventRequestContextWithAuthorizer: true,
11
+ HandlerRegistry: true
8
12
  };
13
+ Object.defineProperty(exports, "APIGatewayEvent", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _awsLambda.APIGatewayEvent;
17
+ }
18
+ });
19
+ Object.defineProperty(exports, "APIGatewayEventRequestContextWithAuthorizer", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _awsLambda.APIGatewayEventRequestContextWithAuthorizer;
23
+ }
24
+ });
9
25
  exports.Base64EncodeHeader = void 0;
10
-
26
+ Object.defineProperty(exports, "HandlerRegistry", {
27
+ enumerable: true,
28
+ get: function () {
29
+ return _registry.HandlerRegistry;
30
+ }
31
+ });
32
+ Object.defineProperty(exports, "LambdaContext", {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _awsLambda.Context;
36
+ }
37
+ });
38
+ var _awsLambda = require("aws-lambda");
11
39
  require("fastify");
12
-
40
+ var _registry = require("./registry");
13
41
  var _types = require("@webiny/handler/types");
14
-
15
42
  Object.keys(_types).forEach(function (key) {
16
43
  if (key === "default" || key === "__esModule") return;
17
44
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -23,10 +50,11 @@ Object.keys(_types).forEach(function (key) {
23
50
  }
24
51
  });
25
52
  });
26
- let Base64EncodeHeader;
27
- exports.Base64EncodeHeader = Base64EncodeHeader;
28
-
29
- (function (Base64EncodeHeader) {
53
+ let Base64EncodeHeader = /*#__PURE__*/function (Base64EncodeHeader) {
30
54
  Base64EncodeHeader["encoded"] = "x-webiny-base64-encoded";
31
55
  Base64EncodeHeader["binary"] = "x-webiny-binary";
32
- })(Base64EncodeHeader || (exports.Base64EncodeHeader = Base64EncodeHeader = {}));
56
+ return Base64EncodeHeader;
57
+ }({});
58
+ exports.Base64EncodeHeader = Base64EncodeHeader;
59
+
60
+ //# sourceMappingURL=types.js.map
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["Base64EncodeHeader"],"sources":["types.ts"],"sourcesContent":["import { APIGatewayEvent, Context as LambdaContext } from \"aws-lambda\";\nimport \"fastify\";\nexport * from \"@webiny/handler/types\";\n\nexport enum Base64EncodeHeader {\n encoded = \"x-webiny-base64-encoded\",\n binary = \"x-webiny-binary\"\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n __webiny_raw_result: any;\n }\n interface FastifyRequest {\n awsLambda: {\n event: APIGatewayEvent;\n context: LambdaContext;\n };\n }\n}\n"],"mappings":";;;;;;;;;;AACA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;IAEYA,kB;;;WAAAA,kB;EAAAA,kB;EAAAA,kB;GAAAA,kB,kCAAAA,kB"}
1
+ {"version":3,"names":["_awsLambda","require","_registry","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","Base64EncodeHeader"],"sources":["types.ts"],"sourcesContent":["import {\n APIGatewayEvent,\n Context as LambdaContext,\n APIGatewayEventRequestContextWithAuthorizer,\n DynamoDBStreamEvent,\n EventBridgeEvent,\n S3Event,\n SQSEvent,\n SNSEvent\n} from \"aws-lambda\";\nimport \"fastify\";\nimport { CreateHandlerParams as BaseCreateHandlerParams } from \"@webiny/handler\";\nimport { LambdaFastifyOptions as LambdaOptions } from \"@fastify/aws-lambda\";\n\nexport { HandlerRegistry } from \"~/registry\";\n\nexport * from \"@webiny/handler/types\";\n\nexport { APIGatewayEvent, LambdaContext, APIGatewayEventRequestContextWithAuthorizer };\n\nexport type HandlerEvent =\n | APIGatewayEvent\n | SNSEvent\n | SQSEvent\n | S3Event\n | EventBridgeEvent<string, string>\n | DynamoDBStreamEvent;\n\nexport interface EventResolver<T = any> {\n (event: HandlerEvent, context: LambdaContext): T;\n}\n\nexport interface HandlerFactoryParams extends BaseCreateHandlerParams {\n lambdaOptions?: LambdaOptions;\n}\n\nexport interface HandlerFactory<T extends HandlerFactoryParams = HandlerFactoryParams, R = any> {\n (params: T): EventResolver<R>;\n}\n\nexport interface HandlerParams<E, P extends HandlerFactoryParams> {\n params: P;\n event: E;\n context: LambdaContext;\n}\n\nexport interface SourceHandler<\n E = HandlerEvent,\n P extends HandlerFactoryParams = HandlerFactoryParams,\n T = any\n> {\n name: string;\n canUse: (event: Partial<E>, context: LambdaContext) => boolean;\n handle: (params: HandlerParams<E, P>) => Promise<T>;\n}\n\nexport enum Base64EncodeHeader {\n encoded = \"x-webiny-base64-encoded\",\n binary = \"x-webiny-binary\"\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n __webiny_raw_result: any;\n }\n interface FastifyRequest {\n awsLambda: {\n event: APIGatewayEvent;\n context: LambdaContext;\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAUAA,OAAA;AAIA,IAAAC,SAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAF,MAAA,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,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAAsC,IAwC1BS,kBAAkB,0BAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA;AAAAJ,OAAA,CAAAI,kBAAA,GAAAA,kBAAA"}
@@ -0,0 +1,6 @@
1
+ import { Plugin } from "@webiny/plugins/types";
2
+ declare type WrappedInput<TInput, TOutput> = TInput & {
3
+ next: () => Promise<TOutput>;
4
+ };
5
+ export declare const createComposedHandler: <P extends Plugin<Record<string, any>>, TInput, TOutput>(plugins: P[]) => import("@webiny/utils").NextAsyncProcessor<WrappedInput<TInput, TOutput>, TOutput>;
6
+ export {};