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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/createHandler.js +16 -22
  2. package/createHandler.js.map +1 -1
  3. package/dynamodb/index.js +34 -49
  4. package/dynamodb/index.js.map +1 -1
  5. package/dynamodb/plugins/DynamoDBEventHandler.js +10 -9
  6. package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
  7. package/dynamodb/register.js +8 -18
  8. package/dynamodb/register.js.map +1 -1
  9. package/eventBridge/index.js +34 -49
  10. package/eventBridge/index.js.map +1 -1
  11. package/eventBridge/plugins/EventBridgeEventHandler.js +10 -9
  12. package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
  13. package/eventBridge/register.js +3 -11
  14. package/eventBridge/register.js.map +1 -1
  15. package/execute.js +52 -60
  16. package/execute.js.map +1 -1
  17. package/gateway/index.js +39 -67
  18. package/gateway/index.js.map +1 -1
  19. package/gateway/register.js +3 -11
  20. package/gateway/register.js.map +1 -1
  21. package/index.js +8 -39
  22. package/package.json +8 -8
  23. package/plugins/index.js +3 -4
  24. package/plugins/index.js.map +1 -1
  25. package/raw/index.js +38 -63
  26. package/raw/index.js.map +1 -1
  27. package/raw/plugins/RawEventHandler.js +11 -21
  28. package/raw/plugins/RawEventHandler.js.map +1 -1
  29. package/registry.js +17 -32
  30. package/registry.js.map +1 -1
  31. package/s3/index.js +34 -49
  32. package/s3/index.js.map +1 -1
  33. package/s3/plugins/S3EventHandler.js +10 -9
  34. package/s3/plugins/S3EventHandler.js.map +1 -1
  35. package/s3/register.js +7 -15
  36. package/s3/register.js.map +1 -1
  37. package/sns/index.js +34 -49
  38. package/sns/index.js.map +1 -1
  39. package/sns/plugins/SNSEventHandler.js +10 -9
  40. package/sns/plugins/SNSEventHandler.js.map +1 -1
  41. package/sns/register.js +7 -15
  42. package/sns/register.js.map +1 -1
  43. package/sourceHandler.js +2 -3
  44. package/sourceHandler.js.map +1 -1
  45. package/sqs/index.js +35 -52
  46. package/sqs/index.js.map +1 -1
  47. package/sqs/plugins/SQSEventHandler.js +10 -9
  48. package/sqs/plugins/SQSEventHandler.js.map +1 -1
  49. package/sqs/register.js +8 -18
  50. package/sqs/register.js.map +1 -1
  51. package/types.js +5 -4
  52. package/types.js.map +1 -1
  53. package/utils/composedHandler.js +5 -14
  54. package/utils/composedHandler.js.map +1 -1
  55. package/utils/index.js +0 -2
  56. package/utils/timer/CustomTimer.js +9 -8
  57. package/utils/timer/CustomTimer.js.map +1 -1
  58. package/utils/timer/Timer.js +12 -13
  59. package/utils/timer/Timer.js.map +1 -1
  60. package/utils/timer/abstractions/ITimer.js +0 -3
  61. package/utils/timer/factory.js +7 -8
  62. package/utils/timer/factory.js.map +1 -1
  63. package/utils/timer/index.js +0 -2
  64. package/index.js.map +0 -1
  65. package/utils/index.js.map +0 -1
  66. package/utils/timer/abstractions/ITimer.js.map +0 -1
  67. package/utils/timer/index.js.map +0 -1
package/s3/index.js CHANGED
@@ -1,57 +1,42 @@
1
- import { createHandler as createBaseHandler } from "@webiny/handler";
1
+ import { createHandler } from "@webiny/handler";
2
2
  import { registerDefaultPlugins } from "../plugins/index.js";
3
3
  import { S3EventHandler } from "./plugins/S3EventHandler.js";
4
4
  import { execute } from "../execute.js";
5
- /**
6
- * We need a class, not an interface exported from types.
7
- */
8
- // @ts-expect-error
9
- import Reply from "fastify/lib/reply.js";
5
+ import lib_reply from "fastify/lib/reply.js";
10
6
  import { createComposedHandler } from "../utils/composedHandler.js";
11
7
  export * from "./plugins/S3EventHandler.js";
12
8
  const url = "/webiny-s3-event";
