@webiny/handler-aws 6.3.0-beta.4 → 6.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/createHandler.js +16 -22
- package/createHandler.js.map +1 -1
- package/dynamodb/index.js +34 -49
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.js +10 -9
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.js +8 -18
- package/dynamodb/register.js.map +1 -1
- package/eventBridge/index.js +34 -49
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.js +10 -9
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.js +3 -11
- package/eventBridge/register.js.map +1 -1
- package/execute.js +52 -60
- package/execute.js.map +1 -1
- package/gateway/index.js +39 -67
- package/gateway/index.js.map +1 -1
- package/gateway/register.js +3 -11
- package/gateway/register.js.map +1 -1
- package/index.js +8 -39
- package/package.json +8 -8
- package/plugins/index.js +3 -4
- package/plugins/index.js.map +1 -1
- package/raw/index.js +38 -63
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.js +11 -21
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.js +17 -32
- package/registry.js.map +1 -1
- package/s3/index.js +34 -49
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.js +10 -9
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.js +7 -15
- package/s3/register.js.map +1 -1
- package/sns/index.js +34 -49
- package/sns/index.js.map +1 -1
- package/sns/plugins/SNSEventHandler.js +10 -9
- package/sns/plugins/SNSEventHandler.js.map +1 -1
- package/sns/register.js +7 -15
- package/sns/register.js.map +1 -1
- package/sourceHandler.js +2 -3
- package/sourceHandler.js.map +1 -1
- package/sqs/index.js +35 -52
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.js +10 -9
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.js +8 -18
- package/sqs/register.js.map +1 -1
- package/types.js +5 -4
- package/types.js.map +1 -1
- package/utils/composedHandler.js +5 -14
- package/utils/composedHandler.js.map +1 -1
- package/utils/index.js +0 -2
- package/utils/timer/CustomTimer.js +9 -8
- package/utils/timer/CustomTimer.js.map +1 -1
- package/utils/timer/Timer.js +12 -13
- package/utils/timer/Timer.js.map +1 -1
- package/utils/timer/abstractions/ITimer.js +0 -3
- package/utils/timer/factory.js +7 -8
- package/utils/timer/factory.js.map +1 -1
- package/utils/timer/index.js +0 -2
- package/index.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/timer/abstractions/ITimer.js.map +0 -1
- package/utils/timer/index.js.map +0 -1
package/s3/index.js
CHANGED
|
@@ -1,57 +1,42 @@
|
|
|
1
|
-
import { createHandler
|
|
1
|
+
import { createHandler } from "@webiny/handler";
|
|
2
2
|
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
3
|
import { S3EventHandler } from "./plugins/S3EventHandler.js";
|
|
4
4
|
import { execute } from "../execute.js";
|
|
5
|
-
|
|
6
|
-
* We need a class, not an interface exported from types.
|
|
7
|
-
*/
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
import Reply from "fastify/lib/reply.js";
|
|
5
|
+
import lib_reply from "fastify/lib/reply.js";
|
|
10
6
|
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
11
7
|
export * from "./plugins/S3EventHandler.js";
|
|
12
8
|
const url = "/webiny-s3-event";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
app.__webiny_raw_result = result;
|
|
47
|
-
return reply.send({});
|
|
48
|
-
});
|
|
49
|
-
return execute({
|
|
50
|
-
app,
|
|
51
|
-
url,
|
|
52
|
-
payload: event
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
};
|
|
9
|
+
const s3_createHandler = (params)=>async (event, context)=>{
|
|
10
|
+
const app = createHandler({
|
|
11
|
+
...params,
|
|
12
|
+
options: {
|
|
13
|
+
logger: true === params.debug,
|
|
14
|
+
...params.options || {}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
registerDefaultPlugins(app.webiny);
|
|
18
|
+
const plugins = app.webiny.plugins.byType(S3EventHandler.type).reverse();
|
|
19
|
+
if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/s3, you must have S3EventHandler set.");
|
|
20
|
+
const handler = createComposedHandler(plugins);
|
|
21
|
+
app.post(url, async (request, reply)=>{
|
|
22
|
+
const params = {
|
|
23
|
+
request,
|
|
24
|
+
reply,
|
|
25
|
+
context: app.webiny,
|
|
26
|
+
event,
|
|
27
|
+
lambdaContext: context
|
|
28
|
+
};
|
|
29
|
+
const result = await handler(params);
|
|
30
|
+
if (result instanceof lib_reply) return result;
|
|
31
|
+
app.__webiny_raw_result = result;
|
|
32
|
+
return reply.send({});
|
|
33
|
+
});
|
|
34
|
+
return execute({
|
|
35
|
+
app,
|
|
36
|
+
url: url,
|
|
37
|
+
payload: event
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export { s3_createHandler as createHandler };
|
|
56
41
|
|
|
57
42
|
//# sourceMappingURL=index.js.map
|
package/s3/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"s3/index.js","sources":["../../src/s3/index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { S3EventHandlerCallableParams } from \"~/s3/plugins/S3EventHandler.js\";\nimport { S3EventHandler } from \"~/s3/plugins/S3EventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n S3Event\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/S3EventHandler.js\";\n\nexport interface HandlerCallable {\n (event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-s3-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<S3EventHandler>(S3EventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);\n }\n\n const handler = createComposedHandler<\n S3EventHandler,\n S3EventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<S3EventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n const result = await handler(\n params as unknown as S3EventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"names":["url","createHandler","params","event","context","app","createBaseHandler","registerDefaultPlugins","plugins","S3EventHandler","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AA0BA,MAAMA,MAAM;AAEL,MAAMC,mBAAgB,CAACC,SACnB,OAAOC,OAAOC;QACjB,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAiBI,eAAe,IAAI,EAAE,OAAO;QACtF,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIE,MAAM;QAGpB,MAAMC,UAAUC,sBAIdJ;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOa,SAASC;YAC1B,MAAMZ,SAA4E;gBAC9EW;gBACAC;gBACA,SAAST,IAAI,MAAM;gBACnBF;gBACA,eAAeC;YACnB;YACA,MAAMW,SAAS,MAAMJ,QACjBT;YAGJ,IAAIa,kBAAkBC,WAClB,OAAOD;YAGXV,IAAI,mBAAmB,GAAGU;YAC1B,OAAOD,MAAM,IAAI,CAAC,CAAC;QACvB;QACA,OAAOG,QAAQ;YACXZ;YACAL,KAAAA;YACA,SAASG;QACb;IACJ"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
class S3EventHandler extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.fastify.aws.s3.eventHandler";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
11
|
+
const createEventHandler = (cb)=>new S3EventHandler(cb);
|
|
12
|
+
export { S3EventHandler, createEventHandler };
|
|
12
13
|
|
|
13
14
|
//# sourceMappingURL=S3EventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"s3/plugins/S3EventHandler.js","sources":["../../../src/s3/plugins/S3EventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, S3Event } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface S3EventHandlerCallableParams<Response = Reply> {\n request: Request;\n context: Context;\n event: S3Event;\n lambdaContext: LambdaContext;\n reply: Reply;\n next: () => Promise<Response>;\n}\n\nexport interface S3EventHandlerCallable<Response = Reply> {\n (params: S3EventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class S3EventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.s3.eventHandler\";\n\n public readonly cb: S3EventHandlerCallable<Response>;\n\n public constructor(cb: S3EventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: S3EventHandlerCallable<Response>) => {\n return new S3EventHandler<Response>(cb);\n};\n"],"names":["S3EventHandler","Plugin","cb","createEventHandler"],"mappings":";AAiBO,MAAMA,uBAAuCC;;aACzB,IAAI,GAAG;;IAI9B,YAAmBC,EAAoC,CAAE;QACrD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,qBAAqB,CAAWD,KAClC,IAAIF,eAAyBE"}
|
package/s3/register.js
CHANGED
|
@@ -2,21 +2,13 @@ import { registry } from "../registry.js";
|
|
|
2
2
|
import { createSourceHandler } from "../sourceHandler.js";
|
|
3
3
|
import { createHandler } from "./index.js";
|
|
4
4
|
const handler = createSourceHandler({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
handle: async ({
|
|
14
|
-
params,
|
|
15
|
-
event,
|
|
16
|
-
context
|
|
17
|
-
}) => {
|
|
18
|
-
return createHandler(params)(event, context);
|
|
19
|
-
}
|
|
5
|
+
name: "handler-aws-s3",
|
|
6
|
+
canUse: (event)=>{
|
|
7
|
+
if (!Array.isArray(event.Records) || 0 === event.Records.length) return false;
|
|
8
|
+
const [record] = event.Records;
|
|
9
|
+
return !!record.s3;
|
|
10
|
+
},
|
|
11
|
+
handle: async ({ params, event, context })=>createHandler(params)(event, context)
|
|
20
12
|
});
|
|
21
13
|
registry.register(handler);
|
|
22
14
|
|
package/s3/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"s3/register.js","sources":["../../src/s3/register.ts"],"sourcesContent":["import type { S3Event } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\nimport { createHandler } from \"./index.js\";\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst handler = createSourceHandler<S3Event, HandlerParams>({\n name: \"handler-aws-s3\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.s3;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"names":["handler","createSourceHandler","event","Array","record","params","context","createHandler","registry"],"mappings":";;;AAUA,MAAMA,UAAUC,oBAA4C;IACxD,MAAM;IACN,QAAQC,CAAAA;QACJ,IAAI,CAACC,MAAM,OAAO,CAACD,MAAM,OAAO,KAAKA,AAAyB,MAAzBA,MAAM,OAAO,CAAC,MAAM,EACrD,OAAO;QAEX,MAAM,CAACE,OAAO,GAAGF,MAAM,OAAO;QAC9B,OAAO,CAAC,CAACE,OAAO,EAAE;IACtB;IACA,QAAQ,OAAO,EAAEC,MAAM,EAAEH,KAAK,EAAEI,OAAO,EAAE,GAC9BC,cAAcF,QAAQH,OAAOI;AAE5C;AAEAE,SAAS,QAAQ,CAACR"}
|
package/sns/index.js
CHANGED
|
@@ -1,57 +1,42 @@
|
|
|
1
|
-
import { createHandler
|
|
1
|
+
import { createHandler } from "@webiny/handler";
|
|
2
2
|
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
3
|
import { SNSEventHandler } from "./plugins/SNSEventHandler.js";
|
|
4
4
|
import { execute } from "../execute.js";
|
|
5
|
-
|
|
6
|
-
* We need a class, not an interface exported from types.
|
|
7
|
-
*/
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
import Reply from "fastify/lib/reply.js";
|
|
5
|
+
import lib_reply from "fastify/lib/reply.js";
|
|
10
6
|
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
11
7
|
export * from "./plugins/SNSEventHandler.js";
|
|
12
8
|
const url = "/webiny-sns-event";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
app.__webiny_raw_result = result;
|
|
47
|
-
return reply.send({});
|
|
48
|
-
});
|
|
49
|
-
return execute({
|
|
50
|
-
app,
|
|
51
|
-
url,
|
|
52
|
-
payload: event
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
};
|
|
9
|
+
const sns_createHandler = (params)=>async (event, context)=>{
|
|
10
|
+
const app = createHandler({
|
|
11
|
+
...params,
|
|
12
|
+
options: {
|
|
13
|
+
logger: true === params.debug,
|
|
14
|
+
...params.options || {}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
registerDefaultPlugins(app.webiny);
|
|
18
|
+
const plugins = app.webiny.plugins.byType(SNSEventHandler.type).reverse();
|
|
19
|
+
if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/sns, you must have SNSEventHandler set.");
|
|
20
|
+
const handler = createComposedHandler(plugins);
|
|
21
|
+
app.post(url, async (request, reply)=>{
|
|
22
|
+
const params = {
|
|
23
|
+
request,
|
|
24
|
+
reply,
|
|
25
|
+
context: app.webiny,
|
|
26
|
+
event,
|
|
27
|
+
lambdaContext: context
|
|
28
|
+
};
|
|
29
|
+
const result = await handler(params);
|
|
30
|
+
if (result instanceof lib_reply) return result;
|
|
31
|
+
app.__webiny_raw_result = result;
|
|
32
|
+
return reply.send({});
|
|
33
|
+
});
|
|
34
|
+
return execute({
|
|
35
|
+
app,
|
|
36
|
+
url: url,
|
|
37
|
+
payload: event
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export { sns_createHandler as createHandler };
|
|
56
41
|
|
|
57
42
|
//# sourceMappingURL=index.js.map
|
package/sns/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sns/index.js","sources":["../../src/sns/index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n SNSEvent,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { SNSEventHandlerCallableParams } from \"./plugins/SNSEventHandler.js\";\nimport { SNSEventHandler } from \"./plugins/SNSEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/SNSEventHandler.js\";\n\nexport interface HandlerCallable {\n (event: SNSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-sns-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<SNSEventHandler>(SNSEventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n SNSEventHandler,\n SNSEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<SNSEventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n\n const result = await handler(\n params as unknown as SNSEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"names":["url","createHandler","params","event","context","app","createBaseHandler","registerDefaultPlugins","plugins","SNSEventHandler","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AA0BA,MAAMA,MAAM;AAEL,MAAMC,oBAAgB,CAACC,SACnB,OAAOC,OAAOC;QACjB,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAkBI,gBAAgB,IAAI,EAAE,OAAO;QACxF,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIE,MAAM;QAGpB,MAAMC,UAAUC,sBAIdJ;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOa,SAASC;YAC1B,MAAMZ,SAA6E;gBAC/EW;gBACAC;gBACA,SAAST,IAAI,MAAM;gBACnBF;gBACA,eAAeC;YACnB;YAEA,MAAMW,SAAS,MAAMJ,QACjBT;YAGJ,IAAIa,kBAAkBC,WAClB,OAAOD;YAGXV,IAAI,mBAAmB,GAAGU;YAC1B,OAAOD,MAAM,IAAI,CAAC,CAAC;QACvB;QACA,OAAOG,QAAQ;YACXZ;YACAL,KAAAA;YACA,SAASG;QACb;IACJ"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
class SNSEventHandler extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.fastify.aws.sns.eventHandler";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
11
|
+
const createEventHandler = (cb)=>new SNSEventHandler(cb);
|
|
12
|
+
export { SNSEventHandler, createEventHandler };
|
|
12
13
|
|
|
13
14
|
//# sourceMappingURL=SNSEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sns/plugins/SNSEventHandler.js","sources":["../../../src/sns/plugins/SNSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SNSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface SNSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SNSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SNSEventHandlerCallable<Response = Reply> {\n (params: SNSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SNSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sns.eventHandler\";\n\n public readonly cb: SNSEventHandlerCallable<Response>;\n\n public constructor(cb: SNSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SNSEventHandlerCallable<Response>) => {\n return new SNSEventHandler<Response>(cb);\n};\n"],"names":["SNSEventHandler","Plugin","cb","createEventHandler"],"mappings":";AAiBO,MAAMA,wBAAwCC;;aAC1B,IAAI,GAAG;;IAI9B,YAAmBC,EAAqC,CAAE;QACtD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,qBAAqB,CAAWD,KAClC,IAAIF,gBAA0BE"}
|
package/sns/register.js
CHANGED
|
@@ -2,21 +2,13 @@ import { registry } from "../registry.js";
|
|
|
2
2
|
import { createHandler } from "./index.js";
|
|
3
3
|
import { createSourceHandler } from "../sourceHandler.js";
|
|
4
4
|
const handler = createSourceHandler({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
handle: async ({
|
|
14
|
-
params,
|
|
15
|
-
event,
|
|
16
|
-
context
|
|
17
|
-
}) => {
|
|
18
|
-
return createHandler(params)(event, context);
|
|
19
|
-
}
|
|
5
|
+
name: "handler-aws-sns",
|
|
6
|
+
canUse: (event)=>{
|
|
7
|
+
if (!Array.isArray(event.Records) || 0 === event.Records.length) return false;
|
|
8
|
+
const [record] = event.Records;
|
|
9
|
+
return !!record.Sns;
|
|
10
|
+
},
|
|
11
|
+
handle: async ({ params, event, context })=>createHandler(params)(event, context)
|
|
20
12
|
});
|
|
21
13
|
registry.register(handler);
|
|
22
14
|
|
package/sns/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sns/register.js","sources":["../../src/sns/register.ts"],"sourcesContent":["import type { SNSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerParams } from \"./index.js\";\nimport { createHandler } from \"./index.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\n\nconst handler = createSourceHandler<SNSEvent, HandlerParams>({\n name: \"handler-aws-sns\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.Sns;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"names":["handler","createSourceHandler","event","Array","record","params","context","createHandler","registry"],"mappings":";;;AAMA,MAAMA,UAAUC,oBAA6C;IACzD,MAAM;IACN,QAAQC,CAAAA;QACJ,IAAI,CAACC,MAAM,OAAO,CAACD,MAAM,OAAO,KAAKA,AAAyB,MAAzBA,MAAM,OAAO,CAAC,MAAM,EACrD,OAAO;QAEX,MAAM,CAACE,OAAO,GAAGF,MAAM,OAAO;QAC9B,OAAO,CAAC,CAACE,OAAO,GAAG;IACvB;IACA,QAAQ,OAAO,EAAEC,MAAM,EAAEH,KAAK,EAAEI,OAAO,EAAE,GAC9BC,cAAcF,QAAQH,OAAOI;AAE5C;AAEAE,SAAS,QAAQ,CAACR"}
|
package/sourceHandler.js
CHANGED
package/sourceHandler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sourceHandler.js","sources":["../src/sourceHandler.ts"],"sourcesContent":["import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from \"~/types.js\";\n\nexport const createSourceHandler = <\n TEvent = HandlerEvent,\n TParams extends HandlerFactoryParams = HandlerFactoryParams\n>(\n handler: SourceHandler<TEvent, TParams>\n) => {\n return handler;\n};\n"],"names":["createSourceHandler","handler"],"mappings":"AAEO,MAAMA,sBAAsB,CAI/BC,UAEOA"}
|
package/sqs/index.js
CHANGED
|
@@ -1,60 +1,43 @@
|
|
|
1
|
-
import { createHandler
|
|
1
|
+
import { createHandler } from "@webiny/handler";
|
|
2
2
|
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
3
|
import { SQSEventHandler } from "./plugins/SQSEventHandler.js";
|
|
4
4
|
import { execute } from "../execute.js";
|
|
5
|
-
|
|
6
|
-
* We need a class, not an interface exported from types.
|
|
7
|
-
*/
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
import Reply from "fastify/lib/reply.js";
|
|
5
|
+
import lib_reply from "fastify/lib/reply.js";
|
|
10
6
|
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
11
7
|
export * from "./plugins/SQSEventHandler.js";
|
|
12
8
|
const url = "/webiny-sqs-event";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
app.__webiny_raw_result = result;
|
|
47
|
-
if (!reply.sent) {
|
|
48
|
-
reply.send({});
|
|
49
|
-
}
|
|
50
|
-
return reply;
|
|
51
|
-
});
|
|
52
|
-
return execute({
|
|
53
|
-
app,
|
|
54
|
-
url,
|
|
55
|
-
payload: event
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
};
|
|
9
|
+
const sqs_createHandler = (params)=>async (event, context)=>{
|
|
10
|
+
const app = createHandler({
|
|
11
|
+
...params,
|
|
12
|
+
options: {
|
|
13
|
+
logger: true === params.debug,
|
|
14
|
+
...params.options || {}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
registerDefaultPlugins(app.webiny);
|
|
18
|
+
const plugins = app.webiny.plugins.byType(SQSEventHandler.type).reverse();
|
|
19
|
+
if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.");
|
|
20
|
+
const handler = createComposedHandler(plugins);
|
|
21
|
+
app.post(url, async (request, reply)=>{
|
|
22
|
+
const params = {
|
|
23
|
+
request,
|
|
24
|
+
reply,
|
|
25
|
+
context: app.webiny,
|
|
26
|
+
event,
|
|
27
|
+
lambdaContext: context
|
|
28
|
+
};
|
|
29
|
+
const result = await handler(params);
|
|
30
|
+
if (result instanceof lib_reply) return result;
|
|
31
|
+
app.__webiny_raw_result = result;
|
|
32
|
+
if (!reply.sent) reply.send({});
|
|
33
|
+
return reply;
|
|
34
|
+
});
|
|
35
|
+
return execute({
|
|
36
|
+
app,
|
|
37
|
+
url: url,
|
|
38
|
+
payload: event
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export { sqs_createHandler as createHandler };
|
|
59
42
|
|
|
60
43
|
//# sourceMappingURL=index.js.map
|
package/sqs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sqs/index.js","sources":["../../src/sqs/index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n SQSEvent\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { SQSEventHandlerCallableParams } from \"~/sqs/plugins/SQSEventHandler.js\";\nimport { SQSEventHandler } from \"~/sqs/plugins/SQSEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/SQSEventHandler.js\";\n\nexport interface HandlerCallable {\n (event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-sqs-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<SQSEventHandler>(SQSEventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n SQSEventHandler,\n SQSEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<SQSEventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n\n const result = await handler(\n params as unknown as SQSEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n if (!reply.sent) {\n reply.send({});\n }\n return reply;\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"names":["url","createHandler","params","event","context","app","createBaseHandler","registerDefaultPlugins","plugins","SQSEventHandler","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AA0BA,MAAMA,MAAM;AAEL,MAAMC,oBAAgB,CAACC,SACnB,OAAOC,OAAOC;QACjB,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAkBI,gBAAgB,IAAI,EAAE,OAAO;QACxF,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIE,MAAM;QAGpB,MAAMC,UAAUC,sBAIdJ;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOa,SAASC;YAC1B,MAAMZ,SAA6E;gBAC/EW;gBACAC;gBACA,SAAST,IAAI,MAAM;gBACnBF;gBACA,eAAeC;YACnB;YAEA,MAAMW,SAAS,MAAMJ,QACjBT;YAGJ,IAAIa,kBAAkBC,WAClB,OAAOD;YAGXV,IAAI,mBAAmB,GAAGU;YAC1B,IAAI,CAACD,MAAM,IAAI,EACXA,MAAM,IAAI,CAAC,CAAC;YAEhB,OAAOA;QACX;QACA,OAAOG,QAAQ;YACXZ;YACAL,KAAAA;YACA,SAASG;QACb;IACJ"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
class SQSEventHandler extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.fastify.aws.sqs.eventHandler";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
11
|
+
const createEventHandler = (cb)=>new SQSEventHandler(cb);
|
|
12
|
+
export { SQSEventHandler, createEventHandler };
|
|
12
13
|
|
|
13
14
|
//# sourceMappingURL=SQSEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"sqs/plugins/SQSEventHandler.js","sources":["../../../src/sqs/plugins/SQSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SQSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface SQSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SQSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SQSEventHandlerCallable<Response = Reply> {\n (params: SQSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SQSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: SQSEventHandlerCallable<Response>;\n\n public constructor(cb: SQSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SQSEventHandlerCallable<Response>) => {\n return new SQSEventHandler<Response>(cb);\n};\n"],"names":["SQSEventHandler","Plugin","cb","createEventHandler"],"mappings":";AAiBO,MAAMA,wBAAwCC;;aAC1B,IAAI,GAAG;;IAI9B,YAAmBC,EAAqC,CAAE;QACtD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,qBAAqB,CAAWD,KAClC,IAAIF,gBAA0BE"}
|