@webiny/handler-aws 6.0.0-alpha.5 → 6.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -14
- package/createHandler.d.ts +1 -1
- package/createHandler.js +12 -12
- package/createHandler.js.map +1 -1
- package/dynamodb/index.d.ts +3 -3
- package/dynamodb/index.js +14 -36
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +4 -4
- package/dynamodb/plugins/DynamoDBEventHandler.js +3 -11
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.js +6 -8
- package/dynamodb/register.js.map +1 -1
- package/eventBridge/index.d.ts +3 -3
- package/eventBridge/index.js +14 -36
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +4 -4
- package/eventBridge/plugins/EventBridgeEventHandler.js +3 -11
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +1 -1
- package/eventBridge/register.js +6 -8
- package/eventBridge/register.js.map +1 -1
- package/execute.d.ts +1 -1
- package/execute.js +3 -10
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +2 -2
- package/gateway/index.js +16 -30
- package/gateway/index.js.map +1 -1
- package/gateway/register.js +6 -8
- package/gateway/register.js.map +1 -1
- package/index.d.ts +17 -17
- package/index.js +45 -371
- package/index.js.map +1 -1
- package/package.json +15 -16
- package/plugins/handlerClient.js +6 -13
- package/plugins/handlerClient.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +3 -10
- package/plugins/index.js.map +1 -1
- package/raw/index.d.ts +3 -3
- package/raw/index.js +14 -33
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +3 -3
- package/raw/plugins/RawEventHandler.js +3 -11
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +2 -2
- package/registry.js +1 -7
- package/registry.js.map +1 -1
- package/s3/index.d.ts +3 -3
- package/s3/index.js +14 -36
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +4 -4
- package/s3/plugins/S3EventHandler.js +3 -11
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +1 -1
- package/s3/register.js +6 -8
- package/s3/register.js.map +1 -1
- package/sns/index.d.ts +3 -3
- package/sns/index.js +14 -36
- package/sns/index.js.map +1 -1
- package/sns/plugins/SNSEventHandler.d.ts +4 -4
- package/sns/plugins/SNSEventHandler.js +3 -11
- package/sns/plugins/SNSEventHandler.js.map +1 -1
- package/sns/register.js +6 -8
- package/sns/register.js.map +1 -1
- package/sourceHandler.d.ts +2 -2
- package/sourceHandler.js +1 -8
- package/sourceHandler.js.map +1 -1
- package/sqs/index.d.ts +3 -3
- package/sqs/index.js +14 -36
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +4 -4
- package/sqs/plugins/SQSEventHandler.js +3 -11
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.js +6 -8
- package/sqs/register.js.map +1 -1
- package/types.d.ts +3 -3
- package/types.js +3 -31
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +1 -1
- package/utils/composedHandler.js +3 -10
- package/utils/composedHandler.js.map +1 -1
- package/utils/index.d.ts +2 -2
- package/utils/index.js +2 -27
- package/utils/index.js.map +1 -1
- package/utils/timer/CustomTimer.js +1 -8
- package/utils/timer/CustomTimer.js.map +1 -1
- package/utils/timer/Timer.d.ts +1 -1
- package/utils/timer/Timer.js +1 -8
- package/utils/timer/Timer.js.map +1 -1
- package/utils/timer/abstractions/ITimer.js +1 -5
- package/utils/timer/factory.d.ts +2 -2
- package/utils/timer/factory.js +5 -12
- package/utils/timer/factory.js.map +1 -1
- package/utils/timer/index.d.ts +4 -4
- package/utils/timer/index.js +3 -49
- package/utils/timer/index.js.map +1 -1
package/raw/index.js
CHANGED
|
@@ -1,28 +1,3 @@
|
|
|
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
1
|
/**
|
|
27
2
|
* This is the handler implementation for @webiny/handler/plugins/EventPlugin.
|
|
28
3
|
* This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.
|
|
@@ -30,11 +5,17 @@ var _composedHandler = require("../utils/composedHandler");
|
|
|
30
5
|
* We should try to have some kind of standardized event type implementation at some point.
|
|
31
6
|
*/
|
|
32
7
|
|
|
33
|
-
|
|
8
|
+
import { createHandler as createBaseHandler } from "@webiny/handler";
|
|
9
|
+
import { RawEventHandler } from "./plugins/RawEventHandler.js";
|
|
10
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
11
|
+
import { execute } from "../execute.js";
|
|
12
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
import Reply from "fastify/lib/reply.js";
|
|
34
15
|
const url = "/webiny-raw-event";
|
|
35
|
-
const createHandler = params => {
|
|
16
|
+
export const createHandler = params => {
|
|
36
17
|
return (payload, context) => {
|
|
37
|
-
const app = (
|
|
18
|
+
const app = createBaseHandler({
|
|
38
19
|
...params,
|
|
39
20
|
options: {
|
|
40
21
|
logger: params.debug === true,
|
|
@@ -44,11 +25,11 @@ const createHandler = params => {
|
|
|
44
25
|
/**
|
|
45
26
|
* We always must add our default plugins to the app.
|
|
46
27
|
*/
|
|
47
|
-
|
|
28
|
+
registerDefaultPlugins(app.webiny);
|
|
48
29
|
/**
|
|
49
30
|
* There must be an event plugin for this handler to work.
|
|
50
31
|
*/
|
|
51
|
-
const plugins = app.webiny.plugins.byType(
|
|
32
|
+
const plugins = app.webiny.plugins.byType(RawEventHandler.type).filter(plugin => {
|
|
52
33
|
/**
|
|
53
34
|
* Just in case check that the plugin contains canHandle method.
|
|
54
35
|
* If it does not, we assume it can handle any payload.
|
|
@@ -61,7 +42,7 @@ const createHandler = params => {
|
|
|
61
42
|
if (plugins.length === 0) {
|
|
62
43
|
throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);
|
|
63
44
|
}
|
|
64
|
-
const handler =
|
|
45
|
+
const handler = createComposedHandler(plugins);
|
|
65
46
|
app.post(url, async (request, reply) => {
|
|
66
47
|
const params = {
|
|
67
48
|
request,
|
|
@@ -77,13 +58,13 @@ const createHandler = params => {
|
|
|
77
58
|
app.__webiny_raw_result = result;
|
|
78
59
|
return reply.send({});
|
|
79
60
|
});
|
|
80
|
-
return
|
|
61
|
+
return execute({
|
|
81
62
|
app,
|
|
82
63
|
url,
|
|
83
64
|
payload
|
|
84
65
|
});
|
|
85
66
|
};
|
|
86
67
|
};
|
|
87
|
-
|
|
68
|
+
export * from "./plugins/RawEventHandler.js";
|
|
88
69
|
|
|
89
70
|
//# sourceMappingURL=index.js.map
|
package/raw/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["createHandler","createBaseHandler","RawEventHandler","registerDefaultPlugins","execute","createComposedHandler","Reply","url","params","payload","context","app","options","logger","debug","webiny","plugins","byType","type","filter","plugin","canHandle","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","send"],"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 {\n APIGatewayProxyResult,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { CreateHandlerParams as BaseCreateHandlerParams } from \"@webiny/handler\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { RawEventHandler } from \"~/raw/plugins/RawEventHandler.js\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport { execute } from \"~/execute.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\nimport type { Context, Request } from \"@webiny/handler/types.js\";\n\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\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.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;;AAMA,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,eAAe;AACxB,SAASC,sBAAsB;AAC/B,SAASC,OAAO;AAChB,SAASC,qBAAqB;AAG9B;AACA,OAAOC,KAAK,MAAM,sBAAsB;AAExC,MAAMC,GAAG,GAAG,mBAAmB;AAiB/B,OAAO,MAAMP,aAAa,GACtBQ,MAA2B,IACU;EACrC,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,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;IACQT,sBAAsB,CAACQ,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAC7BC,MAAM,CAA0Cf,eAAe,CAACgB,IAAI,CAAC,CACrEC,MAAM,CAACC,MAAM,IAAI;MACd;AAChB;AACA;AACA;MACgB,IAAI,OAAOA,MAAM,CAACC,SAAS,KAAK,UAAU,EAAE;QACxC,OAAO,IAAI;MACf;MACA,OAAOD,MAAM,CAACC,SAAS,CAACZ,OAAO,CAAC;IACpC,CAAC,CAAC,CACDa,OAAO,CAAC,CAAC;IACd,IAAIN,OAAO,CAACO,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAGpB,qBAAqB,CAInCW,OAAO,CAAC;IAEVL,GAAG,CAACe,IAAI,CAACnB,GAAG,EAAE,OAAOoB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMpB,MAAmC,GAAG;QACxCmB,OAAO;QACPC,KAAK;QACLlB,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,OAAO;QACPoB,aAAa,EAAEnB;MACnB,CAAC;MACD,MAAMoB,MAAM,GAAG,MAAML,OAAO,CAACjB,MAAkC,CAAC;MAEhE,IAAIsB,MAAM,YAAYxB,KAAK,EAAE;QACzB,OAAOwB,MAAM;MACjB;MAEAnB,GAAG,CAACoB,mBAAmB,GAAGD,MAAM;MAChC,OAAOF,KAAK,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO5B,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHE;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAED","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
2
|
-
import type { Context as BaseContext, Reply } from "@webiny/handler/types";
|
|
1
|
+
import type { Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
|
|
2
|
+
import type { Context as BaseContext, Reply } from "@webiny/handler/types.js";
|
|
3
3
|
import type { EventPluginCallableParams } from "@webiny/handler";
|
|
4
4
|
import { EventPlugin } from "@webiny/handler";
|
|
5
5
|
export interface RawEventHandlerCallableParams<Event, Context extends BaseContext> extends EventPluginCallableParams<Event, Context> {
|
|
@@ -21,4 +21,4 @@ export declare class RawEventHandler<Event = any, Context extends BaseContext =
|
|
|
21
21
|
*/
|
|
22
22
|
canHandle(event: Event): boolean;
|
|
23
23
|
}
|
|
24
|
-
export declare const createEventHandler: <
|
|
24
|
+
export declare const createEventHandler: <Event = any, Context extends BaseContext = BaseContext, Response = any>(params: RawEventHandlerParams<Event, Context, Response>) => RawEventHandler<Event, Context, Response>;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
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 {
|
|
1
|
+
import { EventPlugin } from "@webiny/handler";
|
|
2
|
+
export class RawEventHandler extends EventPlugin {
|
|
9
3
|
constructor(params) {
|
|
10
4
|
const cb = typeof params === "function" ? params : params.handle;
|
|
11
5
|
/**
|
|
@@ -25,10 +19,8 @@ class RawEventHandler extends _handler.EventPlugin {
|
|
|
25
19
|
return this.params.canHandle(event);
|
|
26
20
|
}
|
|
27
21
|
}
|
|
28
|
-
|
|
29
|
-
const createEventHandler = params => {
|
|
22
|
+
export const createEventHandler = params => {
|
|
30
23
|
return new RawEventHandler(params);
|
|
31
24
|
};
|
|
32
|
-
exports.createEventHandler = createEventHandler;
|
|
33
25
|
|
|
34
26
|
//# sourceMappingURL=RawEventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["EventPlugin","RawEventHandler","constructor","params","cb","handle","canHandle","event","createEventHandler"],"sources":["RawEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\nimport type { Context as BaseContext, Reply } from \"@webiny/handler/types.js\";\nimport type { EventPluginCallableParams } from \"@webiny/handler\";\nimport { EventPlugin } from \"@webiny/handler\";\n\nexport interface RawEventHandlerCallableParams<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,SAASA,WAAW,QAAQ,iBAAiB;AA2B7C,OAAO,MAAMC,eAAe,SAIlBD,WAAW,CAA2B;EAGrCE,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;AAEA,OAAO,MAAMC,kBAAkB,GAK3BL,MAAuD,IACtD;EACD,OAAO,IAAIF,eAAe,CAA2BE,MAAM,CAAC;AAChE,CAAC","ignoreList":[]}
|
package/registry.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TODO: refactor this to use a proper DI container
|
|
3
3
|
*/
|
|
4
|
-
import type { HandlerEvent, SourceHandler } from "./types";
|
|
5
|
-
import type { Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
4
|
+
import type { HandlerEvent, SourceHandler } from "./types.js";
|
|
5
|
+
import type { Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
|
|
6
6
|
interface RegisterOptions {
|
|
7
7
|
silent?: boolean;
|
|
8
8
|
}
|
package/registry.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.registry = void 0;
|
|
7
1
|
/**
|
|
8
2
|
* TODO: refactor this to use a proper DI container
|
|
9
3
|
*/
|
|
@@ -39,6 +33,6 @@ class HandlerRegistry {
|
|
|
39
33
|
throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
|
-
const registry =
|
|
36
|
+
export const registry = HandlerRegistry.create();
|
|
43
37
|
|
|
44
38
|
//# sourceMappingURL=registry.js.map
|
package/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HandlerRegistry","handlers","Map","constructor","create","register","handler","options","has","name","silent","Error","set","getHandler","event","context","values","canUse","JSON","stringify","registry"
|
|
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"],"sources":["registry.ts"],"sourcesContent":["/**\n * TODO: refactor this to use a proper DI container\n */\nimport type { HandlerEvent, SourceHandler } from \"~/types.js\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\n\ninterface RegisterOptions {\n silent?: boolean;\n}\n\nclass HandlerRegistry {\n private readonly handlers = new Map<string, SourceHandler>();\n\n private constructor() {\n /**\n * We don't want this class to be constructed outside the static create() method\n */\n }\n\n public static create() {\n return new HandlerRegistry();\n }\n\n public register(handler: SourceHandler<any>, options?: RegisterOptions) {\n if (this.handlers.has(handler.name)) {\n if (options?.silent) {\n return;\n }\n /**\n * This should only happen during the development phase.\n */\n throw new Error(`Handler \"${handler.name}\" is already registered.`);\n }\n this.handlers.set(handler.name, handler);\n }\n\n public getHandler(event: HandlerEvent, context: LambdaContext): SourceHandler {\n for (const handler of this.handlers.values()) {\n if (handler.canUse(event, context)) {\n return handler;\n }\n }\n throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);\n }\n}\n\nexport type { HandlerRegistry };\n\nexport const registry = HandlerRegistry.create();\n"],"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;AAIA,OAAO,MAAMM,QAAQ,GAAGpB,eAAe,CAACI,MAAM,CAAC,CAAC","ignoreList":[]}
|
package/s3/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { HandlerFactoryParams } from "../types";
|
|
2
|
-
import type { APIGatewayProxyResult, Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types";
|
|
3
|
-
export * from "./plugins/S3EventHandler";
|
|
1
|
+
import type { HandlerFactoryParams } from "../types.js";
|
|
2
|
+
import type { APIGatewayProxyResult, Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types/index.js";
|
|
3
|
+
export * from "./plugins/S3EventHandler.js";
|
|
4
4
|
export interface HandlerCallable {
|
|
5
5
|
(event: S3Event, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
6
6
|
}
|
package/s3/index.js
CHANGED
|
@@ -1,39 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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");
|
|
1
|
+
import { createHandler as createBaseHandler } from "@webiny/handler";
|
|
2
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
3
|
+
import { S3EventHandler } from "./plugins/S3EventHandler.js";
|
|
4
|
+
import { execute } from "../execute.js";
|
|
28
5
|
/**
|
|
29
6
|
* We need a class, not an interface exported from types.
|
|
30
7
|
*/
|
|
31
8
|
// @ts-expect-error
|
|
32
|
-
|
|
9
|
+
import Reply from "fastify/lib/reply.js";
|
|
10
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
11
|
+
export * from "./plugins/S3EventHandler.js";
|
|
33
12
|
const url = "/webiny-s3-event";
|
|
34
|
-
const createHandler = params => {
|
|
13
|
+
export const createHandler = params => {
|
|
35
14
|
return async (event, context) => {
|
|
36
|
-
const app = (
|
|
15
|
+
const app = createBaseHandler({
|
|
37
16
|
...params,
|
|
38
17
|
options: {
|
|
39
18
|
logger: params.debug === true,
|
|
@@ -43,15 +22,15 @@ const createHandler = params => {
|
|
|
43
22
|
/**
|
|
44
23
|
* We always must add our default plugins to the app.
|
|
45
24
|
*/
|
|
46
|
-
|
|
25
|
+
registerDefaultPlugins(app.webiny);
|
|
47
26
|
/**
|
|
48
27
|
* There must be an event plugin for this handler to work.
|
|
49
28
|
*/
|
|
50
|
-
const plugins = app.webiny.plugins.byType(
|
|
29
|
+
const plugins = app.webiny.plugins.byType(S3EventHandler.type).reverse();
|
|
51
30
|
if (plugins.length === 0) {
|
|
52
31
|
throw new Error(`To run @webiny/handler-aws/s3, you must have S3EventHandler set.`);
|
|
53
32
|
}
|
|
54
|
-
const handler =
|
|
33
|
+
const handler = createComposedHandler(plugins);
|
|
55
34
|
app.post(url, async (request, reply) => {
|
|
56
35
|
const params = {
|
|
57
36
|
request,
|
|
@@ -61,19 +40,18 @@ const createHandler = params => {
|
|
|
61
40
|
lambdaContext: context
|
|
62
41
|
};
|
|
63
42
|
const result = await handler(params);
|
|
64
|
-
if (result instanceof
|
|
43
|
+
if (result instanceof Reply) {
|
|
65
44
|
return result;
|
|
66
45
|
}
|
|
67
46
|
app.__webiny_raw_result = result;
|
|
68
47
|
return reply.send({});
|
|
69
48
|
});
|
|
70
|
-
return
|
|
49
|
+
return execute({
|
|
71
50
|
app,
|
|
72
51
|
url,
|
|
73
52
|
payload: event
|
|
74
53
|
});
|
|
75
54
|
};
|
|
76
55
|
};
|
|
77
|
-
exports.createHandler = createHandler;
|
|
78
56
|
|
|
79
57
|
//# sourceMappingURL=index.js.map
|
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,6 +1,6 @@
|
|
|
1
|
-
import type { Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types";
|
|
2
|
-
import { Plugin } from "@webiny/plugins/Plugin";
|
|
3
|
-
import type { Context, Reply, Request } from "@webiny/handler/types";
|
|
1
|
+
import type { Context as LambdaContext, S3Event } from "@webiny/aws-sdk/types/index.js";
|
|
2
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
3
|
+
import type { Context, Reply, Request } from "@webiny/handler/types.js";
|
|
4
4
|
export interface S3EventHandlerCallableParams<Response = Reply> {
|
|
5
5
|
request: Request;
|
|
6
6
|
context: Context;
|
|
@@ -17,4 +17,4 @@ export declare class S3EventHandler<Response = any> extends Plugin {
|
|
|
17
17
|
readonly cb: S3EventHandlerCallable<Response>;
|
|
18
18
|
constructor(cb: S3EventHandlerCallable<Response>);
|
|
19
19
|
}
|
|
20
|
-
export declare const createEventHandler: <
|
|
20
|
+
export declare const createEventHandler: <Response>(cb: S3EventHandlerCallable<Response>) => S3EventHandler<Response>;
|
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
|
|
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 {
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
export class S3EventHandler extends Plugin {
|
|
9
3
|
static type = "handler.fastify.aws.s3.eventHandler";
|
|
10
4
|
constructor(cb) {
|
|
11
5
|
super();
|
|
12
6
|
this.cb = cb;
|
|
13
7
|
}
|
|
14
8
|
}
|
|
15
|
-
|
|
16
|
-
const createEventHandler = cb => {
|
|
9
|
+
export const createEventHandler = cb => {
|
|
17
10
|
return new S3EventHandler(cb);
|
|
18
11
|
};
|
|
19
|
-
exports.createEventHandler = createEventHandler;
|
|
20
12
|
|
|
21
13
|
//# sourceMappingURL=S3EventHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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
CHANGED
package/s3/register.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _index = require("./index");
|
|
6
|
-
const handler = (0, _sourceHandler.createSourceHandler)({
|
|
1
|
+
import { registry } from "../registry.js";
|
|
2
|
+
import { createSourceHandler } from "../sourceHandler.js";
|
|
3
|
+
import { createHandler } from "./index.js";
|
|
4
|
+
const handler = createSourceHandler({
|
|
7
5
|
name: "handler-aws-s3",
|
|
8
6
|
canUse: event => {
|
|
9
7
|
if (!Array.isArray(event.Records) || event.Records.length === 0) {
|
|
@@ -17,9 +15,9 @@ const handler = (0, _sourceHandler.createSourceHandler)({
|
|
|
17
15
|
event,
|
|
18
16
|
context
|
|
19
17
|
}) => {
|
|
20
|
-
return
|
|
18
|
+
return createHandler(params)(event, context);
|
|
21
19
|
}
|
|
22
20
|
});
|
|
23
|
-
|
|
21
|
+
registry.register(handler);
|
|
24
22
|
|
|
25
23
|
//# sourceMappingURL=register.js.map
|
package/s3/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { APIGatewayProxyResult, SNSEvent, Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
2
|
-
import type { HandlerFactoryParams } from "../types";
|
|
3
|
-
export * from "./plugins/SNSEventHandler";
|
|
1
|
+
import type { APIGatewayProxyResult, SNSEvent, Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
|
|
2
|
+
import type { HandlerFactoryParams } from "../types.js";
|
|
3
|
+
export * from "./plugins/SNSEventHandler.js";
|
|
4
4
|
export interface HandlerCallable {
|
|
5
5
|
(event: SNSEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
6
6
|
}
|
package/sns/index.js
CHANGED
|
@@ -1,39 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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");
|
|
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";
|
|
28
5
|
/**
|
|
29
6
|
* We need a class, not an interface exported from types.
|
|
30
7
|
*/
|
|
31
8
|
// @ts-expect-error
|
|
32
|
-
|
|
9
|
+
import Reply from "fastify/lib/reply.js";
|
|
10
|
+
import { createComposedHandler } from "../utils/composedHandler.js";
|
|
11
|
+
export * from "./plugins/SNSEventHandler.js";
|
|
33
12
|
const url = "/webiny-sns-event";
|
|
34
|
-
const createHandler = params => {
|
|
13
|
+
export const createHandler = params => {
|
|
35
14
|
return async (event, context) => {
|
|
36
|
-
const app = (
|
|
15
|
+
const app = createBaseHandler({
|
|
37
16
|
...params,
|
|
38
17
|
options: {
|
|
39
18
|
logger: params.debug === true,
|
|
@@ -43,15 +22,15 @@ const createHandler = params => {
|
|
|
43
22
|
/**
|
|
44
23
|
* We always must add our default plugins to the app.
|
|
45
24
|
*/
|
|
46
|
-
|
|
25
|
+
registerDefaultPlugins(app.webiny);
|
|
47
26
|
/**
|
|
48
27
|
* There must be an event plugin for this handler to work.
|
|
49
28
|
*/
|
|
50
|
-
const plugins = app.webiny.plugins.byType(
|
|
29
|
+
const plugins = app.webiny.plugins.byType(SNSEventHandler.type).reverse();
|
|
51
30
|
if (plugins.length === 0) {
|
|
52
31
|
throw new Error(`To run @webiny/handler-aws/sns, you must have SNSEventHandler set.`);
|
|
53
32
|
}
|
|
54
|
-
const handler =
|
|
33
|
+
const handler = createComposedHandler(plugins);
|
|
55
34
|
app.post(url, async (request, reply) => {
|
|
56
35
|
const params = {
|
|
57
36
|
request,
|
|
@@ -61,19 +40,18 @@ const createHandler = params => {
|
|
|
61
40
|
lambdaContext: context
|
|
62
41
|
};
|
|
63
42
|
const result = await handler(params);
|
|
64
|
-
if (result instanceof
|
|
43
|
+
if (result instanceof Reply) {
|
|
65
44
|
return result;
|
|
66
45
|
}
|
|
67
46
|
app.__webiny_raw_result = result;
|
|
68
47
|
return reply.send({});
|
|
69
48
|
});
|
|
70
|
-
return
|
|
49
|
+
return execute({
|
|
71
50
|
app,
|
|
72
51
|
url,
|
|
73
52
|
payload: event
|
|
74
53
|
});
|
|
75
54
|
};
|
|
76
55
|
};
|
|
77
|
-
exports.createHandler = createHandler;
|
|
78
56
|
|
|
79
57
|
//# sourceMappingURL=index.js.map
|
package/sns/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
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";
|
|
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
4
|
export interface SNSEventHandlerCallableParams<Response = Reply> {
|
|
5
5
|
request: Request;
|
|
6
6
|
reply: Reply;
|
|
@@ -17,4 +17,4 @@ export declare class SNSEventHandler<Response = any> extends Plugin {
|
|
|
17
17
|
readonly cb: SNSEventHandlerCallable<Response>;
|
|
18
18
|
constructor(cb: SNSEventHandlerCallable<Response>);
|
|
19
19
|
}
|
|
20
|
-
export declare const createEventHandler: <
|
|
20
|
+
export declare const createEventHandler: <Response>(cb: SNSEventHandlerCallable<Response>) => SNSEventHandler<Response>;
|