@webiny/handler-aws 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.9bd236cf5e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/createHandler.d.ts +2 -0
  2. package/createHandler.js +29 -0
  3. package/createHandler.js.map +1 -0
  4. package/dynamodb/index.d.ts +5 -8
  5. package/dynamodb/index.js +23 -14
  6. package/dynamodb/index.js.map +1 -1
  7. package/dynamodb/plugins/DynamoDBEventHandler.d.ts +6 -5
  8. package/dynamodb/plugins/DynamoDBEventHandler.js +4 -5
  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 +24 -15
  15. package/eventBridge/index.js.map +1 -1
  16. package/eventBridge/plugins/EventBridgeEventHandler.d.ts +6 -5
  17. package/eventBridge/plugins/EventBridgeEventHandler.js +4 -5
  18. package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
  19. package/eventBridge/register.d.ts +4 -0
  20. package/eventBridge/register.js +21 -0
  21. package/eventBridge/register.js.map +1 -0
  22. package/execute.d.ts +1 -1
  23. package/execute.js +17 -5
  24. package/execute.js.map +1 -1
  25. package/gateway/index.d.ts +7 -11
  26. package/gateway/index.js +15 -12
  27. package/gateway/index.js.map +1 -1
  28. package/gateway/register.d.ts +1 -0
  29. package/gateway/register.js +21 -0
  30. package/gateway/register.js.map +1 -0
  31. package/index.d.ts +33 -5
  32. package/index.js +140 -24
  33. package/index.js.map +1 -1
  34. package/package.json +14 -20
  35. package/plugins/handlerClient.js +10 -9
  36. package/plugins/handlerClient.js.map +1 -1
  37. package/plugins/index.d.ts +1 -1
  38. package/plugins/index.js +3 -1
  39. package/plugins/index.js.map +1 -1
  40. package/raw/index.d.ts +3 -8
  41. package/raw/index.js +24 -13
  42. package/raw/index.js.map +1 -1
  43. package/raw/plugins/RawEventHandler.d.ts +17 -6
  44. package/raw/plugins/RawEventHandler.js +21 -4
  45. package/raw/plugins/RawEventHandler.js.map +1 -1
  46. package/registry.d.ts +17 -0
  47. package/registry.js +44 -0
  48. package/registry.js.map +1 -0
  49. package/s3/index.d.ts +6 -9
  50. package/s3/index.js +26 -17
  51. package/s3/index.js.map +1 -1
  52. package/s3/plugins/S3EventHandler.d.ts +6 -5
  53. package/s3/plugins/S3EventHandler.js +4 -5
  54. package/s3/plugins/S3EventHandler.js.map +1 -1
  55. package/s3/register.d.ts +4 -0
  56. package/s3/register.js +25 -0
  57. package/s3/register.js.map +1 -0
  58. package/sns/index.d.ts +8 -0
  59. package/sns/index.js +79 -0
  60. package/sns/index.js.map +1 -0
  61. package/sns/plugins/SNSEventHandler.d.ts +20 -0
  62. package/sns/plugins/SNSEventHandler.js +21 -0
  63. package/sns/plugins/SNSEventHandler.js.map +1 -0
  64. package/sns/register.d.ts +1 -0
  65. package/sns/register.js +25 -0
  66. package/sns/register.js.map +1 -0
  67. package/sourceHandler.d.ts +2 -0
  68. package/sourceHandler.js +12 -0
  69. package/sourceHandler.js.map +1 -0
  70. package/sqs/index.d.ts +6 -9
  71. package/sqs/index.js +30 -18
  72. package/sqs/index.js.map +1 -1
  73. package/sqs/plugins/SQSEventHandler.d.ts +6 -5
  74. package/sqs/plugins/SQSEventHandler.js +4 -5
  75. package/sqs/plugins/SQSEventHandler.js.map +1 -1
  76. package/sqs/register.d.ts +1 -0
  77. package/sqs/register.js +28 -0
  78. package/sqs/register.js.map +1 -0
  79. package/types.d.ts +27 -4
  80. package/types.js +14 -5
  81. package/types.js.map +1 -1
  82. package/utils/composedHandler.d.ts +6 -0
  83. package/utils/composedHandler.js +24 -0
  84. package/utils/composedHandler.js.map +1 -0
  85. package/utils/index.d.ts +2 -0
  86. package/utils/index.js +29 -0
  87. package/utils/index.js.map +1 -0
  88. package/utils/timer/CustomTimer.d.ts +5 -0
  89. package/utils/timer/CustomTimer.js +19 -0
  90. package/utils/timer/CustomTimer.js.map +1 -0
  91. package/utils/timer/Timer.d.ts +10 -0
  92. package/utils/timer/Timer.js +24 -0
  93. package/utils/timer/Timer.js.map +1 -0
  94. package/utils/timer/abstractions/ITimer.d.ts +10 -0
  95. package/utils/timer/abstractions/ITimer.js +7 -0
  96. package/utils/timer/abstractions/ITimer.js.map +1 -0
  97. package/utils/timer/factory.d.ts +4 -0
  98. package/utils/timer/factory.js +20 -0
  99. package/utils/timer/factory.js.map +1 -0
  100. package/utils/timer/index.d.ts +4 -0
  101. package/utils/timer/index.js +51 -0
  102. package/utils/timer/index.js.map +1 -0
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createEventHandler = exports.SNSEventHandler = void 0;
7
+ var _Plugin = require("@webiny/plugins/Plugin");
8
+ class SNSEventHandler extends _Plugin.Plugin {
9
+ static type = "handler.fastify.aws.sns.eventHandler";
10
+ constructor(cb) {
11
+ super();
12
+ this.cb = cb;
13
+ }
14
+ }
15
+ exports.SNSEventHandler = SNSEventHandler;
16
+ const createEventHandler = cb => {
17
+ return new SNSEventHandler(cb);
18
+ };
19
+ exports.createEventHandler = createEventHandler;
20
+
21
+ //# sourceMappingURL=SNSEventHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_Plugin","require","SNSEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["SNSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SNSEvent } from \"@webiny/aws-sdk/types\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types\";\n\nexport interface SNSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SNSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SNSEventHandlerCallable<Response = Reply> {\n (params: SNSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SNSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sns.eventHandler\";\n\n public readonly cb: SNSEventHandlerCallable<Response>;\n\n public constructor(cb: SNSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SNSEventHandlerCallable<Response>) => {\n return new SNSEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAgBO,MAAMC,eAAe,SAAyBC,cAAM,CAAC;EACxD,OAAuBC,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,eAAA,GAAAA,eAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAAqC,IAAK;EACnF,OAAO,IAAIJ,eAAe,CAAWI,EAAE,CAAC;AAC5C,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _registry = require("../registry");
4
+ var _index = require("./index");
5
+ var _sourceHandler = require("../sourceHandler");
6
+ const handler = (0, _sourceHandler.createSourceHandler)({
7
+ name: "handler-aws-sns",
8
+ canUse: event => {
9
+ if (!Array.isArray(event.Records) || event.Records.length === 0) {
10
+ return false;
11
+ }
12
+ const [record] = event.Records;
13
+ return !!record.Sns;
14
+ },
15
+ handle: async ({
16
+ params,
17
+ event,
18
+ context
19
+ }) => {
20
+ return (0, _index.createHandler)(params)(event, context);
21
+ }
22
+ });
23
+ _registry.registry.register(handler);
24
+
25
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_registry","require","_index","_sourceHandler","handler","createSourceHandler","name","canUse","event","Array","isArray","Records","length","record","Sns","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import type { SNSEvent } from \"@webiny/aws-sdk/types\";\nimport { registry } from \"~/registry\";\nimport type { HandlerParams } from \"./index\";\nimport { createHandler } from \"./index\";\nimport { createSourceHandler } from \"~/sourceHandler\";\n\nconst handler = createSourceHandler<SNSEvent, HandlerParams>({\n name: \"handler-aws-sns\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.Sns;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":";;AACA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAEA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAA0B;EACzDC,IAAI,EAAE,iBAAiB;EACvBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,OAAO,CAAC,CAACE,MAAM,CAACC,GAAG;EACvB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAER,KAAK;IAAES;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAAChB,OAAO,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from "./types";
2
+ export declare const createSourceHandler: <TEvent = HandlerEvent, TParams extends HandlerFactoryParams = HandlerFactoryParams>(handler: SourceHandler<TEvent, TParams, any>) => SourceHandler<TEvent, TParams, any>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createSourceHandler = void 0;
7
+ const createSourceHandler = handler => {
8
+ return handler;
9
+ };
10
+ exports.createSourceHandler = createSourceHandler;
11
+
12
+ //# sourceMappingURL=sourceHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createSourceHandler","handler","exports"],"sources":["sourceHandler.ts"],"sourcesContent":["import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from \"~/types\";\n\nexport const createSourceHandler = <\n TEvent = HandlerEvent,\n TParams extends HandlerFactoryParams = HandlerFactoryParams\n>(\n handler: SourceHandler<TEvent, TParams>\n) => {\n return handler;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,mBAAmB,GAI5BC,OAAuC,IACtC;EACD,OAAOA,OAAO;AAClB,CAAC;AAACC,OAAA,CAAAF,mBAAA,GAAAA,mBAAA","ignoreList":[]}
package/sqs/index.d.ts CHANGED
@@ -1,11 +1,8 @@
1
- import { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
2
- import { SQSEvent, Context as LambdaContext } from "aws-lambda";
3
- import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
1
+ import type { APIGatewayProxyResult, Context as LambdaContext, SQSEvent } from "@webiny/aws-sdk/types";
2
+ import type { HandlerFactoryParams } from "../types";
3
+ export * from "./plugins/SQSEventHandler";
4
4
  export interface HandlerCallable {
5
- (payload: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
6
- }
7
- export interface CreateHandlerParams extends BaseCreateHandlerParams {
8
- debug?: boolean;
5
+ (event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
9
6
  }
10
- export declare const createHandler: (params: CreateHandlerParams) => HandlerCallable;
11
- export * from "./plugins/SQSEventHandler";
7
+ export type HandlerParams = HandlerFactoryParams;
8
+ export declare const createHandler: (params: HandlerParams) => HandlerCallable;
package/sqs/index.js CHANGED
@@ -8,8 +8,8 @@ var _exportNames = {
8
8
  createHandler: true
9
9
  };
10
10
  exports.createHandler = void 0;
11
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
11
  var _handler = require("@webiny/handler");
12
+ var _plugins = require("../plugins");
13
13
  var _SQSEventHandler = require("./plugins/SQSEventHandler");
14
14
  Object.keys(_SQSEventHandler).forEach(function (key) {
15
15
  if (key === "default" || key === "__esModule") return;
@@ -22,17 +22,24 @@ Object.keys(_SQSEventHandler).forEach(function (key) {
22
22
  }
23
23
  });
24
24
  });
25
- var _plugins = require("../plugins");
26
25
  var _execute = require("../execute");
27
- const Reply = require("fastify/lib/reply");
26
+ var _reply = _interopRequireDefault(require("fastify/lib/reply"));
27
+ var _composedHandler = require("../utils/composedHandler");
28
+ /**
29
+ * We need a class, not an interface exported from types.
30
+ */
31
+ // @ts-expect-error
32
+
28
33
  const url = "/webiny-sqs-event";
29
34
  const createHandler = params => {
30
- return (payload, context) => {
31
- const app = (0, _handler.createHandler)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
32
- options: (0, _objectSpread2.default)({
33
- logger: params.debug === true
34
- }, params.options || {})
35
- }));
35
+ return async (event, context) => {
36
+ const app = (0, _handler.createHandler)({
37
+ ...params,
38
+ options: {
39
+ logger: params.debug === true,
40
+ ...(params.options || {})
41
+ }
42
+ });
36
43
  /**
37
44
  * We always must add our default plugins to the app.
38
45
  */
@@ -40,31 +47,36 @@ const createHandler = params => {
40
47
  /**
41
48
  * There must be an event plugin for this handler to work.
42
49
  */
43
- const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type);
44
- const handler = plugins.shift();
45
- if (!handler) {
50
+ const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type).reverse();
51
+ if (plugins.length === 0) {
46
52
  throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);
47
53
  }
54
+ const handler = (0, _composedHandler.createComposedHandler)(plugins);
48
55
  app.post(url, async (request, reply) => {
49
56
  const params = {
50
57
  request,
51
58
  reply,
52
59
  context: app.webiny,
53
- event: payload,
60
+ event,
54
61
  lambdaContext: context
55
62
  };
56
- const result = await handler.cb(params);
57
- if (result instanceof Reply) {
63
+ const result = await handler(params);
64
+ if (result instanceof _reply.default) {
58
65
  return result;
59
66
  }
60
67
  app.__webiny_raw_result = result;
61
- return reply.send({});
68
+ if (!reply.sent) {
69
+ reply.send({});
70
+ }
71
+ return reply;
62
72
  });
63
73
  return (0, _execute.execute)({
64
74
  app,
65
75
  url,
66
- payload
76
+ payload: event
67
77
  });
68
78
  };
69
79
  };
