@webiny/handler-aws 0.0.0-unstable.9bd236cf5e → 0.0.0-unstable.9f53ea597d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -14
- package/createHandler.d.ts +1 -1
- package/createHandler.js +20 -26
- package/createHandler.js.map +1 -1
- package/dynamodb/index.d.ts +3 -3
- package/dynamodb/index.js +39 -76
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +4 -4
- package/dynamodb/plugins/DynamoDBEventHandler.js +11 -18
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.js +13 -25
- package/dynamodb/register.js.map +1 -1
- package/eventBridge/index.d.ts +3 -3
- package/eventBridge/index.js +39 -76
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +4 -4
- package/eventBridge/plugins/EventBridgeEventHandler.js +11 -18
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +1 -1
- package/eventBridge/register.js +8 -18
- package/eventBridge/register.js.map +1 -1
- package/execute.d.ts +1 -1
- package/execute.js +53 -68
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +2 -2
- package/gateway/index.js +41 -83
- package/gateway/index.js.map +1 -1
- package/gateway/register.js +8 -18
- package/gateway/register.js.map +1 -1
- package/index.d.ts +17 -17
- package/index.js +17 -374
- package/package.json +22 -19
- package/plugins/index.d.ts +1 -1
- package/plugins/index.js +3 -10
- package/plugins/index.js.map +1 -1
- package/raw/index.d.ts +3 -3
- package/raw/index.js +42 -86
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +3 -3
- package/raw/plugins/RawEventHandler.js +12 -30
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +2 -2
- package/registry.js +17 -38
- package/registry.js.map +1 -1
- package/s3/index.d.ts +3 -3
- package/s3/index.js +39 -76
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +4 -4
- package/s3/plugins/S3EventHandler.js +11 -18
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +1 -1
- package/s3/register.js +12 -22
- package/s3/register.js.map +1 -1
- package/sns/index.d.ts +3 -3
- package/sns/index.js +39 -76
- package/sns/index.js.map +1 -1
- package/sns/plugins/SNSEventHandler.d.ts +4 -4
- package/sns/plugins/SNSEventHandler.js +11 -18
- package/sns/plugins/SNSEventHandler.js.map +1 -1
- package/sns/register.js +12 -22
- package/sns/register.js.map +1 -1
- package/sourceHandler.d.ts +2 -2
- package/sourceHandler.js +2 -10
- package/sourceHandler.js.map +1 -1
- package/sqs/index.d.ts +3 -3
- package/sqs/index.js +40 -79
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +4 -4
- package/sqs/plugins/SQSEventHandler.js +11 -18
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.js +13 -25
- package/sqs/register.js.map +1 -1
- package/types.d.ts +3 -3
- package/types.js +7 -34
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +1 -1
- package/utils/composedHandler.js +6 -22
- package/utils/composedHandler.js.map +1 -1
- package/utils/index.d.ts +2 -2
- package/utils/index.js +2 -29
- package/utils/timer/CustomTimer.js +8 -14
- package/utils/timer/CustomTimer.js.map +1 -1
- package/utils/timer/Timer.d.ts +1 -1
- package/utils/timer/Timer.js +11 -19
- package/utils/timer/Timer.js.map +1 -1
- package/utils/timer/abstractions/ITimer.js +0 -7
- package/utils/timer/factory.d.ts +2 -2
- package/utils/timer/factory.js +9 -17
- package/utils/timer/factory.js.map +1 -1
- package/utils/timer/index.d.ts +4 -4
- package/utils/timer/index.js +3 -51
- package/index.js.map +0 -1
- package/plugins/handlerClient.d.ts +0 -2
- package/plugins/handlerClient.js +0 -53
- package/plugins/handlerClient.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/timer/abstractions/ITimer.js.map +0 -1
- package/utils/timer/index.js.map +0 -1
package/eventBridge/register.js
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
canUse: event => {
|
|
9
|
-
return !!event.source;
|
|
10
|
-
},
|
|
11
|
-
handle: async ({
|
|
12
|
-
params,
|
|
13
|
-
event,
|
|
14
|
-
context
|
|
15
|
-
}) => {
|
|
16
|
-
return (0, _index.createHandler)(params)(event, context);
|
|
17
|
-
}
|
|
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)
|
|
18
8
|
});
|
|
19
|
-
|
|
9
|
+
registry.register(handler);
|
|
20
10
|
|
|
21
11
|
//# sourceMappingURL=register.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,73 +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
|
-
return resolve(response);
|
|
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
|
-
}
|
|
46
|
-
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;
|
|
47
36
|
};
|
|
48
|
-
const execute = params
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
headers,
|
|
67
|
-
cookies
|
|
68
|
-
}, createHandleResponse(app, resolve));
|
|
69
|
-
});
|
|
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
|
+
});
|
|
70
55
|
};
|
|
71
|
-
|
|
56
|
+
export { execute };
|
|
72
57
|
|
|
73
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,7 +1,7 @@
|
|
|
1
|
-
import type { APIGatewayEvent, Context as LambdaContext } from "@webiny/aws-sdk/types";
|
|
1
|
+
import type { APIGatewayEvent, Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
|
|
2
2
|
import type { LambdaResponse } from "@fastify/aws-lambda";
|
|
3
3
|
import { createRoute, RoutePlugin } from "@webiny/handler";
|
|
4
|
-
import type { HandlerFactoryParams } from "../types";
|
|
4
|
+
import type { HandlerFactoryParams } from "../types.js";
|
|
5
5
|
export { RoutePlugin, createRoute };
|
|
6
6
|
export type HandlerParams = HandlerFactoryParams;
|
|
7
7
|
export interface HandlerCallable {
|
package/gateway/index.js
CHANGED
|
@@ -1,90 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "RoutePlugin", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _handler.RoutePlugin;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
exports.createHandler = void 0;
|
|
14
|
-
Object.defineProperty(exports, "createRoute", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return _handler.createRoute;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
var _awsLambda = _interopRequireDefault(require("@fastify/aws-lambda"));
|
|
21
|
-
var _handler = require("@webiny/handler");
|
|
22
|
-
var _plugins = require("../plugins");
|
|
23
|
-
var _types = require("../types");
|
|
24
|
-
const getHeader = (headers, header) => {
|
|
25
|
-
for (const key in headers) {
|
|
26
|
-
if (key.toLowerCase() !== header) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
return headers[key];
|
|
30
|
-
}
|
|
31
|
-
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];
|
|
32
7
|
};
|
|
33
8
|
const defaultContentType = "application/json";
|
|
34
9
|
const defaultCharset = "utf-8";
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* We check the existing content type and add the default one if it does not exist.
|
|
49
|
-
*
|
|
50
|
-
* Also, if the content-type is the application/json, and the body is not sent, we add it.
|
|
51
|
-
*/
|
|
52
|
-
if (!contentType) {
|
|
53
|
-
event.headers["content-type"] = [defaultContentType, `charset=${defaultCharset}`].join(";");
|
|
54
|
-
event.body = "{}";
|
|
55
|
-
} else if (!event.body && contentType.startsWith(defaultContentType)) {
|
|
56
|
-
event.body = "{}";
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
const createHandler = params => {
|
|
60
|
-
return async (event, context) => {
|
|
61
|
-
const app = (0, _handler.createHandler)({
|
|
62
|
-
...params,
|
|
63
|
-
options: {
|
|
64
|
-
logger: params.debug === true,
|
|
65
|
-
...(params.options || {})
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
/**
|
|
69
|
-
* We always must add our default plugins to the app.
|
|
70
|
-
*/
|
|
71
|
-
(0, _plugins.registerDefaultPlugins)(app.webiny);
|
|
72
|
-
if (app.webiny.plugins.byType(_handler.RoutePlugin.type).length === 0) {
|
|
73
|
-
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 = "{}";
|
|
74
22
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
decorateRequest: true,
|
|
78
|
-
serializeLambdaArguments: true,
|
|
79
|
-
decorationPropertyName: "awsLambda",
|
|
80
|
-
enforceBase64: response => {
|
|
81
|
-
return !!response.headers[_types.Base64EncodeHeader.encoded] || !!response.headers[_types.Base64EncodeHeader.binary];
|
|
82
|
-
},
|
|
83
|
-
...(params.lambdaOptions || {})
|
|
84
|
-
});
|
|
85
|
-
return appLambda(event, context);
|
|
86
|
-
};
|
|
23
|
+
if (!isOptions) return;
|
|
24
|
+
event.body = null;
|
|
87
25
|
};
|
|
88
|
-
|
|
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 };
|
|
89
47
|
|
|
90
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"}
|
package/gateway/register.js
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
canUse: event => {
|
|
9
|
-
return !!event.httpMethod;
|
|
10
|
-
},
|
|
11
|
-
handle: async ({
|
|
12
|
-
params,
|
|
13
|
-
event,
|
|
14
|
-
context
|
|
15
|
-
}) => {
|
|
16
|
-
return (0, _index.createHandler)(params)(event, context);
|
|
17
|
-
}
|
|
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)
|
|
18
8
|
});
|
|
19
|
-
|
|
9
|
+
registry.register(handler);
|
|
20
10
|
|
|
21
11
|
//# sourceMappingURL=register.js.map
|
package/gateway/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,35 +1,35 @@
|
|
|
1
|
-
import "./gateway/register";
|
|
2
|
-
import "./s3/register";
|
|
3
|
-
import "./dynamodb/register";
|
|
4
|
-
import "./sqs/register";
|
|
5
|
-
import "./eventBridge/register";
|
|
6
|
-
import "./sns/register";
|
|
7
|
-
export * from "./utils";
|
|
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
8
|
/**
|
|
9
9
|
* API Gateway
|
|
10
10
|
*/
|
|
11
|
-
export { createHandler as createApiGatewayHandler, HandlerParams as CreateApiGatewayHandlerParams, HandlerCallable as ApiGatewayHandlerCallable, RoutePlugin, createRoute as createApiGatewayRoute } from "./gateway";
|
|
11
|
+
export { createHandler as createApiGatewayHandler, type HandlerParams as CreateApiGatewayHandlerParams, type HandlerCallable as ApiGatewayHandlerCallable, RoutePlugin, createRoute as createApiGatewayRoute } from "./gateway/index.js";
|
|
12
12
|
/**
|
|
13
13
|
* S3
|
|
14
14
|
*/
|
|
15
|
-
export { createHandler as createS3Handler, HandlerParams as CreateS3HandlerParams, S3EventHandler, S3EventHandlerCallable, S3EventHandlerCallableParams, createEventHandler as createS3EventHandler } from "./s3";
|
|
15
|
+
export { createHandler as createS3Handler, type HandlerParams as CreateS3HandlerParams, S3EventHandler, type S3EventHandlerCallable, type S3EventHandlerCallableParams, createEventHandler as createS3EventHandler } from "./s3/index.js";
|
|
16
16
|
/**
|
|
17
17
|
* DynamoDB Stream
|
|
18
18
|
*/
|
|
19
|
-
export { createHandler as createDynamoDBHandler, HandlerParams as CreateDynamoDBHandlerParams, DynamoDBEventHandler, DynamoDBEventHandlerCallable, DynamoDBEventHandlerCallableParams, createEventHandler as createDynamoDBEventHandler } from "./dynamodb";
|
|
19
|
+
export { createHandler as createDynamoDBHandler, type HandlerParams as CreateDynamoDBHandlerParams, DynamoDBEventHandler, type DynamoDBEventHandlerCallable, type DynamoDBEventHandlerCallableParams, createEventHandler as createDynamoDBEventHandler } from "./dynamodb/index.js";
|
|
20
20
|
/**
|
|
21
21
|
* SQS
|
|
22
22
|
*/
|
|
23
|
-
export { createHandler as createSQSHandler, HandlerParams as CreateSQSHandlerParams, SQSEventHandler, SQSEventHandlerCallable, SQSEventHandlerCallableParams, createEventHandler as createSQSEventHandler } from "./sqs";
|
|
23
|
+
export { createHandler as createSQSHandler, type HandlerParams as CreateSQSHandlerParams, SQSEventHandler, type SQSEventHandlerCallable, type SQSEventHandlerCallableParams, createEventHandler as createSQSEventHandler } from "./sqs/index.js";
|
|
24
24
|
/**
|
|
25
25
|
* SNS
|
|
26
26
|
*/
|
|
27
|
-
export { createHandler as createSNSHandler, HandlerParams as CreateSNSHandlerParams, SNSEventHandler, SNSEventHandlerCallable, SNSEventHandlerCallableParams, createEventHandler as createSNSEventHandler } from "./sns";
|
|
27
|
+
export { createHandler as createSNSHandler, type HandlerParams as CreateSNSHandlerParams, SNSEventHandler, type SNSEventHandlerCallable, type SNSEventHandlerCallableParams, createEventHandler as createSNSEventHandler } from "./sns/index.js";
|
|
28
28
|
/**
|
|
29
29
|
* EventBridge
|
|
30
30
|
*/
|
|
31
|
-
export { createHandler as createEventBridgeHandler, HandlerParams as CreateEventBridgeHandlerParams, EventBridgeEventHandler, EventBridgeEventHandlerCallable, EventBridgeEventHandlerCallableParams, createEventHandler as createEventBridgeEventHandler } from "./eventBridge";
|
|
32
|
-
export { createHandler as createRawHandler, CreateHandlerParams as CreateRawHandlerParams, HandlerCallable as RawHandlerCallable, createEventHandler as createRawEventHandler, RawEventHandlerCallableParams, RawEventHandlerCallable, RawEventHandler } from "./raw";
|
|
33
|
-
export { ContextPlugin, createContextPlugin, ContextPluginCallable } from "@webiny/handler";
|
|
34
|
-
export * from "./createHandler";
|
|
35
|
-
export * from "./sourceHandler";
|
|
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";
|