@webiny/handler-aws 0.0.0-unstable.bca7b3e350 → 0.0.0-unstable.c27f4d8a31
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 +29 -0
- package/createHandler.js.map +1 -0
- package/dynamodb/index.d.ts +5 -8
- package/dynamodb/index.js +26 -56
- package/dynamodb/index.js.map +1 -1
- package/dynamodb/plugins/DynamoDBEventHandler.d.ts +8 -7
- package/dynamodb/plugins/DynamoDBEventHandler.js +5 -22
- package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
- package/dynamodb/register.d.ts +1 -0
- package/dynamodb/register.js +26 -0
- package/dynamodb/register.js.map +1 -0
- package/eventBridge/index.d.ts +7 -10
- package/eventBridge/index.js +27 -57
- package/eventBridge/index.js.map +1 -1
- package/eventBridge/plugins/EventBridgeEventHandler.d.ts +8 -7
- package/eventBridge/plugins/EventBridgeEventHandler.js +5 -22
- package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
- package/eventBridge/register.d.ts +4 -0
- package/eventBridge/register.js +19 -0
- package/eventBridge/register.js.map +1 -0
- package/execute.d.ts +1 -1
- package/execute.js +18 -23
- package/execute.js.map +1 -1
- package/gateway/index.d.ts +7 -11
- package/gateway/index.js +27 -57
- package/gateway/index.js.map +1 -1
- package/gateway/register.d.ts +1 -0
- package/gateway/register.js +19 -0
- package/gateway/register.js.map +1 -0
- package/index.d.ts +35 -6
- package/index.js +41 -238
- package/index.js.map +1 -1
- package/package.json +15 -22
- package/plugins/handlerClient.js +11 -27
- package/plugins/handlerClient.js.map +1 -1
- 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 +32 -57
- package/raw/index.js.map +1 -1
- package/raw/plugins/RawEventHandler.d.ts +17 -6
- package/raw/plugins/RawEventHandler.js +21 -18
- package/raw/plugins/RawEventHandler.js.map +1 -1
- package/registry.d.ts +17 -0
- package/registry.js +38 -0
- package/registry.js.map +1 -0
- package/s3/index.d.ts +6 -9
- package/s3/index.js +29 -59
- package/s3/index.js.map +1 -1
- package/s3/plugins/S3EventHandler.d.ts +8 -7
- package/s3/plugins/S3EventHandler.js +5 -22
- package/s3/plugins/S3EventHandler.js.map +1 -1
- package/s3/register.d.ts +4 -0
- package/s3/register.js +23 -0
- package/s3/register.js.map +1 -0
- package/sns/index.d.ts +8 -0
- package/sns/index.js +57 -0
- package/sns/index.js.map +1 -0
- package/sns/plugins/SNSEventHandler.d.ts +20 -0
- package/sns/plugins/SNSEventHandler.js +13 -0
- package/sns/plugins/SNSEventHandler.js.map +1 -0
- package/sns/register.d.ts +1 -0
- package/sns/register.js +23 -0
- package/sns/register.js.map +1 -0
- package/sourceHandler.d.ts +2 -0
- package/sourceHandler.js +5 -0
- package/sourceHandler.js.map +1 -0
- package/sqs/index.d.ts +6 -9
- package/sqs/index.js +33 -60
- package/sqs/index.js.map +1 -1
- package/sqs/plugins/SQSEventHandler.d.ts +8 -7
- package/sqs/plugins/SQSEventHandler.js +5 -22
- package/sqs/plugins/SQSEventHandler.js.map +1 -1
- package/sqs/register.d.ts +1 -0
- package/sqs/register.js +26 -0
- package/sqs/register.js.map +1 -0
- package/types.d.ts +28 -5
- package/types.js +7 -30
- package/types.js.map +1 -1
- package/utils/composedHandler.d.ts +6 -0
- package/utils/composedHandler.js +17 -0
- package/utils/composedHandler.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +4 -0
- package/utils/index.js.map +1 -0
- package/utils/timer/CustomTimer.d.ts +5 -0
- package/utils/timer/CustomTimer.js +12 -0
- package/utils/timer/CustomTimer.js.map +1 -0
- package/utils/timer/Timer.d.ts +10 -0
- package/utils/timer/Timer.js +17 -0
- package/utils/timer/Timer.js.map +1 -0
- package/utils/timer/abstractions/ITimer.d.ts +10 -0
- package/utils/timer/abstractions/ITimer.js +3 -0
- package/utils/timer/abstractions/ITimer.js.map +1 -0
- package/utils/timer/factory.d.ts +4 -0
- package/utils/timer/factory.js +13 -0
- package/utils/timer/factory.js.map +1 -0
- package/utils/timer/index.d.ts +4 -0
- package/utils/timer/index.js +5 -0
- package/utils/timer/index.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["registry","createSourceHandler","createHandler","handler","name","canUse","event","source","handle","params","context","register"],"sources":["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"],"mappings":"AACA,SAASA,QAAQ;AAEjB,SAASC,mBAAmB;AAC5B,SAASC,aAAa;AAMtB,MAAMC,OAAO,GAAGF,mBAAmB,CAAkD;EACjFG,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,OAAOR,aAAa,CAACO,MAAM,CAAC,CAACH,KAAK,EAAEI,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFV,QAAQ,CAACW,QAAQ,CAACR,OAAO,CAAC","ignoreList":[]}
|
package/execute.d.ts
CHANGED
package/execute.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.execute = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
|
-
var _types = require("./types");
|
|
13
|
-
|
|
1
|
+
import { Base64EncodeHeader } from "./types.js";
|
|
14
2
|
const createHandleResponse = (app, resolve) => {
|
|
15
3
|
return (err, result) => {
|
|
16
4
|
if (err) {
|
|
@@ -20,12 +8,18 @@ const createHandleResponse = (app, resolve) => {
|
|
|
20
8
|
headers: {}
|
|
21
9
|
});
|
|
22
10
|
}
|
|
23
|
-
|
|
24
11
|
if (app.__webiny_raw_result) {
|
|
25
12
|
return resolve(app.__webiny_raw_result);
|
|
13
|
+
} else if (!result) {
|
|
14
|
+
const response = {
|
|
15
|
+
statusCode: 200,
|
|
16
|
+
body: "",
|
|
17
|
+
headers: {},
|
|
18
|
+
isBase64Encoded: false
|
|
19
|
+
};
|
|
20
|
+
return resolve(response);
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
const isBase64Encoded = !!result.headers[_types.Base64EncodeHeader.encoded] || !!result.headers[_types.Base64EncodeHeader.binary];
|
|
22
|
+
const isBase64Encoded = !!result.headers[Base64EncodeHeader.encoded] || !!result.headers[Base64EncodeHeader.binary];
|
|
29
23
|
const response = {
|
|
30
24
|
statusCode: result.statusCode,
|
|
31
25
|
body: isBase64Encoded ? result.rawPayload.toString("base64") : result.payload,
|
|
@@ -35,17 +29,17 @@ const createHandleResponse = (app, resolve) => {
|
|
|
35
29
|
return resolve(response);
|
|
36
30
|
};
|
|
37
31
|
};
|
|
38
|
-
|
|
39
32
|
const getPayloadProperty = (payload, prop, defaults = {}) => {
|
|
40
|
-
if (typeof payload === "object") {
|
|
33
|
+
if (payload && typeof payload === "object") {
|
|
41
34
|
const value = payload[prop] ? payload[prop] : {};
|
|
42
|
-
return
|
|
35
|
+
return {
|
|
36
|
+
...defaults,
|
|
37
|
+
...value
|
|
38
|
+
};
|
|
43
39
|
}
|
|
44
|
-
|
|
45
40
|
return defaults;
|
|
46
41
|
};
|
|
47
|
-
|
|
48
|
-
const execute = params => {
|
|
42
|
+
export const execute = params => {
|
|
49
43
|
const {
|
|
50
44
|
app,
|
|
51
45
|
url,
|
|
@@ -61,6 +55,7 @@ const execute = params => {
|
|
|
61
55
|
method: "POST",
|
|
62
56
|
url,
|
|
63
57
|
payload: payload || {},
|
|
58
|
+
body: payload || {},
|
|
64
59
|
query,
|
|
65
60
|
headers,
|
|
66
61
|
cookies
|
|
@@ -68,4 +63,4 @@ const execute = params => {
|
|
|
68
63
|
});
|
|
69
64
|
};
|
|
70
65
|
|
|
71
|
-
|
|
66
|
+
//# sourceMappingURL=execute.js.map
|
package/execute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createHandleResponse","app","resolve","err","result","statusCode","body","JSON","stringify","headers","__webiny_raw_result","
|
|
1
|
+
{"version":3,"names":["Base64EncodeHeader","createHandleResponse","app","resolve","err","result","statusCode","body","JSON","stringify","headers","__webiny_raw_result","response","isBase64Encoded","encoded","binary","rawPayload","toString","payload","getPayloadProperty","prop","defaults","value","execute","params","url","query","cookies","Promise","inject","method"],"sources":["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"],"mappings":"AAGA,SAASA,kBAAkB;AAK3B,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,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C,CAAC;EACtD,MAAMR,OAAO,GAAGS,kBAAkB,CAACD,OAAO,EAAE,SAAS,EAAE;IACnD,CAAC,cAAc,GAAG;EACtB,CAAC,CAAC;EAEF,MAAMS,OAAO,GAAGR,kBAAkB,CAACD,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;EAE1D,OAAO,IAAIU,OAAO,CAACzB,OAAO,IAAI;IAC1BD,GAAG,CAAC2B,MAAM,CACN;MACIC,MAAM,EAAE,MAAM;MACdL,GAAG;MACHP,OAAO,EAAEA,OAAO,IAAI,CAAC,CAAC;MACtBX,IAAI,EAAEW,OAAO,IAAI,CAAC,CAAC;MACnBQ,KAAK;MACLhB,OAAO;MACPiB;IACJ,CAAC,EACD1B,oBAAoB,CAACC,GAAG,EAAEC,OAAO,CACrC,CAAC;EACL,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
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,53 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
value: true
|
|
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
|
-
|
|
1
|
+
import awsLambdaFastify from "@fastify/aws-lambda";
|
|
2
|
+
import { createHandler as createBaseHandler, createRoute, RoutePlugin } from "@webiny/handler";
|
|
3
|
+
import { registerDefaultPlugins } from "../plugins/index.js";
|
|
4
|
+
import { Base64EncodeHeader } from "../types.js";
|
|
5
|
+
export { RoutePlugin, createRoute };
|
|
32
6
|
const getHeader = (headers, header) => {
|
|
33
7
|
for (const key in headers) {
|
|
34
8
|
if (key.toLowerCase() !== header) {
|
|
35
9
|
continue;
|
|
36
10
|
}
|
|
37
|
-
|
|
38
11
|
return headers[key];
|
|
39
12
|
}
|
|
40
|
-
|
|
41
13
|
return undefined;
|
|
42
14
|
};
|
|
43
|
-
|
|
44
15
|
const defaultContentType = "application/json";
|
|
45
16
|
const defaultCharset = "utf-8";
|
|
46
17
|
/**
|
|
47
18
|
* We need to attach default headers to the request, so it does not break if there is none sent.
|
|
48
19
|
*/
|
|
49
|
-
|
|
50
20
|
const attachRequiredProperties = event => {
|
|
21
|
+
const isOptions = event.httpMethod.toLowerCase() === "options";
|
|
51
22
|
/**
|
|
52
23
|
* A possibility that headers are not defined?
|
|
53
24
|
* Maybe during testing?
|
|
@@ -55,52 +26,51 @@ const attachRequiredProperties = event => {
|
|
|
55
26
|
if (!event.headers) {
|
|
56
27
|
event.headers = {};
|
|
57
28
|
}
|
|
58
|
-
|
|
59
29
|
const contentType = getHeader(event.headers, "content-type");
|
|
60
30
|
/**
|
|
61
31
|
* We check the existing content type and add the default one if it does not exist.
|
|
62
32
|
*
|
|
63
33
|
* Also, if the content-type is the application/json, and the body is not sent, we add it.
|
|
64
34
|
*/
|
|
65
|
-
|
|
66
35
|
if (!contentType) {
|
|
67
36
|
event.headers["content-type"] = [defaultContentType, `charset=${defaultCharset}`].join(";");
|
|
68
37
|
event.body = "{}";
|
|
69
38
|
} else if (!event.body && contentType.startsWith(defaultContentType)) {
|
|
70
39
|
event.body = "{}";
|
|
71
40
|
}
|
|
41
|
+
if (!isOptions) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
event.body = null;
|
|
72
45
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}));
|
|
46
|
+
export const createHandler = params => {
|
|
47
|
+
return async (event, context) => {
|
|
48
|
+
const app = createBaseHandler({
|
|
49
|
+
...params,
|
|
50
|
+
options: {
|
|
51
|
+
logger: params.debug === true,
|
|
52
|
+
...(params.options || {})
|
|
53
|
+
}
|
|
54
|
+
});
|
|
83
55
|
/**
|
|
84
56
|
* We always must add our default plugins to the app.
|
|
85
57
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (app.webiny.plugins.byType(_handler.RoutePlugin.type).length === 0) {
|
|
58
|
+
registerDefaultPlugins(app.webiny);
|
|
59
|
+
if (app.webiny.plugins.byType(RoutePlugin.type).length === 0) {
|
|
90
60
|
throw new Error(`To run @webiny/handler-aws/gateway, you must have at least one RoutePlugin set.`);
|
|
91
61
|
}
|
|
92
|
-
|
|
93
62
|
attachRequiredProperties(event);
|
|
94
|
-
const appLambda = (
|
|
63
|
+
const appLambda = awsLambdaFastify(app, {
|
|
95
64
|
decorateRequest: true,
|
|
96
65
|
serializeLambdaArguments: true,
|
|
97
66
|
decorationPropertyName: "awsLambda",
|
|
98
67
|
enforceBase64: response => {
|
|
99
|
-
return !!response.headers[
|
|
100
|
-
}
|
|
101
|
-
|
|
68
|
+
return !!response.headers[Base64EncodeHeader.encoded] || !!response.headers[Base64EncodeHeader.binary];
|
|
69
|
+
},
|
|
70
|
+
...(params.lambdaOptions || {})
|
|
71
|
+
});
|
|
102
72
|
return appLambda(event, context);
|
|
103
73
|
};
|
|
104
74
|
};
|
|
105
75
|
|
|
106
|
-
|
|
76
|
+
//# sourceMappingURL=index.js.map
|
package/gateway/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getHeader","headers","header","key","toLowerCase","undefined","defaultContentType","defaultCharset","attachRequiredProperties","event","contentType","join","body","startsWith","
|
|
1
|
+
{"version":3,"names":["awsLambdaFastify","createHandler","createBaseHandler","createRoute","RoutePlugin","registerDefaultPlugins","Base64EncodeHeader","getHeader","headers","header","key","toLowerCase","undefined","defaultContentType","defaultCharset","attachRequiredProperties","event","isOptions","httpMethod","contentType","join","body","startsWith","params","context","app","options","logger","debug","webiny","plugins","byType","type","length","Error","appLambda","decorateRequest","serializeLambdaArguments","decorationPropertyName","enforceBase64","response","encoded","binary","lambdaOptions"],"sources":["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"],"mappings":"AAMA,OAAOA,gBAAgB,MAAM,qBAAqB;AAClD,SAASC,aAAa,IAAIC,iBAAiB,EAAEC,WAAW,EAAEC,WAAW,QAAQ,iBAAiB;AAC9F,SAASC,sBAAsB;AAE/B,SAASC,kBAAkB;AAE3B,SAASF,WAAW,EAAED,WAAW;AAQjC,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,MAAMC,SAAS,GAAGD,KAAK,CAACE,UAAU,CAACP,WAAW,CAAC,CAAC,KAAK,SAAS;EAC9D;AACJ;AACA;AACA;EACI,IAAI,CAACK,KAAK,CAACR,OAAO,EAAE;IAChBQ,KAAK,CAACR,OAAO,GAAG,CAAC,CAAC;EACtB;EACA,MAAMW,WAAW,GAAGZ,SAAS,CAACS,KAAK,CAACR,OAAO,EAAE,cAAc,CAAC;EAC5D;AACJ;AACA;AACA;AACA;EACI,IAAI,CAACW,WAAW,EAAE;IACdH,KAAK,CAACR,OAAO,CAAC,cAAc,CAAC,GAAG,CAACK,kBAAkB,EAAE,WAAWC,cAAc,EAAE,CAAC,CAACM,IAAI,CAAC,GAA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C;IAClC,CAAC,CAAC;IACF,OAAOR,SAAS,CAACnB,KAAK,EAAEQ,OAAO,CAAC;EACpC,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
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 => {
|
|
7
|
+
return !!event.httpMethod;
|
|
8
|
+
},
|
|
9
|
+
handle: async ({
|
|
10
|
+
params,
|
|
11
|
+
event,
|
|
12
|
+
context
|
|
13
|
+
}) => {
|
|
14
|
+
return createHandler(params)(event, context);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
registry.register(handler);
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["registry","createSourceHandler","createHandler","handler","name","canUse","event","httpMethod","handle","params","context","register"],"sources":["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"],"mappings":"AACA,SAASA,QAAQ;AACjB,SAASC,mBAAmB;AAE5B,SAASC,aAAa;AAEtB,MAAMC,OAAO,GAAGF,mBAAmB,CAAiC;EAChEG,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,OAAOR,aAAa,CAACO,MAAM,CAAC,CAACH,KAAK,EAAEI,OAAO,CAAC;EAChD;AACJ,CAAC,CAAC;AAEFV,QAAQ,CAACW,QAAQ,CAACR,OAAO,CAAC","ignoreList":[]}
|
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";
|