@webiny/handler-aws 5.39.0-beta.1 → 5.39.0-beta.2
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.
- package/createHandler.d.ts +2 -0
- package/createHandler.js +29 -0
- package/createHandler.js.map +1 -0
- package/dynamodb/index.d.ts +5 -8
- package/dynamodb/index.js +18 -13
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +6 -5
- package/dynamodb/plugins/DynamoDBEventHandler.js +1 -4
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.d.ts +1 -0
- package/dynamodb/register.js +28 -0
- package/dynamodb/register.js.map +1 -0
- package/eventBridge/index.d.ts +7 -10
- package/eventBridge/index.js +19 -14
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +6 -5
- package/eventBridge/plugins/EventBridgeEventHandler.js +1 -4
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +4 -0
- package/eventBridge/register.js +21 -0
- package/eventBridge/register.js.map +1 -0
- package/execute.js +5 -4
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +6 -10
- package/gateway/index.js +12 -11
- package/gateway/index.js.map +1 -1
- package/gateway/register.d.ts +1 -0
- package/gateway/register.js +21 -0
- package/gateway/register.js.map +1 -0
- package/index.d.ts +32 -5
- package/index.js +125 -23
- package/index.js.map +1 -1
- package/package.json +10 -8
- package/plugins/handlerClient.js +7 -8
- package/plugins/handlerClient.js.map +1 -1
- package/raw/index.d.ts +1 -5
- package/raw/index.js +12 -12
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +2 -2
- package/raw/plugins/RawEventHandler.js +4 -0
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +11 -0
- package/registry.js +38 -0
- package/registry.js.map +1 -0
- package/s3/index.d.ts +7 -9
- package/s3/index.js +21 -16
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +6 -5
- package/s3/plugins/S3EventHandler.js +1 -4
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +4 -0
- package/s3/register.js +25 -0
- package/s3/register.js.map +1 -0
- package/sns/index.d.ts +9 -0
- package/sns/index.js +77 -0
- package/sns/index.js.map +1 -0
- package/sns/plugins/SNSEventHandler.d.ts +20 -0
- package/sns/plugins/SNSEventHandler.js +21 -0
- package/sns/plugins/SNSEventHandler.js.map +1 -0
- package/sns/register.d.ts +1 -0
- package/sns/register.js +25 -0
- package/sns/register.js.map +1 -0
- package/sourceHandler.d.ts +2 -0
- package/sourceHandler.js +12 -0
- package/sourceHandler.js.map +1 -0
- package/sqs/index.d.ts +7 -9
- package/sqs/index.js +21 -16
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +6 -5
- package/sqs/plugins/SQSEventHandler.js +1 -4
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.d.ts +1 -0
- package/sqs/register.js +28 -0
- package/sqs/register.js.map +1 -0
- package/types.d.ts +25 -1
- package/types.js +31 -1
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +6 -0
- package/utils/composedHandler.js +24 -0
- package/utils/composedHandler.js.map +1 -0
package/registry.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.registry = void 0;
|
|
7
|
+
class HandlerRegistry {
|
|
8
|
+
handlers = new Map();
|
|
9
|
+
constructor() {
|
|
10
|
+
/**
|
|
11
|
+
* We don't want this class to be constructed outside the static create() method
|
|
12
|
+
*/
|
|
13
|
+
}
|
|
14
|
+
static create() {
|
|
15
|
+
return new HandlerRegistry();
|
|
16
|
+
}
|
|
17
|
+
register(handler) {
|
|
18
|
+
if (this.handlers.has(handler.name)) {
|
|
19
|
+
/**
|
|
20
|
+
* This should only happen during the development phase.
|
|
21
|
+
*/
|
|
22
|
+
throw new Error(`Handler "${handler.name}" is already registered.`);
|
|
23
|
+
}
|
|
24
|
+
this.handlers.set(handler.name, handler);
|
|
25
|
+
}
|
|
26
|
+
getHandler(event, context) {
|
|
27
|
+
for (const handler of this.handlers.values()) {
|
|
28
|
+
if (handler.canUse(event, context)) {
|
|
29
|
+
return handler;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const registry = HandlerRegistry.create();
|
|
36
|
+
exports.registry = registry;
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=registry.js.map
|
package/registry.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["HandlerRegistry","handlers","Map","constructor","create","register","handler","has","name","Error","set","getHandler","event","context","values","canUse","JSON","stringify","registry","exports"],"sources":["registry.ts"],"sourcesContent":["import { HandlerEvent, SourceHandler } from \"~/types\";\nimport { Context as LambdaContext } from \"aws-lambda/handler\";\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>) {\n if (this.handlers.has(handler.name)) {\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":";;;;;;AAGA,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,EAAE;IACzC,IAAI,IAAI,CAACL,QAAQ,CAACM,GAAG,CAACD,OAAO,CAACE,IAAI,CAAC,EAAE;MACjC;AACZ;AACA;MACY,MAAM,IAAIC,KAAK,CAAE,YAAWH,OAAO,CAACE,IAAK,0BAAyB,CAAC;IACvE;IACA,IAAI,CAACP,QAAQ,CAACS,GAAG,CAACJ,OAAO,CAACE,IAAI,EAAEF,OAAO,CAAC;EAC5C;EAEOK,UAAUA,CAACC,KAAmB,EAAEC,OAAsB,EAAiB;IAC1E,KAAK,MAAMP,OAAO,IAAI,IAAI,CAACL,QAAQ,CAACa,MAAM,CAAC,CAAC,EAAE;MAC1C,IAAIR,OAAO,CAACS,MAAM,CAACH,KAAK,EAAEC,OAAO,CAAC,EAAE;QAChC,OAAOP,OAAO;MAClB;IACJ;IACA,MAAM,IAAIG,KAAK,CAAE,sCAAqCO,IAAI,CAACC,SAAS,CAACL,KAAK,CAAE,EAAC,CAAC;EAClF;AACJ;AAIO,MAAMM,QAAQ,GAAGlB,eAAe,CAACI,MAAM,CAAC,CAAC;AAACe,OAAA,CAAAD,QAAA,GAAAA,QAAA"}
|
package/s3/index.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { HandlerFactoryParams } from "../types";
|
|
2
|
+
import { APIGatewayProxyResult, S3Event } from "aws-lambda";
|
|
3
|
+
import { Context as LambdaContext } from "aws-lambda/handler";
|
|
4
|
+
export * from "./plugins/S3EventHandler";
|
|
4
5
|
export interface HandlerCallable {
|
|
5
|
-
(
|
|
6
|
-
}
|
|
7
|
-
export interface CreateHandlerParams extends BaseCreateHandlerParams {
|
|
8
|
-
debug?: boolean;
|
|
6
|
+
(event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
9
7
|
}
|
|
10
|
-
export declare
|
|
11
|
-
export
|
|
8
|
+
export declare type HandlerParams = HandlerFactoryParams;
|
|
9
|
+
export declare const createHandler: (params: HandlerParams) => HandlerCallable;
|
package/s3/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 _S3EventHandler = require("./plugins/S3EventHandler");
|
|
14
14
|
Object.keys(_S3EventHandler).forEach(function (key) {
|
|
15
15
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -22,17 +22,22 @@ Object.keys(_S3EventHandler).forEach(function (key) {
|
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
-
var _plugins = require("../plugins");
|
|
26
25
|
var _execute = require("../execute");
|
|
27
|
-
|
|
26
|
+
var _reply = _interopRequireDefault(require("fastify/lib/reply"));
|
|
27
|
+
var _composedHandler = require("../utils/composedHandler");
|
|
28
|
+
/**
|
|
29
|
+
* We need a class, not an interface exported from types.
|
|
30
|
+
*/ // @ts-expect-error
|
|
28
31
|
const url = "/webiny-s3-event";
|
|
29
32
|
const createHandler = params => {
|
|
30
|
-
return (
|
|
31
|
-
const app = (0, _handler.createHandler)(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
return async (event, context) => {
|
|
34
|
+
const app = (0, _handler.createHandler)({
|
|
35
|
+
...params,
|
|
36
|
+
options: {
|
|
37
|
+
logger: params.debug === true,
|
|
38
|
+
...(params.options || {})
|
|
39
|
+
}
|
|
40
|
+
});
|
|
36
41
|
/**
|
|
37
42
|
* We always must add our default plugins to the app.
|
|
38
43
|
*/
|
|
@@ -40,21 +45,21 @@ const createHandler = params => {
|
|
|
40
45
|
/**
|
|
41
46
|
* There must be an event plugin for this handler to work.
|
|
42
47
|
*/
|
|
43
|
-
const plugins = app.webiny.plugins.byType(_S3EventHandler.S3EventHandler.type);
|
|
44
|
-
|
|
45
|
-
if (!handler) {
|
|
48
|
+
const plugins = app.webiny.plugins.byType(_S3EventHandler.S3EventHandler.type).reverse();
|
|
49
|
+
if (plugins.length === 0) {
|
|
46
50
|
throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);
|
|
47
51
|
}
|
|
52
|
+
const handler = (0, _composedHandler.createComposedHandler)(plugins);
|
|
48
53
|
app.post(url, async (request, reply) => {
|
|
49
54
|
const params = {
|
|
50
55
|
request,
|
|
51
56
|
reply,
|
|
52
57
|
context: app.webiny,
|
|
53
|
-
event
|
|
58
|
+
event,
|
|
54
59
|
lambdaContext: context
|
|
55
60
|
};
|
|
56
|
-
const result = await handler
|
|
57
|
-
if (result instanceof
|
|
61
|
+
const result = await handler(params);
|
|
62
|
+
if (result instanceof _reply.default) {
|
|
58
63
|
return result;
|
|
59
64
|
}
|
|
60
65
|
app.__webiny_raw_result = result;
|
|
@@ -63,7 +68,7 @@ const createHandler = params => {
|
|
|
63
68
|
return (0, _execute.execute)({
|
|
64
69
|
app,
|
|
65
70
|
url,
|
|
66
|
-
payload
|
|
71
|
+
payload: event
|
|
67
72
|
});
|
|
68
73
|
};
|
|
69
74
|
};
|
package/s3/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_handler","require","_S3EventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","
|
|
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 { S3EventHandler, S3EventHandlerCallableParams } from \"~/s3/plugins/S3EventHandler\";\nimport { execute } from \"~/execute\";\nimport { 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 { APIGatewayProxyResult, S3Event } from \"aws-lambda\";\nimport { Context as LambdaContext } from \"aws-lambda/handler\";\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;AACA,IAAAE,eAAA,GAAAF,OAAA;AAYAG,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;AAXA,IAAAS,QAAA,GAAAf,OAAA;AAMA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AAGA,IAAAkB,gBAAA,GAAAlB,OAAA;AAPA;AACA;AACA,GAFA,CAGA;AAcA,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,CAAE,kEAAiE,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"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export interface S3EventHandlerCallableParams {
|
|
2
|
+
import { Context, Reply, Request } from "@webiny/handler/types";
|
|
3
|
+
import { Context as LambdaContext, S3Event } from "aws-lambda";
|
|
4
|
+
export interface S3EventHandlerCallableParams<Response = Reply> {
|
|
5
5
|
request: Request;
|
|
6
6
|
context: Context;
|
|
7
7
|
event: S3Event;
|
|
8
8
|
lambdaContext: LambdaContext;
|
|
9
9
|
reply: Reply;
|
|
10
|
+
next: () => Promise<Response>;
|
|
10
11
|
}
|
|
11
|
-
export interface S3EventHandlerCallable<Response> {
|
|
12
|
-
(params: S3EventHandlerCallableParams): Promise<Response
|
|
12
|
+
export interface S3EventHandlerCallable<Response = Reply> {
|
|
13
|
+
(params: S3EventHandlerCallableParams<Response>): Promise<Response>;
|
|
13
14
|
}
|
|
14
15
|
export declare class S3EventHandler<Response = any> extends Plugin {
|
|
15
16
|
static type: string;
|
|
@@ -1,21 +1,18 @@
|
|
|
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.S3EventHandler = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
7
|
var _Plugin = require("@webiny/plugins/Plugin");
|
|
10
8
|
class S3EventHandler extends _Plugin.Plugin {
|
|
9
|
+
static type = "handler.fastify.aws.s3.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.S3EventHandler = S3EventHandler;
|
|
18
|
-
(0, _defineProperty2.default)(S3EventHandler, "type", "handler.fastify.aws.s3.eventHandler");
|
|
19
16
|
const createEventHandler = cb => {
|
|
20
17
|
return new S3EventHandler(cb);
|
|
21
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Plugin","require","S3EventHandler","Plugin","
|
|
1
|
+
{"version":3,"names":["_Plugin","require","S3EventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["S3EventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, Reply, Request } from \"@webiny/handler/types\";\nimport { Context as LambdaContext, S3Event } from \"aws-lambda\";\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":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAiBO,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"}
|
package/s3/register.d.ts
ADDED
package/s3/register.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _registry = require("../registry");
|
|
4
|
+
var _sourceHandler = require("../sourceHandler");
|
|
5
|
+
var _index = require("./index");
|
|
6
|
+
const handler = (0, _sourceHandler.createSourceHandler)({
|
|
7
|
+
name: "handler-aws-s3",
|
|
8
|
+
canUse: event => {
|
|
9
|
+
if (!Array.isArray(event.Records) || event.Records.length === 0) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const [record] = event.Records;
|
|
13
|
+
return !!record.s3;
|
|
14
|
+
},
|
|
15
|
+
handle: async ({
|
|
16
|
+
params,
|
|
17
|
+
event,
|
|
18
|
+
context
|
|
19
|
+
}) => {
|
|
20
|
+
return (0, _index.createHandler)(params)(event, context);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
_registry.registry.register(handler);
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_registry","require","_sourceHandler","_index","handler","createSourceHandler","name","canUse","event","Array","isArray","Records","length","record","s3","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import { registry } from \"~/registry\";\nimport { HandlerFactoryParams } from \"~/types\";\nimport { S3Event } from \"aws-lambda\";\nimport { createSourceHandler } from \"~/sourceHandler\";\nimport { createHandler } from \"./index\";\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst handler = createSourceHandler<S3Event, HandlerParams>({\n name: \"handler-aws-s3\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.s3;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":";;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAGA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAMA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAAyB;EACxDC,IAAI,EAAE,gBAAgB;EACtBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,OAAO,CAAC,CAACE,MAAM,CAACC,EAAE;EACtB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAER,KAAK;IAAES;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAAChB,OAAO,CAAC"}
|
package/sns/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HandlerFactoryParams } from "../types";
|
|
2
|
+
import { APIGatewayProxyResult, SNSEvent } from "aws-lambda";
|
|
3
|
+
import { Context as LambdaContext } from "aws-lambda/handler";
|
|
4
|
+
export * from "./plugins/SNSEventHandler";
|
|
5
|
+
export interface HandlerCallable {
|
|
6
|
+
(event: SNSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
7
|
+
}
|
|
8
|
+
export declare type HandlerParams = HandlerFactoryParams;
|
|
9
|
+
export declare const createHandler: (params: HandlerParams) => HandlerCallable;
|
package/sns/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
var _exportNames = {
|
|
8
|
+
createHandler: true
|
|
9
|
+
};
|
|
10
|
+
exports.createHandler = void 0;
|
|
11
|
+
var _handler = require("@webiny/handler");
|
|
12
|
+
var _plugins = require("../plugins");
|
|
13
|
+
var _SNSEventHandler = require("./plugins/SNSEventHandler");
|
|
14
|
+
Object.keys(_SNSEventHandler).forEach(function (key) {
|
|
15
|
+
if (key === "default" || key === "__esModule") return;
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
17
|
+
if (key in exports && exports[key] === _SNSEventHandler[key]) return;
|
|
18
|
+
Object.defineProperty(exports, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _SNSEventHandler[key];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
var _execute = require("../execute");
|
|
26
|
+
var _reply = _interopRequireDefault(require("fastify/lib/reply"));
|
|
27
|
+
var _composedHandler = require("../utils/composedHandler");
|
|
28
|
+
/**
|
|
29
|
+
* We need a class, not an interface exported from types.
|
|
30
|
+
*/ // @ts-expect-error
|
|
31
|
+
const url = "/webiny-sns-event";
|
|
32
|
+
const createHandler = params => {
|
|
33
|
+
return async (event, context) => {
|
|
34
|
+
const app = (0, _handler.createHandler)({
|
|
35
|
+
...params,
|
|
36
|
+
options: {
|
|
37
|
+
logger: params.debug === true,
|
|
38
|
+
...(params.options || {})
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* We always must add our default plugins to the app.
|
|
43
|
+
*/
|
|
44
|
+
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
45
|
+
/**
|
|
46
|
+
* There must be an event plugin for this handler to work.
|
|
47
|
+
*/
|
|
48
|
+
const plugins = app.webiny.plugins.byType(_SNSEventHandler.SNSEventHandler.type).reverse();
|
|
49
|
+
if (plugins.length === 0) {
|
|
50
|
+
throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);
|
|
51
|
+
}
|
|
52
|
+
const handler = (0, _composedHandler.createComposedHandler)(plugins);
|
|
53
|
+
app.post(url, async (request, reply) => {
|
|
54
|
+
const params = {
|
|
55
|
+
request,
|
|
56
|
+
reply,
|
|
57
|
+
context: app.webiny,
|
|
58
|
+
event,
|
|
59
|
+
lambdaContext: context
|
|
60
|
+
};
|
|
61
|
+
const result = await handler(params);
|
|
62
|
+
if (result instanceof _reply.default) {
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
app.__webiny_raw_result = result;
|
|
66
|
+
return reply.send({});
|
|
67
|
+
});
|
|
68
|
+
return (0, _execute.execute)({
|
|
69
|
+
app,
|
|
70
|
+
url,
|
|
71
|
+
payload: event
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
exports.createHandler = createHandler;
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
package/sns/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_handler","require","_plugins","_SNSEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","event","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","SNSEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","send","execute","payload"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { SNSEventHandler, SNSEventHandlerCallableParams } from \"./plugins/SNSEventHandler\";\nimport { execute } from \"~/execute\";\nimport { HandlerFactoryParams } from \"~/types\";\nimport { APIGatewayProxyResult, SNSEvent } from \"aws-lambda\";\nimport { Context as LambdaContext } from \"aws-lambda/handler\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\n\nexport * from \"./plugins/SNSEventHandler\";\n\nexport interface HandlerCallable {\n (event: SNSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-sns-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<SNSEventHandler>(SNSEventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n SNSEventHandler,\n SNSEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<SNSEventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n\n const result = await handler(\n params as unknown as SNSEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAYAG,MAAA,CAAAC,IAAA,CAAAF,gBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,gBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,gBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAXA,IAAAS,QAAA,GAAAf,OAAA;AAQA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AACA,IAAAkB,gBAAA,GAAAlB,OAAA;AALA;AACA;AACA,GAFA,CAGA;AAYA,MAAMmB,GAAG,GAAG,mBAAmB;AAExB,MAAMC,aAAa,GAAIC,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,EAAC;MAC1B,GAAGJ,MAAM;MACTK,OAAO,EAAE;QACLC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK,IAAI;QAC7B,IAAIP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBC,gCAAe,CAACC,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IAC1F,IAAIJ,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAE,oEAAmE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAG,IAAAC,sCAAqB,EAInCR,OAAO,CAAC;IAEVP,GAAG,CAACgB,IAAI,CAACrB,GAAG,EAAE,OAAOsB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAA0E,GAAG;QAC/EoB,OAAO;QACPC,KAAK;QACLnB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,KAAK;QACLqB,aAAa,EAAEpB;MACnB,CAAC;MAED,MAAMqB,MAAM,GAAG,MAAMN,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIuB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEApB,GAAG,CAACsB,mBAAmB,GAAGF,MAAM;MAChC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXxB,GAAG;MACHL,GAAG;MACH8B,OAAO,EAAE3B;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
+
import { Context, Reply, Request } from "@webiny/handler/types";
|
|
3
|
+
import { Context as LambdaContext, SNSEvent } from "aws-lambda";
|
|
4
|
+
export interface SNSEventHandlerCallableParams<Response = Reply> {
|
|
5
|
+
request: Request;
|
|
6
|
+
reply: Reply;
|
|
7
|
+
context: Context;
|
|
8
|
+
event: SNSEvent;
|
|
9
|
+
lambdaContext: LambdaContext;
|
|
10
|
+
next: () => Promise<Response>;
|
|
11
|
+
}
|
|
12
|
+
export interface SNSEventHandlerCallable<Response = Reply> {
|
|
13
|
+
(params: SNSEventHandlerCallableParams<Response>): Promise<Response>;
|
|
14
|
+
}
|
|
15
|
+
export declare class SNSEventHandler<Response = any> extends Plugin {
|
|
16
|
+
static type: string;
|
|
17
|
+
readonly cb: SNSEventHandlerCallable<Response>;
|
|
18
|
+
constructor(cb: SNSEventHandlerCallable<Response>);
|
|
19
|
+
}
|
|
20
|
+
export declare const createEventHandler: <Response_1>(cb: SNSEventHandlerCallable<Response_1>) => SNSEventHandler<Response_1>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createEventHandler = exports.SNSEventHandler = void 0;
|
|
7
|
+
var _Plugin = require("@webiny/plugins/Plugin");
|
|
8
|
+
class SNSEventHandler extends _Plugin.Plugin {
|
|
9
|
+
static type = "handler.fastify.aws.sns.eventHandler";
|
|
10
|
+
constructor(cb) {
|
|
11
|
+
super();
|
|
12
|
+
this.cb = cb;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.SNSEventHandler = SNSEventHandler;
|
|
16
|
+
const createEventHandler = cb => {
|
|
17
|
+
return new SNSEventHandler(cb);
|
|
18
|
+
};
|
|
19
|
+
exports.createEventHandler = createEventHandler;
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=SNSEventHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_Plugin","require","SNSEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["SNSEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, Reply, Request } from \"@webiny/handler/types\";\nimport { Context as LambdaContext, SNSEvent } from \"aws-lambda\";\n\nexport interface SNSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SNSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SNSEventHandlerCallable<Response = Reply> {\n (params: SNSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SNSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sns.eventHandler\";\n\n public readonly cb: SNSEventHandlerCallable<Response>;\n\n public constructor(cb: SNSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SNSEventHandlerCallable<Response>) => {\n return new SNSEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAiBO,MAAMC,eAAe,SAAyBC,cAAM,CAAC;EACxD,OAAuBC,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,eAAA,GAAAA,eAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAAqC,IAAK;EACnF,OAAO,IAAIJ,eAAe,CAAWI,EAAE,CAAC;AAC5C,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/sns/register.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _registry = require("../registry");
|
|
4
|
+
var _index = require("./index");
|
|
5
|
+
var _sourceHandler = require("../sourceHandler");
|
|
6
|
+
const handler = (0, _sourceHandler.createSourceHandler)({
|
|
7
|
+
name: "handler-aws-sns",
|
|
8
|
+
canUse: event => {
|
|
9
|
+
if (!Array.isArray(event.Records) || event.Records.length === 0) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const [record] = event.Records;
|
|
13
|
+
return !!record.Sns;
|
|
14
|
+
},
|
|
15
|
+
handle: async ({
|
|
16
|
+
params,
|
|
17
|
+
event,
|
|
18
|
+
context
|
|
19
|
+
}) => {
|
|
20
|
+
return (0, _index.createHandler)(params)(event, context);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
_registry.registry.register(handler);
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_registry","require","_index","_sourceHandler","handler","createSourceHandler","name","canUse","event","Array","isArray","Records","length","record","Sns","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import { registry } from \"~/registry\";\nimport { SNSEvent } from \"aws-lambda\";\nimport { createHandler, HandlerParams } from \"./index\";\nimport { createSourceHandler } from \"~/sourceHandler\";\n\nconst handler = createSourceHandler<SNSEvent, HandlerParams>({\n name: \"handler-aws-sns\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.Sns;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":";;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAF,OAAA;AAEA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAA0B;EACzDC,IAAI,EAAE,iBAAiB;EACvBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,OAAO,CAAC,CAACE,MAAM,CAACC,GAAG;EACvB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAER,KAAK;IAAES;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAAChB,OAAO,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { SourceHandler, HandlerEvent, HandlerFactoryParams } from "./types";
|
|
2
|
+
export declare const createSourceHandler: <TEvent = HandlerEvent, TParams extends HandlerFactoryParams = HandlerFactoryParams>(handler: SourceHandler<TEvent, TParams, any>) => SourceHandler<TEvent, TParams, any>;
|
package/sourceHandler.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSourceHandler = void 0;
|
|
7
|
+
const createSourceHandler = handler => {
|
|
8
|
+
return handler;
|
|
9
|
+
};
|
|
10
|
+
exports.createSourceHandler = createSourceHandler;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=sourceHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSourceHandler","handler","exports"],"sources":["sourceHandler.ts"],"sourcesContent":["import { SourceHandler, HandlerEvent, HandlerFactoryParams } from \"~/types\";\n\nexport const createSourceHandler = <\n TEvent = HandlerEvent,\n TParams extends HandlerFactoryParams = HandlerFactoryParams\n>(\n handler: SourceHandler<TEvent, TParams>\n) => {\n return handler;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,mBAAmB,GAI5BC,OAAuC,IACtC;EACD,OAAOA,OAAO;AAClB,CAAC;AAACC,OAAA,CAAAF,mBAAA,GAAAA,mBAAA"}
|
package/sqs/index.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { HandlerFactoryParams } from "../types";
|
|
2
|
+
import { APIGatewayProxyResult, SQSEvent } from "aws-lambda";
|
|
3
|
+
import { Context as LambdaContext } from "aws-lambda/handler";
|
|
4
|
+
export * from "./plugins/SQSEventHandler";
|
|
4
5
|
export interface HandlerCallable {
|
|
5
|
-
(
|
|
6
|
-
}
|
|
7
|
-
export interface CreateHandlerParams extends BaseCreateHandlerParams {
|
|
8
|
-
debug?: boolean;
|
|
6
|
+
(event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
9
7
|
}
|
|
10
|
-
export declare
|
|
11
|
-
export
|
|
8
|
+
export declare type HandlerParams = HandlerFactoryParams;
|
|
9
|
+
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,22 @@ Object.keys(_SQSEventHandler).forEach(function (key) {
|
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
-
var _plugins = require("../plugins");
|
|
26
25
|
var _execute = require("../execute");
|
|
27
|
-
|
|
26
|
+
var _reply = _interopRequireDefault(require("fastify/lib/reply"));
|
|
27
|
+
var _composedHandler = require("../utils/composedHandler");
|
|
28
|
+
/**
|
|
29
|
+
* We need a class, not an interface exported from types.
|
|
30
|
+
*/ // @ts-expect-error
|
|
28
31
|
const url = "/webiny-sqs-event";
|
|
29
32
|
const createHandler = params => {
|
|
30
|
-
return (
|
|
31
|
-
const app = (0, _handler.createHandler)(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
return async (event, context) => {
|
|
34
|
+
const app = (0, _handler.createHandler)({
|
|
35
|
+
...params,
|
|
36
|
+
options: {
|
|
37
|
+
logger: params.debug === true,
|
|
38
|
+
...(params.options || {})
|
|
39
|
+
}
|
|
40
|
+
});
|
|
36
41
|
/**
|
|
37
42
|
* We always must add our default plugins to the app.
|
|
38
43
|
*/
|
|
@@ -40,21 +45,21 @@ const createHandler = params => {
|
|
|
40
45
|
/**
|
|
41
46
|
* There must be an event plugin for this handler to work.
|
|
42
47
|
*/
|
|
43
|
-
const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type);
|
|
44
|
-
|
|
45
|
-
if (!handler) {
|
|
48
|
+
const plugins = app.webiny.plugins.byType(_SQSEventHandler.SQSEventHandler.type).reverse();
|
|
49
|
+
if (plugins.length === 0) {
|
|
46
50
|
throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);
|
|
47
51
|
}
|
|
52
|
+
const handler = (0, _composedHandler.createComposedHandler)(plugins);
|
|
48
53
|
app.post(url, async (request, reply) => {
|
|
49
54
|
const params = {
|
|
50
55
|
request,
|
|
51
56
|
reply,
|
|
52
57
|
context: app.webiny,
|
|
53
|
-
event
|
|
58
|
+
event,
|
|
54
59
|
lambdaContext: context
|
|
55
60
|
};
|
|
56
|
-
const result = await handler
|
|
57
|
-
if (result instanceof
|
|
61
|
+
const result = await handler(params);
|
|
62
|
+
if (result instanceof _reply.default) {
|
|
58
63
|
return result;
|
|
59
64
|
}
|
|
60
65
|
app.__webiny_raw_result = result;
|
|
@@ -63,7 +68,7 @@ const createHandler = params => {
|
|
|
63
68
|
return (0, _execute.execute)({
|
|
64
69
|
app,
|
|
65
70
|
url,
|
|
66
|
-
payload
|
|
71
|
+
payload: event
|
|
67
72
|
});
|
|
68
73
|
};
|
|
69
74
|
};
|
package/sqs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_handler","require","_SQSEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","
|
|
1
|
+
{"version":3,"names":["_handler","require","_plugins","_SQSEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","event","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","SQSEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","send","execute","payload"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { SQSEventHandler, SQSEventHandlerCallableParams } from \"~/sqs/plugins/SQSEventHandler\";\nimport { execute } from \"~/execute\";\nimport { HandlerFactoryParams } from \"~/types\";\nimport { APIGatewayProxyResult, SQSEvent } from \"aws-lambda\";\nimport { Context as LambdaContext } from \"aws-lambda/handler\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\n\nexport * from \"./plugins/SQSEventHandler\";\n\nexport interface HandlerCallable {\n (event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-sqs-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<SQSEventHandler>(SQSEventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n SQSEventHandler,\n SQSEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<SQSEventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n\n const result = await handler(\n params as unknown as SQSEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAYAG,MAAA,CAAAC,IAAA,CAAAF,gBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,gBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,gBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAXA,IAAAS,QAAA,GAAAf,OAAA;AAQA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AACA,IAAAkB,gBAAA,GAAAlB,OAAA;AALA;AACA;AACA,GAFA,CAGA;AAYA,MAAMmB,GAAG,GAAG,mBAAmB;AAExB,MAAMC,aAAa,GAAIC,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAG,IAAAC,sBAAiB,EAAC;MAC1B,GAAGJ,MAAM;MACTK,OAAO,EAAE;QACLC,MAAM,EAAEN,MAAM,CAACO,KAAK,KAAK,IAAI;QAC7B,IAAIP,MAAM,CAACK,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQ,IAAAG,+BAAsB,EAACL,GAAG,CAACM,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGP,GAAG,CAACM,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBC,gCAAe,CAACC,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IAC1F,IAAIJ,OAAO,CAACK,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAE,oEAAmE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAG,IAAAC,sCAAqB,EAInCR,OAAO,CAAC;IAEVP,GAAG,CAACgB,IAAI,CAACrB,GAAG,EAAE,OAAOsB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAA0E,GAAG;QAC/EoB,OAAO;QACPC,KAAK;QACLnB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,KAAK;QACLqB,aAAa,EAAEpB;MACnB,CAAC;MAED,MAAMqB,MAAM,GAAG,MAAMN,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIuB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEApB,GAAG,CAACsB,mBAAmB,GAAGF,MAAM;MAChC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXxB,GAAG;MACHL,GAAG;MACH8B,OAAO,EAAE3B;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA"}
|