13
- export const createHandler = params => {
14
- return async (event, context) => {
15
- const app = createBaseHandler({
16
- ...params,
17
- options: {
18
- logger: params.debug === true,
19
- ...(params.options || {})
20
- }
21
- });
22
- /**
23
- * We always must add our default plugins to the app.
24
- */
25
- registerDefaultPlugins(app.webiny);
26
- /**
27
- * There must be an event plugin for this handler to work.
28
- */
29
- const plugins = app.webiny.plugins.byType(S3EventHandler.type).reverse();
30
- if (plugins.length === 0) {
31
- throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);
32
- }
33
- const handler = createComposedHandler(plugins);
34
- app.post(url, async (request, reply) => {
35
- const params = {
36
- request,
37
- reply,
38
- context: app.webiny,
39
- event,
40
- lambdaContext: context
41
- };
42
- const result = await handler(params);
43
- if (result instanceof Reply) {
44
- return result;
45
- }
46
- app.__webiny_raw_result = result;
47
- return reply.send({});
48
- });
49
- return execute({
50
- app,
51
- url,
52
- payload: event
53
- });
54
- };
55
- };
9
+ const s3_createHandler = (params)=>async (event, context)=>{
10
+ const app = createHandler({
11
+ ...params,
12
+ options: {
13
+ logger: true === params.debug,
14
+ ...params.options || {}
15
+ }
16
+ });
17
+ registerDefaultPlugins(app.webiny);
18
+ const plugins = app.webiny.plugins.byType(S3EventHandler.type).reverse();
19
+ if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/s3, you must have S3EventHandler set.");
20
+ const handler = createComposedHandler(plugins);
21
+ app.post(url, async (request, reply)=>{
22
+ const params = {
23
+ request,
24
+ reply,
25
+ context: app.webiny,
26
+ event,
27
+ lambdaContext: context
28
+ };
29
+ const result = await handler(params);
30
+ if (result instanceof lib_reply) return result;
31
+ app.__webiny_raw_result = result;
32
+ return reply.send({});
33
+ });
34
+ return execute({
35
+ app,
36
+ url: url,
37
+ payload: event
38
+ });
39
+ };
40
+ export { s3_createHandler as createHandler };
56
41
 
57
42
  //# sourceMappingURL=index.js.map
package/s3/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createHandler","createBaseHandler","registerDefaultPlugins","S3EventHandler","execute","Reply","createComposedHandler","url","params","event","context","app","options","logger","debug","webiny","plugins","byType","type","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","send","payload"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { S3EventHandlerCallableParams } from \"~/s3/plugins/S3EventHandler.js\";\nimport { S3EventHandler } from \"~/s3/plugins/S3EventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n S3Event\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/S3EventHandler.js\";\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,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,sBAAsB;AAE/B,SAASC,cAAc;AACvB,SAASC,OAAO;AAEhB;AACA;AACA;AACA;AACA,OAAOC,KAAK,MAAM,sBAAsB;AAMxC,SAASC,qBAAqB;AAE9B;AAQA,MAAMC,GAAG,GAAG,kBAAkB;AAE9B,OAAO,MAAMP,aAAa,GAAIQ,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQV,sBAAsB,CAACS,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAACC,MAAM,CAAiBd,cAAc,CAACe,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IACxF,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,kEAAkE,CAAC;IACvF;IAEA,MAAMC,OAAO,GAAGhB,qBAAqB,CAInCU,OAAO,CAAC;IAEVL,GAAG,CAACY,IAAI,CAAChB,GAAG,EAAE,OAAOiB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMjB,MAAyE,GAAG;QAC9EgB,OAAO;QACPC,KAAK;QACLf,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,KAAK;QACLiB,aAAa,EAAEhB;MACnB,CAAC;MACD,MAAMiB,MAAM,GAAG,MAAML,OAAO,CACxBd,MACJ,CAAC;MAED,IAAImB,MAAM,YAAYtB,KAAK,EAAE;QACzB,OAAOsB,MAAM;MACjB;MAEAhB,GAAG,CAACiB,mBAAmB,GAAGD,MAAM;MAChC,OAAOF,KAAK,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAOzB,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHuB,OAAO,EAAErB;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"s3/index.js","sources":["../../src/s3/index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { S3EventHandlerCallableParams } from \"~/s3/plugins/S3EventHandler.js\";\nimport { S3EventHandler } from \"~/s3/plugins/S3EventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n S3Event\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/S3EventHandler.js\";\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"],"names":["url","createHandler","params","event","context","app","createBaseHandler","registerDefaultPlugins","plugins","S3EventHandler","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AA0BA,MAAMA,MAAM;AAEL,MAAMC,mBAAgB,CAACC,SACnB,OAAOC,OAAOC;QACjB,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAiBI,eAAe,IAAI,EAAE,OAAO;QACtF,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIE,MAAM;QAGpB,MAAMC,UAAUC,sBAIdJ;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOa,SAASC;YAC1B,MAAMZ,SAA4E;gBAC9EW;gBACAC;gBACA,SAAST,IAAI,MAAM;gBACnBF;gBACA,eAAeC;YACnB;YACA,MAAMW,SAAS,MAAMJ,QACjBT;YAGJ,IAAIa,kBAAkBC,WAClB,OAAOD;YAGXV,IAAI,mBAAmB,GAAGU;YAC1B,OAAOD,MAAM,IAAI,CAAC,CAAC;QACvB;QACA,OAAOG,QAAQ;YACXZ;YACAL,KAAAA;YACA,SAASG;QACb;IACJ"}
@@ -1,13 +1,14 @@
1
1
  import { Plugin } from "@webiny/plugins/Plugin.js";
