@webiny/handler-aws 0.0.0-unstable.aa00eecd97 → 0.0.0-unstable.ac6ebf63c6
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/README.md +10 -14
- 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 +27 -40
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +8 -7
- package/dynamodb/plugins/DynamoDBEventHandler.js +6 -15
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.d.ts +1 -0
- package/dynamodb/register.js +26 -0
- package/dynamodb/register.js.map +1 -0
- package/eventBridge/index.d.ts +7 -10
- package/eventBridge/index.js +28 -41
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +8 -7
- package/eventBridge/plugins/EventBridgeEventHandler.js +6 -15
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +4 -0
- package/eventBridge/register.js +19 -0
- package/eventBridge/register.js.map +1 -0
- package/execute.d.ts +1 -1
- package/execute.js +19 -14
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +7 -11
- package/gateway/index.js +28 -39
- package/gateway/index.js.map +1 -1
- package/gateway/register.d.ts +1 -0
- package/gateway/register.js +19 -0
- package/gateway/register.js.map +1 -0
- package/index.d.ts +35 -7
- package/index.js +47 -257
- package/index.js.map +1 -1
- package/package.json +15 -22
- package/plugins/handlerClient.js +12 -18
- package/plugins/handlerClient.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +5 -10
- package/plugins/index.js.map +1 -1
- package/raw/index.d.ts +5 -10
- package/raw/index.js +33 -41
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +17 -6
- package/raw/plugins/RawEventHandler.js +22 -13
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +17 -0
- package/registry.js +38 -0
- package/registry.js.map +1 -0
- package/s3/index.d.ts +6 -9
- package/s3/index.js +30 -43
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +8 -7
- package/s3/plugins/S3EventHandler.js +6 -15
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +4 -0
- package/s3/register.js +23 -0
- package/s3/register.js.map +1 -0
- package/sns/index.d.ts +8 -0
- package/sns/index.js +57 -0
- package/sns/index.js.map +1 -0
- package/sns/plugins/SNSEventHandler.d.ts +20 -0
- package/sns/plugins/SNSEventHandler.js +13 -0
- package/sns/plugins/SNSEventHandler.js.map +1 -0
- package/sns/register.d.ts +1 -0
- package/sns/register.js +23 -0
- package/sns/register.js.map +1 -0
- package/sourceHandler.d.ts +2 -0
- package/sourceHandler.js +5 -0
- package/sourceHandler.js.map +1 -0
- package/sqs/index.d.ts +6 -9
- package/sqs/index.js +34 -44
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +8 -7
- package/sqs/plugins/SQSEventHandler.js +6 -15
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.d.ts +1 -0
- package/sqs/register.js +26 -0
- package/sqs/register.js.map +1 -0
- package/types.d.ts +28 -5
- package/types.js +7 -26
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +6 -0
- package/utils/composedHandler.js +17 -0
- package/utils/composedHandler.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +4 -0
- package/utils/index.js.map +1 -0
- package/utils/timer/CustomTimer.d.ts +5 -0
- package/utils/timer/CustomTimer.js +12 -0
- package/utils/timer/CustomTimer.js.map +1 -0
- package/utils/timer/Timer.d.ts +10 -0
- package/utils/timer/Timer.js +17 -0
- package/utils/timer/Timer.js.map +1 -0
- package/utils/timer/abstractions/ITimer.d.ts +10 -0
- package/utils/timer/abstractions/ITimer.js +3 -0
- package/utils/timer/abstractions/ITimer.js.map +1 -0
- package/utils/timer/factory.d.ts +4 -0
- package/utils/timer/factory.js +13 -0
- package/utils/timer/factory.js.map +1 -0
- package/utils/timer/index.d.ts +4 -0
- package/utils/timer/index.js +5 -0
- package/utils/timer/index.js.map +1 -0
package/s3/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createHandler","createBaseHandler","registerDefaultPlugins","S3EventHandler","execute","Reply","createComposedHandler","url","params","event","context","app","options","logger","debug","webiny","plugins","byType","type","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","send","payload"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { S3EventHandlerCallableParams } from \"~/s3/plugins/S3EventHandler.js\";\nimport { S3EventHandler } from \"~/s3/plugins/S3EventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n S3Event\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/S3EventHandler.js\";\n\nexport interface HandlerCallable {\n (event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-s3-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<S3EventHandler>(S3EventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);\n }\n\n const handler = createComposedHandler<\n S3EventHandler,\n S3EventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<S3EventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n const result = await handler(\n params as unknown as S3EventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"mappings":"AAAA,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,sBAAsB;AAE/B,SAASC,cAAc;AACvB,SAASC,OAAO;AAEhB;AACA;AACA;AACA;AACA,OAAOC,KAAK,MAAM,sBAAsB;AAMxC,SAASC,qBAAqB;AAE9B;AAQA,MAAMC,GAAG,GAAG,kBAAkB;AAE9B,OAAO,MAAMP,aAAa,GAAIQ,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQV,sBAAsB,CAACS,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAACC,MAAM,CAAiBd,cAAc,CAACe,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IACxF,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,kEAAkE,CAAC;IACvF;IAEA,MAAMC,OAAO,GAAGhB,qBAAqB,CAInCU,OAAO,CAAC;IAEVL,GAAG,CAACY,IAAI,CAAChB,GAAG,EAAE,OAAOiB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMjB,MAAyE,GAAG;QAC9EgB,OAAO;QACPC,KAAK;QACLf,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,KAAK;QACLiB,aAAa,EAAEhB;MACnB,CAAC;MACD,MAAMiB,MAAM,GAAG,MAAML,OAAO,CACxBd,MACJ,CAAC;MAED,IAAImB,MAAM,YAAYtB,KAAK,EAAE;QACzB,OAAOsB,MAAM;MACjB;MAEAhB,GAAG,CAACiB,mBAAmB,GAAGD,MAAM;MAChC,OAAOF,KAAK,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAOzB,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHuB,OAAO,EAAErB;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export interface S3EventHandlerCallableParams {
|
|
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
|
+
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;
|
|
16
17
|
readonly cb: S3EventHandlerCallable<Response>;
|
|
17
18
|
constructor(cb: S3EventHandlerCallable<Response>);
|
|
18
19
|
}
|
|
19
|
-
export declare const createEventHandler: <
|
|
20
|
+
export declare const createEventHandler: <Response>(cb: S3EventHandlerCallable<Response>) => S3EventHandler<Response>;
|
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createEventHandler = exports.S3EventHandler = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _Plugin = require("@webiny/plugins/Plugin");
|
|
10
|
-
class S3EventHandler extends _Plugin.Plugin {
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
export class S3EventHandler extends Plugin {
|
|
3
|
+
static type = "handler.fastify.aws.s3.eventHandler";
|
|
11
4
|
constructor(cb) {
|
|
12
5
|
super();
|
|
13
|
-
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
14
6
|
this.cb = cb;
|
|
15
7
|
}
|
|
16
8
|
}
|
|
17
|
-
|
|
18
|
-
(0, _defineProperty2.default)(S3EventHandler, "type", "handler.fastify.aws.s3.eventHandler");
|
|
19
|
-
const createEventHandler = cb => {
|
|
9
|
+
export const createEventHandler = cb => {
|
|
20
10
|
return new S3EventHandler(cb);
|
|
21
11
|
};
|
|
22
|
-
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=S3EventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["S3EventHandler","
|
|
1
|
+
{"version":3,"names":["Plugin","S3EventHandler","type","constructor","cb","createEventHandler"],"sources":["S3EventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, S3Event } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface S3EventHandlerCallableParams<Response = Reply> {\n request: Request;\n context: Context;\n event: S3Event;\n lambdaContext: LambdaContext;\n reply: Reply;\n next: () => Promise<Response>;\n}\n\nexport interface S3EventHandlerCallable<Response = Reply> {\n (params: S3EventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class S3EventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.s3.eventHandler\";\n\n public readonly cb: S3EventHandlerCallable<Response>;\n\n public constructor(cb: S3EventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: S3EventHandlerCallable<Response>) => {\n return new S3EventHandler<Response>(cb);\n};\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,2BAA2B;AAgBlD,OAAO,MAAMC,cAAc,SAAyBD,MAAM,CAAC;EACvD,OAAuBE,IAAI,GAAG,qCAAqC;EAI5DC,WAAWA,CAACC,EAAoC,EAAE;IACrD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAcD,EAAoC,IAAK;EAClF,OAAO,IAAIH,cAAc,CAAWG,EAAE,CAAC;AAC3C,CAAC","ignoreList":[]}
|
package/s3/register.d.ts
ADDED
package/s3/register.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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) || event.Records.length === 0) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const [record] = event.Records;
|
|
11
|
+
return !!record.s3;
|
|
12
|
+
},
|
|
13
|
+
handle: async ({
|
|
14
|
+
params,
|
|
15
|
+
event,
|
|
16
|
+
context
|
|
17
|
+
}) => {
|
|
18
|
+
return createHandler(params)(event, context);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
registry.register(handler);
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["registry","createSourceHandler","createHandler","handler","name","canUse","event","Array","isArray","Records","length","record","s3","handle","params","context","register"],"sources":["register.ts"],"sourcesContent":["import type { S3Event } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\nimport { createHandler } from \"./index.js\";\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst handler = createSourceHandler<S3Event, HandlerParams>({\n name: \"handler-aws-s3\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.s3;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":"AACA,SAASA,QAAQ;AAEjB,SAASC,mBAAmB;AAC5B,SAASC,aAAa;AAMtB,MAAMC,OAAO,GAAGF,mBAAmB,CAAyB;EACxDG,IAAI,EAAE,gBAAgB;EACtBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,OAAO,CAAC,CAACE,MAAM,CAACC,EAAE;EACtB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAER,KAAK;IAAES;EAAQ,CAAC,KAAK;IAC1C,OAAOb,aAAa,CAACY,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFf,QAAQ,CAACgB,QAAQ,CAACb,OAAO,CAAC","ignoreList":[]}
|
package/sns/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
export interface HandlerCallable {
|
|
5
|
+
(event: SNSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
6
|
+
}
|
|
7
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
8
|
+
export declare const createHandler: (params: HandlerParams) => HandlerCallable;
|
package/sns/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createHandler as createBaseHandler } from "@webiny/handler";
|
|
2
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
|
+
import { SNSEventHandler } from "./plugins/SNSEventHandler.js";
|
|
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";
|
|
10
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
11
|
+
export * from "./plugins/SNSEventHandler.js";
|
|
12
|
+
const url = "/webiny-sns-event";
|
|
13
|
+
export const createHandler = params => {
|
|
14
|
+
return async (event, context) => {
|
|
15
|
+
const app = createBaseHandler({
|
|
16
|
+
...params,
|
|
17
|
+
options: {
|
|
18
|
+
logger: params.debug === true,
|
|
19
|
+
...(params.options || {})
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* We always must add our default plugins to the app.
|
|
24
|
+
*/
|
|
25
|
+
registerDefaultPlugins(app.webiny);
|
|
26
|
+
/**
|
|
27
|
+
* There must be an event plugin for this handler to work.
|
|
28
|
+
*/
|
|
29
|
+
const plugins = app.webiny.plugins.byType(SNSEventHandler.type).reverse();
|
|
30
|
+
if (plugins.length === 0) {
|
|
31
|
+
throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);
|
|
32
|
+
}
|
|
33
|
+
const handler = createComposedHandler(plugins);
|
|
34
|
+
app.post(url, async (request, reply) => {
|
|
35
|
+
const params = {
|
|
36
|
+
request,
|
|
37
|
+
reply,
|
|
38
|
+
context: app.webiny,
|
|
39
|
+
event,
|
|
40
|
+
lambdaContext: context
|
|
41
|
+
};
|
|
42
|
+
const result = await handler(params);
|
|
43
|
+
if (result instanceof Reply) {
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
app.__webiny_raw_result = result;
|
|
47
|
+
return reply.send({});
|
|
48
|
+
});
|
|
49
|
+
return execute({
|
|
50
|
+
app,
|
|
51
|
+
url,
|
|
52
|
+
payload: event
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
package/sns/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createHandler","createBaseHandler","registerDefaultPlugins","SNSEventHandler","execute","Reply","createComposedHandler","url","params","event","context","app","options","logger","debug","webiny","plugins","byType","type","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","send","payload"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n SNSEvent,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { SNSEventHandlerCallableParams } from \"./plugins/SNSEventHandler.js\";\nimport { SNSEventHandler } from \"./plugins/SNSEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/SNSEventHandler.js\";\n\nexport interface HandlerCallable {\n (event: SNSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-sns-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<SNSEventHandler>(SNSEventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n SNSEventHandler,\n SNSEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<SNSEventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n\n const result = await handler(\n params as unknown as SNSEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"mappings":"AAKA,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,sBAAsB;AAE/B,SAASC,eAAe;AACxB,SAASC,OAAO;AAEhB;AACA;AACA;AACA;AACA,OAAOC,KAAK,MAAM,sBAAsB;AACxC,SAASC,qBAAqB;AAE9B;AAQA,MAAMC,GAAG,GAAG,mBAAmB;AAE/B,OAAO,MAAMP,aAAa,GAAIQ,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQV,sBAAsB,CAACS,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBd,eAAe,CAACe,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IAC1F,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAGhB,qBAAqB,CAInCU,OAAO,CAAC;IAEVL,GAAG,CAACY,IAAI,CAAChB,GAAG,EAAE,OAAOiB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMjB,MAA0E,GAAG;QAC/EgB,OAAO;QACPC,KAAK;QACLf,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,KAAK;QACLiB,aAAa,EAAEhB;MACnB,CAAC;MAED,MAAMiB,MAAM,GAAG,MAAML,OAAO,CACxBd,MACJ,CAAC;MAED,IAAImB,MAAM,YAAYtB,KAAK,EAAE;QACzB,OAAOsB,MAAM;MACjB;MAEAhB,GAAG,CAACiB,mBAAmB,GAAGD,MAAM;MAChC,OAAOF,KAAK,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAOzB,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHuB,OAAO,EAAErB;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Context as LambdaContext, SNSEvent } 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
|
+
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>(cb: SNSEventHandlerCallable<Response>) => SNSEventHandler<Response>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
export class SNSEventHandler extends Plugin {
|
|
3
|
+
static type = "handler.fastify.aws.sns.eventHandler";
|
|
4
|
+
constructor(cb) {
|
|
5
|
+
super();
|
|
6
|
+
this.cb = cb;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export const createEventHandler = cb => {
|
|
10
|
+
return new SNSEventHandler(cb);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=SNSEventHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Plugin","SNSEventHandler","type","constructor","cb","createEventHandler"],"sources":["SNSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SNSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface SNSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SNSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SNSEventHandlerCallable<Response = Reply> {\n (params: SNSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SNSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sns.eventHandler\";\n\n public readonly cb: SNSEventHandlerCallable<Response>;\n\n public constructor(cb: SNSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SNSEventHandlerCallable<Response>) => {\n return new SNSEventHandler<Response>(cb);\n};\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,2BAA2B;AAgBlD,OAAO,MAAMC,eAAe,SAAyBD,MAAM,CAAC;EACxD,OAAuBE,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAcD,EAAqC,IAAK;EACnF,OAAO,IAAIH,eAAe,CAAWG,EAAE,CAAC;AAC5C,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/sns/register.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { registry } from "../registry.js";
|
|
2
|
+
import { createHandler } from "./index.js";
|
|
3
|
+
import { createSourceHandler } from "../sourceHandler.js";
|
|
4
|
+
const handler = createSourceHandler({
|
|
5
|
+
name: "handler-aws-sns",
|
|
6
|
+
canUse: event => {
|
|
7
|
+
if (!Array.isArray(event.Records) || event.Records.length === 0) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const [record] = event.Records;
|
|
11
|
+
return !!record.Sns;
|
|
12
|
+
},
|
|
13
|
+
handle: async ({
|
|
14
|
+
params,
|
|
15
|
+
event,
|
|
16
|
+
context
|
|
17
|
+
}) => {
|
|
18
|
+
return createHandler(params)(event, context);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
registry.register(handler);
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["registry","createHandler","createSourceHandler","handler","name","canUse","event","Array","isArray","Records","length","record","Sns","handle","params","context","register"],"sources":["register.ts"],"sourcesContent":["import type { SNSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport type { HandlerParams } from \"./index.js\";\nimport { createHandler } from \"./index.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\n\nconst handler = createSourceHandler<SNSEvent, HandlerParams>({\n name: \"handler-aws-sns\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.Sns;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":"AACA,SAASA,QAAQ;AAEjB,SAASC,aAAa;AACtB,SAASC,mBAAmB;AAE5B,MAAMC,OAAO,GAAGD,mBAAmB,CAA0B;EACzDE,IAAI,EAAE,iBAAiB;EACvBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,OAAO,CAAC,CAACE,MAAM,CAACC,GAAG;EACvB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAER,KAAK;IAAES;EAAQ,CAAC,KAAK;IAC1C,OAAOd,aAAa,CAACa,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFf,QAAQ,CAACgB,QAAQ,CAACb,OAAO,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from "./types.js";
|
|
2
|
+
export declare const createSourceHandler: <TEvent = HandlerEvent, TParams extends HandlerFactoryParams = HandlerFactoryParams>(handler: SourceHandler<TEvent, TParams>) => SourceHandler<TEvent, TParams, any>;
|
package/sourceHandler.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createSourceHandler","handler"],"sources":["sourceHandler.ts"],"sourcesContent":["import type { SourceHandler, HandlerEvent, HandlerFactoryParams } from \"~/types.js\";\n\nexport const createSourceHandler = <\n TEvent = HandlerEvent,\n TParams extends HandlerFactoryParams = HandlerFactoryParams\n>(\n handler: SourceHandler<TEvent, TParams>\n) => {\n return handler;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,mBAAmB,GAI5BC,OAAuC,IACtC;EACD,OAAOA,OAAO;AAClB,CAAC","ignoreList":[]}
|
package/sqs/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { APIGatewayProxyResult, Context as LambdaContext, SQSEvent } from "@webiny/aws-sdk/types/index.js";
|
|
2
|
+
import type { HandlerFactoryParams } from "../types.js";
|
|
3
|
+
export * from "./plugins/SQSEventHandler.js";
|
|
4
4
|
export interface HandlerCallable {
|
|
5
|
-
(
|
|
5
|
+
(event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
export declare const createHandler: (params: CreateHandlerParams) => HandlerCallable;
|
|
11
|
-
export * from "./plugins/SQSEventHandler";
|
|
7
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
8
|
+
export declare const createHandler: (params: HandlerParams) => HandlerCallable;
|
package/sqs/index.js
CHANGED
|
@@ -1,70 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _handler = require("@webiny/handler");
|
|
13
|
-
var _SQSEventHandler = require("./plugins/SQSEventHandler");
|
|
14
|
-
Object.keys(_SQSEventHandler).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] === _SQSEventHandler[key]) return;
|
|
18
|
-
Object.defineProperty(exports, key, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _SQSEventHandler[key];
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
var _plugins = require("../plugins");
|
|
26
|
-
var _execute = require("../execute");
|
|
27
|
-
const Reply = require("fastify/lib/reply");
|
|
1
|
+
import { createHandler as createBaseHandler } from "@webiny/handler";
|
|
2
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
|
+
import { SQSEventHandler } from "./plugins/SQSEventHandler.js";
|
|
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";
|
|
10
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
11
|
+
export * from "./plugins/SQSEventHandler.js";
|
|
28
12
|
const url = "/webiny-sqs-event";
|
|
29
|
-
const createHandler = params => {
|
|
30
|
-
return (
|
|
31
|
-
const app = (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
export const createHandler = params => {
|
|
14
|
+
return async (event, context) => {
|
|
15
|
+
const app = createBaseHandler({
|
|
16
|
+
...params,
|
|
17
|
+
options: {
|
|
18
|
+
logger: params.debug === true,
|
|
19
|
+
...(params.options || {})
|
|
20
|
+
}
|
|
21
|
+
});
|
|
36
22
|
/**
|
|
37
23
|
* We always must add our default plugins to the app.
|
|
38
24
|
*/
|
|
39
|
-
|
|
25
|
+
registerDefaultPlugins(app.webiny);
|
|
40
26
|
/**
|
|
41
27
|
* There must be an event plugin for this handler to work.
|
|
42
28
|
*/
|
|
43
|
-
const plugins = app.webiny.plugins.byType(
|
|
44
|
-
|
|
45
|
-
if (!handler) {
|
|
29
|
+
const plugins = app.webiny.plugins.byType(SQSEventHandler.type).reverse();
|
|
30
|
+
if (plugins.length === 0) {
|
|
46
31
|
throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);
|
|
47
32
|
}
|
|
33
|
+
const handler = createComposedHandler(plugins);
|
|
48
34
|
app.post(url, async (request, reply) => {
|
|
49
35
|
const params = {
|
|
50
36
|
request,
|
|
51
37
|
reply,
|
|
52
38
|
context: app.webiny,
|
|
53
|
-
event
|
|
39
|
+
event,
|
|
54
40
|
lambdaContext: context
|
|
55
41
|
};
|
|
56
|
-
const result = await handler
|
|
42
|
+
const result = await handler(params);
|
|
57
43
|
if (result instanceof Reply) {
|
|
58
44
|
return result;
|
|
59
45
|
}
|
|
60
46
|
app.__webiny_raw_result = result;
|
|
61
|
-
|
|
47
|
+
if (!reply.sent) {
|
|
48
|
+
reply.send({});
|
|
49
|
+
}
|
|
50
|
+
return reply;
|
|
62
51
|
});
|
|
63
|
-
return
|
|
52
|
+
return execute({
|
|
64
53
|
app,
|
|
65
54
|
url,
|
|
66
|
-
payload
|
|
55
|
+
payload: event
|
|
67
56
|
});
|
|
68
57
|
};
|
|
69
58
|
};
|
|
70
|
-
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
package/sqs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createHandler","createBaseHandler","registerDefaultPlugins","SQSEventHandler","execute","Reply","createComposedHandler","url","params","event","context","app","options","logger","debug","webiny","plugins","byType","type","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","sent","send","payload"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n SQSEvent\n} from \"@webiny/aws-sdk/types/index.js\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport type { SQSEventHandlerCallableParams } from \"~/sqs/plugins/SQSEventHandler.js\";\nimport { SQSEventHandler } from \"~/sqs/plugins/SQSEventHandler.js\";\nimport { execute } from \"~/execute.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\n\nexport * from \"./plugins/SQSEventHandler.js\";\n\nexport interface HandlerCallable {\n (event: SQSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-sqs-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<SQSEventHandler>(SQSEventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/sqs, you must have SQSEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n SQSEventHandler,\n SQSEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<SQSEventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n\n const result = await handler(\n params as unknown as SQSEventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n if (!reply.sent) {\n reply.send({});\n }\n return reply;\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"mappings":"AAKA,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,sBAAsB;AAE/B,SAASC,eAAe;AACxB,SAASC,OAAO;AAEhB;AACA;AACA;AACA;AACA,OAAOC,KAAK,MAAM,sBAAsB;AACxC,SAASC,qBAAqB;AAE9B;AAQA,MAAMC,GAAG,GAAG,mBAAmB;AAE/B,OAAO,MAAMP,aAAa,GAAIQ,MAAqB,IAAsB;EACrE,OAAO,OAAOC,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQV,sBAAsB,CAACS,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAACC,MAAM,CAAkBd,eAAe,CAACe,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;IAC1F,IAAIH,OAAO,CAACI,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAGhB,qBAAqB,CAInCU,OAAO,CAAC;IAEVL,GAAG,CAACY,IAAI,CAAChB,GAAG,EAAE,OAAOiB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMjB,MAA0E,GAAG;QAC/EgB,OAAO;QACPC,KAAK;QACLf,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,KAAK;QACLiB,aAAa,EAAEhB;MACnB,CAAC;MAED,MAAMiB,MAAM,GAAG,MAAML,OAAO,CACxBd,MACJ,CAAC;MAED,IAAImB,MAAM,YAAYtB,KAAK,EAAE;QACzB,OAAOsB,MAAM;MACjB;MAEAhB,GAAG,CAACiB,mBAAmB,GAAGD,MAAM;MAChC,IAAI,CAACF,KAAK,CAACI,IAAI,EAAE;QACbJ,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;MAClB;MACA,OAAOL,KAAK;IAChB,CAAC,CAAC;IACF,OAAOrB,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHwB,OAAO,EAAEtB;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export interface SQSEventHandlerCallableParams {
|
|
1
|
+
import type { Context as LambdaContext, SQSEvent } 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
|
+
export interface SQSEventHandlerCallableParams<Response = Reply> {
|
|
5
5
|
request: Request;
|
|
6
6
|
reply: Reply;
|
|
7
7
|
context: Context;
|
|
8
8
|
event: SQSEvent;
|
|
9
9
|
lambdaContext: LambdaContext;
|
|
10
|
+
next: () => Promise<Response>;
|
|
10
11
|
}
|
|
11
|
-
export interface SQSEventHandlerCallable<Response> {
|
|
12
|
-
(params: SQSEventHandlerCallableParams): Promise<Response
|
|
12
|
+
export interface SQSEventHandlerCallable<Response = Reply> {
|
|
13
|
+
(params: SQSEventHandlerCallableParams<Response>): Promise<Response>;
|
|
13
14
|
}
|
|
14
15
|
export declare class SQSEventHandler<Response = any> extends Plugin {
|
|
15
16
|
static type: string;
|
|
16
17
|
readonly cb: SQSEventHandlerCallable<Response>;
|
|
17
18
|
constructor(cb: SQSEventHandlerCallable<Response>);
|
|
18
19
|
}
|
|
19
|
-
export declare const createEventHandler: <
|
|
20
|
+
export declare const createEventHandler: <Response>(cb: SQSEventHandlerCallable<Response>) => SQSEventHandler<Response>;
|
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createEventHandler = exports.SQSEventHandler = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _Plugin = require("@webiny/plugins/Plugin");
|
|
10
|
-
class SQSEventHandler extends _Plugin.Plugin {
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
export class SQSEventHandler extends Plugin {
|
|
3
|
+
static type = "handler.fastify.aws.sqs.eventHandler";
|
|
11
4
|
constructor(cb) {
|
|
12
5
|
super();
|
|
13
|
-
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
14
6
|
this.cb = cb;
|
|
15
7
|
}
|
|
16
8
|
}
|
|
17
|
-
|
|
18
|
-
(0, _defineProperty2.default)(SQSEventHandler, "type", "handler.fastify.aws.sqs.eventHandler");
|
|
19
|
-
const createEventHandler = cb => {
|
|
9
|
+
export const createEventHandler = cb => {
|
|
20
10
|
return new SQSEventHandler(cb);
|
|
21
11
|
};
|
|
22
|
-
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=SQSEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SQSEventHandler","
|
|
1
|
+
{"version":3,"names":["Plugin","SQSEventHandler","type","constructor","cb","createEventHandler"],"sources":["SQSEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, SQSEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types.js\";\n\nexport interface SQSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SQSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SQSEventHandlerCallable<Response = Reply> {\n (params: SQSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SQSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sqs.eventHandler\";\n\n public readonly cb: SQSEventHandlerCallable<Response>;\n\n public constructor(cb: SQSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SQSEventHandlerCallable<Response>) => {\n return new SQSEventHandler<Response>(cb);\n};\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,2BAA2B;AAgBlD,OAAO,MAAMC,eAAe,SAAyBD,MAAM,CAAC;EACxD,OAAuBE,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAcD,EAAqC,IAAK;EACnF,OAAO,IAAIH,eAAe,CAAWG,EAAE,CAAC;AAC5C,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/sqs/register.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { registry } from "../registry.js";
|
|
2
|
+
import { createHandler } from "./index.js";
|
|
3
|
+
import { createSourceHandler } from "../sourceHandler.js";
|
|
4
|
+
const handler = createSourceHandler({
|
|
5
|
+
name: "handler-aws-sqs",
|
|
6
|
+
canUse: event => {
|
|
7
|
+
if (!Array.isArray(event.Records) || event.Records.length === 0) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const [record] = event.Records;
|
|
11
|
+
if (typeof record.eventSource !== "string") {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return record.eventSource.toLowerCase() === "aws:sqs";
|
|
15
|
+
},
|
|
16
|
+
handle: async ({
|
|
17
|
+
params,
|
|
18
|
+
event,
|
|
19
|
+
context
|
|
20
|
+
}) => {
|
|
21
|
+
return createHandler(params)(event, context);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
registry.register(handler);
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["registry","createHandler","createSourceHandler","handler","name","canUse","event","Array","isArray","Records","length","record","eventSource","toLowerCase","handle","params","context","register"],"sources":["register.ts"],"sourcesContent":["import type { SQSEvent } 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<SQSEvent, HandlerParams>({\n name: \"handler-aws-sqs\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n if (typeof record.eventSource !== \"string\") {\n return false;\n }\n return record.eventSource.toLowerCase() === \"aws:sqs\";\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":"AACA,SAASA,QAAQ;AAEjB,SAASC,aAAa;AACtB,SAASC,mBAAmB;AAE5B,MAAMC,OAAO,GAAGD,mBAAmB,CAA0B;EACzDE,IAAI,EAAE,iBAAiB;EACvBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,IAAI,OAAOE,MAAM,CAACC,WAAW,KAAK,QAAQ,EAAE;MACxC,OAAO,KAAK;IAChB;IACA,OAAOD,MAAM,CAACC,WAAW,CAACC,WAAW,CAAC,CAAC,KAAK,SAAS;EACzD,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAET,KAAK;IAAEU;EAAQ,CAAC,KAAK;IAC1C,OAAOf,aAAa,CAACc,MAAM,CAAC,CAACT,KAAK,EAAEU,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFhB,QAAQ,CAACiB,QAAQ,CAACd,OAAO,CAAC","ignoreList":[]}
|
package/types.d.ts
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
|
-
import { APIGatewayEvent, Context as LambdaContext } from "aws-
|
|
1
|
+
import type { APIGatewayEvent, APIGatewayEventRequestContextWithAuthorizer, AttributeValue, Context as LambdaContext, DynamoDBRecord, DynamoDBStreamEvent, EventBridgeEvent, S3Event, SNSEvent, SQSEvent } from "@webiny/aws-sdk/types/index.js";
|
|
2
2
|
import "fastify";
|
|
3
|
-
|
|
3
|
+
import type { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
|
|
4
|
+
import type { LambdaFastifyOptions as LambdaOptions } from "@fastify/aws-lambda";
|
|
5
|
+
import type { GenericRecord } from "@webiny/utils";
|
|
6
|
+
export type { AttributeValue, DynamoDBRecord };
|
|
7
|
+
export type { HandlerRegistry } from "./registry.js";
|
|
8
|
+
export * from "@webiny/handler/types.js";
|
|
9
|
+
export type { APIGatewayEvent, LambdaContext, APIGatewayEventRequestContextWithAuthorizer };
|
|
10
|
+
export type HandlerEvent = APIGatewayEvent | SNSEvent | SQSEvent | S3Event | EventBridgeEvent<string, string> | DynamoDBStreamEvent | GenericRecord<string>;
|
|
11
|
+
export interface EventResolver<T = any> {
|
|
12
|
+
(event: HandlerEvent, context: LambdaContext): T;
|
|
13
|
+
}
|
|
14
|
+
export interface HandlerFactoryParams extends BaseCreateHandlerParams {
|
|
15
|
+
lambdaOptions?: LambdaOptions;
|
|
16
|
+
}
|
|
17
|
+
export interface HandlerFactory<T extends HandlerFactoryParams = HandlerFactoryParams, R = any> {
|
|
18
|
+
(params: T): EventResolver<R>;
|
|
19
|
+
}
|
|
20
|
+
export interface HandlerParams<E, P extends HandlerFactoryParams> {
|
|
21
|
+
params: P;
|
|
22
|
+
event: E;
|
|
23
|
+
context: LambdaContext;
|
|
24
|
+
}
|
|
25
|
+
export interface SourceHandler<E = HandlerEvent, P extends HandlerFactoryParams = HandlerFactoryParams, T = any> {
|
|
26
|
+
name: string;
|
|
27
|
+
canUse: (event: Partial<E>, context: LambdaContext) => boolean;
|
|
28
|
+
handle: (params: HandlerParams<E, P>) => Promise<T>;
|
|
29
|
+
}
|
|
4
30
|
export declare enum Base64EncodeHeader {
|
|
5
31
|
encoded = "x-webiny-base64-encoded",
|
|
6
32
|
binary = "x-webiny-binary"
|
|
7
33
|
}
|
|
8
34
|
declare module "fastify" {
|
|
9
|
-
interface FastifyInstance {
|
|
10
|
-
__webiny_raw_result: any;
|
|
11
|
-
}
|
|
12
35
|
interface FastifyRequest {
|
|
13
36
|
awsLambda: {
|
|
14
37
|
event: APIGatewayEvent;
|