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

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 (98) hide show
  1. package/README.md +10 -14
  2. package/createHandler.d.ts +1 -1
  3. package/createHandler.js +20 -26
  4. package/createHandler.js.map +1 -1
  5. package/dynamodb/index.d.ts +3 -3
  6. package/dynamodb/index.js +39 -76
  7. package/dynamodb/index.js.map +1 -1
  8. package/dynamodb/plugins/DynamoDBEventHandler.d.ts +4 -4
  9. package/dynamodb/plugins/DynamoDBEventHandler.js +11 -18
  10. package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
  11. package/dynamodb/register.js +13 -25
  12. package/dynamodb/register.js.map +1 -1
  13. package/eventBridge/index.d.ts +3 -3
  14. package/eventBridge/index.js +39 -76
  15. package/eventBridge/index.js.map +1 -1
  16. package/eventBridge/plugins/EventBridgeEventHandler.d.ts +4 -4
  17. package/eventBridge/plugins/EventBridgeEventHandler.js +11 -18
  18. package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
  19. package/eventBridge/register.d.ts +1 -1
  20. package/eventBridge/register.js +8 -18
  21. package/eventBridge/register.js.map +1 -1
  22. package/execute.d.ts +1 -1
  23. package/execute.js +53 -68
  24. package/execute.js.map +1 -1
  25. package/gateway/index.d.ts +2 -2
  26. package/gateway/index.js +41 -83
  27. package/gateway/index.js.map +1 -1
  28. package/gateway/register.js +8 -18
  29. package/gateway/register.js.map +1 -1
  30. package/index.d.ts +17 -17
  31. package/index.js +17 -374
  32. package/package.json +22 -19
  33. package/plugins/index.d.ts +1 -1
  34. package/plugins/index.js +3 -10
  35. package/plugins/index.js.map +1 -1
  36. package/raw/index.d.ts +3 -3
  37. package/raw/index.js +42 -86
  38. package/raw/index.js.map +1 -1
  39. package/raw/plugins/RawEventHandler.d.ts +3 -3
  40. package/raw/plugins/RawEventHandler.js +12 -30
  41. package/raw/plugins/RawEventHandler.js.map +1 -1
  42. package/registry.d.ts +2 -2
  43. package/registry.js +17 -38
  44. package/registry.js.map +1 -1
  45. package/s3/index.d.ts +3 -3
  46. package/s3/index.js +39 -76
  47. package/s3/index.js.map +1 -1
  48. package/s3/plugins/S3EventHandler.d.ts +4 -4
  49. package/s3/plugins/S3EventHandler.js +11 -18
  50. package/s3/plugins/S3EventHandler.js.map +1 -1
  51. package/s3/register.d.ts +1 -1
  52. package/s3/register.js +12 -22
  53. package/s3/register.js.map +1 -1
  54. package/sns/index.d.ts +3 -3
  55. package/sns/index.js +39 -76
  56. package/sns/index.js.map +1 -1
  57. package/sns/plugins/SNSEventHandler.d.ts +4 -4
  58. package/sns/plugins/SNSEventHandler.js +11 -18
  59. package/sns/plugins/SNSEventHandler.js.map +1 -1
  60. package/sns/register.js +12 -22
  61. package/sns/register.js.map +1 -1
  62. package/sourceHandler.d.ts +2 -2
  63. package/sourceHandler.js +2 -10
  64. package/sourceHandler.js.map +1 -1
  65. package/sqs/index.d.ts +3 -3
  66. package/sqs/index.js +40 -79
  67. package/sqs/index.js.map +1 -1
  68. package/sqs/plugins/SQSEventHandler.d.ts +4 -4
  69. package/sqs/plugins/SQSEventHandler.js +11 -18
  70. package/sqs/plugins/SQSEventHandler.js.map +1 -1
  71. package/sqs/register.js +13 -25
  72. package/sqs/register.js.map +1 -1
  73. package/types.d.ts +3 -3
  74. package/types.js +7 -34
  75. package/types.js.map +1 -1
  76. package/utils/composedHandler.d.ts +1 -1
  77. package/utils/composedHandler.js +6 -22
  78. package/utils/composedHandler.js.map +1 -1
  79. package/utils/index.d.ts +2 -2
  80. package/utils/index.js +2 -29
  81. package/utils/timer/CustomTimer.js +8 -14
  82. package/utils/timer/CustomTimer.js.map +1 -1
  83. package/utils/timer/Timer.d.ts +1 -1
  84. package/utils/timer/Timer.js +11 -19
  85. package/utils/timer/Timer.js.map +1 -1
  86. package/utils/timer/abstractions/ITimer.js +0 -7
  87. package/utils/timer/factory.d.ts +2 -2
  88. package/utils/timer/factory.js +9 -17
  89. package/utils/timer/factory.js.map +1 -1
  90. package/utils/timer/index.d.ts +4 -4
  91. package/utils/timer/index.js +3 -51
  92. package/index.js.map +0 -1
  93. package/plugins/handlerClient.d.ts +0 -2
  94. package/plugins/handlerClient.js +0 -53
  95. package/plugins/handlerClient.js.map +0 -1
  96. package/utils/index.js.map +0 -1
  97. package/utils/timer/abstractions/ITimer.js.map +0 -1
  98. package/utils/timer/index.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import type { Context as LambdaContext } from "@webiny/aws-sdk/types";
