@webiny/handler-aws 0.0.0-unstable.de38392959 → 0.0.0-unstable.e0bfc55d5a
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 +1 -1
- package/createHandler.js.map +1 -1
- package/dynamodb/index.d.ts +3 -3
- package/dynamodb/index.js +3 -1
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +2 -2
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.js.map +1 -1
- package/eventBridge/index.d.ts +3 -3
- package/eventBridge/index.js +3 -1
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +2 -2
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +1 -1
- package/eventBridge/register.js.map +1 -1
- package/execute.d.ts +1 -1
- package/execute.js +9 -0
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +4 -4
- package/gateway/index.js.map +1 -1
- package/gateway/register.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +12 -0
- package/index.js.map +1 -1
- package/package.json +14 -22
- package/plugins/handlerClient.js.map +1 -1
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js.map +1 -1
- package/raw/index.d.ts +3 -4
- package/raw/index.js +10 -1
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +16 -5
- package/raw/plugins/RawEventHandler.js +14 -3
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +9 -3
- package/registry.js +9 -3
- package/registry.js.map +1 -1
- package/s3/index.d.ts +3 -4
- package/s3/index.js +3 -1
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +2 -2
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +1 -1
- package/s3/register.js.map +1 -1
- package/sns/index.d.ts +3 -4
- package/sns/index.js +3 -1
- package/sns/index.js.map +1 -1
- package/sns/plugins/SNSEventHandler.d.ts +2 -2
- package/sns/plugins/SNSEventHandler.js.map +1 -1
- package/sns/register.js.map +1 -1
- package/sourceHandler.d.ts +1 -1
- package/sourceHandler.js.map +1 -1
- package/sqs/index.d.ts +3 -4
- package/sqs/index.js +7 -2
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +2 -2
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.js.map +1 -1
- package/types.d.ts +7 -8
- package/types.js +1 -24
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +3 -3
- package/utils/composedHandler.js.map +1 -1
- 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/createHandler.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { HandlerFactory } from "./types";
|
|
1
|
+
import type { HandlerFactory } from "./types";
|
|
2
2
|
export declare const createHandler: HandlerFactory;
|
package/createHandler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_plugins","require","_registry","createHandler","plugins","params","pluginsContainer","AsyncPluginsContainer","event","context","init","handler","registry","getHandler","handle","exports"],"sources":["createHandler.ts"],"sourcesContent":["import { AsyncPluginsContainer } from \"@webiny/plugins\";\nimport { HandlerFactory } from \"~/types\";\nimport { registry } from \"./registry\";\n\nexport const createHandler: HandlerFactory = ({ plugins, ...params }) => {\n const pluginsContainer = new AsyncPluginsContainer(plugins);\n\n return async (event, context) => {\n const plugins = await pluginsContainer.init();\n const handler = registry.getHandler(event, context);\n return handler.handle({\n params: {\n ...params,\n plugins\n },\n event,\n context\n });\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AAEO,MAAME,aAA6B,GAAGA,CAAC;EAAEC,OAAO;EAAE,GAAGC;AAAO,CAAC,KAAK;EACrE,MAAMC,gBAAgB,GAAG,IAAIC,8BAAqB,CAACH,OAAO,CAAC;EAE3D,OAAO,OAAOI,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAML,OAAO,GAAG,MAAME,gBAAgB,CAACI,IAAI,CAAC,CAAC;IAC7C,MAAMC,OAAO,GAAGC,kBAAQ,CAACC,UAAU,CAACL,KAAK,EAAEC,OAAO,CAAC;IACnD,OAAOE,OAAO,CAACG,MAAM,CAAC;MAClBT,MAAM,EAAE;QACJ,GAAGA,MAAM;QACTD;MACJ,CAAC;MACDI,KAAK;MACLC;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACM,OAAA,CAAAZ,aAAA,GAAAA,aAAA"}
|
|
1
|
+
{"version":3,"names":["_plugins","require","_registry","createHandler","plugins","params","pluginsContainer","AsyncPluginsContainer","event","context","init","handler","registry","getHandler","handle","exports"],"sources":["createHandler.ts"],"sourcesContent":["import { AsyncPluginsContainer } from \"@webiny/plugins\";\nimport type { HandlerFactory } from \"~/types\";\nimport { registry } from \"./registry\";\n\nexport const createHandler: HandlerFactory = ({ plugins, ...params }) => {\n const pluginsContainer = new AsyncPluginsContainer(plugins);\n\n return async (event, context) => {\n const plugins = await pluginsContainer.init();\n const handler = registry.getHandler(event, context);\n return handler.handle({\n params: {\n ...params,\n plugins\n },\n event,\n context\n });\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AAEO,MAAME,aAA6B,GAAGA,CAAC;EAAEC,OAAO;EAAE,GAAGC;AAAO,CAAC,KAAK;EACrE,MAAMC,gBAAgB,GAAG,IAAIC,8BAAqB,CAACH,OAAO,CAAC;EAE3D,OAAO,OAAOI,KAAK,EAAEC,OAAO,KAAK;IAC7B,MAAML,OAAO,GAAG,MAAME,gBAAgB,CAACI,IAAI,CAAC,CAAC;IAC7C,MAAMC,OAAO,GAAGC,kBAAQ,CAACC,UAAU,CAACL,KAAK,EAAEC,OAAO,CAAC;IACnD,OAAOE,OAAO,CAACG,MAAM,CAAC;MAClBT,MAAM,EAAE;QACJ,GAAGA,MAAM;QACTD;MACJ,CAAC;MACDI,KAAK;MACLC;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACM,OAAA,CAAAZ,aAAA,GAAAA,aAAA","ignoreList":[]}
|
package/dynamodb/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { APIGatewayProxyResult, Context as LambdaContext, DynamoDBStreamEvent } from "aws-
|
|
2
|
-
import { HandlerFactoryParams } from "../types";
|
|
1
|
+
import type { APIGatewayProxyResult, Context as LambdaContext, DynamoDBStreamEvent } from "@webiny/aws-sdk/types";
|
|
2
|
+
import type { HandlerFactoryParams } from "../types";
|
|
3
3
|
export * from "./plugins/DynamoDBEventHandler";
|
|
4
|
-
export
|
|
4
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
5
5
|
export interface HandlerCallable {
|
|
6
6
|
(event: DynamoDBStreamEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
7
7
|
}
|
package/dynamodb/index.js
CHANGED
|
@@ -27,7 +27,9 @@ var _execute = require("../execute");
|
|
|
27
27
|
var _composedHandler = require("../utils/composedHandler");
|
|
28
28
|
/**
|
|
29
29
|
* We need a class, not an interface exported from types.
|
|
30
|
-
*/
|
|
30
|
+
*/
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
|
|
31
33
|
const url = "/webiny-dynamodb-event";
|
|
32
34
|
const createHandler = params => {
|
|
33
35
|
return (payload, context) => {
|
package/dynamodb/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_handler","require","_plugins","_DynamoDBEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_reply","_interopRequireDefault","_execute","_composedHandler","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","DynamoDBEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","event","lambdaContext","result","Reply","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":["_handler","require","_plugins","_DynamoDBEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_reply","_interopRequireDefault","_execute","_composedHandler","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","DynamoDBEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","event","lambdaContext","result","Reply","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n DynamoDBStreamEvent\n} from \"@webiny/aws-sdk/types\";\nimport type { HandlerFactoryParams } from \"~/types\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport type { DynamoDBEventHandlerCallableParams } from \"./plugins/DynamoDBEventHandler\";\nimport { DynamoDBEventHandler } from \"./plugins/DynamoDBEventHandler\";\n/**\n * We need a class, not an interface exported from types.\n */\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply\";\nimport { execute } from \"~/execute\";\nimport { createComposedHandler } from \"~/utils/composedHandler\";\n\nexport * from \"./plugins/DynamoDBEventHandler\";\n\nconst url = \"/webiny-dynamodb-event\";\n\nexport type HandlerParams = HandlerFactoryParams;\n\nexport interface HandlerCallable {\n (event: DynamoDBStreamEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\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<DynamoDBEventHandler>(DynamoDBEventHandler.type)\n .reverse();\n if (plugins.length === 0) {\n throw new Error(\n `To run @webiny/handler-aws/dynamodb, you must have DynamoDBHandler set.`\n );\n }\n\n const handler = createComposedHandler<\n DynamoDBEventHandler,\n DynamoDBEventHandlerCallableParams<APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<\n DynamoDBEventHandlerCallableParams<APIGatewayProxyResult>,\n \"next\"\n > = {\n request,\n context: app.webiny,\n event: payload,\n lambdaContext: context,\n reply\n };\n const result = await handler(\n params as unknown as DynamoDBEventHandlerCallableParams<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\n });\n };\n};\n"],"mappings":";;;;;;;;;;AAMA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,qBAAA,GAAAF,OAAA;AASAG,MAAA,CAAAC,IAAA,CAAAF,qBAAA,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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B,aAAa,EAAErB,OAAO;QACtBmB;MACJ,CAAC;MACD,MAAMG,MAAM,GAAG,MAAMP,OAAO,CACxBjB,MACJ,CAAC;MAED,IAAIwB,MAAM,YAAYC,cAAK,EAAE;QACzB,OAAOD,MAAM;MACjB;MAEArB,GAAG,CAACuB,mBAAmB,GAAGF,MAAM;MAChC,OAAOH,KAAK,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO,IAAAC,gBAAO,EAAC;MACXzB,GAAG;MACHL,GAAG;MACHG;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
-
import { Context, Reply, Request } from "@webiny/handler/types";
|
|
3
|
-
import { Context as LambdaContext, DynamoDBStreamEvent } from "aws-
|
|
2
|
+
import type { Context, Reply, Request } from "@webiny/handler/types";
|
|
3
|
+
import type { Context as LambdaContext, DynamoDBStreamEvent } from "@webiny/aws-sdk/types";
|
|
4
4
|
export interface DynamoDBEventHandlerCallableParams<Response = Reply> {
|
|
5
5
|
request: Request;
|
|
6
6
|
context: Context;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Plugin","require","DynamoDBEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["DynamoDBEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, Reply, Request } from \"@webiny/handler/types\";\nimport { Context as LambdaContext, DynamoDBStreamEvent } from \"aws-
|
|
1
|
+
{"version":3,"names":["_Plugin","require","DynamoDBEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["DynamoDBEventHandler.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types\";\nimport type { Context as LambdaContext, DynamoDBStreamEvent } from \"@webiny/aws-sdk/types\";\n\nexport interface DynamoDBEventHandlerCallableParams<Response = Reply> {\n request: Request;\n context: Context;\n event: DynamoDBStreamEvent;\n lambdaContext: LambdaContext;\n reply: Reply;\n next: () => Promise<Response>;\n}\n\nexport interface DynamoDBEventHandlerCallable<Response = Reply> {\n (params: DynamoDBEventHandlerCallableParams<Response>): Promise<Response>;\n}\n\nexport class DynamoDBEventHandler<Response = any> extends Plugin {\n public static override type = \"handler.fastify.aws.dynamodb.eventHandler\";\n\n public readonly cb: DynamoDBEventHandlerCallable<Response>;\n\n public constructor(cb: DynamoDBEventHandlerCallable<Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <Response>(cb: DynamoDBEventHandlerCallable<Response>) => {\n return new DynamoDBEventHandler<Response>(cb);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAiBO,MAAMC,oBAAoB,SAAyBC,cAAM,CAAC;EAC7D,OAAuBC,IAAI,GAAG,2CAA2C;EAIlEC,WAAWA,CAACC,EAA0C,EAAE;IAC3D,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,oBAAA,GAAAA,oBAAA;AAEM,MAAMM,kBAAkB,GAAcF,EAA0C,IAAK;EACxF,OAAO,IAAIJ,oBAAoB,CAAWI,EAAE,CAAC;AACjD,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
package/dynamodb/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_registry","require","_sourceHandler","_index","handler","createSourceHandler","name","canUse","event","Array","isArray","Records","length","record","eventSource","toLowerCase","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import { registry } from \"~/registry\";\nimport { DynamoDBStreamEvent } from \"aws-
|
|
1
|
+
{"version":3,"names":["_registry","require","_sourceHandler","_index","handler","createSourceHandler","name","canUse","event","Array","isArray","Records","length","record","eventSource","toLowerCase","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import { registry } from \"~/registry\";\nimport type { DynamoDBStreamEvent } from \"@webiny/aws-sdk/types\";\nimport { createSourceHandler } from \"~/sourceHandler\";\nimport type { HandlerParams } from \"~/dynamodb/index\";\nimport { createHandler } from \"~/dynamodb/index\";\n\nconst handler = createSourceHandler<DynamoDBStreamEvent, HandlerParams>({\n name: \"handler-aws-dynamodb-stream\",\n canUse: event => {\n if (!Array.isArray(event.Records) || event.Records.length === 0) {\n return false;\n }\n const [record] = event.Records;\n if (typeof record.eventSource !== \"string\") {\n return false;\n }\n return record.eventSource.toLowerCase() === \"aws:dynamodb\";\n },\n handle: async ({ params, event, context }) => {\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"mappings":";;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAEA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAAqC;EACpEC,IAAI,EAAE,6BAA6B;EACnCC,MAAM,EAAEC,KAAK,IAAI;IACb,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,KAAK,CAACG,OAAO,CAAC,IAAIH,KAAK,CAACG,OAAO,CAACC,MAAM,KAAK,CAAC,EAAE;MAC7D,OAAO,KAAK;IAChB;IACA,MAAM,CAACC,MAAM,CAAC,GAAGL,KAAK,CAACG,OAAO;IAC9B,IAAI,OAAOE,MAAM,CAACC,WAAW,KAAK,QAAQ,EAAE;MACxC,OAAO,KAAK;IAChB;IACA,OAAOD,MAAM,CAACC,WAAW,CAACC,WAAW,CAAC,CAAC,KAAK,cAAc;EAC9D,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAET,KAAK;IAAEU;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACT,KAAK,EAAEU,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAACjB,OAAO,CAAC","ignoreList":[]}
|
package/eventBridge/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { HandlerFactoryParams } from "../types";
|
|
2
|
-
import { APIGatewayProxyResult, Context as LambdaContext, EventBridgeEvent } from "aws-
|
|
1
|
+
import type { HandlerFactoryParams } from "../types";
|
|
2
|
+
import type { APIGatewayProxyResult, Context as LambdaContext, EventBridgeEvent } from "@webiny/aws-sdk/types";
|
|
3
3
|
export * from "./plugins/EventBridgeEventHandler";
|
|
4
|
-
export
|
|
4
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
5
5
|
export interface HandlerCallable {
|
|
6
6
|
(event: EventBridgeEvent<string, string>, context: LambdaContext): Promise<APIGatewayProxyResult>;
|
|
7
7
|
}
|
package/eventBridge/index.js
CHANGED
|
@@ -27,7 +27,9 @@ var _reply = _interopRequireDefault(require("fastify/lib/reply"));
|
|
|
27
27
|
var _composedHandler = require("../utils/composedHandler");
|
|
28
28
|
/**
|
|
29
29
|
* We need a class, not an interface exported from types.
|
|
30
|
-
*/
|
|
30
|
+
*/
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
|
|
31
33
|
const url = "/webiny-eventBridge-event";
|
|
32
34
|
const createHandler = params => {
|
|
33
35
|
return (payload, context) => {
|
package/eventBridge/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_handler","require","_plugins","_EventBridgeEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","EventBridgeEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport {\
|
|
1
|
+
{"version":3,"names":["_handler","require","_plugins","_EventBridgeEventHandler","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_execute","_reply","_interopRequireDefault","_composedHandler","url","createHandler","params","payload","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","EventBridgeEventHandler","type","reverse","length","Error","handler","createComposedHandler","post","request","reply","lambdaContext","result","Reply","__webiny_raw_result","send","execute"],"sources":["index.ts"],"sourcesContent":["import { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport type { EventBridgeEventHandlerCallableParams } from \"~/eventBridge/plugins/EventBridgeEventHandler\";\nimport { EventBridgeEventHandler } from \"~/eventBridge/plugins/EventBridgeEventHandler\";\nimport { execute } from \"~/execute\";\nimport type { HandlerFactoryParams } from \"~/types\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext,\n EventBridgeEvent\n} from \"@webiny/aws-sdk/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/EventBridgeEventHandler\";\n\nexport type HandlerParams = HandlerFactoryParams;\n\nexport interface HandlerCallable {\n (\n event: EventBridgeEvent<string, string>,\n context: LambdaContext\n ): Promise<APIGatewayProxyResult>;\n}\n\nconst url = \"/webiny-eventBridge-event\";\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\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<EventBridgeEventHandler<string, string>>(EventBridgeEventHandler.type)\n .reverse();\n if (plugins.length === 0) {\n throw new Error(\n `To run @webiny/handler-aws/eventBridge, you must have EventBridgeEventHandler set.`\n );\n }\n\n const handler = createComposedHandler<\n EventBridgeEventHandler<string, string>,\n EventBridgeEventHandlerCallableParams<string, string, APIGatewayProxyResult>,\n APIGatewayProxyResult\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<\n EventBridgeEventHandlerCallableParams<string, string, APIGatewayProxyResult>,\n \"next\"\n > = {\n request,\n reply,\n context: app.webiny,\n payload,\n lambdaContext: context\n };\n const result = await handler(\n params as unknown as EventBridgeEventHandlerCallableParams<\n string,\n string,\n APIGatewayProxyResult\n >\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\n });\n };\n};\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,wBAAA,GAAAF,OAAA;AAeAG,MAAA,CAAAC,IAAA,CAAAF,wBAAA,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,wBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,wBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAdA,IAAAS,QAAA,GAAAf,OAAA;AAWA,IAAAgB,MAAA,GAAAC,sBAAA,CAAAjB,OAAA;AACA,IAAAkB,gBAAA,GAAAlB,OAAA;AALA;AACA;AACA;AACA;;AAeA,MAAMmB,GAAG,GAA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CAAC;AAACX,OAAA,CAAAS,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { Context as LambdaContext, EventBridgeEvent } from "@webiny/aws-sdk/types";
|
|
1
2
|
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
-
import { Context, Reply, Request } from "@webiny/handler/types";
|
|
3
|
-
import { Context as LambdaContext, EventBridgeEvent } from "aws-lambda";
|
|
3
|
+
import type { Context, Reply, Request } from "@webiny/handler/types";
|
|
4
4
|
export interface EventBridgeEventHandlerCallableParams<DetailType extends string, Detail, Response = Reply> {
|
|
5
5
|
request: Request;
|
|
6
6
|
reply: Reply;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Plugin","require","EventBridgeEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["EventBridgeEventHandler.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":["_Plugin","require","EventBridgeEventHandler","Plugin","type","constructor","cb","exports","createEventHandler"],"sources":["EventBridgeEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, EventBridgeEvent } from \"@webiny/aws-sdk/types\";\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport type { Context, Reply, Request } from \"@webiny/handler/types\";\n\nexport interface EventBridgeEventHandlerCallableParams<\n DetailType extends string,\n Detail,\n Response = Reply\n> {\n request: Request;\n reply: Reply;\n context: Context;\n payload: EventBridgeEvent<DetailType, Detail>;\n lambdaContext: LambdaContext;\n next: () => Promise<Response>;\n}\nexport interface EventBridgeEventHandlerCallable<\n DetailType extends string,\n Detail,\n Response = Reply\n> {\n (\n params: EventBridgeEventHandlerCallableParams<DetailType, Detail, Response>\n ): Promise<Response>;\n}\n\nexport class EventBridgeEventHandler<\n DetailType extends string,\n Detail,\n Response = any\n> extends Plugin {\n public static override type = \"handler.fastify.aws.eventBridge.eventHandler\";\n\n public readonly cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>;\n\n public constructor(cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEventHandler = <DetailType extends string, Detail, Response = any>(\n cb: EventBridgeEventHandlerCallable<DetailType, Detail, Response>\n) => {\n return new EventBridgeEventHandler<DetailType, Detail, Response>(cb);\n};\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAyBO,MAAMC,uBAAuB,SAI1BC,cAAM,CAAC;EACb,OAAuBC,IAAI,GAAG,8CAA8C;EAIrEC,WAAWA,CAACC,EAAiE,EAAE;IAClF,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAACC,OAAA,CAAAL,uBAAA,GAAAA,uBAAA;AAEM,MAAMM,kBAAkB,GAC3BF,EAAiE,IAChE;EACD,OAAO,IAAIJ,uBAAuB,CAA+BI,EAAE,CAAC;AACxE,CAAC;AAACC,OAAA,CAAAC,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_registry","require","_sourceHandler","_index","handler","createSourceHandler","name","canUse","event","source","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":["_registry","require","_sourceHandler","_index","handler","createSourceHandler","name","canUse","event","source","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import type { EventBridgeEvent } from \"@webiny/aws-sdk/types\";\nimport { registry } from \"~/registry\";\nimport type { HandlerFactoryParams } from \"~/types\";\nimport { createSourceHandler } from \"~/sourceHandler\";\nimport { createHandler } from \"~/eventBridge/index\";\n\nexport interface HandlerParams extends HandlerFactoryParams {\n debug?: boolean;\n}\n\nconst handler = createSourceHandler<EventBridgeEvent<string, string>, HandlerParams>({\n name: \"handler-aws-event-bridge\",\n canUse: event => {\n return !!event.source;\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,EAAkD;EACjFC,IAAI,EAAE,0BAA0B;EAChCC,MAAM,EAAEC,KAAK,IAAI;IACb,OAAO,CAAC,CAACA,KAAK,CAACC,MAAM;EACzB,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAEH,KAAK;IAAEI;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACH,KAAK,EAAEI,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAACX,OAAO,CAAC","ignoreList":[]}
|
package/execute.d.ts
CHANGED
package/execute.js
CHANGED
|
@@ -16,6 +16,14 @@ const createHandleResponse = (app, resolve) => {
|
|
|
16
16
|
}
|
|
17
17
|
if (app.__webiny_raw_result) {
|
|
18
18
|
return resolve(app.__webiny_raw_result);
|
|
19
|
+
} else if (!result) {
|
|
20
|
+
const response = {
|
|
21
|
+
statusCode: 200,
|
|
22
|
+
body: "",
|
|
23
|
+
headers: {},
|
|
24
|
+
isBase64Encoded: false
|
|
25
|
+
};
|
|
26
|
+
return resolve(response);
|
|
19
27
|
}
|
|
20
28
|
const isBase64Encoded = !!result.headers[_types.Base64EncodeHeader.encoded] || !!result.headers[_types.Base64EncodeHeader.binary];
|
|
21
29
|
const response = {
|
|
@@ -53,6 +61,7 @@ const execute = params => {
|
|
|
53
61
|
method: "POST",
|
|
54
62
|
url,
|
|
55
63
|
payload: payload || {},
|
|
64
|
+
body: payload || {},
|
|
56
65
|
query,
|
|
57
66
|
headers,
|
|
58
67
|
cookies
|
package/execute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_types","require","createHandleResponse","app","resolve","err","result","statusCode","body","JSON","stringify","headers","__webiny_raw_result","isBase64Encoded","Base64EncodeHeader","encoded","binary","
|
|
1
|
+
{"version":3,"names":["_types","require","createHandleResponse","app","resolve","err","result","statusCode","body","JSON","stringify","headers","__webiny_raw_result","response","isBase64Encoded","Base64EncodeHeader","encoded","binary","rawPayload","toString","payload","getPayloadProperty","prop","defaults","value","execute","params","url","query","cookies","Promise","inject","method","exports"],"sources":["execute.ts"],"sourcesContent":["import type { FastifyInstance } from \"@webiny/handler/types\";\nimport type { APIGatewayProxyResult } from \"@webiny/aws-sdk/types\";\nimport type { LightMyRequestCallback } from \"fastify\";\nimport { Base64EncodeHeader } from \"~/types\";\n\ninterface Resolve {\n (response: APIGatewayProxyResult | any): void;\n}\nconst createHandleResponse = (app: FastifyInstance, resolve: Resolve): LightMyRequestCallback => {\n return (err, result) => {\n if (err) {\n return resolve({\n statusCode: 500,\n body: JSON.stringify(err),\n headers: {}\n });\n }\n if (app.__webiny_raw_result) {\n return resolve(app.__webiny_raw_result);\n } else if (!result) {\n const response: APIGatewayProxyResult = {\n statusCode: 200,\n body: \"\",\n headers: {},\n isBase64Encoded: false\n };\n return resolve(response);\n }\n\n const isBase64Encoded =\n !!result.headers[Base64EncodeHeader.encoded] ||\n !!result.headers[Base64EncodeHeader.binary];\n const response: APIGatewayProxyResult = {\n statusCode: result.statusCode,\n body: isBase64Encoded ? result.rawPayload.toString(\"base64\") : result.payload,\n headers: result.headers as APIGatewayProxyResult[\"headers\"],\n isBase64Encoded\n };\n return resolve(response);\n };\n};\n\nconst getPayloadProperty = (\n payload: any,\n prop: string,\n defaults: Record<string, any> = {}\n): Record<string, any> => {\n if (payload && typeof payload === \"object\") {\n const value = payload[prop] ? payload[prop] : {};\n\n return {\n ...defaults,\n ...value\n };\n }\n return defaults;\n};\n\nexport interface ExecuteParams {\n app: FastifyInstance;\n url: string;\n payload: any;\n}\n\nexport const execute = (params: ExecuteParams): Promise<any> => {\n const { app, url, payload } = params;\n\n const query = getPayloadProperty(payload, \"query\", {});\n const headers = getPayloadProperty(payload, \"headers\", {\n [\"content-type\"]: \"application/json\"\n });\n\n const cookies = getPayloadProperty(payload, \"cookies\", {});\n\n return new Promise(resolve => {\n app.inject(\n {\n method: \"POST\",\n url,\n payload: payload || {},\n body: payload || {},\n query,\n headers,\n cookies\n },\n createHandleResponse(app, resolve)\n );\n });\n};\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AAKA,MAAMC,oBAAoB,GAAGA,CAACC,GAAoB,EAAEC,OAAgB,KAA6B;EAC7F,OAAO,CAACC,GAAG,EAAEC,MAAM,KAAK;IACpB,IAAID,GAAG,EAAE;MACL,OAAOD,OAAO,CAAC;QACXG,UAAU,EAAE,GAAG;QACfC,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACL,GAAG,CAAC;QACzBM,OAAO,EAAE,CAAC;MACd,CAAC,CAAC;IACN;IACA,IAAIR,GAAG,CAACS,mBAAmB,EAAE;MACzB,OAAOR,OAAO,CAACD,GAAG,CAACS,mBAAmB,CAAC;IAC3C,CAAC,MAAM,IAAI,CAACN,MAAM,EAAE;MAChB,MAAMO,QAA+B,GAAG;QACpCN,UAAU,EAAE,GAAG;QACfC,IAAI,EAAE,EAAE;QACRG,OAAO,EAAE,CAAC,CAAC;QACXG,eAAe,EAAE;MACrB,CAAC;MACD,OAAOV,OAAO,CAACS,QAAQ,CAAC;IAC5B;IAEA,MAAMC,eAAe,GACjB,CAAC,CAACR,MAAM,CAACK,OAAO,CAACI,yBAAkB,CAACC,OAAO,CAAC,IAC5C,CAAC,CAACV,MAAM,CAACK,OAAO,CAACI,yBAAkB,CAACE,MAAM,CAAC;IAC/C,MAAMJ,QAA+B,GAAG;MACpCN,UAAU,EAAED,MAAM,CAACC,UAAU;MAC7BC,IAAI,EAAEM,eAAe,GAAGR,MAAM,CAACY,UAAU,CAACC,QAAQ,CAAC,QAAQ,CAAC,GAAGb,MAAM,CAACc,OAAO;MAC7ET,OAAO,EAAEL,MAAM,CA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ED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { APIGatewayEvent, Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
2
|
+
import type { LambdaResponse } from "@fastify/aws-lambda";
|
|
2
3
|
import { createRoute, RoutePlugin } from "@webiny/handler";
|
|
3
|
-
import {
|
|
4
|
-
import { HandlerFactoryParams } from "../types";
|
|
4
|
+
import type { HandlerFactoryParams } from "../types";
|
|
5
5
|
export { RoutePlugin, createRoute };
|
|
6
|
-
export
|
|
6
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
7
7
|
export interface HandlerCallable {
|
|
8
8
|
(event: APIGatewayEvent, ctx: LambdaContext): Promise<LambdaResponse>;
|
|
9
9
|
}
|
package/gateway/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_awsLambda","_interopRequireDefault","require","_handler","_plugins","_types","getHeader","headers","header","key","toLowerCase","undefined","defaultContentType","defaultCharset","attachRequiredProperties","event","contentType","join","body","startsWith","createHandler","params","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","RoutePlugin","type","length","Error","appLambda","awsLambdaFastify","decorateRequest","serializeLambdaArguments","decorationPropertyName","enforceBase64","response","Base64EncodeHeader","encoded","binary","lambdaOptions","exports"],"sources":["index.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"names":["_awsLambda","_interopRequireDefault","require","_handler","_plugins","_types","getHeader","headers","header","key","toLowerCase","undefined","defaultContentType","defaultCharset","attachRequiredProperties","event","contentType","join","body","startsWith","createHandler","params","context","app","createBaseHandler","options","logger","debug","registerDefaultPlugins","webiny","plugins","byType","RoutePlugin","type","length","Error","appLambda","awsLambdaFastify","decorateRequest","serializeLambdaArguments","decorationPropertyName","enforceBase64","response","Base64EncodeHeader","encoded","binary","lambdaOptions","exports"],"sources":["index.ts"],"sourcesContent":["import type {\n APIGatewayEvent,\n APIGatewayProxyEventHeaders,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types\";\nimport type { LambdaResponse } from \"@fastify/aws-lambda\";\nimport awsLambdaFastify from \"@fastify/aws-lambda\";\nimport { createHandler as createBaseHandler, createRoute, RoutePlugin } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"~/plugins\";\nimport type { HandlerFactoryParams } from \"~/types\";\nimport { Base64EncodeHeader } from \"~/types\";\n\nexport { RoutePlugin, createRoute };\n\nexport type HandlerParams = HandlerFactoryParams;\n\nexport interface HandlerCallable {\n (event: APIGatewayEvent, ctx: LambdaContext): Promise<LambdaResponse>;\n}\n\nconst getHeader = (headers: APIGatewayProxyEventHeaders, header: string): string | undefined => {\n for (const key in headers) {\n if (key.toLowerCase() !== header) {\n continue;\n }\n return headers[key];\n }\n return undefined;\n};\n\nconst defaultContentType = \"application/json\";\nconst defaultCharset = \"utf-8\";\n/**\n * We need to attach default headers to the request, so it does not break if there is none sent.\n */\nconst attachRequiredProperties = (event: APIGatewayEvent): void => {\n /**\n * A possibility that headers are not defined?\n * Maybe during testing?\n */\n if (!event.headers) {\n event.headers = {};\n }\n const contentType = getHeader(event.headers, \"content-type\");\n /**\n * We check the existing content type and add the default one if it does not exist.\n *\n * Also, if the content-type is the application/json, and the body is not sent, we add it.\n */\n if (!contentType) {\n event.headers[\"content-type\"] = [defaultContentType, `charset=${defaultCharset}`].join(\";\");\n event.body = \"{}\";\n } else if (!event.body && contentType.startsWith(defaultContentType)) {\n event.body = \"{}\";\n }\n};\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 if (app.webiny.plugins.byType<RoutePlugin>(RoutePlugin.type).length === 0) {\n throw new Error(\n `To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.`\n );\n }\n attachRequiredProperties(event);\n\n const appLambda = awsLambdaFastify(app, {\n decorateRequest: true,\n serializeLambdaArguments: true,\n decorationPropertyName: \"awsLambda\",\n enforceBase64: response => {\n return (\n !!response.headers[Base64EncodeHeader.encoded] ||\n !!response.headers[Base64EncodeHeader.binary]\n );\n },\n ...(params.lambdaOptions || {})\n });\n return appLambda(event, context);\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAMA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAH,OAAA;AAUA,MAAMI,SAAS,GAAGA,CAACC,OAAoC,EAAEC,MAAc,KAAyB;EAC5F,KAAK,MAAMC,GAAG,IAAIF,OAAO,EAAE;IACvB,IAAIE,GAAG,CAACC,WAAW,CAAC,CAAC,KAAKF,MAAM,EAAE;MAC9B;IACJ;IACA,OAAOD,OAAO,CAACE,GAAG,CAAC;EACvB;EACA,OAAOE,SAAS;AACpB,CAAC;AAED,MAAMC,kBAAkB,GAAG,kBAAkB;AAC7C,MAAMC,cAAc,GAAG,OAAO;AAC9B;AACA;AACA;AACA,MAAMC,wBAAwB,GAAIC,KAAsB,IAAW;EAC/D;AACJ;AACA;AACA;EACI,IAAI,CAACA,KAAK,CAACR,OAAO,EAAE;IAChBQ,KAAK,CAACR,OAAO,GAAG,CAAC,CAAC;EACtB;EACA,MAAMS,WAAW,GAAGV,SAAS,CAACS,KAAK,CAACR,OAAO,EAAE,cAAc,CAAC;EAC5D;AACJ;AACA;AACA;AACA;EACI,IAAI,CAACS,WAAW,EAAE;IACdD,KAAK,CAACR,OAAO,CAAC,cAAc,CAAC,GAAG,CAACK,kBAAkB,EAAE,WAAWC,cAAc,EAAE,CAAC,CAACI,IAAI,CAAC,GAAG,CAAC;IAC3FF,KAAK,CAACG,IAAI,GAAG,IAAI;EACrB,CAAC,MAAM,IAAI,CAACH,KAAK,CAACG,IAAI,IAAIF,WAAW,CAACG,UAAU,CAACP,kBAAkB,C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require","_sourceHandler","_index","handler","createSourceHandler","name","canUse","event","httpMethod","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":["_registry","require","_sourceHandler","_index","handler","createSourceHandler","name","canUse","event","httpMethod","handle","params","context","createHandler","registry","register"],"sources":["register.ts"],"sourcesContent":["import type { APIGatewayEvent } from \"@webiny/aws-sdk/types\";\nimport { registry } from \"~/registry\";\nimport { createSourceHandler } from \"~/sourceHandler\";\nimport type { HandlerParams } from \"./index\";\nimport { createHandler } from \"./index\";\n\nconst handler = createSourceHandler<APIGatewayEvent, HandlerParams>({\n name: \"handler-aws-api-gateway\",\n canUse: event => {\n return !!event.httpMethod;\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;AACA,IAAAC,cAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAEA,MAAMG,OAAO,GAAG,IAAAC,kCAAmB,EAAiC;EAChEC,IAAI,EAAE,yBAAyB;EAC/BC,MAAM,EAAEC,KAAK,IAAI;IACb,OAAO,CAAC,CAACA,KAAK,CAACC,UAAU;EAC7B,CAAC;EACDC,MAAM,EAAE,MAAAA,CAAO;IAAEC,MAAM;IAAEH,KAAK;IAAEI;EAAQ,CAAC,KAAK;IAC1C,OAAO,IAAAC,oBAAa,EAACF,MAAM,CAAC,CAACH,KAAK,EAAEI,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFE,kBAAQ,CAACC,QAAQ,CAACX,OAAO,CAAC","ignoreList":[]}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -326,6 +326,18 @@ require("./dynamodb/register");
|
|
|
326
326
|
require("./sqs/register");
|
|
327
327
|
require("./eventBridge/register");
|
|
328
328
|
require("./sns/register");
|
|
329
|
+
var _utils = require("./utils");
|
|
330
|
+
Object.keys(_utils).forEach(function (key) {
|
|
331
|
+
if (key === "default" || key === "__esModule") return;
|
|
332
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
333
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
|
334
|
+
Object.defineProperty(exports, key, {
|
|
335
|
+
enumerable: true,
|
|
336
|
+
get: function () {
|
|
337
|
+
return _utils[key];
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
});
|
|
329
341
|
var _gateway = require("./gateway");
|
|
330
342
|
var _s = require("./s3");
|
|
331
343
|
var _dynamodb = require("./dynamodb");
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require","
|
|
1
|
+
{"version":3,"names":["require","_utils","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_gateway","_s","_dynamodb","_sqs","_sns","_eventBridge","_raw","_handler","_createHandler","_sourceHandler"],"sources":["index.ts"],"sourcesContent":["import \"./gateway/register\";\nimport \"./s3/register\";\nimport \"./dynamodb/register\";\nimport \"./sqs/register\";\nimport \"./eventBridge/register\";\nimport \"./sns/register\";\n\nexport * from \"./utils\";\n\n/**\n * API Gateway\n */\nexport {\n createHandler as createApiGatewayHandler,\n HandlerParams as CreateApiGatewayHandlerParams,\n HandlerCallable as ApiGatewayHandlerCallable,\n RoutePlugin,\n createRoute as createApiGatewayRoute\n} from \"~/gateway\";\n\n/**\n * S3\n */\n//\nexport {\n createHandler as createS3Handler,\n HandlerParams as CreateS3HandlerParams,\n S3EventHandler,\n S3EventHandlerCallable,\n S3EventHandlerCallableParams,\n createEventHandler as createS3EventHandler\n} from \"~/s3\";\n\n/**\n * DynamoDB Stream\n */\n//\nexport {\n createHandler as createDynamoDBHandler,\n HandlerParams as CreateDynamoDBHandlerParams,\n DynamoDBEventHandler,\n DynamoDBEventHandlerCallable,\n DynamoDBEventHandlerCallableParams,\n createEventHandler as createDynamoDBEventHandler\n} from \"~/dynamodb\";\n\n/**\n * SQS\n */\n//\nexport {\n createHandler as createSQSHandler,\n HandlerParams as CreateSQSHandlerParams,\n SQSEventHandler,\n SQSEventHandlerCallable,\n SQSEventHandlerCallableParams,\n createEventHandler as createSQSEventHandler\n} from \"~/sqs\";\n\n/**\n * SNS\n */\n//\nexport {\n createHandler as createSNSHandler,\n HandlerParams as CreateSNSHandlerParams,\n SNSEventHandler,\n SNSEventHandlerCallable,\n SNSEventHandlerCallableParams,\n createEventHandler as createSNSEventHandler\n} from \"~/sns\";\n\n/**\n * EventBridge\n */\n//\nexport {\n createHandler as createEventBridgeHandler,\n HandlerParams as CreateEventBridgeHandlerParams,\n EventBridgeEventHandler,\n EventBridgeEventHandlerCallable,\n EventBridgeEventHandlerCallableParams,\n createEventHandler as createEventBridgeEventHandler\n} from \"~/eventBridge\";\n\nexport {\n createHandler as createRawHandler,\n CreateHandlerParams as CreateRawHandlerParams,\n HandlerCallable as RawHandlerCallable,\n createEventHandler as createRawEventHandler,\n RawEventHandlerCallableParams,\n RawEventHandlerCallable,\n RawEventHandler\n} from \"~/raw\";\n\nexport { ContextPlugin, createContextPlugin, ContextPluginCallable } from \"@webiny/handler\";\n\nexport * from \"./createHandler\";\nexport * from \"./sourceHandler\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAA,OAAA;AACAA,OAAA;AACAA,OAAA;AACAA,OAAA;AACAA,OAAA;AACAA,OAAA;AAEA,IAAAC,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cAAA,EAAAnB,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,MAAAkB,cAAA,CAAAlB,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAU,cAAA,CAAAlB,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-aws",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.e0bfc55d5a",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,34 +12,26 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@
|
|
16
|
-
"@
|
|
17
|
-
"@webiny/
|
|
18
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
19
|
-
"@webiny/
|
|
20
|
-
"@webiny/
|
|
21
|
-
"
|
|
22
|
-
"fastify": "4.11.0"
|
|
15
|
+
"@fastify/aws-lambda": "4.1.0",
|
|
16
|
+
"@webiny/aws-sdk": "0.0.0-unstable.e0bfc55d5a",
|
|
17
|
+
"@webiny/handler": "0.0.0-unstable.e0bfc55d5a",
|
|
18
|
+
"@webiny/handler-client": "0.0.0-unstable.e0bfc55d5a",
|
|
19
|
+
"@webiny/plugins": "0.0.0-unstable.e0bfc55d5a",
|
|
20
|
+
"@webiny/utils": "0.0.0-unstable.e0bfc55d5a",
|
|
21
|
+
"fastify": "4.29.1"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"@babel/preset-typescript": "7.22.5",
|
|
29
|
-
"@webiny/cli": "0.0.0-unstable.de38392959",
|
|
30
|
-
"@webiny/project-utils": "0.0.0-unstable.de38392959",
|
|
31
|
-
"aws-lambda": "1.0.7",
|
|
32
|
-
"rimraf": "3.0.2",
|
|
33
|
-
"ttypescript": "1.5.15",
|
|
34
|
-
"typescript": "4.7.4"
|
|
24
|
+
"@webiny/project-utils": "0.0.0-unstable.e0bfc55d5a",
|
|
25
|
+
"rimraf": "6.0.1",
|
|
26
|
+
"typescript": "5.3.3"
|
|
35
27
|
},
|
|
36
28
|
"publishConfig": {
|
|
37
29
|
"access": "public",
|
|
38
30
|
"directory": "dist"
|
|
39
31
|
},
|
|
40
32
|
"scripts": {
|
|
41
|
-
"build": "
|
|
42
|
-
"watch": "
|
|
33
|
+
"build": "node ../cli/bin.js run build",
|
|
34
|
+
"watch": "node ../cli/bin.js run watch"
|
|
43
35
|
},
|
|
44
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "e0bfc55d5a4d6a42b32e6558d9fb2eb6753e331b"
|
|
45
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_clientLambda","require","_handlerClient","createHandlerClientPlugin","plugin","HandlerClientPlugin","invoke","params","await","useAwait","name","payload","lambdaClient","LambdaClient","region","process","env","AWS_REGION","response","send","InvokeCommand","FunctionName","InvocationType","Payload","JSON","stringify","decoder","TextDecoder","parse","decode","canUse","AWS_LAMBDA_FUNCTION_NAME","match","exports"],"sources":["handlerClient.ts"],"sourcesContent":["import { LambdaClient, InvokeCommand } from \"@webiny/aws-sdk/client-lambda\";\nimport { HandlerClientPlugin } from \"@webiny/handler-client\";\n\nexport const createHandlerClientPlugin = () => {\n const plugin = new HandlerClientPlugin({\n invoke: async params => {\n const { await: useAwait, name, payload } = params;\n const lambdaClient = new LambdaClient({\n region: process.env.AWS_REGION\n });\n const response = await lambdaClient.send(\n new InvokeCommand({\n FunctionName: name,\n InvocationType: useAwait === false ? \"Event\" : \"RequestResponse\",\n Payload: JSON.stringify(payload)\n })\n );\n\n if (useAwait === false) {\n return null;\n }\n\n const decoder = new TextDecoder(\"utf-8\");\n return JSON.parse(decoder.decode(response.Payload));\n },\n canUse: params => {\n if (!params?.name) {\n return true;\n }\n const { name } = params;\n /**\n * In case we are invoking currently active lambda, let's use this plugin as well.\n * When invoking some other lambda, name starts with arn.\n */\n if (name === process.env.AWS_LAMBDA_FUNCTION_NAME) {\n return true;\n }\n return name.match(\"arn:\") !== null;\n }\n });\n\n plugin.name = \"handler-client\";\n\n return plugin;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAEO,MAAME,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,MAAMC,MAAM,GAAG,IAAIC,kCAAmB,CAAC;IACnCC,MAAM,EAAE,MAAMC,MAAM,IAAI;MACpB,MAAM;QAAEC,KAAK,EAAEC,QAAQ;QAAEC,IAAI;QAAEC;MAAQ,CAAC,GAAGJ,MAAM;MACjD,MAAMK,YAAY,GAAG,IAAIC,0BAAY,CAAC;QAClCC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;MACxB,CAAC,CAAC;MACF,MAAMC,QAAQ,GAAG,MAAMN,YAAY,CAACO,IAAI,CACpC,IAAIC,2BAAa,CAAC;QACdC,YAAY,EAAEX,IAAI;QAClBY,cAAc,EAAEb,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,iBAAiB;QAChEc,OAAO,EAAEC,IAAI,CAACC,SAAS,CAACd,OAAO;MACnC,CAAC,CACL,CAAC;MAED,IAAIF,QAAQ,KAAK,KAAK,EAAE;QACpB,OAAO,IAAI;MACf;MAEA,MAAMiB,OAAO,GAAG,IAAIC,WAAW,CAAC,OAAO,CAAC;MACxC,OAAOH,IAAI,CAACI,KAAK,CAACF,OAAO,CAACG,MAAM,CAACX,QAAQ,CAACK,OAAO,CAAC,CAAC;IACvD,CAAC;IACDO,MAAM,EAAEvB,MAAM,IAAI;MACd,IAAI,CAACA,MAAM,EAAEG,IAAI,EAAE;QACf,OAAO,IAAI;MACf;MACA,MAAM;QAAEA;MAAK,CAAC,GAAGH,MAAM;MACvB;AACZ;AACA;AACA;MACY,IAAIG,IAAI,KAAKK,OAAO,CAACC,GAAG,CAACe,wBAAwB,EAAE;QAC/C,OAAO,IAAI;MACf;MACA,OAAOrB,IAAI,CAACsB,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI;IACtC;EACJ,CAAC,CAAC;EAEF5B,MAAM,CAACM,IAAI,GAAG,gBAAgB;EAE9B,OAAON,MAAM;AACjB,CAAC;AAAC6B,OAAA,CAAA9B,yBAAA,GAAAA,yBAAA"}
|
|
1
|
+
{"version":3,"names":["_clientLambda","require","_handlerClient","createHandlerClientPlugin","plugin","HandlerClientPlugin","invoke","params","await","useAwait","name","payload","lambdaClient","LambdaClient","region","process","env","AWS_REGION","response","send","InvokeCommand","FunctionName","InvocationType","Payload","JSON","stringify","decoder","TextDecoder","parse","decode","canUse","AWS_LAMBDA_FUNCTION_NAME","match","exports"],"sources":["handlerClient.ts"],"sourcesContent":["import { LambdaClient, InvokeCommand } from \"@webiny/aws-sdk/client-lambda\";\nimport { HandlerClientPlugin } from \"@webiny/handler-client\";\n\nexport const createHandlerClientPlugin = () => {\n const plugin = new HandlerClientPlugin({\n invoke: async params => {\n const { await: useAwait, name, payload } = params;\n const lambdaClient = new LambdaClient({\n region: process.env.AWS_REGION\n });\n const response = await lambdaClient.send(\n new InvokeCommand({\n FunctionName: name,\n InvocationType: useAwait === false ? \"Event\" : \"RequestResponse\",\n Payload: JSON.stringify(payload)\n })\n );\n\n if (useAwait === false) {\n return null;\n }\n\n const decoder = new TextDecoder(\"utf-8\");\n return JSON.parse(decoder.decode(response.Payload));\n },\n canUse: params => {\n if (!params?.name) {\n return true;\n }\n const { name } = params;\n /**\n * In case we are invoking currently active lambda, let's use this plugin as well.\n * When invoking some other lambda, name starts with arn.\n */\n if (name === process.env.AWS_LAMBDA_FUNCTION_NAME) {\n return true;\n }\n return name.match(\"arn:\") !== null;\n }\n });\n\n plugin.name = \"handler-client\";\n\n return plugin;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAEO,MAAME,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,MAAMC,MAAM,GAAG,IAAIC,kCAAmB,CAAC;IACnCC,MAAM,EAAE,MAAMC,MAAM,IAAI;MACpB,MAAM;QAAEC,KAAK,EAAEC,QAAQ;QAAEC,IAAI;QAAEC;MAAQ,CAAC,GAAGJ,MAAM;MACjD,MAAMK,YAAY,GAAG,IAAIC,0BAAY,CAAC;QAClCC,MAAM,EAAEC,OAAO,CAACC,GAAG,CAACC;MACxB,CAAC,CAAC;MACF,MAAMC,QAAQ,GAAG,MAAMN,YAAY,CAACO,IAAI,CACpC,IAAIC,2BAAa,CAAC;QACdC,YAAY,EAAEX,IAAI;QAClBY,cAAc,EAAEb,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,iBAAiB;QAChEc,OAAO,EAAEC,IAAI,CAACC,SAAS,CAACd,OAAO;MACnC,CAAC,CACL,CAAC;MAED,IAAIF,QAAQ,KAAK,KAAK,EAAE;QACpB,OAAO,IAAI;MACf;MAEA,MAAMiB,OAAO,GAAG,IAAIC,WAAW,CAAC,OAAO,CAAC;MACxC,OAAOH,IAAI,CAACI,KAAK,CAACF,OAAO,CAACG,MAAM,CAACX,QAAQ,CAACK,OAAO,CAAC,CAAC;IACvD,CAAC;IACDO,MAAM,EAAEvB,MAAM,IAAI;MACd,IAAI,CAACA,MAAM,EAAEG,IAAI,EAAE;QACf,OAAO,IAAI;MACf;MACA,MAAM;QAAEA;MAAK,CAAC,GAAGH,MAAM;MACvB;AACZ;AACA;AACA;MACY,IAAIG,IAAI,KAAKK,OAAO,CAACC,GAAG,CAACe,wBAAwB,EAAE;QAC/C,OAAO,IAAI;MACf;MACA,OAAOrB,IAAI,CAACsB,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI;IACtC;EACJ,CAAC,CAAC;EAEF5B,MAAM,CAACM,IAAI,GAAG,gBAAgB;EAE9B,OAAON,MAAM;AACjB,CAAC;AAAC6B,OAAA,CAAA9B,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
package/plugins/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Context } from "@webiny/handler/types";
|
|
1
|
+
import type { Context } from "@webiny/handler/types";
|
|
2
2
|
export declare const registerDefaultPlugins: (context: Context) => void;
|
package/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_handlerClient","require","registerDefaultPlugins","context","plugins","register","createHandlerClientPlugin","exports"],"sources":["index.ts"],"sourcesContent":["import { createHandlerClientPlugin } from \"./handlerClient\";\nimport { 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"}
|
|
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
CHANGED
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
*
|
|
5
5
|
* We should try to have some kind of standardized event type implementation at some point.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
|
|
7
|
+
import type { APIGatewayProxyResult, Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
8
|
+
import type { CreateHandlerParams as BaseCreateHandlerParams } from "@webiny/handler";
|
|
10
9
|
export interface HandlerCallable<Payload, Response = APIGatewayProxyResult> {
|
|
11
10
|
(payload: Payload, context: LambdaContext): Promise<Response>;
|
|
12
11
|
}
|
|
13
|
-
export
|
|
12
|
+
export type CreateHandlerParams = BaseCreateHandlerParams;
|
|
14
13
|
export declare const createHandler: <Payload = any, Response_1 = APIGatewayProxyResult>(params: CreateHandlerParams) => HandlerCallable<Payload, Response_1>;
|
|
15
14
|
export * from "./plugins/RawEventHandler";
|
package/raw/index.js
CHANGED
|
@@ -48,7 +48,16 @@ const createHandler = params => {
|
|
|
48
48
|
/**
|
|
49
49
|
* There must be an event plugin for this handler to work.
|
|
50
50
|
*/
|
|
51
|
-
const plugins = app.webiny.plugins.byType(_RawEventHandler.RawEventHandler.type).
|
|
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();
|
|
52
61
|
if (plugins.length === 0) {
|
|
53
62
|
throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);
|
|
54
63
|
}
|
package/raw/index.js.map
CHANGED
|
@@ -1 +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","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 {
|
|
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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MAAM,CAACC,SAAS,KAAK,UAAU,EAAE;QACxC,OAAO,IAAI;MACf;MACA,OAAOD,MAAM,CAACC,SAAS,CAACf,OAAO,CAAC;IACpC,CAAC,CAAC,CACDgB,OAAO,CAAC,CAAC;IACd,IAAIP,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":[]}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import { Context as
|
|
2
|
-
import { Context as
|
|
3
|
-
import {
|
|
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";
|
|
4
5
|
export interface RawEventHandlerCallableParams<Event, Context extends BaseContext> extends EventPluginCallableParams<Event, Context> {
|
|
5
6
|
lambdaContext: LambdaContext;
|
|
6
7
|
}
|
|
7
8
|
export interface RawEventHandlerCallable<Event, Context extends BaseContext, Response> {
|
|
8
9
|
(params: RawEventHandlerCallableParams<Event, Context>): Promise<Response | Reply>;
|
|
9
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>;
|
|
10
16
|
export declare class RawEventHandler<Event = any, Context extends BaseContext = BaseContext, Response = any> extends EventPlugin<Event, Context, Response> {
|
|
11
|
-
|
|
17
|
+
private readonly params;
|
|
18
|
+
constructor(params: RawEventHandlerParams<Event, Context, Response>);
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
canHandle(event: Event): boolean;
|
|
12
23
|
}
|
|
13
|
-
export declare const createEventHandler: <Event_1 = any, Context extends BaseContext = BaseContext, Response_1 = any>(
|
|
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>;
|