70
- exports.createHandler = createHandler;
80
+ exports.createHandler = createHandler;
81
+
82
+ //# sourceMappingURL=index.js.map
package/sqs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["Reply","require","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","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 ...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);\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,mBAAmB,CAAC;AAO1C,MAAMC,GAAG,GAAG,mBAAmB;AAUxB,MAAMC,aAAa,GAAIC,MAA2B,IAAsB;EAC3E,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,8DACtBJ,MAAM;MACTK,OAAO;QACHC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK;MAAI,GACzBP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;IAC3B,GACH;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;IAChF,MAAMC,OAAO,GAAGJ,OAAO,CAACK,KAAK,EAAE;IAC/B,IAAI,CAACD,OAAO,EAAE;MACV,MAAM,IAAIE,KAAK,CAAE,oEAAmE,CAAC;IACzF;IAEAb,GAAG,CAACc,IAAI,CAACnB,GAAG,EAAE,OAAOoB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMnB,MAAqC,GAAG;QAC1CkB,OAAO;QACPC,KAAK;QACLjB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBW,KAAK,EAAEnB,OAAO;QACdoB,aAAa,EAAEnB;MACnB,CAAC;MACD,MAAMoB,MAAM,GAAG,MAAMR,OAAO,CAACS,EAAE,CAACvB,MAAM,CAAC;MAEvC,IAAIsB,MAAM,YAAY1B,KAAK,EAAE;QACzB,OAAO0B,MAAM;MACjB;MAECnB,GAAG,CAASqB,mBAAmB,GAAGF,MAAM;MACzC,OAAOH,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXvB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["_handler","require","_plugins","_SQSEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","event","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","SQSEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","sent","send","execute","payload"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n SQSEvent\n} from \"@webiny/aws-sdk/types\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport type { SQSEventHandlerCallableParams } from \"~/sqs/plugins/SQSEventHandler\";\nimport { SQSEventHandler } from \"~/sqs/plugins/SQSEventHandler\";\nimport { execute } from \"~/execute\";\nimport type { HandlerFactoryParams } from \"~/types\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\n\nexport * from \"./plugins/SQSEventHandler\";\n\nexport interface HandlerCallable {\n (event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-sqs-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<SQSEventHandler>(SQSEventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n SQSEventHandler,\n SQSEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<SQSEventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n\n const result = await handler(\n params as unknown as SQSEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n if (!reply.sent) {\n reply.send({});\n }\n return reply;\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"mappings":";;;;;;;;;;AAKA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAF,OAAA;AAUAG,MAAA,CAAAC,IAAA,CAAAF,gBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,gBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,gBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AATA,IAAAS,QAAA,GAAAf,OAAA;AAMA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AACA,IAAAkB,gBAAA,GAAAlB,OAAA;AALA;AACA;AACA;AACA;;AAYA,MAAMmB,GAAG,GAAG,mBAAmB;AAExB,MAAMC,aAAa,GAAIC,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,EAAC;MAC1B,GAAGJ,MAAM;MACTK,OAAO,EAAE;QACLC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK,IAAI;QAC7B,IAAIP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBC,gCAAe,CAACC,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IAC1F,IAAIJ,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAG,IAAAC,sCAAqB,EAInCR,OAAO,CAAC;IAEVP,GAAG,CAACgB,IAAI,CAACrB,GAAG,EAAE,OAAOsB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAA0E,GAAG;QAC/EoB,OAAO;QACPC,KAAK;QACLnB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,KAAK;QACLqB,aAAa,EAAEpB;MACnB,CAAC;MAED,MAAMqB,MAAM,GAAG,MAAMN,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIuB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEApB,GAAG,CAACsB,mBAAmB,GAAGF,MAAM;MAChC,IAAI,CAACF,KAAK,CAACK,IAAI,EAAE;QACbL,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;MAClB;MACA,OAAON,KAAK;IAChB,CAAC,CAAC;IACF,OAAO,IAAAO,gBAAO,EAAC;MACXzB,GAAG;MACHL,GAAG;MACH+B,OAAO,EAAE5B;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -1,15 +1,16 @@
1
+ import type { Context as LambdaContext, SQSEvent } from "@webiny/aws-sdk/types";
1
2
  import { Plugin } from "@webiny/plugins/Plugin";
2
- import { Request, Reply, Context } from "@webiny/handler/types";
3
- import { SQSEvent, Context as LambdaContext } from "aws-lambda";
4
- export interface SQSEventHandlerCallableParams {
3
+ import type { Context, Reply, Request } from "@webiny/handler/types";
4
+ export interface SQSEventHandlerCallableParams<Response = Reply> {
5
5
  request: Request;
6
6
  reply: Reply;
7
7
  context: Context;
8
8
  event: SQSEvent;
9
9
  lambdaContext: LambdaContext;
10
+ next: () => Promise<Response>;
10
11
  }
11
- export interface SQSEventHandlerCallable<Response> {
12
- (params: SQSEventHandlerCallableParams): Promise<Response | Reply>;
12
+ export interface SQSEventHandlerCallable<Response = Reply> {
13
+ (params: SQSEventHandlerCallableParams<Response>): Promise<Response>;
13
14
  }
14
15
  export declare class SQSEventHandler<Response = any> extends Plugin {
15
16
  static type: string;
@@ -1,22 +1,21 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.createEventHandler = exports.SQSEventHandler = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _Plugin = require("@webiny/plugins/Plugin");
10
8
  class SQSEventHandler extends _Plugin.Plugin {
9
+ static type = "handler.fastify.aws.sqs.eventHandler";
11
10
  constructor(cb) {
12
11
  super();
13
- (0, _defineProperty2.default)(this, "cb", void 0);
14
12
  this.cb = cb;
15
13
  }
16
14
  }
17
15
  exports.SQSEventHandler = SQSEventHandler;
18
- (0, _defineProperty2.default)(SQSEventHandler, "type", "handler.fastify.aws.sqs.eventHandler");
19
16
  const createEventHandler = cb => {
20
17
  return new SQSEventHandler(cb);
21
18
  };
22
- exports.createEventHandler = createEventHandler;
19
+ exports.createEventHandler = createEventHandler;
20
+
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,eAAe,SAAyBC,cAAM,CAAC;EAKjDC,WAAW,CAACC,EAAqC,EAAE;IACtD,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAAC;AAAA,8BATYH,eAAe,UACM,sCAAsC;AAUjE,MAAMI,kBAAkB,GAAcD,EAAqC,IAAK;EACnF,OAAO,IAAIH,eAAe,CAAWG,EAAE,CAAC;AAC5C,CAAC;AAAC"}
1
+ {"version":3,"names":["_Plugin","require","SQSEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["SQSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SQSEvent } from \"@webiny/aws-sdk/types\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types\";\n\nexport interface SQSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SQSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SQSEventHandlerCallable<Response = Reply> {\n (params: SQSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SQSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: SQSEventHandlerCallable<Response>;\n\n public constructor(cb: SQSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SQSEventHandlerCallable<Response>) => {\n return new SQSEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAgBO,MAAMC,eAAe,SAAyBC,cAAM,CAAC;EACxD,OAAuBC,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,eAAA,GAAAA,eAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAAqC,IAAK;EACnF,OAAO,IAAIJ,eAAe,CAAWI,EAAE,CAAC;AAC5C,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _registry = require("../registry");
4
+ var _index = require("./index");
5
+ var _sourceHandler = require("../sourceHandler");
6
+ const handler = (0, _sourceHandler.createSourceHandler)({
7
+ name: "handler-aws-sqs",
8
+ canUse: event => {
9
+ if (!Array.isArray(event.Records) || event.Records.length === 0) {
10
+ return false;
11
+ }
12
+ const [record] = event.Records;
13
+ if (typeof record.eventSource !== "string") {
14
+ return false;
15
+ }
16
+ return record.eventSource.toLowerCase() === "aws:sqs";
17
+ },
18
+ handle: async ({
19
+ params,
20
+ event,
21
+ context
22
+ }) => {
23
+ return (0, _index.createHandler)(params)(event, context);
24
+ }
25
+ });
26
+ _registry.registry.register(handler);
27
+
28
+ //# sourceMappingURL=register.js.map
@@ -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 type { SQSEvent } from \"@webiny/aws-sdk/types\";\nimport { registry } from \"~/registry\";\nimport type { HandlerParams } from \"./index\";\nimport { createHandler } from \"./index\";\nimport { createSourceHandler } from \"~/sourceHandler\";\n\nconst handler = createSourceHandler<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":";;AACA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAEA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAA0B;EACzDC,IAAI,EAAE,iBAAiB;EACvBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,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","ignoreList":[]}
package/types.d.ts CHANGED
@@ -1,14 +1,37 @@
1
- import { APIGatewayEvent, Context as LambdaContext } from "aws-lambda";
1
+ import type { APIGatewayEvent, APIGatewayEventRequestContextWithAuthorizer, AttributeValue, Context as LambdaContext, DynamoDBRecord, DynamoDBStreamEvent, EventBridgeEvent, S3Event, SNSEvent, SQSEvent } from "@webiny/aws-sdk/types";
2
2
  import "fastify";
3
+ import type { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
4
+ import type { LambdaFastifyOptions as LambdaOptions } from "@fastify/aws-lambda";
5
+ import type { GenericRecord } from "@webiny/utils";
6
+ export type { AttributeValue, DynamoDBRecord };
7
+ export { HandlerRegistry } from "./registry";
3
8
  export * from "@webiny/handler/types";
9
+ export type { APIGatewayEvent, LambdaContext, APIGatewayEventRequestContextWithAuthorizer };
10
+ export type HandlerEvent = APIGatewayEvent | SNSEvent | SQSEvent | S3Event | EventBridgeEvent<string, string> | DynamoDBStreamEvent | GenericRecord<string>;
11
+ export interface EventResolver<T = any> {
12
+ (event: HandlerEvent, context: LambdaContext): T;
13
+ }
14
+ export interface HandlerFactoryParams extends BaseCreateHandlerParams {
15
+ lambdaOptions?: LambdaOptions;
16
+ }
17
+ export interface HandlerFactory<T extends HandlerFactoryParams = HandlerFactoryParams, R = any> {
18
+ (params: T): EventResolver<R>;
19
+ }
20
+ export interface HandlerParams<E, P extends HandlerFactoryParams> {
21
+ params: P;
22
+ event: E;
23
+ context: LambdaContext;
24
+ }
25
+ export interface SourceHandler<E = HandlerEvent, P extends HandlerFactoryParams = HandlerFactoryParams, T = any> {
26
+ name: string;
27
+ canUse: (event: Partial<E>, context: LambdaContext) => boolean;
28
+ handle: (params: HandlerParams<E, P>) => Promise<T>;
29
+ }
4
30
  export declare enum Base64EncodeHeader {
5
31
  encoded = "x-webiny-base64-encoded",
6
32
  binary = "x-webiny-binary"
7
33
  }
8
34
  declare module "fastify" {
9
- interface FastifyInstance {
10
- __webiny_raw_result: any;
11
- }
12
35
  interface FastifyRequest {
13
36
  awsLambda: {
14
37
  event: APIGatewayEvent;
package/types.js CHANGED
@@ -4,10 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
- Base64EncodeHeader: true
7
+ Base64EncodeHeader: true,
8
+ HandlerRegistry: true
8
9
  };
9
10
  exports.Base64EncodeHeader = void 0;
11
+ Object.defineProperty(exports, "HandlerRegistry", {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _registry.HandlerRegistry;
15
+ }
16
+ });
10
17
  require("fastify");
18
+ var _registry = require("./registry");
11
19
  var _types = require("@webiny/handler/types");
12
20
  Object.keys(_types).forEach(function (key) {
13
21
  if (key === "default" || key === "__esModule") return;
@@ -20,9 +28,10 @@ Object.keys(_types).forEach(function (key) {
20
28
  }
21
29
  });
22
30
  });
23
- let Base64EncodeHeader;
24
- exports.Base64EncodeHeader = Base64EncodeHeader;
25
- (function (Base64EncodeHeader) {
31
+ let Base64EncodeHeader = exports.Base64EncodeHeader = /*#__PURE__*/function (Base64EncodeHeader) {
26
32
  Base64EncodeHeader["encoded"] = "x-webiny-base64-encoded";
27
33
  Base64EncodeHeader["binary"] = "x-webiny-binary";
28
- })(Base64EncodeHeader || (exports.Base64EncodeHeader = Base64EncodeHeader = {}));
34
+ return Base64EncodeHeader;
35
+ }({});
36
+
37
+ //# 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;AAAsC,IAE1BA,kBAAkB;AAAA;AAAA,WAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;AAAA,GAAlBA,kBAAkB,kCAAlBA,kBAAkB"}
1
+ {"version":3,"names":["require","_registry","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","Base64EncodeHeader"],"sources":["types.ts"],"sourcesContent":["import type {\n APIGatewayEvent,\n APIGatewayEventRequestContextWithAuthorizer,\n AttributeValue,\n Context as LambdaContext,\n DynamoDBRecord,\n DynamoDBStreamEvent,\n EventBridgeEvent,\n S3Event,\n SNSEvent,\n SQSEvent\n} from \"@webiny/aws-sdk/types\";\nimport \"fastify\";\nimport type { CreateHandlerParams as BaseCreateHandlerParams } from \"@webiny/handler\";\nimport type { LambdaFastifyOptions as LambdaOptions } from \"@fastify/aws-lambda\";\nimport type { GenericRecord } from \"@webiny/utils\";\n\nexport type { AttributeValue, DynamoDBRecord };\n\nexport { HandlerRegistry } from \"~/registry\";\n\nexport * from \"@webiny/handler/types\";\n\nexport type { APIGatewayEvent, LambdaContext, APIGatewayEventRequestContextWithAuthorizer };\n\nexport type HandlerEvent =\n | APIGatewayEvent\n | SNSEvent\n | SQSEvent\n | S3Event\n | EventBridgeEvent<string, string>\n | DynamoDBStreamEvent\n | GenericRecord<string>;\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 FastifyRequest {\n awsLambda: {\n event: APIGatewayEvent;\n context: LambdaContext;\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAYAA,OAAA;AAOA,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,IAyC1BS,kBAAkB,GAAAJ,OAAA,CAAAI,kBAAA,0BAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from "@webiny/plugins/types";
2
+ type WrappedInput<TInput, TOutput> = TInput & {
3
+ next: () => Promise<TOutput>;
4
+ };
5
+ export declare const createComposedHandler: <P extends Plugin, TInput, TOutput>(plugins: P[]) => import("@webiny/utils").NextAsyncProcessor<WrappedInput<TInput, TOutput>, TOutput>;
6
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createComposedHandler = void 0;
7
+ var _utils = require("@webiny/utils");
8
+ const createComposedHandler = plugins => {
9
+ return (0, _utils.composeAsync)(plugins.map(plugin => {
10
+ return next => {
11
+ return async params => {
12
+ return plugin.cb({
13
+ ...params,
14
+ next: () => {
15
+ return next(params);
16
+ }
17
+ });
18
+ };
19
+ };
20
+ }));
21
+ };
22
+ exports.createComposedHandler = createComposedHandler;
23
+
24
+ //# sourceMappingURL=composedHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_utils","require","createComposedHandler","plugins","composeAsync","map","plugin","next","params","cb","exports"],"sources":["composedHandler.ts"],"sourcesContent":["import type { Plugin } from \"@webiny/plugins/types\";\nimport { composeAsync } from \"@webiny/utils\";\n\ntype WrappedInput<TInput, TOutput> = TInput & {\n next: () => Promise<TOutput>;\n};\n\nexport const createComposedHandler = <P extends Plugin, TInput, TOutput>(plugins: P[]) => {\n return composeAsync<WrappedInput<TInput, TOutput>, TOutput>(\n plugins.map(plugin => {\n return next => {\n return async params => {\n return plugin.cb({\n ...params,\n next: () => {\n return next(params);\n }\n });\n };\n };\n })\n );\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAMO,MAAMC,qBAAqB,GAAuCC,OAAY,IAAK;EACtF,OAAO,IAAAC,mBAAY,EACfD,OAAO,CAACE,GAAG,CAACC,MAAM,IAAI;IAClB,OAAOC,IAAI,IAAI;MACX,OAAO,MAAMC,MAAM,IAAI;QACnB,OAAOF,MAAM,CAACG,EAAE,CAAC;UACb,GAAGD,MAAM;UACTD,IAAI,EAAEA,CAAA,KAAM;YACR,OAAOA,IAAI,CAACC,MAAM,CAAC;UACvB;QACJ,CAAC,CAAC;MACN,CAAC;IACL,CAAC;EACL,CAAC,CACL,CAAC;AACL,CAAC;AAACE,OAAA,CAAAR,qBAAA,GAAAA,qBAAA","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./composedHandler";
2
+ export * from "./timer";
package/utils/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _composedHandler = require("./composedHandler");
7
+ Object.keys(_composedHandler).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _composedHandler[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _composedHandler[key];
14
+ }
15
+ });
16
+ });
17
+ var _timer = require("./timer");
18
+ Object.keys(_timer).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _timer[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _timer[key];
25
+ }
26
+ });
27
+ });
28
+
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_composedHandler","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_timer"],"sources":["index.ts"],"sourcesContent":["export * from \"./composedHandler\";\nexport * from \"./timer\";\n"],"mappings":";;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,gBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,gBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,gBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,MAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,MAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,MAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ export declare class CustomTimer {
2
+ private readonly startTime;
3
+ constructor();
4
+ getRemainingMilliseconds(): number;
5
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CustomTimer = void 0;
7
+ const MAX_RUNNING_MINUTES = 14;
8
+ const MAX_RUNNING_MILLISECONDS = MAX_RUNNING_MINUTES * 60 * 1000;
9
+ class CustomTimer {
10
+ constructor() {
11
+ this.startTime = Date.now();
12
+ }
13
+ getRemainingMilliseconds() {
14
+ return this.startTime + MAX_RUNNING_MILLISECONDS - Date.now(); // 14 minutes
15
+ }
16
+ }
17
+ exports.CustomTimer = CustomTimer;
18
+
19
+ //# sourceMappingURL=CustomTimer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["MAX_RUNNING_MINUTES","MAX_RUNNING_MILLISECONDS","CustomTimer","constructor","startTime","Date","now","getRemainingMilliseconds","exports"],"sources":["CustomTimer.ts"],"sourcesContent":["const MAX_RUNNING_MINUTES = 14;\nconst MAX_RUNNING_MILLISECONDS = MAX_RUNNING_MINUTES * 60 * 1000;\n\nexport class CustomTimer {\n private readonly startTime: number;\n\n public constructor() {\n this.startTime = Date.now();\n }\n\n public getRemainingMilliseconds(): number {\n return this.startTime + MAX_RUNNING_MILLISECONDS - Date.now(); // 14 minutes\n }\n}\n"],"mappings":";;;;;;AAAA,MAAMA,mBAAmB,GAAG,EAAE;AAC9B,MAAMC,wBAAwB,GAAGD,mBAAmB,GAAG,EAAE,GAAG,IAAI;AAEzD,MAAME,WAAW,CAAC;EAGdC,WAAWA,CAAA,EAAG;IACjB,IAAI,CAACC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;EAC/B;EAEOC,wBAAwBA,CAAA,EAAW;IACtC,OAAO,IAAI,CAACH,SAAS,GAAGH,wBAAwB,GAAGI,IAAI,CAACC,GAAG,CAAC,CAAC,CAAC,CAAC;EACnE;AACJ;AAACE,OAAA,CAAAN,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import type { ITimer } from "./abstractions/ITimer";
2
+ export interface ITimerCb {
3
+ (): number;
4
+ }
5
+ export declare class Timer implements ITimer {
6
+ private readonly cb;
7
+ constructor(cb: ITimerCb);
8
+ getRemainingMilliseconds(): number;
9
+ getRemainingSeconds(): number;
10
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Timer = void 0;
7
+ class Timer {
8
+ constructor(cb) {
9
+ this.cb = cb;
10
+ }
11
+ getRemainingMilliseconds() {
12
+ return this.cb();
13
+ }
14
+ getRemainingSeconds() {
15
+ const result = this.cb();
16
+ if (result > 0) {
17
+ return Math.floor(result / 1000);
18
+ }
19
+ return 0;
20
+ }
21
+ }
22
+ exports.Timer = Timer;
23
+
24
+ //# sourceMappingURL=Timer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Timer","constructor","cb","getRemainingMilliseconds","getRemainingSeconds","result","Math","floor","exports"],"sources":["Timer.ts"],"sourcesContent":["import type { ITimer } from \"./abstractions/ITimer\";\n\nexport interface ITimerCb {\n (): number;\n}\n\nexport class Timer implements ITimer {\n private readonly cb: ITimerCb;\n\n public constructor(cb: ITimerCb) {\n this.cb = cb;\n }\n public getRemainingMilliseconds(): number {\n return this.cb();\n }\n\n public getRemainingSeconds(): number {\n const result = this.cb();\n if (result > 0) {\n return Math.floor(result / 1000);\n }\n return 0;\n }\n}\n"],"mappings":";;;;;;AAMO,MAAMA,KAAK,CAAmB;EAG1BC,WAAWA,CAACC,EAAY,EAAE;IAC7B,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EACOC,wBAAwBA,CAAA,EAAW;IACtC,OAAO,IAAI,CAACD,EAAE,CAAC,CAAC;EACpB;EAEOE,mBAAmBA,CAAA,EAAW;IACjC,MAAMC,MAAM,GAAG,IAAI,CAACH,EAAE,CAAC,CAAC;IACxB,IAAIG,MAAM,GAAG,CAAC,EAAE;MACZ,OAAOC,IAAI,CAACC,KAAK,CAACF,MAAM,GAAG,IAAI,CAAC;IACpC;IACA,OAAO,CAAC;EACZ;AACJ;AAACG,OAAA,CAAAR,KAAA,GAAAA,KAAA","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ export interface ITimer {
2
+ /**
3
+ * Return value must be in milliseconds.
4
+ */
5
+ getRemainingMilliseconds(): number;
6
+ /**
7
+ * Return value must be in seconds.
8
+ */
9
+ getRemainingSeconds(): number;
10
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=ITimer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["ITimer.ts"],"sourcesContent":["export interface ITimer {\n /**\n * Return value must be in milliseconds.\n */\n getRemainingMilliseconds(): number;\n /**\n * Return value must be in seconds.\n */\n getRemainingSeconds(): number;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { ITimer } from "./abstractions/ITimer";
2
+ import type { Context as LambdaContext } from "@webiny/aws-sdk/types";
3
+ export type ITimerFactoryParams = Pick<LambdaContext, "getRemainingTimeInMillis">;
4
+ export declare const timerFactory: (params?: Partial<ITimerFactoryParams>) => ITimer;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.timerFactory = void 0;
7
+ var _CustomTimer = require("./CustomTimer");
8
+ var _Timer = require("./Timer");
9
+ const timerFactory = params => {
10
+ const customTimer = new _CustomTimer.CustomTimer();
11
+ return new _Timer.Timer(() => {
12
+ if (params?.getRemainingTimeInMillis) {
13
+ return params.getRemainingTimeInMillis();
14
+ }
15
+ return customTimer.getRemainingMilliseconds();
16
+ });
17
+ };
18
+ exports.timerFactory = timerFactory;
19
+
20
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_CustomTimer","require","_Timer","timerFactory","params","customTimer","CustomTimer","Timer","getRemainingTimeInMillis","getRemainingMilliseconds","exports"],"sources":["factory.ts"],"sourcesContent":["import type { ITimer } from \"./abstractions/ITimer\";\nimport { CustomTimer } from \"./CustomTimer\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types\";\nimport { Timer } from \"./Timer\";\n\nexport type ITimerFactoryParams = Pick<LambdaContext, \"getRemainingTimeInMillis\">;\n\nexport const timerFactory = (params?: Partial<ITimerFactoryParams>): ITimer => {\n const customTimer = new CustomTimer();\n\n return new Timer(() => {\n if (params?.getRemainingTimeInMillis) {\n return params.getRemainingTimeInMillis();\n }\n return customTimer.getRemainingMilliseconds();\n });\n};\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAIO,MAAME,YAAY,GAAIC,MAAqC,IAAa;EAC3E,MAAMC,WAAW,GAAG,IAAIC,wBAAW,CAAC,CAAC;EAErC,OAAO,IAAIC,YAAK,CAAC,MAAM;IACnB,IAAIH,MAAM,EAAEI,wBAAwB,EAAE;MAClC,OAAOJ,MAAM,CAACI,wBAAwB,CAAC,CAAC;IAC5C;IACA,OAAOH,WAAW,CAACI,wBAAwB,CAAC,CAAC;EACjD,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAP,YAAA,GAAAA,YAAA","ignoreList":[]}