@webiny/handler-aws 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -14
- package/createHandler.d.ts +2 -0
- package/createHandler.js +23 -0
- package/createHandler.js.map +1 -0
- package/dynamodb/index.d.ts +5 -8
- package/dynamodb/index.js +41 -87
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +8 -7
- package/dynamodb/plugins/DynamoDBEventHandler.js +12 -28
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.d.ts +1 -0
- package/dynamodb/register.js +16 -0
- package/dynamodb/register.js.map +1 -0
- package/eventBridge/index.d.ts +7 -10
- package/eventBridge/index.js +42 -88
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +8 -7
- package/eventBridge/plugins/EventBridgeEventHandler.js +12 -28
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +4 -0
- package/eventBridge/register.js +11 -0
- package/eventBridge/register.js.map +1 -0
- package/execute.d.ts +1 -1
- package/execute.js +54 -67
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +7 -11
- package/gateway/index.js +43 -102
- package/gateway/index.js.map +1 -1
- package/gateway/register.d.ts +1 -0
- package/gateway/register.js +11 -0
- package/gateway/register.js.map +1 -0
- package/index.d.ts +35 -6
- package/index.js +17 -245
- package/package.json +22 -25
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +4 -12
- package/plugins/index.js.map +1 -1
- package/raw/index.d.ts +5 -10
- package/raw/index.js +44 -95
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +17 -6
- package/raw/plugins/RawEventHandler.js +14 -21
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +17 -0
- package/registry.js +23 -0
- package/registry.js.map +1 -0
- package/s3/index.d.ts +6 -9
- package/s3/index.js +41 -87
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +8 -7
- package/s3/plugins/S3EventHandler.js +12 -28
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +4 -0
- package/s3/register.js +15 -0
- package/s3/register.js.map +1 -0
- package/sns/index.d.ts +8 -0
- package/sns/index.js +42 -0
- package/sns/index.js.map +1 -0
- package/sns/plugins/SNSEventHandler.d.ts +20 -0
- package/sns/plugins/SNSEventHandler.js +14 -0
- package/sns/plugins/SNSEventHandler.js.map +1 -0
- package/sns/register.d.ts +1 -0
- package/sns/register.js +15 -0
- package/sns/register.js.map +1 -0
- package/sourceHandler.d.ts +2 -0
- package/sourceHandler.js +4 -0
- package/sourceHandler.js.map +1 -0
- package/sqs/index.d.ts +6 -9
- package/sqs/index.js +42 -87
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +8 -7
- package/sqs/plugins/SQSEventHandler.js +12 -28
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.d.ts +1 -0
- package/sqs/register.js +16 -0
- package/sqs/register.js.map +1 -0
- package/types.d.ts +28 -5
- package/types.js +10 -32
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +6 -0
- package/utils/composedHandler.js +8 -0
- package/utils/composedHandler.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +2 -0
- package/utils/timer/CustomTimer.d.ts +5 -0
- package/utils/timer/CustomTimer.js +13 -0
- package/utils/timer/CustomTimer.js.map +1 -0
- package/utils/timer/Timer.d.ts +10 -0
- package/utils/timer/Timer.js +16 -0
- package/utils/timer/Timer.js.map +1 -0
- package/utils/timer/abstractions/ITimer.d.ts +10 -0
- package/utils/timer/abstractions/ITimer.js +0 -0
- package/utils/timer/factory.d.ts +4 -0
- package/utils/timer/factory.js +12 -0
- package/utils/timer/factory.js.map +1 -0
- package/utils/timer/index.d.ts +4 -0
- package/utils/timer/index.js +3 -0
- package/index.js.map +0 -1
- package/plugins/handlerClient.d.ts +0 -2
- package/plugins/handlerClient.js +0 -62
- package/plugins/handlerClient.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"eventBridge/plugins/EventBridgeEventHandler.js","sources":["../../../src/eventBridge/plugins/EventBridgeEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext, EventBridgeEvent } 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 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"],"names":["EventBridgeEventHandler","Plugin","cb","createEventHandler"],"mappings":";AA0BO,MAAMA,gCAIHC;;aACiB,IAAI,GAAG;;IAI9B,YAAmBC,EAAiE,CAAE;QAClF,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,qBAAqB,CAC9BD,KAEO,IAAIF,wBAAsDE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { registry } from "../registry.js";
|
|
2
|
+
import { createSourceHandler } from "../sourceHandler.js";
|
|
3
|
+
import { createHandler } from "./index.js";
|
|
4
|
+
const handler = createSourceHandler({
|
|
5
|
+
name: "handler-aws-event-bridge",
|
|
6
|
+
canUse: (event)=>!!event.source,
|
|
7
|
+
handle: async ({ params, event, context })=>createHandler(params)(event, context)
|
|
8
|
+
});
|
|
9
|
+
registry.register(handler);
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventBridge/register.js","sources":["../../src/eventBridge/register.ts"],"sourcesContent":["import type { EventBridgeEvent } 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 \"~/eventBridge/index.js\";\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"],"names":["handler","createSourceHandler","event","params","context","createHandler","registry"],"mappings":";;;AAUA,MAAMA,UAAUC,oBAAqE;IACjF,MAAM;IACN,QAAQC,CAAAA,QACG,CAAC,CAACA,MAAM,MAAM;IAEzB,QAAQ,OAAO,EAAEC,MAAM,EAAED,KAAK,EAAEE,OAAO,EAAE,GAC9BC,cAAcF,QAAQD,OAAOE;AAE5C;AAEAE,SAAS,QAAQ,CAACN"}
|
package/execute.d.ts
CHANGED
package/execute.js
CHANGED
|
@@ -1,71 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const isBase64Encoded = !!result.headers[_types.Base64EncodeHeader.encoded] || !!result.headers[_types.Base64EncodeHeader.binary];
|
|
29
|
-
const response = {
|
|
30
|
-
statusCode: result.statusCode,
|
|
31
|
-
body: isBase64Encoded ? result.rawPayload.toString("base64") : result.payload,
|
|
32
|
-
headers: result.headers,
|
|
33
|
-
isBase64Encoded
|
|
1
|
+
import { Base64EncodeHeader } from "./types.js";
|
|
2
|
+
const createHandleResponse = (app, resolve)=>(err, result)=>{
|
|
3
|
+
if (err) return resolve({
|
|
4
|
+
statusCode: 500,
|
|
5
|
+
body: JSON.stringify(err),
|
|
6
|
+
headers: {}
|
|
7
|
+
});
|
|
8
|
+
if (app.__webiny_raw_result) return resolve(app.__webiny_raw_result);
|
|
9
|
+
if (!result) {
|
|
10
|
+
const response = {
|
|
11
|
+
statusCode: 200,
|
|
12
|
+
body: "",
|
|
13
|
+
headers: {},
|
|
14
|
+
isBase64Encoded: false
|
|
15
|
+
};
|
|
16
|
+
return resolve(response);
|
|
17
|
+
}
|
|
18
|
+
const isBase64Encoded = !!result.headers[Base64EncodeHeader.encoded] || !!result.headers[Base64EncodeHeader.binary];
|
|
19
|
+
const response = {
|
|
20
|
+
statusCode: result.statusCode,
|
|
21
|
+
body: isBase64Encoded ? result.rawPayload.toString("base64") : result.payload,
|
|
22
|
+
headers: result.headers,
|
|
23
|
+
isBase64Encoded
|
|
24
|
+
};
|
|
25
|
+
return resolve(response);
|
|
34
26
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return defaults;
|
|
27
|
+
const getPayloadProperty = (payload, prop, defaults = {})=>{
|
|
28
|
+
if (payload && "object" == typeof payload) {
|
|
29
|
+
const value = payload[prop] ? payload[prop] : {};
|
|
30
|
+
return {
|
|
31
|
+
...defaults,
|
|
32
|
+
...value
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return defaults;
|
|
46
36
|
};
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
headers,
|
|
66
|
-
cookies
|
|
67
|
-
}, createHandleResponse(app, resolve));
|
|
68
|
-
});
|
|
37
|
+
const execute = (params)=>{
|
|
38
|
+
const { app, url, payload } = params;
|
|
39
|
+
const query = getPayloadProperty(payload, "query", {});
|
|
40
|
+
const headers = getPayloadProperty(payload, "headers", {
|
|
41
|
+
["content-type"]: "application/json"
|
|
42
|
+
});
|
|
43
|
+
const cookies = getPayloadProperty(payload, "cookies", {});
|
|
44
|
+
return new Promise((resolve)=>{
|
|
45
|
+
app.inject({
|
|
46
|
+
method: "POST",
|
|
47
|
+
url,
|
|
48
|
+
payload: payload || {},
|
|
49
|
+
body: payload || {},
|
|
50
|
+
query,
|
|
51
|
+
headers,
|
|
52
|
+
cookies
|
|
53
|
+
}, createHandleResponse(app, resolve));
|
|
54
|
+
});
|
|
69
55
|
};
|
|
56
|
+
export { execute };
|
|
70
57
|
|
|
71
|
-
|
|
58
|
+
//# sourceMappingURL=execute.js.map
|
package/execute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"execute.js","sources":["../src/execute.ts"],"sourcesContent":["import type { FastifyInstance } from \"@webiny/handler/types.js\";\nimport type { APIGatewayProxyResult } from \"@webiny/aws-sdk/types/index.js\";\nimport type { LightMyRequestCallback } from \"fastify\";\nimport { Base64EncodeHeader } from \"~/types.js\";\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"],"names":["createHandleResponse","app","resolve","err","result","JSON","response","isBase64Encoded","Base64EncodeHeader","getPayloadProperty","payload","prop","defaults","value","execute","params","url","query","headers","cookies","Promise"],"mappings":";AAQA,MAAMA,uBAAuB,CAACC,KAAsBC,UACzC,CAACC,KAAKC;QACT,IAAID,KACA,OAAOD,QAAQ;YACX,YAAY;YACZ,MAAMG,KAAK,SAAS,CAACF;YACrB,SAAS,CAAC;QACd;QAEJ,IAAIF,IAAI,mBAAmB,EACvB,OAAOC,QAAQD,IAAI,mBAAmB;QACnC,IAAI,CAACG,QAAQ;YAChB,MAAME,WAAkC;gBACpC,YAAY;gBACZ,MAAM;gBACN,SAAS,CAAC;gBACV,iBAAiB;YACrB;YACA,OAAOJ,QAAQI;QACnB;QAEA,MAAMC,kBACF,CAAC,CAACH,OAAO,OAAO,CAACI,mBAAmB,OAAO,CAAC,IAC5C,CAAC,CAACJ,OAAO,OAAO,CAACI,mBAAmB,MAAM,CAAC;QAC/C,MAAMF,WAAkC;YACpC,YAAYF,OAAO,UAAU;YAC7B,MAAMG,kBAAkBH,OAAO,UAAU,CAAC,QAAQ,CAAC,YAAYA,OAAO,OAAO;YAC7E,SAASA,OAAO,OAAO;YACvBG;QACJ;QACA,OAAOL,QAAQI;IACnB;AAGJ,MAAMG,qBAAqB,CACvBC,SACAC,MACAC,WAAgC,CAAC,CAAC;IAElC,IAAIF,WAAW,AAAmB,YAAnB,OAAOA,SAAsB;QACxC,MAAMG,QAAQH,OAAO,CAACC,KAAK,GAAGD,OAAO,CAACC,KAAK,GAAG,CAAC;QAE/C,OAAO;YACH,GAAGC,QAAQ;YACX,GAAGC,KAAK;QACZ;IACJ;IACA,OAAOD;AACX;AAQO,MAAME,UAAU,CAACC;IACpB,MAAM,EAAEd,GAAG,EAAEe,GAAG,EAAEN,OAAO,EAAE,GAAGK;IAE9B,MAAME,QAAQR,mBAAmBC,SAAS,SAAS,CAAC;IACpD,MAAMQ,UAAUT,mBAAmBC,SAAS,WAAW;QACnD,CAAC,eAAe,EAAE;IACtB;IAEA,MAAMS,UAAUV,mBAAmBC,SAAS,WAAW,CAAC;IAExD,OAAO,IAAIU,QAAQlB,CAAAA;QACfD,IAAI,MAAM,CACN;YACI,QAAQ;YACRe;YACA,SAASN,WAAW,CAAC;YACrB,MAAMA,WAAW,CAAC;YAClBO;YACAC;YACAC;QACJ,GACAnB,qBAAqBC,KAAKC;IAElC;AACJ"}
|
package/gateway/index.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { APIGatewayEvent, Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
|
|
2
|
+
import type { LambdaResponse } from "@fastify/aws-lambda";
|
|
3
|
+
import { createRoute, RoutePlugin } from "@webiny/handler";
|
|
4
|
+
import type { HandlerFactoryParams } from "../types.js";
|
|
5
|
+
export { RoutePlugin, createRoute };
|
|
6
|
+
export type HandlerParams = HandlerFactoryParams;
|
|
4
7
|
export interface HandlerCallable {
|
|
5
8
|
(event: APIGatewayEvent, ctx: LambdaContext): Promise<LambdaResponse>;
|
|
6
9
|
}
|
|
7
|
-
export
|
|
8
|
-
http?: {
|
|
9
|
-
debug?: boolean;
|
|
10
|
-
};
|
|
11
|
-
lambdaOptions?: LambdaOptions;
|
|
12
|
-
}
|
|
13
|
-
export declare const createHandler: (params: CreateHandlerParams) => HandlerCallable;
|
|
14
|
-
export { RoutePlugin, createRoute };
|
|
10
|
+
export declare const createHandler: (params: HandlerParams) => HandlerCallable;
|
package/gateway/index.js
CHANGED
|
@@ -1,107 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
Object.defineProperty(exports, "RoutePlugin", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () {
|
|
11
|
-
return _handler.RoutePlugin;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
exports.createHandler = void 0;
|
|
15
|
-
Object.defineProperty(exports, "createRoute", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () {
|
|
18
|
-
return _handler.createRoute;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
23
|
-
|
|
24
|
-
var _awsLambda = _interopRequireDefault(require("@fastify/aws-lambda"));
|
|
25
|
-
|
|
26
|
-
var _handler = require("@webiny/handler");
|
|
27
|
-
|
|
28
|
-
var _plugins = require("../plugins");
|
|
29
|
-
|
|
30
|
-
var _types = require("../types");
|
|
31
|
-
|
|
32
|
-
const getHeader = (headers, header) => {
|
|
33
|
-
for (const key in headers) {
|
|
34
|
-
if (key.toLowerCase() !== header) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return headers[key];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return undefined;
|
|
1
|
+
import aws_lambda from "@fastify/aws-lambda";
|
|
2
|
+
import { RoutePlugin, createHandler, createRoute } from "@webiny/handler";
|
|
3
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
4
|
+
import { Base64EncodeHeader } from "../types.js";
|
|
5
|
+
const getHeader = (headers, header)=>{
|
|
6
|
+
for(const key in headers)if (key.toLowerCase() === header) return headers[key];
|
|
42
7
|
};
|
|
43
|
-
|
|
44
8
|
const defaultContentType = "application/json";
|
|
45
9
|
const defaultCharset = "utf-8";
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const contentType = getHeader(event.headers, "content-type");
|
|
60
|
-
/**
|
|
61
|
-
* We check the existing content type and add the default one if it does not exist.
|
|
62
|
-
*
|
|
63
|
-
* Also, if the content-type is the application/json, and the body is not sent, we add it.
|
|
64
|
-
*/
|
|
65
|
-
|
|
66
|
-
if (!contentType) {
|
|
67
|
-
event.headers["content-type"] = [defaultContentType, `charset=${defaultCharset}`].join(";");
|
|
68
|
-
event.body = "{}";
|
|
69
|
-
} else if (!event.body && contentType.startsWith(defaultContentType)) {
|
|
70
|
-
event.body = "{}";
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const createHandler = params => {
|
|
75
|
-
return (event, context) => {
|
|
76
|
-
var _params$http;
|
|
77
|
-
|
|
78
|
-
const app = (0, _handler.createHandler)({
|
|
79
|
-
plugins: params.plugins,
|
|
80
|
-
options: (0, _objectSpread2.default)({
|
|
81
|
-
logger: ((_params$http = params.http) === null || _params$http === void 0 ? void 0 : _params$http.debug) === true
|
|
82
|
-
}, params.options || {})
|
|
83
|
-
});
|
|
84
|
-
/**
|
|
85
|
-
* We always must add our default plugins to the app.
|
|
86
|
-
*/
|
|
87
|
-
|
|
88
|
-
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
89
|
-
|
|
90
|
-
if (app.webiny.plugins.byType(_handler.RoutePlugin.type).length === 0) {
|
|
91
|
-
throw new Error(`To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.`);
|
|
10
|
+
const attachRequiredProperties = (event)=>{
|
|
11
|
+
const isOptions = "options" === event.httpMethod.toLowerCase();
|
|
12
|
+
if (!event.headers) event.headers = {};
|
|
13
|
+
const contentType = getHeader(event.headers, "content-type");
|
|
14
|
+
if (contentType) {
|
|
15
|
+
if (!event.body && contentType.startsWith(defaultContentType)) event.body = "{}";
|
|
16
|
+
} else {
|
|
17
|
+
event.headers["content-type"] = [
|
|
18
|
+
defaultContentType,
|
|
19
|
+
`charset=${defaultCharset}`
|
|
20
|
+
].join(";");
|
|
21
|
+
event.body = "{}";
|
|
92
22
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const appLambda = (0, _awsLambda.default)(app, (0, _objectSpread2.default)({
|
|
96
|
-
decorateRequest: true,
|
|
97
|
-
serializeLambdaArguments: true,
|
|
98
|
-
decorationPropertyName: "awsLambda",
|
|
99
|
-
enforceBase64: response => {
|
|
100
|
-
return !!response.headers[_types.Base64EncodeHeader.encoded] || !!response.headers[_types.Base64EncodeHeader.binary];
|
|
101
|
-
}
|
|
102
|
-
}, params.lambdaOptions || {}));
|
|
103
|
-
return appLambda(event, context);
|
|
104
|
-
};
|
|
23
|
+
if (!isOptions) return;
|
|
24
|
+
event.body = null;
|
|
105
25
|
};
|
|
106
|
-
|
|
107
|
-
|
|
26
|
+
const gateway_createHandler = (params)=>async (event, context)=>{
|
|
27
|
+
const app = createHandler({
|
|
28
|
+
...params,
|
|
29
|
+
options: {
|
|
30
|
+
logger: true === params.debug,
|
|
31
|
+
...params.options || {}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
registerDefaultPlugins(app.webiny);
|
|
35
|
+
if (0 === app.webiny.plugins.byType(RoutePlugin.type).length) throw new Error("To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.");
|
|
36
|
+
attachRequiredProperties(event);
|
|
37
|
+
const appLambda = aws_lambda(app, {
|
|
38
|
+
decorateRequest: true,
|
|
39
|
+
serializeLambdaArguments: true,
|
|
40
|
+
decorationPropertyName: "awsLambda",
|
|
41
|
+
enforceBase64: (response)=>!!response.headers[Base64EncodeHeader.encoded] || !!response.headers[Base64EncodeHeader.binary],
|
|
42
|
+
...params.lambdaOptions || {}
|
|
43
|
+
});
|
|
44
|
+
return appLambda(event, context);
|
|
45
|
+
};
|
|
46
|
+
export { RoutePlugin, createRoute, gateway_createHandler as createHandler };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
package/gateway/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"gateway/index.js","sources":["../../src/gateway/index.ts"],"sourcesContent":["import type {\n APIGatewayEvent,\n APIGatewayProxyEventHeaders,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\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/index.js\";\nimport type { HandlerFactoryParams } from \"~/types.js\";\nimport { Base64EncodeHeader } from \"~/types.js\";\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 const isOptions = event.httpMethod.toLowerCase() === \"options\";\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 if (!isOptions) {\n return;\n }\n event.body = null;\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"],"names":["getHeader","headers","header","key","defaultContentType","defaultCharset","attachRequiredProperties","event","isOptions","contentType","createHandler","params","context","app","createBaseHandler","registerDefaultPlugins","RoutePlugin","Error","appLambda","awsLambdaFastify","response","Base64EncodeHeader"],"mappings":";;;;AAoBA,MAAMA,YAAY,CAACC,SAAsCC;IACrD,IAAK,MAAMC,OAAOF,QACd,IAAIE,IAAI,WAAW,OAAOD,QAG1B,OAAOD,OAAO,CAACE,IAAI;AAG3B;AAEA,MAAMC,qBAAqB;AAC3B,MAAMC,iBAAiB;AAIvB,MAAMC,2BAA2B,CAACC;IAC9B,MAAMC,YAAYD,AAAmC,cAAnCA,MAAM,UAAU,CAAC,WAAW;IAK9C,IAAI,CAACA,MAAM,OAAO,EACdA,MAAM,OAAO,GAAG,CAAC;IAErB,MAAME,cAAcT,UAAUO,MAAM,OAAO,EAAE;IAM7C,IAAKE,aAGE;QAAA,IAAI,CAACF,MAAM,IAAI,IAAIE,YAAY,UAAU,CAACL,qBAC7CG,MAAM,IAAI,GAAG;IACjB,OALkB;QACdA,MAAM,OAAO,CAAC,eAAe,GAAG;YAACH;YAAoB,CAAC,QAAQ,EAAEC,gBAAgB;SAAC,CAAC,IAAI,CAAC;QACvFE,MAAM,IAAI,GAAG;IACjB;IAGA,IAAI,CAACC,WACD;IAEJD,MAAM,IAAI,GAAG;AACjB;AAEO,MAAMG,wBAAgB,CAACC,SACnB,OAAOJ,OAAOK;QACjB,MAAMC,MAAMC,cAAkB;YAC1B,GAAGH,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAI,uBAAuBF,IAAI,MAAM;QAEjC,IAAIA,AAAoE,MAApEA,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAcG,YAAY,IAAI,EAAE,MAAM,EAC/D,MAAM,IAAIC,MACN;QAGRX,yBAAyBC;QAEzB,MAAMW,YAAYC,WAAiBN,KAAK;YACpC,iBAAiB;YACjB,0BAA0B;YAC1B,wBAAwB;YACxB,eAAeO,CAAAA,WAEP,CAAC,CAACA,SAAS,OAAO,CAACC,mBAAmB,OAAO,CAAC,IAC9C,CAAC,CAACD,SAAS,OAAO,CAACC,mBAAmB,MAAM,CAAC;YAGrD,GAAIV,OAAO,aAAa,IAAI,CAAC,CAAC;QAClC;QACA,OAAOO,UAAUX,OAAOK;IAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { registry } from "../registry.js";
|
|
2
|
+
import { createSourceHandler } from "../sourceHandler.js";
|
|
3
|
+
import { createHandler } from "./index.js";
|
|
4
|
+
const handler = createSourceHandler({
|
|
5
|
+
name: "handler-aws-api-gateway",
|
|
6
|
+
canUse: (event)=>!!event.httpMethod,
|
|
7
|
+
handle: async ({ params, event, context })=>createHandler(params)(event, context)
|
|
8
|
+
});
|
|
9
|
+
registry.register(handler);
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway/register.js","sources":["../../src/gateway/register.ts"],"sourcesContent":["import type { APIGatewayEvent } from \"@webiny/aws-sdk/types/index.js\";\nimport { registry } from \"~/registry.js\";\nimport { createSourceHandler } from \"~/sourceHandler.js\";\nimport type { HandlerParams } from \"./index.js\";\nimport { createHandler } from \"./index.js\";\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"],"names":["handler","createSourceHandler","event","params","context","createHandler","registry"],"mappings":";;;AAMA,MAAMA,UAAUC,oBAAoD;IAChE,MAAM;IACN,QAAQC,CAAAA,QACG,CAAC,CAACA,MAAM,UAAU;IAE7B,QAAQ,OAAO,EAAEC,MAAM,EAAED,KAAK,EAAEE,OAAO,EAAE,GAC9BC,cAAcF,QAAQD,OAAOE;AAE5C;AAEAE,SAAS,QAAQ,CAACN"}
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import "./gateway/register.js";
|
|
2
|
+
import "./s3/register.js";
|
|
3
|
+
import "./dynamodb/register.js";
|
|
4
|
+
import "./sqs/register.js";
|
|
5
|
+
import "./eventBridge/register.js";
|
|
6
|
+
import "./sns/register.js";
|
|
7
|
+
export * from "./utils/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* API Gateway
|
|
10
|
+
*/
|
|
11
|
+
export { createHandler as createApiGatewayHandler, type HandlerParams as CreateApiGatewayHandlerParams, type HandlerCallable as ApiGatewayHandlerCallable, RoutePlugin, createRoute as createApiGatewayRoute } from "./gateway/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* S3
|
|
14
|
+
*/
|
|
15
|
+
export { createHandler as createS3Handler, type HandlerParams as CreateS3HandlerParams, S3EventHandler, type S3EventHandlerCallable, type S3EventHandlerCallableParams, createEventHandler as createS3EventHandler } from "./s3/index.js";
|
|
16
|
+
/**
|
|
17
|
+
* DynamoDB Stream
|
|
18
|
+
*/
|
|
19
|
+
export { createHandler as createDynamoDBHandler, type HandlerParams as CreateDynamoDBHandlerParams, DynamoDBEventHandler, type DynamoDBEventHandlerCallable, type DynamoDBEventHandlerCallableParams, createEventHandler as createDynamoDBEventHandler } from "./dynamodb/index.js";
|
|
20
|
+
/**
|
|
21
|
+
* SQS
|
|
22
|
+
*/
|
|
23
|
+
export { createHandler as createSQSHandler, type HandlerParams as CreateSQSHandlerParams, SQSEventHandler, type SQSEventHandlerCallable, type SQSEventHandlerCallableParams, createEventHandler as createSQSEventHandler } from "./sqs/index.js";
|
|
24
|
+
/**
|
|
25
|
+
* SNS
|
|
26
|
+
*/
|
|
27
|
+
export { createHandler as createSNSHandler, type HandlerParams as CreateSNSHandlerParams, SNSEventHandler, type SNSEventHandlerCallable, type SNSEventHandlerCallableParams, createEventHandler as createSNSEventHandler } from "./sns/index.js";
|
|
28
|
+
/**
|
|
29
|
+
* EventBridge
|
|
30
|
+
*/
|
|
31
|
+
export { createHandler as createEventBridgeHandler, type HandlerParams as CreateEventBridgeHandlerParams, EventBridgeEventHandler, type EventBridgeEventHandlerCallable, type EventBridgeEventHandlerCallableParams, createEventHandler as createEventBridgeEventHandler } from "./eventBridge/index.js";
|
|
32
|
+
export { createHandler as createRawHandler, type CreateHandlerParams as CreateRawHandlerParams, type HandlerCallable as RawHandlerCallable, createEventHandler as createRawEventHandler, type RawEventHandlerCallableParams, type RawEventHandlerCallable, RawEventHandler } from "./raw/index.js";
|
|
33
|
+
export { ContextPlugin, createContextPlugin, type ContextPluginCallable } from "@webiny/handler";
|
|
34
|
+
export * from "./createHandler.js";
|
|
35
|
+
export * from "./sourceHandler.js";
|