2
- import type { Context as BaseContext, Reply } from "@webiny/handler/types";
1
+ import type { Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
2
+ import type { Context as BaseContext, Reply } from "@webiny/handler/types.js";
3
3
  import type { EventPluginCallableParams } from "@webiny/handler";
4
4
  import { EventPlugin } from "@webiny/handler";
5
5
  export interface RawEventHandlerCallableParams<Event, Context extends BaseContext> extends EventPluginCallableParams<Event, Context> {
@@ -21,4 +21,4 @@ export declare class RawEventHandler<Event = any, Context extends BaseContext =
21
21
  */
22
22
  canHandle(event: Event): boolean;
23
23
  }
24
- export declare const createEventHandler: <Event_1 = any, Context extends BaseContext = BaseContext, Response_1 = any>(params: RawEventHandlerParams<Event_1, Context, Response_1>) => RawEventHandler<Event_1, Context, Response_1>;
24
+ export declare const createEventHandler: <Event = any, Context extends BaseContext = BaseContext, Response = any>(params: RawEventHandlerParams<Event, Context, Response>) => RawEventHandler<Event, Context, Response>;
@@ -1,34 +1,16 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createEventHandler = exports.RawEventHandler = void 0;
7
- var _handler = require("@webiny/handler");
8
- class RawEventHandler extends _handler.EventPlugin {
9
- constructor(params) {
10
- const cb = typeof params === "function" ? params : params.handle;
11
- /**
12
- * Callable is correct, TS is just having problems with the override.
13
- */
14
- // @ts-expect-error
15
- super(cb);
16
- this.params = params;
17
- }
18
- /**
19
- *
20
- */
21
- canHandle(event) {
22
- if (typeof this.params === "function" || !this.params?.canHandle) {
23
- return true;
1
+ import { EventPlugin } from "@webiny/handler";
2
+ class RawEventHandler extends EventPlugin {
3
+ constructor(params){
4
+ const cb = "function" == typeof params ? params : params.handle;
5
+ super(cb);
6
+ this.params = params;
7
+ }
8
+ canHandle(event) {
9
+ if ("function" == typeof this.params || !this.params?.canHandle) return true;
10
+ return this.params.canHandle(event);
24
11
  }
25
- return this.params.canHandle(event);
26
- }
27
12
  }
28
- exports.RawEventHandler = RawEventHandler;
29
- const createEventHandler = params => {
30
- return new RawEventHandler(params);
31
- };
32
- exports.createEventHandler = createEventHandler;
13
+ const createEventHandler = (params)=>new RawEventHandler(params);
14
+ export { RawEventHandler, createEventHandler };
33
15
 
34
16
  //# sourceMappingURL=RawEventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_handler","require","RawEventHandler","EventPlugin","constructor","params","cb","handle","canHandle","event","exports","createEventHandler"],"sources":["RawEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext } from \"@webiny/aws-sdk/types\";\nimport type { Context as BaseContext, Reply } from \"@webiny/handler/types\";\nimport type { EventPluginCallableParams } from \"@webiny/handler\";\nimport { EventPlugin } from \"@webiny/handler\";\n\nexport interface RawEventHandlerCallableParams<Event, Context extends BaseContext>\n extends EventPluginCallableParams<Event, Context> {\n lambdaContext: LambdaContext;\n}\nexport interface RawEventHandlerCallable<Event, Context extends BaseContext, Response> {\n (params: RawEventHandlerCallableParams<Event, Context>): Promise<Response | Reply>;\n}\n\nexport interface RawEventHandlerParamsConfig<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> {\n canHandle(event: Event): boolean;\n handle: RawEventHandlerCallable<Event, Context, Response>;\n}\n\nexport type RawEventHandlerParams<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> =\n | RawEventHandlerCallable<Event, Context, Response>\n | RawEventHandlerParamsConfig<Event, Context, Response>;\n\nexport class RawEventHandler<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends EventPlugin<Event, Context, Response> {\n private readonly params: RawEventHandlerParams<Event, Context, Response>;\n\n public constructor(params: RawEventHandlerParams<Event, Context, Response>) {\n const cb = typeof params === \"function\" ? params : params.handle;\n /**\n * Callable is correct, TS is just having problems with the override.\n */\n // @ts-expect-error\n super(cb);\n this.params = params;\n }\n /**\n *\n */\n public canHandle(event: Event): boolean {\n if (typeof this.params === \"function\" || !this.params?.canHandle) {\n return true;\n }\n return this.params.canHandle(event);\n }\n}\n\nexport const createEventHandler = <\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n params: RawEventHandlerParams<Event, Context, Response>\n) => {\n return new RawEventHandler<Event, Context, Response>(params);\n};\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AA2BO,MAAMC,eAAe,SAIlBC,oBAAW,CAA2B;EAGrCC,WAAWA,CAACC,MAAuD,EAAE;IACxE,MAAMC,EAAE,GAAG,OAAOD,MAAM,KAAK,UAAU,GAAGA,MAAM,GAAGA,MAAM,CAACE,MAAM;IAChE;AACR;AACA;IACQ;IACA,KAAK,CAACD,EAAE,CAAC;IACT,IAAI,CAACD,MAAM,GAAGA,MAAM;EACxB;EACA;AACJ;AACA;EACWG,SAASA,CAACC,KAAY,EAAW;IACpC,IAAI,OAAO,IAAI,CAACJ,MAAM,KAAK,UAAU,IAAI,CAAC,IAAI,CAACA,MAAM,EAAEG,SAAS,EAAE;MAC9D,OAAO,IAAI;IACf;IACA,OAAO,IAAI,CAACH,MAAM,CAACG,SAAS,CAACC,KAAK,CAAC;EACvC;AACJ;AAACC,OAAA,CAAAR,eAAA,GAAAA,eAAA;AAEM,MAAMS,kBAAkB,GAK3BN,MAAuD,IACtD;EACD,OAAO,IAAIH,eAAe,CAA2BG,MAAM,CAAC;AAChE,CAAC;AAACK,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
1
+ {"version":3,"file":"raw/plugins/RawEventHandler.js","sources":["../../../src/raw/plugins/RawEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\nimport type { Context as BaseContext, Reply } from \"@webiny/handler/types.js\";\nimport type { EventPluginCallableParams } from \"@webiny/handler\";\nimport { EventPlugin } from \"@webiny/handler\";\n\nexport interface RawEventHandlerCallableParams<\n Event,\n Context extends BaseContext\n> extends EventPluginCallableParams<Event, Context> {\n lambdaContext: LambdaContext;\n}\nexport interface RawEventHandlerCallable<Event, Context extends BaseContext, Response> {\n (params: RawEventHandlerCallableParams<Event, Context>): Promise<Response | Reply>;\n}\n\nexport interface RawEventHandlerParamsConfig<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> {\n canHandle(event: Event): boolean;\n handle: RawEventHandlerCallable<Event, Context, Response>;\n}\n\nexport type RawEventHandlerParams<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> =\n | RawEventHandlerCallable<Event, Context, Response>\n | RawEventHandlerParamsConfig<Event, Context, Response>;\n\nexport class RawEventHandler<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends EventPlugin<Event, Context, Response> {\n private readonly params: RawEventHandlerParams<Event, Context, Response>;\n\n public constructor(params: RawEventHandlerParams<Event, Context, Response>) {\n const cb = typeof params === \"function\" ? params : params.handle;\n /**\n * Callable is correct, TS is just having problems with the override.\n */\n // @ts-expect-error\n super(cb);\n this.params = params;\n }\n /**\n *\n */\n public canHandle(event: Event): boolean {\n if (typeof this.params === \"function\" || !this.params?.canHandle) {\n return true;\n }\n return this.params.canHandle(event);\n }\n}\n\nexport const createEventHandler = <\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n params: RawEventHandlerParams<Event, Context, Response>\n) => {\n return new RawEventHandler<Event, Context, Response>(params);\n};\n"],"names":["RawEventHandler","EventPlugin","params","cb","event","createEventHandler"],"mappings":";AAgCO,MAAMA,wBAIHC;IAGN,YAAmBC,MAAuD,CAAE;QACxE,MAAMC,KAAK,AAAkB,cAAlB,OAAOD,SAAwBA,SAASA,OAAO,MAAM;QAKhE,KAAK,CAACC;QACN,IAAI,CAAC,MAAM,GAAGD;IAClB;IAIO,UAAUE,KAAY,EAAW;QACpC,IAAI,AAAuB,cAAvB,OAAO,IAAI,CAAC,MAAM,IAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,WACnD,OAAO;QAEX,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAACA;IACjC;AACJ;AAEO,MAAMC,qBAAqB,CAK9BH,SAEO,IAAIF,gBAA0CE"}
package/registry.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * TODO: refactor this to use a proper DI container
3
3
  */
4
- import type { HandlerEvent, SourceHandler } from "./types";
5
- import type { Context as LambdaContext } from "@webiny/aws-sdk/types";
4
+ import type { HandlerEvent, SourceHandler } from "./types.js";
5
+ import type { Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
6
6
  interface RegisterOptions {
7
7
  silent?: boolean;
8
8
  }
package/registry.js CHANGED
@@ -1,44 +1,23 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.registry = void 0;
7
- /**
8
- * TODO: refactor this to use a proper DI container
9
- */
10
-
11
1
  class HandlerRegistry {
12
- handlers = new Map();
13
- constructor() {
14
- /**
15
- * We don't want this class to be constructed outside the static create() method
16
- */
17
- }
18
- static create() {
19
- return new HandlerRegistry();
20
- }
21
- register(handler, options) {
22
- if (this.handlers.has(handler.name)) {
23
- if (options?.silent) {
24
- return;
25
- }
26
- /**
27
- * This should only happen during the development phase.
28
- */
29
- throw new Error(`Handler "${handler.name}" is already registered.`);
2
+ constructor(){
3
+ this.handlers = new Map();
4
+ }
5
+ static create() {
6
+ return new HandlerRegistry();
7
+ }
8
+ register(handler, options) {
9
+ if (this.handlers.has(handler.name)) {
10
+ if (options?.silent) return;
11
+ throw new Error(`Handler "${handler.name}" is already registered.`);
12
+ }
13
+ this.handlers.set(handler.name, handler);
30
14
  }
31
- this.handlers.set(handler.name, handler);
32
- }
33
- getHandler(event, context) {
34
- for (const handler of this.handlers.values()) {
35
- if (handler.canUse(event, context)) {
36
- return handler;
37
- }
15
+ getHandler(event, context) {
16
+ for (const handler of this.handlers.values())if (handler.canUse(event, context)) return handler;
17
+ throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
38
18
  }
39
- throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
40
- }
41
19
  }
42
- const registry = exports.registry = HandlerRegistry.create();
20
+ const registry = HandlerRegistry.create();
21
+ export { registry };
43
22
 
44
23
  //# sourceMappingURL=registry.js.map
package/registry.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["HandlerRegistry","handlers","Map","constructor","create","register","handler","options","has","name","silent","Error","set","getHandler","event","context","values","canUse","JSON","stringify","registry","exports"],"sources":["registry.ts"],"sourcesContent":["/**\n * TODO: refactor this to use a proper DI container\n */\nimport type { HandlerEvent, SourceHandler } from \"~/types\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types\";\n\ninterface RegisterOptions {\n silent?: boolean;\n}\n\nclass HandlerRegistry {\n private readonly handlers = new Map<string, SourceHandler>();\n\n private constructor() {\n /**\n * We don't want this class to be constructed outside the static create() method\n */\n }\n\n public static create() {\n return new HandlerRegistry();\n }\n\n public register(handler: SourceHandler<any>, options?: RegisterOptions) {\n if (this.handlers.has(handler.name)) {\n if (options?.silent) {\n return;\n }\n /**\n * This should only happen during the development phase.\n */\n throw new Error(`Handler \"${handler.name}\" is already registered.`);\n }\n this.handlers.set(handler.name, handler);\n }\n\n public getHandler(event: HandlerEvent, context: LambdaContext): SourceHandler {\n for (const handler of this.handlers.values()) {\n if (handler.canUse(event, context)) {\n return handler;\n }\n }\n throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);\n }\n}\n\nexport type { HandlerRegistry };\n\nexport const registry = HandlerRegistry.create();\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAQA,MAAMA,eAAe,CAAC;EACDC,QAAQ,GAAG,IAAIC,GAAG,CAAwB,CAAC;EAEpDC,WAAWA,CAAA,EAAG;IAClB;AACR;AACA;EAFQ;EAKJ,OAAcC,MAAMA,CAAA,EAAG;IACnB,OAAO,IAAIJ,eAAe,CAAC,CAAC;EAChC;EAEOK,QAAQA,CAACC,OAA2B,EAAEC,OAAyB,EAAE;IACpE,IAAI,IAAI,CAACN,QAAQ,CAACO,GAAG,CAACF,OAAO,CAACG,IAAI,CAAC,EAAE;MACjC,IAAIF,OAAO,EAAEG,MAAM,EAAE;QACjB;MACJ;MACA;AACZ;AACA;MACY,MAAM,IAAIC,KAAK,CAAC,YAAYL,OAAO,CAACG,IAAI,0BAA0B,CAAC;IACvE;IACA,IAAI,CAACR,QAAQ,CAACW,GAAG,CAACN,OAAO,CAACG,IAAI,EAAEH,OAAO,CAAC;EAC5C;EAEOO,UAAUA,CAACC,KAAmB,EAAEC,OAAsB,EAAiB;IAC1E,KAAK,MAAMT,OAAO,IAAI,IAAI,CAACL,QAAQ,CAACe,MAAM,CAAC,CAAC,EAAE;MAC1C,IAAIV,OAAO,CAACW,MAAM,CAACH,KAAK,EAAEC,OAAO,CAAC,EAAE;QAChC,OAAOT,OAAO;MAClB;IACJ;IACA,MAAM,IAAIK,KAAK,CAAC,sCAAsCO,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC,EAAE,CAAC;EAClF;AACJ;AAIO,MAAMM,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAGpB,eAAe,CAACI,MAAM,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"registry.js","sources":["../src/registry.ts"],"sourcesContent":["/**\n * TODO: refactor this to use a proper DI container\n */\nimport type { HandlerEvent, SourceHandler } from \"~/types.js\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\n\ninterface RegisterOptions {\n silent?: boolean;\n}\n\nclass HandlerRegistry {\n private readonly handlers = new Map<string, SourceHandler>();\n\n private constructor() {\n /**\n * We don't want this class to be constructed outside the static create() method\n */\n }\n\n public static create() {\n return new HandlerRegistry();\n }\n\n public register(handler: SourceHandler<any>, options?: RegisterOptions) {\n if (this.handlers.has(handler.name)) {\n if (options?.silent) {\n return;\n }\n /**\n * This should only happen during the development phase.\n */\n throw new Error(`Handler \"${handler.name}\" is already registered.`);\n }\n this.handlers.set(handler.name, handler);\n }\n\n public getHandler(event: HandlerEvent, context: LambdaContext): SourceHandler {\n for (const handler of this.handlers.values()) {\n if (handler.canUse(event, context)) {\n return handler;\n }\n }\n throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);\n }\n}\n\nexport type { HandlerRegistry };\n\nexport const registry = HandlerRegistry.create();\n"],"names":["HandlerRegistry","Map","handler","options","Error","event","context","JSON","registry"],"mappings":"AAUA,MAAMA;IAGF,aAAsB;aAFL,QAAQ,GAAG,IAAIC;IAMhC;IAEA,OAAc,SAAS;QACnB,OAAO,IAAID;IACf;IAEO,SAASE,OAA2B,EAAEC,OAAyB,EAAE;QACpE,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACD,QAAQ,IAAI,GAAG;YACjC,IAAIC,SAAS,QACT;YAKJ,MAAM,IAAIC,MAAM,CAAC,SAAS,EAAEF,QAAQ,IAAI,CAAC,wBAAwB,CAAC;QACtE;QACA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA,QAAQ,IAAI,EAAEA;IACpC;IAEO,WAAWG,KAAmB,EAAEC,OAAsB,EAAiB;QAC1E,KAAK,MAAMJ,WAAW,IAAI,CAAC,QAAQ,CAAC,MAAM,GACtC,IAAIA,QAAQ,MAAM,CAACG,OAAOC,UACtB,OAAOJ;QAGf,MAAM,IAAIE,MAAM,CAAC,mCAAmC,EAAEG,KAAK,SAAS,CAACF,QAAQ;IACjF;AACJ;AAIO,MAAMG,WAAWR,gBAAgB,MAAM"}
package/s3/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { HandlerFactoryParams } from "../types";
2
- import type { APIGatewayProxyResult, Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types";
3
- export * from "./plugins/S3EventHandler";
1
+ import type { HandlerFactoryParams } from "../types.js";
2
+ import type { APIGatewayProxyResult, Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types/index.js";
3
+ export * from "./plugins/S3EventHandler.js";
4
4
  export interface HandlerCallable {
5
5
  (event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;
6
6
  }
package/s3/index.js CHANGED
@@ -1,79 +1,42 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- var _exportNames = {
8
- createHandler: true
9
- };
10
- exports.createHandler = void 0;
11
- var _handler = require("@webiny/handler");
12
- var _plugins = require("../plugins");
13
- var _S3EventHandler = require("./plugins/S3EventHandler");
14
- Object.keys(_S3EventHandler).forEach(function (key) {
15
- if (key === "default" || key === "__esModule") return;
16
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
17
- if (key in exports && exports[key] === _S3EventHandler[key]) return;
18
- Object.defineProperty(exports, key, {
19
- enumerable: true,
20
- get: function () {
21
- return _S3EventHandler[key];
22
- }
23
- });
24
- });
25
- var _execute = require("../execute");
26
- var _reply = _interopRequireDefault(require("fastify/lib/reply"));
27
- var _composedHandler = require("../utils/composedHandler");
28
- /**
29
- * We need a class, not an interface exported from types.
30
- */
31
- // @ts-expect-error
32
-
1
+ import { createHandler } from "@webiny/handler";
2
+ import { registerDefaultPlugins } from "../plugins/index.js";
3
+ import { S3EventHandler } from "./plugins/S3EventHandler.js";
4
+ import { execute } from "../execute.js";
5
+ import lib_reply from "fastify/lib/reply.js";
6
+ import { createComposedHandler } from "../utils/composedHandler.js";
7
+ export * from "./plugins/S3EventHandler.js";
33
8
  const url = "/webiny-s3-event";
34
- const createHandler = params => {
35
- return async (event, context) => {
36
- const app = (0, _handler.createHandler)({
37
- ...params,
38
- options: {
39
- logger: params.debug === true,
40
- ...(params.options || {})
41
- }
42
- });
43
- /**
44
- * We always must add our default plugins to the app.
45
- */
46
- (0, _plugins.registerDefaultPlugins)(app.webiny);
47
- /**
48
- * There must be an event plugin for this handler to work.
49
- */
50
- const plugins = app.webiny.plugins.byType(_S3EventHandler.S3EventHandler.type).reverse();
51
- if (plugins.length === 0) {
52
- throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);
53
- }
54
- const handler = (0, _composedHandler.createComposedHandler)(plugins);
55
- app.post(url, async (request, reply) => {
56
- const params = {
57
- request,
58
- reply,
59
- context: app.webiny,
60
- event,
61
- lambdaContext: context
62
- };
63
- const result = await handler(params);
64
- if (result instanceof _reply.default) {
65
- return result;
66
- }
67
- app.__webiny_raw_result = result;
68
- return reply.send({});
69
- });
70
- return (0, _execute.execute)({
71
- app,
72
- url,
73
- payload: event
74
- });
75
- };
76
- };
77
- exports.createHandler = createHandler;
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 };
78
41
 
79
42
  //# sourceMappingURL=index.js.map
package/s3/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_handler","require","_plugins","_S3EventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","event","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","S3EventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","send","execute","payload"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport type { S3EventHandlerCallableParams } from \"~/s3/plugins/S3EventHandler\";\nimport { S3EventHandler } from \"~/s3/plugins/S3EventHandler\";\nimport { execute } from \"~/execute\";\nimport type { HandlerFactoryParams } from \"~/types\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n S3Event\n} from \"@webiny/aws-sdk/types\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\n\nexport * from \"./plugins/S3EventHandler\";\n\nexport interface HandlerCallable {\n (event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-s3-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<S3EventHandler>(S3EventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);\n }\n\n const handler = createComposedHandler<\n S3EventHandler,\n S3EventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<S3EventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n const result = await handler(\n params as unknown as S3EventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AAeAG,MAAA,CAAAC,IAAA,CAAAF,eAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,eAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,eAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAdA,IAAAS,QAAA,GAAAf,OAAA;AAMA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AAMA,IAAAkB,gBAAA,GAAAlB,OAAA;AAVA;AACA;AACA;AACA;;AAiBA,MAAMmB,GAAG,GAAG,kBAAkB;AAEvB,MAAMC,aAAa,GAAIC,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,EAAC;MAC1B,GAAGJ,MAAM;MACTK,OAAO,EAAE;QACLC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK,IAAI;QAC7B,IAAIP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CAAiBC,8BAAc,CAACC,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IACxF,IAAIJ,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,kEAAkE,CAAC;IACvF;IAEA,MAAMC,OAAO,GAAG,IAAAC,sCAAqB,EAInCR,OAAO,CAAC;IAEVP,GAAG,CAACgB,IAAI,CAACrB,GAAG,EAAE,OAAOsB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAAyE,GAAG;QAC9EoB,OAAO;QACPC,KAAK;QACLnB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,KAAK;QACLqB,aAAa,EAAEpB;MACnB,CAAC;MACD,MAAMqB,MAAM,GAAG,MAAMN,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIuB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEApB,GAAG,CAACsB,mBAAmB,GAAGF,MAAM;MAChC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXxB,GAAG;MACHL,GAAG;MACH8B,OAAO,EAAE3B;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
1
+ {"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,6 +1,6 @@
1
- import type { Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types";
2
- import { Plugin } from "@webiny/plugins/Plugin";
3
- import type { Context, Reply, Request } from "@webiny/handler/types";
1
+ import type { Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types/index.js";
2
+ import { Plugin } from "@webiny/plugins/Plugin.js";
3
+ import type { Context, Reply, Request } from "@webiny/handler/types.js";
4
4
  export interface S3EventHandlerCallableParams<Response = Reply> {
5
5
  request: Request;
6
6
  context: Context;
@@ -17,4 +17,4 @@ export declare class S3EventHandler<Response = any> extends Plugin {
17
17
  readonly cb: S3EventHandlerCallable<Response>;
18
18
  constructor(cb: S3EventHandlerCallable<Response>);
19
19
  }
20
- export declare const createEventHandler: <Response_1>(cb: S3EventHandlerCallable<Response_1>) => S3EventHandler<Response_1>;
20
+ export declare const createEventHandler: <Response>(cb: S3EventHandlerCallable<Response>) => S3EventHandler<Response>;
@@ -1,21 +1,14 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createEventHandler = exports.S3EventHandler = void 0;
7
- var _Plugin = require("@webiny/plugins/Plugin");
8
- class S3EventHandler extends _Plugin.Plugin {
9
- static type = "handler.fastify.aws.s3.eventHandler";
10
- constructor(cb) {
11
- super();
12
- this.cb = cb;
13
- }
1
+ import { Plugin } from "@webiny/plugins/Plugin.js";
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
+ }
14
10
  }
15
- exports.S3EventHandler = S3EventHandler;
16
- const createEventHandler = cb => {
17
- return new S3EventHandler(cb);
18
- };
19
- exports.createEventHandler = createEventHandler;
11
+ const createEventHandler = (cb)=>new S3EventHandler(cb);
12
+ export { S3EventHandler, createEventHandler };
20
13
 
21
14
  //# sourceMappingURL=S3EventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_Plugin","require","S3EventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["S3EventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, S3Event } from \"@webiny/aws-sdk/types\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types\";\n\nexport interface S3EventHandlerCallableParams<Response = Reply> {\n request: Request;\n context: Context;\n event: S3Event;\n lambdaContext: LambdaContext;\n reply: Reply;\n next: () => Promise<Response>;\n}\n\nexport interface S3EventHandlerCallable<Response = Reply> {\n (params: S3EventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class S3EventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.s3.eventHandler\";\n\n public readonly cb: S3EventHandlerCallable<Response>;\n\n public constructor(cb: S3EventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: S3EventHandlerCallable<Response>) => {\n return new S3EventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAgBO,MAAMC,cAAc,SAAyBC,cAAM,CAAC;EACvD,OAAuBC,IAAI,GAAG,qCAAqC;EAI5DC,WAAWA,CAACC,EAAoC,EAAE;IACrD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,cAAA,GAAAA,cAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAAoC,IAAK;EAClF,OAAO,IAAIJ,cAAc,CAAWI,EAAE,CAAC;AAC3C,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { HandlerFactoryParams } from "../types";
1
+ import type { HandlerFactoryParams } from "../types.js";
2
2
  export interface HandlerParams extends HandlerFactoryParams {
3
3
  debug?: boolean;
4
4
  }
package/s3/register.js CHANGED
@@ -1,25 +1,15 @@
1
- "use strict";
2
-
3
- var _registry = require("../registry");
4
- var _sourceHandler = require("../sourceHandler");
5
- var _index = require("./index");
6
- const handler = (0, _sourceHandler.createSourceHandler)({
7
- name: "handler-aws-s3",
8
- canUse: event => {
9
- if (!Array.isArray(event.Records) || event.Records.length === 0) {
10
- return false;
11
- }
12
- const [record] = event.Records;
13
- return !!record.s3;
14
- },
15
- handle: async ({
16
- params,
17
- event,
18
- context
19
- }) => {
20
- return (0, _index.createHandler)(params)(event, context);
21
- }
1
+ import { registry } from "../registry.js";
2
+ import { createSourceHandler } from "../sourceHandler.js";
3
+ import { createHandler } from "./index.js";
4
+ const handler = createSourceHandler({
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)
22
12
  });
23
- _registry.registry.register(handler);
13
+ registry.register(handler);
24
14
 
25
15
  //# sourceMappingURL=register.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_registry","require","_sourceHandler","_index","handler","createSourceHandler","name","canUse","event","Array","isArray","Records","length","record","s3","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import type { S3Event } from \"@webiny/aws-sdk/types\";\nimport { registry } from \"~/registry\";\nimport type { HandlerFactoryParams } from \"~/types\";\nimport { createSourceHandler } from \"~/sourceHandler\";\nimport { createHandler } from \"./index\";\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst handler = createSourceHandler<S3Event, HandlerParams>({\n name: \"handler-aws-s3\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.s3;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":";;AACA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAMA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAAyB;EACxDC,IAAI,EAAE,gBAAgB;EACtBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,OAAO,CAAC,CAACE,MAAM,CAACC,EAAE;EACtB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAER,KAAK;IAAES;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAAChB,OAAO,CAAC","ignoreList":[]}
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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { APIGatewayProxyResult, SNSEvent, Context as LambdaContext } from "@webiny/aws-sdk/types";
2
- import type { HandlerFactoryParams } from "../types";
3
- export * from "./plugins/SNSEventHandler";
1
+ import type { APIGatewayProxyResult, SNSEvent, Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
2
+ import type { HandlerFactoryParams } from "../types.js";
3
+ export * from "./plugins/SNSEventHandler.js";
4
4
  export interface HandlerCallable {
5
5
  (event: SNSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
6
6
  }
package/sns/index.js CHANGED
@@ -1,79 +1,42 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- var _exportNames = {
8
- createHandler: true
9
- };
10
- exports.createHandler = void 0;
11
- var _handler = require("@webiny/handler");
12
- var _plugins = require("../plugins");
13
- var _SNSEventHandler = require("./plugins/SNSEventHandler");
14
- Object.keys(_SNSEventHandler).forEach(function (key) {
15
- if (key === "default" || key === "__esModule") return;
16
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
17
- if (key in exports && exports[key] === _SNSEventHandler[key]) return;
18
- Object.defineProperty(exports, key, {
19
- enumerable: true,
20
- get: function () {
21
- return _SNSEventHandler[key];
22
- }
23
- });
24
- });
25
- var _execute = require("../execute");
26
- var _reply = _interopRequireDefault(require("fastify/lib/reply"));
27
- var _composedHandler = require("../utils/composedHandler");
28
- /**
29
- * We need a class, not an interface exported from types.
30
- */
31
- // @ts-expect-error
32
-
1
+ import { createHandler } from "@webiny/handler";
2
+ import { registerDefaultPlugins } from "../plugins/index.js";
3
+ import { SNSEventHandler } from "./plugins/SNSEventHandler.js";
4
+ import { execute } from "../execute.js";
5
+ import lib_reply from "fastify/lib/reply.js";
6
+ import { createComposedHandler } from "../utils/composedHandler.js";
7
+ export * from "./plugins/SNSEventHandler.js";
33
8
  const url = "/webiny-sns-event";
34
- const createHandler = params => {
35
- return async (event, context) => {
36
- const app = (0, _handler.createHandler)({
37
- ...params,
38
- options: {
39
- logger: params.debug === true,
40
- ...(params.options || {})
41
- }
42
- });
43
- /**
44
- * We always must add our default plugins to the app.
45
- */
46
- (0, _plugins.registerDefaultPlugins)(app.webiny);
47
- /**
48
- * There must be an event plugin for this handler to work.
49
- */
50
- const plugins = app.webiny.plugins.byType(_SNSEventHandler.SNSEventHandler.type).reverse();
51
- if (plugins.length === 0) {
52
- throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);
53
- }
54
- const handler = (0, _composedHandler.createComposedHandler)(plugins);
55
- app.post(url, async (request, reply) => {
56
- const params = {
57
- request,
58
- reply,
59
- context: app.webiny,
60
- event,
61
- lambdaContext: context
62
- };
63
- const result = await handler(params);
64
- if (result instanceof _reply.default) {
65
- return result;
66
- }
67
- app.__webiny_raw_result = result;
68
- return reply.send({});
69
- });
70
- return (0, _execute.execute)({
71
- app,
72
- url,
73
- payload: event
74
- });
75
- };
76
- };
77
- exports.createHandler = createHandler;
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 };
78
41
 
79
42
  //# sourceMappingURL=index.js.map