2
- export class S3EventHandler extends Plugin {
3
- static type = "handler.fastify.aws.s3.eventHandler";
4
- constructor(cb) {
5
- super();
6
- this.cb = cb;
7
- }
2
+ class S3EventHandler extends Plugin {
3
+ static{
4
+ this.type = "handler.fastify.aws.s3.eventHandler";
5
+ }
6
+ constructor(cb){
7
+ super();
8
+ this.cb = cb;
9
+ }
8
10
  }
9
- export const createEventHandler = cb => {
10
- return new S3EventHandler(cb);
11
- };
11
+ const createEventHandler = (cb)=>new S3EventHandler(cb);
12
+ export { S3EventHandler, createEventHandler };
12
13
 
13
14
  //# sourceMappingURL=S3EventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Plugin","S3EventHandler","type","constructor","cb","createEventHandler"],"sources":["S3EventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, S3Event } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface 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,SAASA,MAAM,QAAQ,2BAA2B;AAgBlD,OAAO,MAAMC,cAAc,SAAyBD,MAAM,CAAC;EACvD,OAAuBE,IAAI,GAAG,qCAAqC;EAI5DC,WAAWA,CAACC,EAAoC,EAAE;IACrD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAcD,EAAoC,IAAK;EAClF,OAAO,IAAIH,cAAc,CAAWG,EAAE,CAAC;AAC3C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"s3/plugins/S3EventHandler.js","sources":["../../../src/s3/plugins/S3EventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, S3Event } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface 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"],"names":["S3EventHandler","Plugin","cb","createEventHandler"],"mappings":";AAiBO,MAAMA,uBAAuCC;;aACzB,IAAI,GAAG;;IAI9B,YAAmBC,EAAoC,CAAE;QACrD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,qBAAqB,CAAWD,KAClC,IAAIF,eAAyBE"}
package/s3/register.js CHANGED
@@ -2,21 +2,13 @@ import { registry } from "../registry.js";
2
2
  import { createSourceHandler } from "../sourceHandler.js";
3
3
  import { createHandler } from "./index.js";
4
4
  const handler = createSourceHandler({
5
- name: "handler-aws-s3",
6
- canUse: event => {
7
- if (!Array.isArray(event.Records) || event.Records.length === 0) {
8
- return false;
9
- }
10
- const [record] = event.Records;
11
- return !!record.s3;
12
- },
13
- handle: async ({
14
- params,
15
- event,
16
- context
17
- }) => {
18
- return createHandler(params)(event, context);
19
- }
5
+ name: "handler-aws-s3",
6
+ canUse: (event)=>{
7
+ if (!Array.isArray(event.Records) || 0 === event.Records.length) return false;
8
+ const [record] = event.Records;
9
+ return !!record.s3;
10
+ },
11
+ handle: async ({ params, event, context })=>createHandler(params)(event, context)
20
12
  });
21
13
  registry.register(handler);
22
14
 
@@ -1 +1 @@
1
- {"version":3,"names":["registry","createSourceHandler","createHandler","handler","name","canUse","event","Array","isArray","Records","length","record","s3","handle","params","context","register"],"sources":["register.ts"],"sourcesContent":["import type { S3Event } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\nimport { createHandler } from \"./index.js\";\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,SAASA,QAAQ;AAEjB,SAASC,mBAAmB;AAC5B,SAASC,aAAa;AAMtB,MAAMC,OAAO,GAAGF,mBAAmB,CAAyB;EACxDG,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,OAAOb,aAAa,CAACY,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFf,QAAQ,CAACgB,QAAQ,CAACb,OAAO,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"s3/register.js","sources":["../../src/s3/register.ts"],"sourcesContent":["import type { S3Event } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\nimport { createHandler } from \"./index.js\";\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"],"names":["handler","createSourceHandler","event","Array","record","params","context","createHandler","registry"],"mappings":";;;AAUA,MAAMA,UAAUC,oBAA4C;IACxD,MAAM;IACN,QAAQC,CAAAA;QACJ,IAAI,CAACC,MAAM,OAAO,CAACD,MAAM,OAAO,KAAKA,AAAyB,MAAzBA,MAAM,OAAO,CAAC,MAAM,EACrD,OAAO;QAEX,MAAM,CAACE,OAAO,GAAGF,MAAM,OAAO;QAC9B,OAAO,CAAC,CAACE,OAAO,EAAE;IACtB;IACA,QAAQ,OAAO,EAAEC,MAAM,EAAEH,KAAK,EAAEI,OAAO,EAAE,GAC9BC,cAAcF,QAAQH,OAAOI;AAE5C;AAEAE,SAAS,QAAQ,CAACR"}
package/sns/index.js CHANGED
@@ -1,57 +1,42 @@
1
- import { createHandler as createBaseHandler } from "@webiny/handler";
1
+ import { createHandler } from "@webiny/handler";
2
2
  import { registerDefaultPlugins } from "../plugins/index.js";
3
3
  import { SNSEventHandler } from "./plugins/SNSEventHandler.js";
4
4
  import { execute } from "../execute.js";
5
- /**
6
- * We need a class, not an interface exported from types.
7
- */
8
- // @ts-expect-error
9
- import Reply from "fastify/lib/reply.js";
5
+ import lib_reply from "fastify/lib/reply.js";
10
6
  import { createComposedHandler } from "../utils/composedHandler.js";
11
7
  export * from "./plugins/SNSEventHandler.js";
12
8
  const url = "/webiny-sns-event";
13
- export const createHandler = params => {
14
- return async (event, context) => {
15
- const app = createBaseHandler({
16
- ...params,
17
- options: {
18
- logger: params.debug === true,
19
- ...(params.options || {})
20
- }
21
- });
22
- /**
23
- * We always must add our default plugins to the app.
24
- */
25
- registerDefaultPlugins(app.webiny);
26
- /**
27
- * There must be an event plugin for this handler to work.
28
- */
29
- const plugins = app.webiny.plugins.byType(SNSEventHandler.type).reverse();
30
- if (plugins.length === 0) {
31
- throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);
32
- }
33
- const handler = createComposedHandler(plugins);
34
- app.post(url, async (request, reply) => {
35
- const params = {
36
- request,
37
- reply,
38
- context: app.webiny,
39
- event,
40
- lambdaContext: context
41
- };
42
- const result = await handler(params);
43
- if (result instanceof Reply) {
44
- return result;
45
- }
46
- app.__webiny_raw_result = result;
47
- return reply.send({});
48
- });
49
- return execute({
50
- app,
51
- url,
52
- payload: event
53
- });
54
- };
55
- };
9
+ const sns_createHandler = (params)=>async (event, context)=>{
10
+ const app = createHandler({
11
+ ...params,
12
+ options: {
13
+ logger: true === params.debug,
14
+ ...params.options || {}
15
+ }
16
+ });
17
+ registerDefaultPlugins(app.webiny);
18
+ const plugins = app.webiny.plugins.byType(SNSEventHandler.type).reverse();
19
+ if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/sns, you must have SNSEventHandler set.");
20
+ const handler = createComposedHandler(plugins);
21
+ app.post(url, async (request, reply)=>{
22
+ const params = {
23
+ request,
24
+ reply,
25
+ context: app.webiny,
26
+ event,
27
+ lambdaContext: context
28
+ };
29
+ const result = await handler(params);
30
+ if (result instanceof lib_reply) return result;
31
+ app.__webiny_raw_result = result;
32
+ return reply.send({});
33
+ });
34
+ return execute({
35
+ app,
36
+ url: url,
37
+ payload: event
38
+ });
39
+ };
40
+ export { sns_createHandler as createHandler };
56
41
 
