@webiny/handler-aws 0.0.0-mt-3 → 0.0.0-unstable.06b2ede40f
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 +8 -0
- package/dynamodb/index.js +79 -0
- package/dynamodb/index.js.map +1 -0
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +20 -0
- package/dynamodb/plugins/DynamoDBEventHandler.js +21 -0
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -0
- 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 +8 -0
- package/eventBridge/index.js +79 -0
- package/eventBridge/index.js.map +1 -0
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +20 -0
- package/eventBridge/plugins/EventBridgeEventHandler.js +21 -0
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -0
- package/eventBridge/register.d.ts +4 -0
- package/eventBridge/register.js +21 -0
- package/eventBridge/register.js.map +1 -0
- package/execute.d.ts +7 -0
- package/execute.js +73 -0
- package/execute.js.map +1 -0
- package/gateway/index.d.ts +10 -0
- package/gateway/index.js +90 -0
- package/gateway/index.js.map +1 -0
- package/gateway/register.d.ts +1 -0
- package/gateway/register.js +21 -0
- package/gateway/register.js.map +1 -0
- package/index.d.ts +33 -17
- package/index.js +367 -33
- package/index.js.map +1 -0
- package/package.json +16 -24
- package/plugins/handlerClient.d.ts +2 -3
- package/plugins/handlerClient.js +46 -33
- package/plugins/handlerClient.js.map +1 -0
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +13 -0
- package/plugins/index.js.map +1 -0
- package/raw/index.d.ts +14 -0
- package/raw/index.js +89 -0
- package/raw/index.js.map +1 -0
- package/raw/plugins/RawEventHandler.d.ts +24 -0
- package/raw/plugins/RawEventHandler.js +34 -0
- package/raw/plugins/RawEventHandler.js.map +1 -0
- package/registry.d.ts +17 -0
- package/registry.js +44 -0
- package/registry.js.map +1 -0
- package/s3/index.d.ts +8 -0
- package/s3/index.js +79 -0
- package/s3/index.js.map +1 -0
- package/s3/plugins/S3EventHandler.d.ts +20 -0
- package/s3/plugins/S3EventHandler.js +21 -0
- package/s3/plugins/S3EventHandler.js.map +1 -0
- 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 +8 -0
- package/sns/index.js +79 -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 +8 -0
- package/sqs/index.js +82 -0
- package/sqs/index.js.map +1 -0
- package/sqs/plugins/SQSEventHandler.d.ts +20 -0
- package/sqs/plugins/SQSEventHandler.js +21 -0
- package/sqs/plugins/SQSEventHandler.js.map +1 -0
- package/sqs/register.d.ts +1 -0
- package/sqs/register.js +28 -0
- package/sqs/register.js.map +1 -0
- package/types.d.ts +41 -0
- package/types.js +37 -0
- package/types.js.map +1 -0
- package/utils/composedHandler.d.ts +6 -0
- package/utils/composedHandler.js +24 -0
- package/utils/composedHandler.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +29 -0
- package/utils/index.js.map +1 -0
- package/utils/timer/CustomTimer.d.ts +5 -0
- package/utils/timer/CustomTimer.js +19 -0
- package/utils/timer/CustomTimer.js.map +1 -0
- package/utils/timer/Timer.d.ts +10 -0
- package/utils/timer/Timer.js +24 -0
- package/utils/timer/Timer.js.map +1 -0
- package/utils/timer/abstractions/ITimer.d.ts +10 -0
- package/utils/timer/abstractions/ITimer.js +7 -0
- package/utils/timer/abstractions/ITimer.js.map +1 -0
- package/utils/timer/factory.d.ts +4 -0
- package/utils/timer/factory.js +20 -0
- package/utils/timer/factory.js.map +1 -0
- package/utils/timer/index.d.ts +4 -0
- package/utils/timer/index.js +51 -0
- package/utils/timer/index.js.map +1 -0
- package/plugins/handlerArgs.d.ts +0 -7
- package/plugins/handlerArgs.js +0 -16
- package/plugins/handlerHttp.d.ts +0 -5
- package/plugins/handlerHttp.js +0 -65
package/plugins/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.registerDefaultPlugins = void 0;
|
|
7
|
+
var _handlerClient = require("./handlerClient");
|
|
8
|
+
const registerDefaultPlugins = context => {
|
|
9
|
+
context.plugins.register([(0, _handlerClient.createHandlerClientPlugin)()]);
|
|
10
|
+
};
|
|
11
|
+
exports.registerDefaultPlugins = registerDefaultPlugins;
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_handlerClient","require","registerDefaultPlugins","context","plugins","register","createHandlerClientPlugin","exports"],"sources":["index.ts"],"sourcesContent":["import { createHandlerClientPlugin } from \"./handlerClient\";\nimport type { Context } from \"@webiny/handler/types\";\n\nexport const registerDefaultPlugins = (context: Context): void => {\n context.plugins.register([createHandlerClientPlugin()]);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAGO,MAAMC,sBAAsB,GAAIC,OAAgB,IAAW;EAC9DA,OAAO,CAACC,OAAO,CAACC,QAAQ,CAAC,CAAC,IAAAC,wCAAyB,EAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAACC,OAAA,CAAAL,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
package/raw/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the handler implementation for @webiny/handler/plugins/EventPlugin.
|
|
3
|
+
* This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.
|
|
4
|
+
*
|
|
5
|
+
* We should try to have some kind of standardized event type implementation at some point.
|
|
6
|
+
*/
|
|
7
|
+
import type { APIGatewayProxyResult, Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
8
|
+
import type { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
|
|
9
|
+
export interface HandlerCallable<Payload, Response = APIGatewayProxyResult> {
|
|
10
|
+
(payload: Payload, context: LambdaContext): Promise<Response>;
|
|
11
|
+
}
|
|
12
|
+
export type CreateHandlerParams = BaseCreateHandlerParams;
|
|
13
|
+
export declare const createHandler: <Payload = any, Response_1 = APIGatewayProxyResult>(params: CreateHandlerParams) => HandlerCallable<Payload, Response_1>;
|
|
14
|
+
export * from "./plugins/RawEventHandler";
|
package/raw/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
createHandler: true
|
|
8
|
+
};
|
|
9
|
+
exports.createHandler = void 0;
|
|
10
|
+
var _handler = require("@webiny/handler");
|
|
11
|
+
var _RawEventHandler = require("./plugins/RawEventHandler");
|
|
12
|
+
Object.keys(_RawEventHandler).forEach(function (key) {
|
|
13
|
+
if (key === "default" || key === "__esModule") return;
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
15
|
+
if (key in exports && exports[key] === _RawEventHandler[key]) return;
|
|
16
|
+
Object.defineProperty(exports, key, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _RawEventHandler[key];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
var _plugins = require("../plugins");
|
|
24
|
+
var _execute = require("../execute");
|
|
25
|
+
var _composedHandler = require("../utils/composedHandler");
|
|
26
|
+
/**
|
|
27
|
+
* This is the handler implementation for @webiny/handler/plugins/EventPlugin.
|
|
28
|
+
* This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.
|
|
29
|
+
*
|
|
30
|
+
* We should try to have some kind of standardized event type implementation at some point.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const Reply = require("fastify/lib/reply");
|
|
34
|
+
const url = "/webiny-raw-event";
|
|
35
|
+
const createHandler = params => {
|
|
36
|
+
return (payload, context) => {
|
|
37
|
+
const app = (0, _handler.createHandler)({
|
|
38
|
+
...params,
|
|
39
|
+
options: {
|
|
40
|
+
logger: params.debug === true,
|
|
41
|
+
...(params.options || {})
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* We always must add our default plugins to the app.
|
|
46
|
+
*/
|
|
47
|
+
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
48
|
+
/**
|
|
49
|
+
* There must be an event plugin for this handler to work.
|
|
50
|
+
*/
|
|
51
|
+
const plugins = app.webiny.plugins.byType(_RawEventHandler.RawEventHandler.type).filter(plugin => {
|
|
52
|
+
/**
|
|
53
|
+
* Just in case check that the plugin contains canHandle method.
|
|
54
|
+
* If it does not, we assume it can handle any payload.
|
|
55
|
+
*/
|
|
56
|
+
if (typeof plugin.canHandle !== "function") {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return plugin.canHandle(payload);
|
|
60
|
+
}).reverse();
|
|
61
|
+
if (plugins.length === 0) {
|
|
62
|
+
throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);
|
|
63
|
+
}
|
|
64
|
+
const handler = (0, _composedHandler.createComposedHandler)(plugins);
|
|
65
|
+
app.post(url, async (request, reply) => {
|
|
66
|
+
const params = {
|
|
67
|
+
request,
|
|
68
|
+
reply,
|
|
69
|
+
context: app.webiny,
|
|
70
|
+
payload,
|
|
71
|
+
lambdaContext: context
|
|
72
|
+
};
|
|
73
|
+
const result = await handler(params);
|
|
74
|
+
if (result instanceof Reply) {
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
app.__webiny_raw_result = result;
|
|
78
|
+
return reply.send({});
|
|
79
|
+
});
|
|
80
|
+
return (0, _execute.execute)({
|
|
81
|
+
app,
|
|
82
|
+
url,
|
|
83
|
+
payload
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
exports.createHandler = createHandler;
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
package/raw/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_handler","require","_RawEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_plugins","_execute","_composedHandler","Reply","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","RawEventHandler","type","filter","plugin","canHandle","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["/**\n * This is the handler implementation for @webiny/handler/plugins/EventPlugin.\n * This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.\n *\n * We should try to have some kind of standardized event type implementation at some point.\n */\nimport type { APIGatewayProxyResult, Context as LambdaContext } from \"@webiny/aws-sdk/types\";\nimport type { CreateHandlerParams as BaseCreateHandlerParams } from \"@webiny/handler\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { RawEventHandler } from \"~/raw/plugins/RawEventHandler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport { execute } from \"~/execute\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\nimport type { Context, Request } from \"@webiny/handler/types\";\n\nconst Reply = require(\"fastify/lib/reply\");\n\nconst url = \"/webiny-raw-event\";\n\nexport interface HandlerCallable<Payload, Response = APIGatewayProxyResult> {\n (payload: Payload, context: LambdaContext): Promise<Response>;\n}\n\nexport type CreateHandlerParams = BaseCreateHandlerParams;\n\ninterface HandlerParams<Payload = any> {\n request: Request;\n context: Context;\n payload: Payload;\n lambdaContext: LambdaContext;\n reply: Record<string, any>;\n next: () => Promise<Payload>;\n}\n\nexport const createHandler = <Payload = any, Response = APIGatewayProxyResult>(\n params: CreateHandlerParams\n): HandlerCallable<Payload, Response> => {\n return (payload, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins\n .byType<RawEventHandler<Payload, any, Response>>(RawEventHandler.type)\n .filter(plugin => {\n /**\n * Just in case check that the plugin contains canHandle method.\n * If it does not, we assume it can handle any payload.\n */\n if (typeof plugin.canHandle !== \"function\") {\n return true;\n }\n return plugin.canHandle(payload);\n })\n .reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n RawEventHandler<Payload, any, Response>,\n HandlerParams,\n Response\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<HandlerParams, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n payload,\n lambdaContext: context\n };\n const result = await handler(params as unknown as HandlerParams);\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\n });\n };\n};\n\nexport * from \"./plugins/RawEventHandler\";\n"],"mappings":";;;;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AA2FAE,MAAA,CAAAC,IAAA,CAAAF,gBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,C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AAIP,OAAO,CAACQ,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAG,IAAAC,sCAAqB,EAInCX,OAAO,CAAC;IAEVP,GAAG,CAACmB,IAAI,CAACxB,GAAG,EAAE,OAAOyB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMxB,MAAmC,GAAG;QACxCuB,OAAO;QACPC,KAAK;QACLtB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,OAAO;QACPwB,aAAa,EAAEvB;MACnB,CAAC;MACD,MAAMwB,MAAM,GAAG,MAAMN,OAAO,CAACpB,MAAkC,CAAC;MAEhE,IAAI0B,MAAM,YAAY7B,KAAK,EAAE;QACzB,OAAO6B,MAAM;MACjB;MAEAvB,GAAG,CAACwB,mBAAmB,GAAGD,MAAM;MAChC,OAAOF,KAAK,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACX1B,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
2
|
+
import type { Context as BaseContext, Reply } from "@webiny/handler/types";
|
|
3
|
+
import type { EventPluginCallableParams } from "@webiny/handler";
|
|
4
|
+
import { EventPlugin } from "@webiny/handler";
|
|
5
|
+
export interface RawEventHandlerCallableParams<Event, Context extends BaseContext> extends EventPluginCallableParams<Event, Context> {
|
|
6
|
+
lambdaContext: LambdaContext;
|
|
7
|
+
}
|
|
8
|
+
export interface RawEventHandlerCallable<Event, Context extends BaseContext, Response> {
|
|
9
|
+
(params: RawEventHandlerCallableParams<Event, Context>): Promise<Response | Reply>;
|
|
10
|
+
}
|
|
11
|
+
export interface RawEventHandlerParamsConfig<Event = any, Context extends BaseContext = BaseContext, Response = any> {
|
|
12
|
+
canHandle(event: Event): boolean;
|
|
13
|
+
handle: RawEventHandlerCallable<Event, Context, Response>;
|
|
14
|
+
}
|
|
15
|
+
export type RawEventHandlerParams<Event = any, Context extends BaseContext = BaseContext, Response = any> = RawEventHandlerCallable<Event, Context, Response> | RawEventHandlerParamsConfig<Event, Context, Response>;
|
|
16
|
+
export declare class RawEventHandler<Event = any, Context extends BaseContext = BaseContext, Response = any> extends EventPlugin<Event, Context, Response> {
|
|
17
|
+
private readonly params;
|
|
18
|
+
constructor(params: RawEventHandlerParams<Event, Context, Response>);
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
canHandle(event: Event): boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare const createEventHandler: <Event_1 = any, Context extends BaseContext = BaseContext, Response_1 = any>(params: RawEventHandlerParams<Event_1, Context, Response_1>) => RawEventHandler<Event_1, Context, Response_1>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createEventHandler = exports.RawEventHandler = void 0;
|
|
7
|
+
var _handler = require("@webiny/handler");
|
|
8
|
+
class RawEventHandler extends _handler.EventPlugin {
|
|
9
|
+
constructor(params) {
|
|
10
|
+
const cb = typeof params === "function" ? params : params.handle;
|
|
11
|
+
/**
|
|
12
|
+
* Callable is correct, TS is just having problems with the override.
|
|
13
|
+
*/
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
super(cb);
|
|
16
|
+
this.params = params;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
canHandle(event) {
|
|
22
|
+
if (typeof this.params === "function" || !this.params?.canHandle) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return this.params.canHandle(event);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.RawEventHandler = RawEventHandler;
|
|
29
|
+
const createEventHandler = params => {
|
|
30
|
+
return new RawEventHandler(params);
|
|
31
|
+
};
|
|
32
|
+
exports.createEventHandler = createEventHandler;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=RawEventHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_handler","require","RawEventHandler","EventPlugin","constructor","params","cb","handle","canHandle","event","exports","createEventHandler"],"sources":["RawEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext } from \"@webiny/aws-sdk/types\";\nimport type { Context as BaseContext, Reply } from \"@webiny/handler/types\";\nimport type { EventPluginCallableParams } from \"@webiny/handler\";\nimport { EventPlugin } from \"@webiny/handler\";\n\nexport interface RawEventHandlerCallableParams<Event, Context extends BaseContext>\n extends EventPluginCallableParams<Event, Context> {\n lambdaContext: LambdaContext;\n}\nexport interface RawEventHandlerCallable<Event, Context extends BaseContext, Response> {\n (params: RawEventHandlerCallableParams<Event, Context>): Promise<Response | Reply>;\n}\n\nexport interface RawEventHandlerParamsConfig<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> {\n canHandle(event: Event): boolean;\n handle: RawEventHandlerCallable<Event, Context, Response>;\n}\n\nexport type RawEventHandlerParams<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> =\n | RawEventHandlerCallable<Event, Context, Response>\n | RawEventHandlerParamsConfig<Event, Context, Response>;\n\nexport class RawEventHandler<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends EventPlugin<Event, Context, Response> {\n private readonly params: RawEventHandlerParams<Event, Context, Response>;\n\n public constructor(params: RawEventHandlerParams<Event, Context, Response>) {\n const cb = typeof params === \"function\" ? params : params.handle;\n /**\n * Callable is correct, TS is just having problems with the override.\n */\n // @ts-expect-error\n super(cb);\n this.params = params;\n }\n /**\n *\n */\n public canHandle(event: Event): boolean {\n if (typeof this.params === \"function\" || !this.params?.canHandle) {\n return true;\n }\n return this.params.canHandle(event);\n }\n}\n\nexport const createEventHandler = <\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n params: RawEventHandlerParams<Event, Context, Response>\n) => {\n return new RawEventHandler<Event, Context, Response>(params);\n};\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AA2BO,MAAMC,eAAe,SAIlBC,oBAAW,CAA2B;EAGrCC,WAAWA,CAACC,MAAuD,EAAE;IACxE,MAAMC,EAAE,GAAG,OAAOD,MAAM,KAAK,UAAU,GAAGA,MAAM,GAAGA,MAAM,CAACE,MAAM;IAChE;AACR;AACA;IACQ;IACA,KAAK,CAACD,EAAE,CAAC;IACT,IAAI,CAACD,MAAM,GAAGA,MAAM;EACxB;EACA;AACJ;AACA;EACWG,SAASA,CAACC,KAAY,EAAW;IACpC,IAAI,OAAO,IAAI,CAACJ,MAAM,KAAK,UAAU,IAAI,CAAC,IAAI,CAACA,MAAM,EAAEG,SAAS,EAAE;MAC9D,OAAO,IAAI;IACf;IACA,OAAO,IAAI,CAACH,MAAM,CAACG,SAAS,CAACC,KAAK,CAAC;EACvC;AACJ;AAACC,OAAA,CAAAR,eAAA,GAAAA,eAAA;AAEM,MAAMS,kBAAkB,GAK3BN,MAAuD,IACtD;EACD,OAAO,IAAIH,eAAe,CAA2BG,MAAM,CAAC;AAChE,CAAC;AAACK,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
package/registry.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TODO: refactor this to use a proper DI container
|
|
3
|
+
*/
|
|
4
|
+
import type { HandlerEvent, SourceHandler } from "./types";
|
|
5
|
+
import type { Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
6
|
+
interface RegisterOptions {
|
|
7
|
+
silent?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare class HandlerRegistry {
|
|
10
|
+
private readonly handlers;
|
|
11
|
+
private constructor();
|
|
12
|
+
static create(): HandlerRegistry;
|
|
13
|
+
register(handler: SourceHandler<any>, options?: RegisterOptions): void;
|
|
14
|
+
getHandler(event: HandlerEvent, context: LambdaContext): SourceHandler;
|
|
15
|
+
}
|
|
16
|
+
export type { HandlerRegistry };
|
|
17
|
+
export declare const registry: HandlerRegistry;
|
package/registry.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.registry = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* TODO: refactor this to use a proper DI container
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
class HandlerRegistry {
|
|
12
|
+
handlers = new Map();
|
|
13
|
+
constructor() {
|
|
14
|
+
/**
|
|
15
|
+
* We don't want this class to be constructed outside the static create() method
|
|
16
|
+
*/
|
|
17
|
+
}
|
|
18
|
+
static create() {
|
|
19
|
+
return new HandlerRegistry();
|
|
20
|
+
}
|
|
21
|
+
register(handler, options) {
|
|
22
|
+
if (this.handlers.has(handler.name)) {
|
|
23
|
+
if (options?.silent) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* This should only happen during the development phase.
|
|
28
|
+
*/
|
|
29
|
+
throw new Error(`Handler "${handler.name}" is already registered.`);
|
|
30
|
+
}
|
|
31
|
+
this.handlers.set(handler.name, handler);
|
|
32
|
+
}
|
|
33
|
+
getHandler(event, context) {
|
|
34
|
+
for (const handler of this.handlers.values()) {
|
|
35
|
+
if (handler.canUse(event, context)) {
|
|
36
|
+
return handler;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const registry = exports.registry = HandlerRegistry.create();
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=registry.js.map
|
package/registry.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["HandlerRegistry","handlers","Map","constructor","create","register","handler","options","has","name","silent","Error","set","getHandler","event","context","values","canUse","JSON","stringify","registry","exports"],"sources":["registry.ts"],"sourcesContent":["/**\n * TODO: refactor this to use a proper DI container\n */\nimport type { HandlerEvent, SourceHandler } from \"~/types\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types\";\n\ninterface RegisterOptions {\n silent?: boolean;\n}\n\nclass HandlerRegistry {\n private readonly handlers = new Map<string, SourceHandler>();\n\n private constructor() {\n /**\n * We don't want this class to be constructed outside the static create() method\n */\n }\n\n public static create() {\n return new HandlerRegistry();\n }\n\n public register(handler: SourceHandler<any>, options?: RegisterOptions) {\n if (this.handlers.has(handler.name)) {\n if (options?.silent) {\n return;\n }\n /**\n * This should only happen during the development phase.\n */\n throw new Error(`Handler \"${handler.name}\" is already registered.`);\n }\n this.handlers.set(handler.name, handler);\n }\n\n public getHandler(event: HandlerEvent, context: LambdaContext): SourceHandler {\n for (const handler of this.handlers.values()) {\n if (handler.canUse(event, context)) {\n return handler;\n }\n }\n throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);\n }\n}\n\nexport type { HandlerRegistry };\n\nexport const registry = HandlerRegistry.create();\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAQA,MAAMA,eAAe,CAAC;EACDC,QAAQ,GAAG,IAAIC,GAAG,CAAwB,CAAC;EAEpDC,WAAWA,CAAA,EAAG;IAClB;AACR;AACA;EAFQ;EAKJ,OAAcC,MAAMA,CAAA,EAAG;IACnB,OAAO,IAAIJ,eAAe,CAAC,CAAC;EAChC;EAEOK,QAAQA,CAACC,OAA2B,EAAEC,OAAyB,EAAE;IACpE,IAAI,IAAI,CAACN,QAAQ,CAACO,GAAG,CAACF,OAAO,CAACG,IAAI,CAAC,EAAE;MACjC,IAAIF,OAAO,EAAEG,MAAM,EAAE;QACjB;MACJ;MACA;AACZ;AACA;MACY,MAAM,IAAIC,KAAK,CAAC,YAAYL,OAAO,CAACG,IAAI,0BAA0B,CAAC;IACvE;IACA,IAAI,CAACR,QAAQ,CAACW,GAAG,CAACN,OAAO,CAACG,IAAI,EAAEH,OAAO,CAAC;EAC5C;EAEOO,UAAUA,CAACC,KAAmB,EAAEC,OAAsB,EAAiB;IAC1E,KAAK,MAAMT,OAAO,IAAI,IAAI,CAACL,QAAQ,CAACe,MAAM,CAAC,CAAC,EAAE;MAC1C,IAAIV,OAAO,CAACW,MAAM,CAACH,KAAK,EAAEC,OAAO,CAAC,EAAE;QAChC,OAAOT,OAAO;MAClB;IACJ;IACA,MAAM,IAAIK,KAAK,CAAC,sCAAsCO,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC,EAAE,CAAC;EAClF;AACJ;AAIO,MAAMM,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAGpB,eAAe,CAACI,MAAM,CAAC,CAAC","ignoreList":[]}
|
package/s3/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HandlerFactoryParams } from "../types";
|
|
2
|
+
import type { APIGatewayProxyResult, Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types";
|
|
3
|
+
export * from "./plugins/S3EventHandler";
|
|
4
|
+
export interface HandlerCallable {
|
|
5
|
+
(event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
6
|
+
}
|
|
7
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
8
|
+
export declare const createHandler: (params: HandlerParams) => HandlerCallable;
|
package/s3/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
var _exportNames = {
|
|
8
|
+
createHandler: true
|
|
9
|
+
};
|
|
10
|
+
exports.createHandler = void 0;
|
|
11
|
+
var _handler = require("@webiny/handler");
|
|
12
|
+
var _plugins = require("../plugins");
|
|
13
|
+
var _S3EventHandler = require("./plugins/S3EventHandler");
|
|
14
|
+
Object.keys(_S3EventHandler).forEach(function (key) {
|
|
15
|
+
if (key === "default" || key === "__esModule") return;
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
17
|
+
if (key in exports && exports[key] === _S3EventHandler[key]) return;
|
|
18
|
+
Object.defineProperty(exports, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _S3EventHandler[key];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
var _execute = require("../execute");
|
|
26
|
+
var _reply = _interopRequireDefault(require("fastify/lib/reply"));
|
|
27
|
+
var _composedHandler = require("../utils/composedHandler");
|
|
28
|
+
/**
|
|
29
|
+
* We need a class, not an interface exported from types.
|
|
30
|
+
*/
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
|
|
33
|
+
const url = "/webiny-s3-event";
|
|
34
|
+
const createHandler = params => {
|
|
35
|
+
return async (event, context) => {
|
|
36
|
+
const app = (0, _handler.createHandler)({
|
|
37
|
+
...params,
|
|
38
|
+
options: {
|
|
39
|
+
logger: params.debug === true,
|
|
40
|
+
...(params.options || {})
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* We always must add our default plugins to the app.
|
|
45
|
+
*/
|
|
46
|
+
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
47
|
+
/**
|
|
48
|
+
* There must be an event plugin for this handler to work.
|
|
49
|
+
*/
|
|
50
|
+
const plugins = app.webiny.plugins.byType(_S3EventHandler.S3EventHandler.type).reverse();
|
|
51
|
+
if (plugins.length === 0) {
|
|
52
|
+
throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);
|
|
53
|
+
}
|
|
54
|
+
const handler = (0, _composedHandler.createComposedHandler)(plugins);
|
|
55
|
+
app.post(url, async (request, reply) => {
|
|
56
|
+
const params = {
|
|
57
|
+
request,
|
|
58
|
+
reply,
|
|
59
|
+
context: app.webiny,
|
|
60
|
+
event,
|
|
61
|
+
lambdaContext: context
|
|
62
|
+
};
|
|
63
|
+
const result = await handler(params);
|
|
64
|
+
if (result instanceof _reply.default) {
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
app.__webiny_raw_result = result;
|
|
68
|
+
return reply.send({});
|
|
69
|
+
});
|
|
70
|
+
return (0, _execute.execute)({
|
|
71
|
+
app,
|
|
72
|
+
url,
|
|
73
|
+
payload: event
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
exports.createHandler = createHandler;
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
package/s3/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_handler","require","_plugins","_S3EventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","event","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","S3EventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","send","execute","payload"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport type { S3EventHandlerCallableParams } from \"~/s3/plugins/S3EventHandler\";\nimport { S3EventHandler } from \"~/s3/plugins/S3EventHandler\";\nimport { execute } from \"~/execute\";\nimport type { HandlerFactoryParams } from \"~/types\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n S3Event\n} from \"@webiny/aws-sdk/types\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\n\nexport * from \"./plugins/S3EventHandler\";\n\nexport interface HandlerCallable {\n (event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport type HandlerParams = HandlerFactoryParams;\n\nconst url = \"/webiny-s3-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n return async (event, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins.byType<S3EventHandler>(S3EventHandler.type).reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);\n }\n\n const handler = createComposedHandler<\n S3EventHandler,\n S3EventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<S3EventHandlerCallableParams<APIGatewayProxyResult>, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n event,\n lambdaContext: context\n };\n const result = await handler(\n params as unknown as S3EventHandlerCallableParams<APIGatewayProxyResult>\n );\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload: event\n });\n };\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AAeAG,MAAA,CAAAC,IAAA,CAAAF,eAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,eAA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AAMqB,MAAM,GAAG,MAAMN,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIuB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEApB,GAAG,CAACsB,mBAAmB,GAAGF,MAAM;MAChC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXxB,GAAG;MACHL,GAAG;MACH8B,OAAO,EAAE3B;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types";
|
|
2
|
+
import { Plugin } from "@webiny/plugins/Plugin";
|
|
3
|
+
import type { Context, Reply, Request } from "@webiny/handler/types";
|
|
4
|
+
export interface S3EventHandlerCallableParams<Response = Reply> {
|
|
5
|
+
request: Request;
|
|
6
|
+
context: Context;
|
|
7
|
+
event: S3Event;
|
|
8
|
+
lambdaContext: LambdaContext;
|
|
9
|
+
reply: Reply;
|
|
10
|
+
next: () => Promise<Response>;
|
|
11
|
+
}
|
|
12
|
+
export interface S3EventHandlerCallable<Response = Reply> {
|
|
13
|
+
(params: S3EventHandlerCallableParams<Response>): Promise<Response>;
|
|
14
|
+
}
|
|
15
|
+
export declare class S3EventHandler<Response = any> extends Plugin {
|
|
16
|
+
static type: string;
|
|
17
|
+
readonly cb: S3EventHandlerCallable<Response>;
|
|
18
|
+
constructor(cb: S3EventHandlerCallable<Response>);
|
|
19
|
+
}
|
|
20
|
+
export declare const createEventHandler: <Response_1>(cb: S3EventHandlerCallable<Response_1>) => S3EventHandler<Response_1>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createEventHandler = exports.S3EventHandler = void 0;
|
|
7
|
+
var _Plugin = require("@webiny/plugins/Plugin");
|
|
8
|
+
class S3EventHandler extends _Plugin.Plugin {
|
|
9
|
+
static type = "handler.fastify.aws.s3.eventHandler";
|
|
10
|
+
constructor(cb) {
|
|
11
|
+
super();
|
|
12
|
+
this.cb = cb;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.S3EventHandler = S3EventHandler;
|
|
16
|
+
const createEventHandler = cb => {
|
|
17
|
+
return new S3EventHandler(cb);
|
|
18
|
+
};
|
|
19
|
+
exports.createEventHandler = createEventHandler;
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=S3EventHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_Plugin","require","S3EventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["S3EventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, S3Event } from \"@webiny/aws-sdk/types\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types\";\n\nexport interface S3EventHandlerCallableParams<Response = Reply> {\n request: Request;\n context: Context;\n event: S3Event;\n lambdaContext: LambdaContext;\n reply: Reply;\n next: () => Promise<Response>;\n}\n\nexport interface S3EventHandlerCallable<Response = Reply> {\n (params: S3EventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class S3EventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.s3.eventHandler\";\n\n public readonly cb: S3EventHandlerCallable<Response>;\n\n public constructor(cb: S3EventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: S3EventHandlerCallable<Response>) => {\n return new S3EventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAgBO,MAAMC,cAAc,SAAyBC,cAAM,CAAC;EACvD,OAAuBC,IAAI,GAAG,qCAAqC;EAI5DC,WAAWA,CAACC,EAAoC,EAAE;IACrD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,cAAA,GAAAA,cAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAAoC,IAAK;EAClF,OAAO,IAAIJ,cAAc,CAAWI,EAAE,CAAC;AAC3C,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
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 type { S3Event } from \"@webiny/aws-sdk/types\";\nimport { registry } from \"~/registry\";\nimport type { HandlerFactoryParams } from \"~/types\";\nimport { createSourceHandler } from \"~/sourceHandler\";\nimport { createHandler } from \"./index\";\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst handler = createSourceHandler<S3Event, HandlerParams>({\n name: \"handler-aws-s3\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n return !!record.s3;\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":";;AACA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAMA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAAyB;EACxDC,IAAI,EAAE,gBAAgB;EACtBC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,OAAO,CAAC,CAACE,MAAM,CAACC,EAAE;EACtB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAER,KAAK;IAAES;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACR,KAAK,EAAES,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAAChB,OAAO,CAAC","ignoreList":[]}
|
package/sns/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { APIGatewayProxyResult, SNSEvent, Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
2
|
+
import type { HandlerFactoryParams } from "../types";
|
|
3
|
+
export * from "./plugins/SNSEventHandler";
|
|
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,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
var _exportNames = {
|
|
8
|
+
createHandler: true
|
|
9
|
+
};
|
|
10
|
+
exports.createHandler = void 0;
|
|
11
|
+
var _handler = require("@webiny/handler");
|
|
12
|
+
var _plugins = require("../plugins");
|
|
13
|
+
var _SNSEventHandler = require("./plugins/SNSEventHandler");
|
|
14
|
+
Object.keys(_SNSEventHandler).forEach(function (key) {
|
|
15
|
+
if (key === "default" || key === "__esModule") return;
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
17
|
+
if (key in exports && exports[key] === _SNSEventHandler[key]) return;
|
|
18
|
+
Object.defineProperty(exports, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _SNSEventHandler[key];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
var _execute = require("../execute");
|
|
26
|
+
var _reply = _interopRequireDefault(require("fastify/lib/reply"));
|
|
27
|
+
var _composedHandler = require("../utils/composedHandler");
|
|
28
|
+
/**
|
|
29
|
+
* We need a class, not an interface exported from types.
|
|
30
|
+
*/
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
|
|
33
|
+
const url = "/webiny-sns-event";
|
|
34
|
+
const createHandler = params => {
|
|
35
|
+
return async (event, context) => {
|
|
36
|
+
const app = (0, _handler.createHandler)({
|
|
37
|
+
...params,
|
|
38
|
+
options: {
|
|
39
|
+
logger: params.debug === true,
|
|
40
|
+
...(params.options || {})
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* We always must add our default plugins to the app.
|
|
45
|
+
*/
|
|
46
|
+
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
47
|
+
/**
|
|
48
|
+
* There must be an event plugin for this handler to work.
|
|
49
|
+
*/
|
|
50
|
+
const plugins = app.webiny.plugins.byType(_SNSEventHandler.SNSEventHandler.type).reverse();
|
|
51
|
+
if (plugins.length === 0) {
|
|
52
|
+
throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);
|
|
53
|
+
}
|
|
54
|
+
const handler = (0, _composedHandler.createComposedHandler)(plugins);
|
|
55
|
+
app.post(url, async (request, reply) => {
|
|
56
|
+
const params = {
|
|
57
|
+
request,
|
|
58
|
+
reply,
|
|
59
|
+
context: app.webiny,
|
|
60
|
+
event,
|
|
61
|
+
lambdaContext: context
|
|
62
|
+
};
|
|
63
|
+
const result = await handler(params);
|
|
64
|
+
if (result instanceof _reply.default) {
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
app.__webiny_raw_result = result;
|
|
68
|
+
return reply.send({});
|
|
69
|
+
});
|
|
70
|
+
return (0, _execute.execute)({
|
|
71
|
+
app,
|
|
72
|
+
url,
|
|
73
|
+
payload: event
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
exports.createHandler = createHandler;
|
|
78
|
+
|
|
79
|
+
//# 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 type {\n APIGatewayProxyResult,\n SNSEvent,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport type { SNSEventHandlerCallableParams } from \"./plugins/SNSEventHandler\";\nimport { SNSEventHandler } from \"./plugins/SNSEventHandler\";\nimport { execute } from \"~/execute\";\nimport type { HandlerFactoryParams } from \"~/types\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\n\nexport * from \"./plugins/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"],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AO,CAACK,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAG,IAAAC,sCAAqB,EAInCR,OAAO,CAAC;IAEVP,GAAG,CAACgB,IAAI,CAACrB,GAAG,EAAE,OAAOsB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMrB,MAA0E,GAAG;QAC/EoB,OAAO;QACPC,KAAK;QACLnB,OAAO,EAAEC,GAAG,CAACM,MAAM;QACnBR,KAAK;QACLqB,aAAa,EAAEpB;MACnB,CAAC;MAED,MAAMqB,MAAM,GAAG,MAAMN,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIuB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEApB,GAAG,CAACsB,mBAAmB,GAAGF,MAAM;MAChC,OAAOF,KAAK,CAACK,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXxB,GAAG;MACHL,GAAG;MACH8B,OAAO,EAAE3B;IACb,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Context as LambdaContext, SNSEvent } from "@webiny/aws-sdk/types";
|
|
2
|
+
import { Plugin } from "@webiny/plugins/Plugin";
|
|
3
|
+
import type { Context, Reply, Request } from "@webiny/handler/types";
|
|
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 type { Context as LambdaContext, SNSEvent } from \"@webiny/aws-sdk/types\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types\";\n\nexport interface SNSEventHandlerCallableParams<Response = Reply> {\n request: Request;\n reply: Reply;\n context: Context;\n event: SNSEvent;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\n\nexport interface SNSEventHandlerCallable<Response = Reply> {\n (params: SNSEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class SNSEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.sns.eventHandler\";\n\n public readonly cb: SNSEventHandlerCallable<Response>;\n\n public constructor(cb: SNSEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: SNSEventHandlerCallable<Response>) => {\n return new SNSEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAgBO,MAAMC,eAAe,SAAyBC,cAAM,CAAC;EACxD,OAAuBC,IAAI,GAAG,sCAAsC;EAI7DC,WAAWA,CAACC,EAAqC,EAAE;IACtD,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,eAAA,GAAAA,eAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAAqC,IAAK;EACnF,OAAO,IAAIJ,eAAe,CAAWI,EAAE,CAAC;AAC5C,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|