57
42
  //# sourceMappingURL=index.js.map
package/sns/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createHandler","createBaseHandler","registerDefaultPlugins","SNSEventHandler","execute","Reply","createComposedHandler","url","params","event","context","app","options","logger","debug","webiny","plugins","byType","type","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","send","payload"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n SNSEvent,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { SNSEventHandlerCallableParams } from \"./plugins/SNSEventHandler.js\";\nimport { SNSEventHandler } from \"./plugins/SNSEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/SNSEventHandler.js\";\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,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,sBAAsB;AAE/B,SAASC,eAAe;AACxB,SAASC,OAAO;AAEhB;AACA;AACA;AACA;AACA,OAAOC,KAAK,MAAM,sBAAsB;AACxC,SAASC,qBAAqB;AAE9B;AAQA,MAAMC,GAAG,GAAG,mBAAmB;AAE/B,OAAO,MAAMP,aAAa,GAAIQ,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQV,sBAAsB,CAACS,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBd,eAAe,CAACe,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IAC1F,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAGhB,qBAAqB,CAInCU,OAAO,CAAC;IAEVL,GAAG,CAACY,IAAI,CAAChB,GAAG,EAAE,OAAOiB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMjB,MAA0E,GAAG;QAC/EgB,OAAO;QACPC,KAAK;QACLf,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,KAAK;QACLiB,aAAa,EAAEhB;MACnB,CAAC;MAED,MAAMiB,MAAM,GAAG,MAAML,OAAO,CACxBd,MACJ,CAAC;MAED,IAAImB,MAAM,YAAYtB,KAAK,EAAE;QACzB,OAAOsB,MAAM;MACjB;MAEAhB,GAAG,CAACiB,mBAAmB,GAAGD,MAAM;MAChC,OAAOF,KAAK,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAOzB,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHuB,OAAO,EAAErB;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"sns/index.js","sources":["../../src/sns/index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n SNSEvent,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { SNSEventHandlerCallableParams } from \"./plugins/SNSEventHandler.js\";\nimport { SNSEventHandler } from \"./plugins/SNSEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/SNSEventHandler.js\";\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"],"names":["url","createHandler","params","event","context","app","createBaseHandler","registerDefaultPlugins","plugins","SNSEventHandler","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AA0BA,MAAMA,MAAM;AAEL,MAAMC,oBAAgB,CAACC,SACnB,OAAOC,OAAOC;QACjB,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAkBI,gBAAgB,IAAI,EAAE,OAAO;QACxF,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIE,MAAM;QAGpB,MAAMC,UAAUC,sBAIdJ;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOa,SAASC;YAC1B,MAAMZ,SAA6E;gBAC/EW;gBACAC;gBACA,SAAST,IAAI,MAAM;gBACnBF;gBACA,eAAeC;YACnB;YAEA,MAAMW,SAAS,MAAMJ,QACjBT;YAGJ,IAAIa,kBAAkBC,WAClB,OAAOD;YAGXV,IAAI,mBAAmB,GAAGU;YAC1B,OAAOD,MAAM,IAAI,CAAC,CAAC;QACvB;QACA,OAAOG,QAAQ;YACXZ;YACAL,KAAAA;YACA,SAASG;QACb;IACJ"}
@@ -1,13 +1,14 @@
1
1
  import { Plugin } from "@webiny/plugins/Plugin.js";
2
- export class SNSEventHandler extends Plugin {
3
- static type = "handler.fastify.aws.sns.eventHandler";
4
- constructor(cb) {
5
- super();
6
- this.cb = cb;
7
- }
2
+ class SNSEventHandler extends Plugin {
3
+ static{
4
+ this.type = "handler.fastify.aws.sns.eventHandler";
5
+ }
6
+ constructor(cb){
7
+ super();
8
+ this.cb = cb;
9
+ }
8
10
  }
9
- export const createEventHandler = cb => {
10
- return new SNSEventHandler(cb);
11
- };
11
+ const createEventHandler = (cb)=>new SNSEventHandler(cb);
12
+ export { SNSEventHandler, createEventHandler };
12
13
 
13
14
  //# sourceMappingURL=SNSEventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Plugin","SNSEventHandler","type","constructor","cb","createEventHandler"],"sources":["SNSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SNSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface 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,SAASA,MAAM,QAAQ,2BAA2B;AAgBlD,OAAO,MAAMC,eAAe,SAAyBD,MAAM,CAAC;EACxD,OAAuBE,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAcD,EAAqC,IAAK;EACnF,OAAO,IAAIH,eAAe,CAAWG,EAAE,CAAC;AAC5C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"sns/plugins/SNSEventHandler.js","sources":["../../../src/sns/plugins/SNSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SNSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface 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"],"names":["SNSEventHandler","Plugin","cb","createEventHandler"],"mappings":";AAiBO,MAAMA,wBAAwCC;;aAC1B,IAAI,GAAG;;IAI9B,YAAmBC,EAAqC,CAAE;QACtD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,qBAAqB,CAAWD,KAClC,IAAIF,gBAA0BE"}
package/sns/register.js CHANGED
@@ -2,21 +2,13 @@ import { registry } from "../registry.js";
2
2
  import { createHandler } from "./index.js";
3
3
  import { createSourceHandler } from "../sourceHandler.js";
4
4
  const handler = createSourceHandler({
5
- name: "handler-aws-sns",
6
- canUse: event => {
7
- if (!Array.isArray(event.Records) || event.Records.length === 0) {
8
- return false;
9
- }
10
- const [record] = event.Records;
11
- return !!record.Sns;
12
- },
13
- handle: async ({
14
- params,
15
- event,
16
- context
17
- }) => {
18
- return createHandler(params)(event, context);
19
- }
5
+ name: "handler-aws-sns",
6
+ canUse: (event)=>{
7
+ if (!Array.isArray(event.Records) || 0 === event.Records.length) return false;
8
+ const [record] = event.Records;
9
+ return !!record.Sns;
10
+ },
11
+ handle: async ({ params, event, context })=>createHandler(params)(event, context)
20
12
  });
21
13
  registry.register(handler);
22
14
 
@@ -1 +1 @@
1
- {"version":3,"names":["registry","createHandler","createSourceHandler","handler","name","canUse","event","Array","isArray","Records","length","record","Sns","handle","params","context","register"],"sources":["register.ts"],"sourcesContent":["import type { SNSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerParams } from \"./index.js\";\nimport { createHandler } from \"./index.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\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,SAASA,QAAQ;AAEjB,SAASC,aAAa;AACtB,SAASC,mBAAmB;AAE5B,MAAMC,OAAO,GAAGD,mBAAmB,CAA0B;EACzDE,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,OAAOd,aAAa,CAACa,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFf,QAAQ,CAACgB,QAAQ,CAACb,OAAO,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"sns/register.js","sources":["../../src/sns/register.ts"],"sourcesContent":["import type { SNSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerParams } from \"./index.js\";\nimport { createHandler } from \"./index.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\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"],"names":["handler","createSourceHandler","event","Array","record","params","context","createHandler","registry"],"mappings":";;;AAMA,MAAMA,UAAUC,oBAA6C;IACzD,MAAM;IACN,QAAQC,CAAAA;QACJ,IAAI,CAACC,MAAM,OAAO,CAACD,MAAM,OAAO,KAAKA,AAAyB,MAAzBA,MAAM,OAAO,CAAC,MAAM,EACrD,OAAO;QAEX,MAAM,CAACE,OAAO,GAAGF,MAAM,OAAO;QAC9B,OAAO,CAAC,CAACE,OAAO,GAAG;IACvB;IACA,QAAQ,OAAO,EAAEC,MAAM,EAAEH,KAAK,EAAEI,OAAO,EAAE,GAC9BC,cAAcF,QAAQH,OAAOI;AAE5C;AAEAE,SAAS,QAAQ,CAACR"}
package/sourceHandler.js CHANGED
@@ -1,5 +1,4 @@
1
- export const createSourceHandler = handler => {
2
- return handler;
3
- };
1
+ const createSourceHandler = (handler)=>handler;
2
+ export { createSourceHandler };
4
3
 
5
4
  //# sourceMappingURL=sourceHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createSourceHandler","handler"],"sources":["sourceHandler.ts"],"sourcesContent":["import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from \"~/types.js\";\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":"AAEA,OAAO,MAAMA,mBAAmB,GAI5BC,OAAuC,IACtC;EACD,OAAOA,OAAO;AAClB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"sourceHandler.js","sources":["../src/sourceHandler.ts"],"sourcesContent":["import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from \"~/types.js\";\n\nexport const createSourceHandler = <\n TEvent = HandlerEvent,\n TParams extends HandlerFactoryParams = HandlerFactoryParams\n>(\n handler: SourceHandler<TEvent, TParams>\n) => {\n return handler;\n};\n"],"names":["createSourceHandler","handler"],"mappings":"AAEO,MAAMA,sBAAsB,CAI/BC,UAEOA"}
package/sqs/index.js CHANGED
@@ -1,60 +1,43 @@
1
- import { createHandler as createBaseHandler } from "@webiny/handler";
1
+ import { createHandler } from "@webiny/handler";
2
2
  import { registerDefaultPlugins } from "../plugins/index.js";
3
3
  import { SQSEventHandler } from "./plugins/SQSEventHandler.js";
4
4
  import { execute } from "../execute.js";
5
- /**
6
- * We need a class, not an interface exported from types.
7
- */
8
- // @ts-expect-error
9
- import Reply from "fastify/lib/reply.js";
5
+ import lib_reply from "fastify/lib/reply.js";
10
6
  import { createComposedHandler } from "../utils/composedHandler.js";
11
7
  export * from "./plugins/SQSEventHandler.js";
12
8
  const url = "/webiny-sqs-event";
13
- export const createHandler = params => {
14
- return async (event, context) => {
15
- const app = createBaseHandler({
16
- ...params,
17
- options: {
18
- logger: params.debug === true,
19
- ...(params.options || {})
20
- }
21
- });
22
- /**
23
- * We always must add our default plugins to the app.
24
- */
25
- registerDefaultPlugins(app.webiny);
26
- /**
27
- * There must be an event plugin for this handler to work.
28
- */
29
- const plugins = app.webiny.plugins.byType(SQSEventHandler.type).reverse();
30
- if (plugins.length === 0) {
31
- throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);
32
- }
33
- const handler = createComposedHandler(plugins);
34
- app.post(url, async (request, reply) => {
35
- const params = {
36
- request,
37
- reply,
38
- context: app.webiny,
39
- event,
40
- lambdaContext: context
41
- };
42
- const result = await handler(params);
43
- if (result instanceof Reply) {
44
- return result;
45
- }
46
- app.__webiny_raw_result = result;
47
- if (!reply.sent) {
48
- reply.send({});
49
- }
50
- return reply;
51
- });
52
- return execute({
53
- app,
54
- url,
55
- payload: event
56
- });
57
- };
58
- };
9
+ const sqs_createHandler = (params)=>async (event, context)=>{
10
+ const app = createHandler({
11
+ ...params,
12
+ options: {
13
+ logger: true === params.debug,
14
+ ...params.options || {}
15
+ }
16
+ });
17
+ registerDefaultPlugins(app.webiny);
18
+ const plugins = app.webiny.plugins.byType(SQSEventHandler.type).reverse();
19
+ if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.");
20
+ const handler = createComposedHandler(plugins);
21
+ app.post(url, async (request, reply)=>{
22
+ const params = {
23
+ request,
24
+ reply,
25
+ context: app.webiny,
26
+ event,
27
+ lambdaContext: context
28
+ };
29
+ const result = await handler(params);
30
+ if (result instanceof lib_reply) return result;
31
+ app.__webiny_raw_result = result;
32
+ if (!reply.sent) reply.send({});
33
+ return reply;
34
+ });
35
+ return execute({
36
+ app,
37
+ url: url,
38
+ payload: event
39
+ });
40
+ };
41
+ export { sqs_createHandler as createHandler };
59
42
 
60
43
  //# sourceMappingURL=index.js.map
package/sqs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createHandler","createBaseHandler","registerDefaultPlugins","SQSEventHandler","execute","Reply","createComposedHandler","url","params","event","context","app","options","logger","debug","webiny","plugins","byType","type","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","sent","send","payload"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n SQSEvent\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { SQSEventHandlerCallableParams } from \"~/sqs/plugins/SQSEventHandler.js\";\nimport { SQSEventHandler } from \"~/sqs/plugins/SQSEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/SQSEventHandler.js\";\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,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,sBAAsB;AAE/B,SAASC,eAAe;AACxB,SAASC,OAAO;AAEhB;AACA;AACA;AACA;AACA,OAAOC,KAAK,MAAM,sBAAsB;AACxC,SAASC,qBAAqB;AAE9B;AAQA,MAAMC,GAAG,GAAG,mBAAmB;AAE/B,OAAO,MAAMP,aAAa,GAAIQ,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQV,sBAAsB,CAACS,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBd,eAAe,CAACe,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IAC1F,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAGhB,qBAAqB,CAInCU,OAAO,CAAC;IAEVL,GAAG,CAACY,IAAI,CAAChB,GAAG,EAAE,OAAOiB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMjB,MAA0E,GAAG;QAC/EgB,OAAO;QACPC,KAAK;QACLf,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,KAAK;QACLiB,aAAa,EAAEhB;MACnB,CAAC;MAED,MAAMiB,MAAM,GAAG,MAAML,OAAO,CACxBd,MACJ,CAAC;MAED,IAAImB,MAAM,YAAYtB,KAAK,EAAE;QACzB,OAAOsB,MAAM;MACjB;MAEAhB,GAAG,CAACiB,mBAAmB,GAAGD,MAAM;MAChC,IAAI,CAACF,KAAK,CAACI,IAAI,EAAE;QACbJ,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;MAClB;MACA,OAAOL,KAAK;IAChB,CAAC,CAAC;IACF,OAAOrB,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHwB,OAAO,EAAEtB;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"sqs/index.js","sources":["../../src/sqs/index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n SQSEvent\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { SQSEventHandlerCallableParams } from \"~/sqs/plugins/SQSEventHandler.js\";\nimport { SQSEventHandler } from \"~/sqs/plugins/SQSEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/SQSEventHandler.js\";\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"],"names":["url","createHandler","params","event","context","app","createBaseHandler","registerDefaultPlugins","plugins","SQSEventHandler","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AA0BA,MAAMA,MAAM;AAEL,MAAMC,oBAAgB,CAACC,SACnB,OAAOC,OAAOC;QACjB,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAkBI,gBAAgB,IAAI,EAAE,OAAO;QACxF,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIE,MAAM;QAGpB,MAAMC,UAAUC,sBAIdJ;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOa,SAASC;YAC1B,MAAMZ,SAA6E;gBAC/EW;gBACAC;gBACA,SAAST,IAAI,MAAM;gBACnBF;gBACA,eAAeC;YACnB;YAEA,MAAMW,SAAS,MAAMJ,QACjBT;YAGJ,IAAIa,kBAAkBC,WAClB,OAAOD;YAGXV,IAAI,mBAAmB,GAAGU;YAC1B,IAAI,CAACD,MAAM,IAAI,EACXA,MAAM,IAAI,CAAC,CAAC;YAEhB,OAAOA;QACX;QACA,OAAOG,QAAQ;YACXZ;YACAL,KAAAA;YACA,SAASG;QACb;IACJ"}
@@ -1,13 +1,14 @@
1
1
  import { Plugin } from "@webiny/plugins/Plugin.js";
2
- export class SQSEventHandler extends Plugin {
3
- static type = "handler.fastify.aws.sqs.eventHandler";
4
- constructor(cb) {
5
- super();
6
- this.cb = cb;
7
- }
2
+ class SQSEventHandler extends Plugin {
3
+ static{
4
+ this.type = "handler.fastify.aws.sqs.eventHandler";
5
+ }
6
+ constructor(cb){
7
+ super();
8
+ this.cb = cb;
9
+ }
8
10
  }
9
- export const createEventHandler = cb => {
10
- return new SQSEventHandler(cb);
11
- };
11
+ const createEventHandler = (cb)=>new SQSEventHandler(cb);
12
+ export { SQSEventHandler, createEventHandler };
12
13
 
13
14
  //# sourceMappingURL=SQSEventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Plugin","SQSEventHandler","type","constructor","cb","createEventHandler"],"sources":["SQSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SQSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface 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,SAASA,MAAM,QAAQ,2BAA2B;AAgBlD,OAAO,MAAMC,eAAe,SAAyBD,MAAM,CAAC;EACxD,OAAuBE,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAcD,EAAqC,IAAK;EACnF,OAAO,IAAIH,eAAe,CAAWG,EAAE,CAAC;AAC5C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"sqs/plugins/SQSEventHandler.js","sources":["../../../src/sqs/plugins/SQSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SQSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface 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"],"names":["SQSEventHandler","Plugin","cb","createEventHandler"],"mappings":";AAiBO,MAAMA,wBAAwCC;;aAC1B,IAAI,GAAG;;IAI9B,YAAmBC,EAAqC,CAAE;QACtD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,qBAAqB,CAAWD,KAClC,IAAIF,gBAA0BE"}