@webiny/handler-aws 6.3.0 → 6.4.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/createHandler.js +16 -22
  2. package/createHandler.js.map +1 -1
  3. package/dynamodb/index.js +34 -49
  4. package/dynamodb/index.js.map +1 -1
  5. package/dynamodb/plugins/DynamoDBEventHandler.js +10 -9
  6. package/dynamodb/plugins/DynamoDBEventHandler.js.map +1 -1
  7. package/dynamodb/register.js +8 -18
  8. package/dynamodb/register.js.map +1 -1
  9. package/eventBridge/index.js +34 -49
  10. package/eventBridge/index.js.map +1 -1
  11. package/eventBridge/plugins/EventBridgeEventHandler.js +10 -9
  12. package/eventBridge/plugins/EventBridgeEventHandler.js.map +1 -1
  13. package/eventBridge/register.js +3 -11
  14. package/eventBridge/register.js.map +1 -1
  15. package/execute.js +52 -60
  16. package/execute.js.map +1 -1
  17. package/gateway/index.js +39 -67
  18. package/gateway/index.js.map +1 -1
  19. package/gateway/register.js +3 -11
  20. package/gateway/register.js.map +1 -1
  21. package/index.js +8 -39
  22. package/package.json +8 -8
  23. package/plugins/index.js +3 -4
  24. package/plugins/index.js.map +1 -1
  25. package/raw/index.js +38 -63
  26. package/raw/index.js.map +1 -1
  27. package/raw/plugins/RawEventHandler.js +11 -21
  28. package/raw/plugins/RawEventHandler.js.map +1 -1
  29. package/registry.js +17 -32
  30. package/registry.js.map +1 -1
  31. package/s3/index.js +34 -49
  32. package/s3/index.js.map +1 -1
  33. package/s3/plugins/S3EventHandler.js +10 -9
  34. package/s3/plugins/S3EventHandler.js.map +1 -1
  35. package/s3/register.js +7 -15
  36. package/s3/register.js.map +1 -1
  37. package/sns/index.js +34 -49
  38. package/sns/index.js.map +1 -1
  39. package/sns/plugins/SNSEventHandler.js +10 -9
  40. package/sns/plugins/SNSEventHandler.js.map +1 -1
  41. package/sns/register.js +7 -15
  42. package/sns/register.js.map +1 -1
  43. package/sourceHandler.js +2 -3
  44. package/sourceHandler.js.map +1 -1
  45. package/sqs/index.js +35 -52
  46. package/sqs/index.js.map +1 -1
  47. package/sqs/plugins/SQSEventHandler.js +10 -9
  48. package/sqs/plugins/SQSEventHandler.js.map +1 -1
  49. package/sqs/register.js +8 -18
  50. package/sqs/register.js.map +1 -1
  51. package/types.js +5 -4
  52. package/types.js.map +1 -1
  53. package/utils/composedHandler.js +5 -14
  54. package/utils/composedHandler.js.map +1 -1
  55. package/utils/index.js +0 -2
  56. package/utils/timer/CustomTimer.js +9 -8
  57. package/utils/timer/CustomTimer.js.map +1 -1
  58. package/utils/timer/Timer.js +12 -13
  59. package/utils/timer/Timer.js.map +1 -1
  60. package/utils/timer/abstractions/ITimer.js +0 -3
  61. package/utils/timer/factory.js +7 -8
  62. package/utils/timer/factory.js.map +1 -1
  63. package/utils/timer/index.js +0 -2
  64. package/index.js.map +0 -1
  65. package/utils/index.js.map +0 -1
  66. package/utils/timer/abstractions/ITimer.js.map +0 -1
  67. package/utils/timer/index.js.map +0 -1
package/execute.js.map CHANGED
@@ -1 +1 @@
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,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,CAACV,kBAAkB,CAACc,OAAO,CAAC,IAC5C,CAAC,CAACT,MAAM,CAACK,OAAO,CAACV,kBAAkB,CAACe,MAAM,CAAC;IAC/C,MAAMH,QAA+B,GAAG;MACpCN,UAAU,EAAED,MAAM,CAACC,UAAU;MAC7BC,IAAI,EAAEM,eAAe,GAAGR,MAAM,CAACW,UAAU,CAACC,QAAQ,CAAC,QAAQ,CAAC,GAAGZ,MAAM,CAACa,OAAO;MAC7ER,OAAO,EAAEL,MAAM,CAACK,OAA2C;MAC3DG;IACJ,CAAC;IACD,OAAOV,OAAO,CAACS,QAAQ,CAAC;EAC5B,CAAC;AACL,CAAC;AAED,MAAMO,kBAAkB,GAAGA,CACvBD,OAAY,EACZE,IAAY,EACZC,QAA6B,GAAG,CAAC,CAAC,KACZ;EACtB,IAAIH,OAAO,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;IACxC,MAAMI,KAAK,GAAGJ,OAAO,CAACE,IAAI,CAAC,GAAGF,OAAO,CAACE,IAAI,CAAC,GAAG,CAAC,CAAC;IAEhD,OAAO;MACH,GAAGC,QAAQ;MACX,GAAGC;IACP,CAAC;EACL;EACA,OAAOD,QAAQ;AACnB,CAAC;AAQD,OAAO,MAAME,OAAO,GAAIC,MAAqB,IAAmB;EAC5D,MAAM;IAAEtB,GAAG;IAAEuB,GAAG;IAAEP;EAAQ,CAAC,GAAGM,MAAM;EAEpC,MAAME,KAAK,GAAGP,kBAAkB,CAACD,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,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":[]}
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.js CHANGED
@@ -1,76 +1,48 @@
1
- import awsLambdaFastify from "@fastify/aws-lambda";
2
- import { createHandler as createBaseHandler, createRoute, RoutePlugin } from "@webiny/handler";
1
+ import aws_lambda from "@fastify/aws-lambda";
2
+ import { RoutePlugin, createHandler, createRoute } from "@webiny/handler";
3
3
  import { registerDefaultPlugins } from "../plugins/index.js";
4
4
  import { Base64EncodeHeader } from "../types.js";
5
- export { RoutePlugin, createRoute };
6
- const getHeader = (headers, header) => {
7
- for (const key in headers) {
8
- if (key.toLowerCase() !== header) {
9
- continue;
10
- }
11
- return headers[key];
12
- }
13
- return undefined;
5
+ const getHeader = (headers, header)=>{
6
+ for(const key in headers)if (key.toLowerCase() === header) return headers[key];
14
7
  };
15
8
  const defaultContentType = "application/json";
16
9
  const defaultCharset = "utf-8";
17
- /**
18
- * We need to attach default headers to the request, so it does not break if there is none sent.
19
- */
20
- const attachRequiredProperties = event => {
21
- const isOptions = event.httpMethod.toLowerCase() === "options";
22
- /**
23
- * A possibility that headers are not defined?
24
- * Maybe during testing?
25
- */
26
- if (!event.headers) {
27
- event.headers = {};
28
- }
29
- const contentType = getHeader(event.headers, "content-type");
30
- /**
31
- * We check the existing content type and add the default one if it does not exist.
32
- *
33
- * Also, if the content-type is the application/json, and the body is not sent, we add it.
34
- */
35
- if (!contentType) {
36
- event.headers["content-type"] = [defaultContentType, `charset=${defaultCharset}`].join(";");
37
- event.body = "{}";
38
- } else if (!event.body && contentType.startsWith(defaultContentType)) {
39
- event.body = "{}";
40
- }
41
- if (!isOptions) {
42
- return;
43
- }
44
- event.body = null;
45
- };
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
- });
55
- /**
56
- * We always must add our default plugins to the app.
57
- */
58
- registerDefaultPlugins(app.webiny);
59
- if (app.webiny.plugins.byType(RoutePlugin.type).length === 0) {
60
- 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 = "{}";
61
22
  }
62
- attachRequiredProperties(event);
63
- const appLambda = awsLambdaFastify(app, {
64
- decorateRequest: true,
65
- serializeLambdaArguments: true,
66
- decorationPropertyName: "awsLambda",
67
- enforceBase64: response => {
68
- return !!response.headers[Base64EncodeHeader.encoded] || !!response.headers[Base64EncodeHeader.binary];
69
- },
70
- ...(params.lambdaOptions || {})
71
- });
72
- return appLambda(event, context);
73
- };
23
+ if (!isOptions) return;
24
+ event.body = null;
74
25
  };
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 };
75
47
 
76
48
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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,GAAG,CAAC;IAC3FJ,KAAK,CAACK,IAAI,GAAG,IAAI;EACrB,CAAC,MAAM,IAAI,CAACL,KAAK,CAACK,IAAI,IAAIF,WAAW,CAACG,UAAU,CAACT,kBAAkB,CAAC,EAAE;IAClEG,KAAK,CAACK,IAAI,GAAG,IAAI;EACrB;EACA,IAAI,CAACJ,SAAS,EAAE;IACZ;EACJ;EACAD,KAAK,CAACK,IAAI,GAAG,IAAI;AACrB,CAAC;AAED,OAAO,MAAMpB,aAAa,GAAIsB,MAAqB,IAAsB;EACrE,OAAO,OAAOP,KAAK,EAAEQ,OAAO,KAAK;IAC7B,MAAMC,GAAG,GAAGvB,iBAAiB,CAAC;MAC1B,GAAGqB,MAAM;MACTG,OAAO,EAAE;QACLC,MAAM,EAAEJ,MAAM,CAACK,KAAK,KAAK,IAAI;QAC7B,IAAIL,MAAM,CAACG,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQrB,sBAAsB,CAACoB,GAAG,CAACI,MAAM,CAAC;IAElC,IAAIJ,GAAG,CAACI,MAAM,CAACC,OAAO,CAACC,MAAM,CAAc3B,WAAW,CAAC4B,IAAI,CAAC,CAACC,MAAM,KAAK,CAAC,EAAE;MACvE,MAAM,IAAIC,KAAK,CACX,iFACJ,CAAC;IACL;IACAnB,wBAAwB,CAACC,KAAK,CAAC;IAE/B,MAAMmB,SAAS,GAAGnC,gBAAgB,CAACyB,GAAG,EAAE;MACpCW,eAAe,EAAE,IAAI;MACrBC,wBAAwB,EAAE,IAAI;MAC9BC,sBAAsB,EAAE,WAAW;MACnCC,aAAa,EAAEC,QAAQ,IAAI;QACvB,OACI,CAAC,CAACA,QAAQ,CAAChC,OAAO,CAACF,kBAAkB,CAACmC,OAAO,CAAC,IAC9C,CAAC,CAACD,QAAQ,CAAChC,OAAO,CAACF,kBAAkB,CAACoC,MAAM,CAAC;MAErD,CAAC;MACD,IAAInB,MAAM,CAACoB,aAAa,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC;IACF,OAAOR,SAAS,CAACnB,KAAK,EAAEQ,OAAO,CAAC;EACpC,CAAC;AACL,CAAC","ignoreList":[]}
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"}
@@ -2,17 +2,9 @@ import { registry } from "../registry.js";
2
2
  import { createSourceHandler } from "../sourceHandler.js";
3
3
  import { createHandler } from "./index.js";
4
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
- }
5
+ name: "handler-aws-api-gateway",
6
+ canUse: (event)=>!!event.httpMethod,
7
+ handle: async ({ params, event, context })=>createHandler(params)(event, context)
16
8
  });
17
9
  registry.register(handler);
18
10
 
@@ -1 +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":[]}
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.js CHANGED
@@ -5,44 +5,13 @@ import "./sqs/register.js";
5
5
  import "./eventBridge/register.js";
6
6
  import "./sns/register.js";
7
7
  export * from "./utils/index.js";
8
-
9
- /**
10
- * API Gateway
11
- */
12
- export { createHandler as createApiGatewayHandler, RoutePlugin, createRoute as createApiGatewayRoute } from "./gateway/index.js";
13
-
14
- /**
15
- * S3
16
- */
17
- //
18
- export { createHandler as createS3Handler, S3EventHandler, createEventHandler as createS3EventHandler } from "./s3/index.js";
19
-
20
- /**
21
- * DynamoDB Stream
22
- */
23
- //
24
- export { createHandler as createDynamoDBHandler, DynamoDBEventHandler, createEventHandler as createDynamoDBEventHandler } from "./dynamodb/index.js";
25
-
26
- /**
27
- * SQS
28
- */
29
- //
30
- export { createHandler as createSQSHandler, SQSEventHandler, createEventHandler as createSQSEventHandler } from "./sqs/index.js";
31
-
32
- /**
33
- * SNS
34
- */
35
- //
36
- export { createHandler as createSNSHandler, SNSEventHandler, createEventHandler as createSNSEventHandler } from "./sns/index.js";
37
-
38
- /**
39
- * EventBridge
40
- */
41
- //
42
- export { createHandler as createEventBridgeHandler, EventBridgeEventHandler, createEventHandler as createEventBridgeEventHandler } from "./eventBridge/index.js";
43
- export { createHandler as createRawHandler, createEventHandler as createRawEventHandler, RawEventHandler } from "./raw/index.js";
44
- export { ContextPlugin, createContextPlugin } from "@webiny/handler";
45
8
  export * from "./createHandler.js";
46
9
  export * from "./sourceHandler.js";
47
-
48
- //# sourceMappingURL=index.js.map
10
+ export { RoutePlugin, createHandler as createApiGatewayHandler, createRoute as createApiGatewayRoute } from "./gateway/index.js";
11
+ export { S3EventHandler, createEventHandler as createS3EventHandler, createHandler as createS3Handler } from "./s3/index.js";
12
+ export { DynamoDBEventHandler, createEventHandler as createDynamoDBEventHandler, createHandler as createDynamoDBHandler } from "./dynamodb/index.js";
13
+ export { SQSEventHandler, createEventHandler as createSQSEventHandler, createHandler as createSQSHandler } from "./sqs/index.js";
14
+ export { SNSEventHandler, createEventHandler as createSNSEventHandler, createHandler as createSNSHandler } from "./sns/index.js";
15
+ export { EventBridgeEventHandler, createEventHandler as createEventBridgeEventHandler, createHandler as createEventBridgeHandler } from "./eventBridge/index.js";
16
+ export { RawEventHandler, createEventHandler as createRawEventHandler, createHandler as createRawHandler } from "./raw/index.js";
17
+ export { ContextPlugin, createContextPlugin } from "@webiny/handler";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/handler-aws",
3
- "version": "6.3.0",
3
+ "version": "6.4.0-beta.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -17,22 +17,22 @@
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
19
  "@fastify/aws-lambda": "6.4.0",
20
- "@webiny/aws-sdk": "6.3.0",
21
- "@webiny/handler": "6.3.0",
22
- "@webiny/plugins": "6.3.0",
23
- "@webiny/utils": "6.3.0",
20
+ "@webiny/aws-sdk": "6.4.0-beta.0",
21
+ "@webiny/handler": "6.4.0-beta.0",
22
+ "@webiny/plugins": "6.4.0-beta.0",
23
+ "@webiny/utils": "6.4.0-beta.0",
24
24
  "fastify": "5.8.5",
25
25
  "pino-lambda": "4.4.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@webiny/build-tools": "6.3.0",
28
+ "@webiny/build-tools": "6.4.0-beta.0",
29
29
  "rimraf": "6.1.3",
30
30
  "typescript": "6.0.3",
31
- "vitest": "4.1.5"
31
+ "vitest": "4.1.6"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public",
35
35
  "directory": "dist"
36
36
  },
37
- "gitHead": "7cefe15431dbd65504e1f58147dc9e55bcbfa693"
37
+ "gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
38
38
  }
package/plugins/index.js CHANGED
@@ -1,7 +1,6 @@
1
- export const registerDefaultPlugins = context => {
2
- context.plugins.register([
3
- //
4
- ]);
1
+ const registerDefaultPlugins = (context)=>{
2
+ context.plugins.register([]);
5
3
  };
4
+ export { registerDefaultPlugins };
6
5
 
7
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["registerDefaultPlugins","context","plugins","register"],"sources":["index.ts"],"sourcesContent":["import type { Context } from \"@webiny/handler/types.js\";\n\nexport const registerDefaultPlugins = (context: Context): void => {\n context.plugins.register([\n //\n ]);\n};\n"],"mappings":"AAEA,OAAO,MAAMA,sBAAsB,GAAIC,OAAgB,IAAW;EAC9DA,OAAO,CAACC,OAAO,CAACC,QAAQ,CAAC;IACrB;EAAA,CACH,CAAC;AACN,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"plugins/index.js","sources":["../../src/plugins/index.ts"],"sourcesContent":["import type { Context } from \"@webiny/handler/types.js\";\n\nexport const registerDefaultPlugins = (context: Context): void => {\n context.plugins.register([\n //\n ]);\n};\n"],"names":["registerDefaultPlugins","context"],"mappings":"AAEO,MAAMA,yBAAyB,CAACC;IACnCA,QAAQ,OAAO,CAAC,QAAQ,CAAC,EAExB;AACL"}
package/raw/index.js CHANGED
@@ -1,70 +1,45 @@
1
- /**
2
- * This is the handler implementation for @webiny/handler/plugins/EventPlugin.
3
- * This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.
4
- *
5
- * We should try to have some kind of standardized event type implementation at some point.
6
- */
7
-
8
- import { createHandler as createBaseHandler } from "@webiny/handler";
1
+ import { createHandler } from "@webiny/handler";
9
2
  import { RawEventHandler } from "./plugins/RawEventHandler.js";
10
3
  import { registerDefaultPlugins } from "../plugins/index.js";
11
4
  import { execute } from "../execute.js";
12
5
  import { createComposedHandler } from "../utils/composedHandler.js";
13
- // @ts-expect-error
14
- import Reply from "fastify/lib/reply.js";
15
- const url = "/webiny-raw-event";
16
- export const createHandler = params => {
17
- return (payload, context) => {
18
- const app = createBaseHandler({
19
- ...params,
20
- options: {
21
- logger: params.debug === true,
22
- ...(params.options || {})
23
- }
24
- });
25
- /**
26
- * We always must add our default plugins to the app.
27
- */
28
- registerDefaultPlugins(app.webiny);
29
- /**
30
- * There must be an event plugin for this handler to work.
31
- */
32
- const plugins = app.webiny.plugins.byType(RawEventHandler.type).filter(plugin => {
33
- /**
34
- * Just in case check that the plugin contains canHandle method.
35
- * If it does not, we assume it can handle any payload.
36
- */
37
- if (typeof plugin.canHandle !== "function") {
38
- return true;
39
- }
40
- return plugin.canHandle(payload);
41
- }).reverse();
42
- if (plugins.length === 0) {
43
- throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);
44
- }
45
- const handler = createComposedHandler(plugins);
46
- app.post(url, async (request, reply) => {
47
- const params = {
48
- request,
49
- reply,
50
- context: app.webiny,
51
- payload,
52
- lambdaContext: context
53
- };
54
- const result = await handler(params);
55
- if (result instanceof Reply) {
56
- return result;
57
- }
58
- app.__webiny_raw_result = result;
59
- return reply.send({});
60
- });
61
- return execute({
62
- app,
63
- url,
64
- payload
65
- });
66
- };
67
- };
6
+ import lib_reply from "fastify/lib/reply.js";
68
7
  export * from "./plugins/RawEventHandler.js";
8
+ const url = "/webiny-raw-event";
9
+ const raw_createHandler = (params)=>(payload, context)=>{
10
+ const app = createHandler({
11
+ ...params,
12
+ options: {
13
+ logger: true === params.debug,
14
+ ...params.options || {}
15
+ }
16
+ });
17
+ registerDefaultPlugins(app.webiny);
18
+ const plugins = app.webiny.plugins.byType(RawEventHandler.type).filter((plugin)=>{
19
+ if ("function" != typeof plugin.canHandle) return true;
20
+ return plugin.canHandle(payload);
21
+ }).reverse();
22
+ if (0 === plugins.length) throw new Error("To run @webiny/handler-aws/raw, you must have RawEventHandler set.");
23
+ const handler = createComposedHandler(plugins);
24
+ app.post(url, async (request, reply)=>{
25
+ const params = {
26
+ request,
27
+ reply,
28
+ context: app.webiny,
29
+ payload,
30
+ lambdaContext: context
31
+ };
32
+ const result = await handler(params);
33
+ if (result instanceof lib_reply) return result;
34
+ app.__webiny_raw_result = result;
35
+ return reply.send({});
36
+ });
37
+ return execute({
38
+ app,
39
+ url: url,
40
+ payload
41
+ });
42
+ };
43
+ export { raw_createHandler as createHandler };
69
44
 
70
45
  //# sourceMappingURL=index.js.map
package/raw/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createHandler","createBaseHandler","RawEventHandler","registerDefaultPlugins","execute","createComposedHandler","Reply","url","params","payload","context","app","options","logger","debug","webiny","plugins","byType","type","filter","plugin","canHandle","reverse","length","Error","handler","post","request","reply","lambdaContext","result","__webiny_raw_result","send"],"sources":["index.ts"],"sourcesContent":["/**\n * This is the handler implementation for @webiny/handler/plugins/EventPlugin.\n * This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.\n *\n * We should try to have some kind of standardized event type implementation at some point.\n */\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { CreateHandlerParams as BaseCreateHandlerParams } from \"@webiny/handler\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { RawEventHandler } from \"~/raw/plugins/RawEventHandler.js\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport { execute } from \"~/execute.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\nimport type { Context, Request } from \"@webiny/handler/types.js\";\n\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\n\nconst url = \"/webiny-raw-event\";\n\nexport interface HandlerCallable<Payload, Response = APIGatewayProxyResult> {\n (payload: Payload, context: LambdaContext): Promise<Response>;\n}\n\nexport type CreateHandlerParams = BaseCreateHandlerParams;\n\ninterface HandlerParams<Payload = any> {\n request: Request;\n context: Context;\n payload: Payload;\n lambdaContext: LambdaContext;\n reply: Record<string, any>;\n next: () => Promise<Payload>;\n}\n\nexport const createHandler = <Payload = any, Response = APIGatewayProxyResult>(\n params: CreateHandlerParams\n): HandlerCallable<Payload, Response> => {\n return (payload, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins\n .byType<RawEventHandler<Payload, any, Response>>(RawEventHandler.type)\n .filter(plugin => {\n /**\n * Just in case check that the plugin contains canHandle method.\n * If it does not, we assume it can handle any payload.\n */\n if (typeof plugin.canHandle !== \"function\") {\n return true;\n }\n return plugin.canHandle(payload);\n })\n .reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n RawEventHandler<Payload, any, Response>,\n HandlerParams,\n Response\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<HandlerParams, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n payload,\n lambdaContext: context\n };\n const result = await handler(params as unknown as HandlerParams);\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload\n });\n };\n};\n\nexport * from \"./plugins/RawEventHandler.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;;AAMA,SAASA,aAAa,IAAIC,iBAAiB,QAAQ,iBAAiB;AACpE,SAASC,eAAe;AACxB,SAASC,sBAAsB;AAC/B,SAASC,OAAO;AAChB,SAASC,qBAAqB;AAG9B;AACA,OAAOC,KAAK,MAAM,sBAAsB;AAExC,MAAMC,GAAG,GAAG,mBAAmB;AAiB/B,OAAO,MAAMP,aAAa,GACtBQ,MAA2B,IACU;EACrC,OAAO,CAACC,OAAO,EAAEC,OAAO,KAAK;IACzB,MAAMC,GAAG,GAAGV,iBAAiB,CAAC;MAC1B,GAAGO,MAAM;MACTI,OAAO,EAAE;QACLC,MAAM,EAAEL,MAAM,CAACM,KAAK,KAAK,IAAI;QAC7B,IAAIN,MAAM,CAACI,OAAO,IAAI,CAAC,CAAC;MAC5B;IACJ,CAAC,CAAC;IACF;AACR;AACA;IACQT,sBAAsB,CAACQ,GAAG,CAACI,MAAM,CAAC;IAClC;AACR;AACA;IACQ,MAAMC,OAAO,GAAGL,GAAG,CAACI,MAAM,CAACC,OAAO,CAC7BC,MAAM,CAA0Cf,eAAe,CAACgB,IAAI,CAAC,CACrEC,MAAM,CAACC,MAAM,IAAI;MACd;AAChB;AACA;AACA;MACgB,IAAI,OAAOA,MAAM,CAACC,SAAS,KAAK,UAAU,EAAE;QACxC,OAAO,IAAI;MACf;MACA,OAAOD,MAAM,CAACC,SAAS,CAACZ,OAAO,CAAC;IACpC,CAAC,CAAC,CACDa,OAAO,CAAC,CAAC;IACd,IAAIN,OAAO,CAACO,MAAM,KAAK,CAAC,EAAE;MACtB,MAAM,IAAIC,KAAK,CAAC,oEAAoE,CAAC;IACzF;IAEA,MAAMC,OAAO,GAAGpB,qBAAqB,CAInCW,OAAO,CAAC;IAEVL,GAAG,CAACe,IAAI,CAACnB,GAAG,EAAE,OAAOoB,OAAO,EAAEC,KAAK,KAAK;MACpC,MAAMpB,MAAmC,GAAG;QACxCmB,OAAO;QACPC,KAAK;QACLlB,OAAO,EAAEC,GAAG,CAACI,MAAM;QACnBN,OAAO;QACPoB,aAAa,EAAEnB;MACnB,CAAC;MACD,MAAMoB,MAAM,GAAG,MAAML,OAAO,CAACjB,MAAkC,CAAC;MAEhE,IAAIsB,MAAM,YAAYxB,KAAK,EAAE;QACzB,OAAOwB,MAAM;MACjB;MAEAnB,GAAG,CAACoB,mBAAmB,GAAGD,MAAM;MAChC,OAAOF,KAAK,CAACI,IAAI,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC;IACF,OAAO5B,OAAO,CAAC;MACXO,GAAG;MACHJ,GAAG;MACHE;IACJ,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAED","ignoreList":[]}
1
+ {"version":3,"file":"raw/index.js","sources":["../../src/raw/index.ts"],"sourcesContent":["/**\n * This is the handler implementation for @webiny/handler/plugins/EventPlugin.\n * This is mostly meant for some custom lambda calls as we are sometimes invoking lambdas directly.\n *\n * We should try to have some kind of standardized event type implementation at some point.\n */\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { CreateHandlerParams as BaseCreateHandlerParams } from \"@webiny/handler\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { RawEventHandler } from \"~/raw/plugins/RawEventHandler.js\";\nimport { registerDefaultPlugins } from \"~/plugins/index.js\";\nimport { execute } from \"~/execute.js\";\nimport { createComposedHandler } from \"~/utils/composedHandler.js\";\nimport type { Context, Request } from \"@webiny/handler/types.js\";\n\n// @ts-expect-error\nimport Reply from \"fastify/lib/reply.js\";\n\nconst url = \"/webiny-raw-event\";\n\nexport interface HandlerCallable<Payload, Response = APIGatewayProxyResult> {\n (payload: Payload, context: LambdaContext): Promise<Response>;\n}\n\nexport type CreateHandlerParams = BaseCreateHandlerParams;\n\ninterface HandlerParams<Payload = any> {\n request: Request;\n context: Context;\n payload: Payload;\n lambdaContext: LambdaContext;\n reply: Record<string, any>;\n next: () => Promise<Payload>;\n}\n\nexport const createHandler = <Payload = any, Response = APIGatewayProxyResult>(\n params: CreateHandlerParams\n): HandlerCallable<Payload, Response> => {\n return (payload, context) => {\n const app = createBaseHandler({\n ...params,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n /**\n * We always must add our default plugins to the app.\n */\n registerDefaultPlugins(app.webiny);\n /**\n * There must be an event plugin for this handler to work.\n */\n const plugins = app.webiny.plugins\n .byType<RawEventHandler<Payload, any, Response>>(RawEventHandler.type)\n .filter(plugin => {\n /**\n * Just in case check that the plugin contains canHandle method.\n * If it does not, we assume it can handle any payload.\n */\n if (typeof plugin.canHandle !== \"function\") {\n return true;\n }\n return plugin.canHandle(payload);\n })\n .reverse();\n if (plugins.length === 0) {\n throw new Error(`To run @webiny/handler-aws/raw, you must have RawEventHandler set.`);\n }\n\n const handler = createComposedHandler<\n RawEventHandler<Payload, any, Response>,\n HandlerParams,\n Response\n >(plugins);\n\n app.post(url, async (request, reply) => {\n const params: Omit<HandlerParams, \"next\"> = {\n request,\n reply,\n context: app.webiny,\n payload,\n lambdaContext: context\n };\n const result = await handler(params as unknown as HandlerParams);\n\n if (result instanceof Reply) {\n return result;\n }\n\n app.__webiny_raw_result = result;\n return reply.send({});\n });\n return execute({\n app,\n url,\n payload\n });\n };\n};\n\nexport * from \"./plugins/RawEventHandler.js\";\n"],"names":["url","createHandler","params","payload","context","app","createBaseHandler","registerDefaultPlugins","plugins","RawEventHandler","plugin","Error","handler","createComposedHandler","request","reply","result","Reply","execute"],"mappings":";;;;;;;AAqBA,MAAMA,MAAM;AAiBL,MAAMC,oBAAgB,CACzBC,SAEO,CAACC,SAASC;QACb,MAAMC,MAAMC,cAAkB;YAC1B,GAAGJ,MAAM;YACT,SAAS;gBACL,QAAQA,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAIAK,uBAAuBF,IAAI,MAAM;QAIjC,MAAMG,UAAUH,IAAI,MAAM,CAAC,OAAO,CAC7B,MAAM,CAA0CI,gBAAgB,IAAI,EACpE,MAAM,CAACC,CAAAA;YAKJ,IAAI,AAA4B,cAA5B,OAAOA,OAAO,SAAS,EACvB,OAAO;YAEX,OAAOA,OAAO,SAAS,CAACP;QAC5B,GACC,OAAO;QACZ,IAAIK,AAAmB,MAAnBA,QAAQ,MAAM,EACd,MAAM,IAAIG,MAAM;QAGpB,MAAMC,UAAUC,sBAIdL;QAEFH,IAAI,IAAI,CAACL,KAAK,OAAOc,SAASC;YAC1B,MAAMb,SAAsC;gBACxCY;gBACAC;gBACA,SAASV,IAAI,MAAM;gBACnBF;gBACA,eAAeC;YACnB;YACA,MAAMY,SAAS,MAAMJ,QAAQV;YAE7B,IAAIc,kBAAkBC,WAClB,OAAOD;YAGXX,IAAI,mBAAmB,GAAGW;YAC1B,OAAOD,MAAM,IAAI,CAAC,CAAC;QACvB;QACA,OAAOG,QAAQ;YACXb;YACAL,KAAAA;YACAG;QACJ;IACJ"}
@@ -1,26 +1,16 @@
1
1
  import { EventPlugin } from "@webiny/handler";
2
- export class RawEventHandler extends EventPlugin {
3
- constructor(params) {
4
- const cb = typeof params === "function" ? params : params.handle;
5
- /**
6
- * Callable is correct, TS is just having problems with the override.
7
- */
8
- // @ts-expect-error
9
- super(cb);
10
- this.params = params;
11
- }
12
- /**
13
- *
14
- */
15
- canHandle(event) {
16
- if (typeof this.params === "function" || !this.params?.canHandle) {
17
- return true;
2
+ class RawEventHandler extends EventPlugin {
3
+ constructor(params){
4
+ const cb = "function" == typeof params ? params : params.handle;
5
+ super(cb);
6
+ this.params = params;
7
+ }
8
+ canHandle(event) {
9
+ if ("function" == typeof this.params || !this.params?.canHandle) return true;
10
+ return this.params.canHandle(event);
18
11
  }
19
- return this.params.canHandle(event);
20
- }
21
12
  }
22
- export const createEventHandler = params => {
23
- return new RawEventHandler(params);
24
- };
13
+ const createEventHandler = (params)=>new RawEventHandler(params);
14
+ export { RawEventHandler, createEventHandler };
25
15
 
26
16
  //# sourceMappingURL=RawEventHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["EventPlugin","RawEventHandler","constructor","params","cb","handle","canHandle","event","createEventHandler"],"sources":["RawEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\nimport type { Context as BaseContext, Reply } from \"@webiny/handler/types.js\";\nimport type { EventPluginCallableParams } from \"@webiny/handler\";\nimport { EventPlugin } from \"@webiny/handler\";\n\nexport interface RawEventHandlerCallableParams<\n Event,\n Context extends BaseContext\n> extends EventPluginCallableParams<Event, Context> {\n lambdaContext: LambdaContext;\n}\nexport interface RawEventHandlerCallable<Event, Context extends BaseContext, Response> {\n (params: RawEventHandlerCallableParams<Event, Context>): Promise<Response | Reply>;\n}\n\nexport interface RawEventHandlerParamsConfig<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> {\n canHandle(event: Event): boolean;\n handle: RawEventHandlerCallable<Event, Context, Response>;\n}\n\nexport type RawEventHandlerParams<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> =\n | RawEventHandlerCallable<Event, Context, Response>\n | RawEventHandlerParamsConfig<Event, Context, Response>;\n\nexport class RawEventHandler<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends EventPlugin<Event, Context, Response> {\n private readonly params: RawEventHandlerParams<Event, Context, Response>;\n\n public constructor(params: RawEventHandlerParams<Event, Context, Response>) {\n const cb = typeof params === \"function\" ? params : params.handle;\n /**\n * Callable is correct, TS is just having problems with the override.\n */\n // @ts-expect-error\n super(cb);\n this.params = params;\n }\n /**\n *\n */\n public canHandle(event: Event): boolean {\n if (typeof this.params === \"function\" || !this.params?.canHandle) {\n return true;\n }\n return this.params.canHandle(event);\n }\n}\n\nexport const createEventHandler = <\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n params: RawEventHandlerParams<Event, Context, Response>\n) => {\n return new RawEventHandler<Event, Context, Response>(params);\n};\n"],"mappings":"AAGA,SAASA,WAAW,QAAQ,iBAAiB;AA6B7C,OAAO,MAAMC,eAAe,SAIlBD,WAAW,CAA2B;EAGrCE,WAAWA,CAACC,MAAuD,EAAE;IACxE,MAAMC,EAAE,GAAG,OAAOD,MAAM,KAAK,UAAU,GAAGA,MAAM,GAAGA,MAAM,CAACE,MAAM;IAChE;AACR;AACA;IACQ;IACA,KAAK,CAACD,EAAE,CAAC;IACT,IAAI,CAACD,MAAM,GAAGA,MAAM;EACxB;EACA;AACJ;AACA;EACWG,SAASA,CAACC,KAAY,EAAW;IACpC,IAAI,OAAO,IAAI,CAACJ,MAAM,KAAK,UAAU,IAAI,CAAC,IAAI,CAACA,MAAM,EAAEG,SAAS,EAAE;MAC9D,OAAO,IAAI;IACf;IACA,OAAO,IAAI,CAACH,MAAM,CAACG,SAAS,CAACC,KAAK,CAAC;EACvC;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAK3BL,MAAuD,IACtD;EACD,OAAO,IAAIF,eAAe,CAA2BE,MAAM,CAAC;AAChE,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"raw/plugins/RawEventHandler.js","sources":["../../../src/raw/plugins/RawEventHandler.ts"],"sourcesContent":["import type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\nimport type { Context as BaseContext, Reply } from \"@webiny/handler/types.js\";\nimport type { EventPluginCallableParams } from \"@webiny/handler\";\nimport { EventPlugin } from \"@webiny/handler\";\n\nexport interface RawEventHandlerCallableParams<\n Event,\n Context extends BaseContext\n> extends EventPluginCallableParams<Event, Context> {\n lambdaContext: LambdaContext;\n}\nexport interface RawEventHandlerCallable<Event, Context extends BaseContext, Response> {\n (params: RawEventHandlerCallableParams<Event, Context>): Promise<Response | Reply>;\n}\n\nexport interface RawEventHandlerParamsConfig<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> {\n canHandle(event: Event): boolean;\n handle: RawEventHandlerCallable<Event, Context, Response>;\n}\n\nexport type RawEventHandlerParams<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> =\n | RawEventHandlerCallable<Event, Context, Response>\n | RawEventHandlerParamsConfig<Event, Context, Response>;\n\nexport class RawEventHandler<\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends EventPlugin<Event, Context, Response> {\n private readonly params: RawEventHandlerParams<Event, Context, Response>;\n\n public constructor(params: RawEventHandlerParams<Event, Context, Response>) {\n const cb = typeof params === \"function\" ? params : params.handle;\n /**\n * Callable is correct, TS is just having problems with the override.\n */\n // @ts-expect-error\n super(cb);\n this.params = params;\n }\n /**\n *\n */\n public canHandle(event: Event): boolean {\n if (typeof this.params === \"function\" || !this.params?.canHandle) {\n return true;\n }\n return this.params.canHandle(event);\n }\n}\n\nexport const createEventHandler = <\n Event = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n params: RawEventHandlerParams<Event, Context, Response>\n) => {\n return new RawEventHandler<Event, Context, Response>(params);\n};\n"],"names":["RawEventHandler","EventPlugin","params","cb","event","createEventHandler"],"mappings":";AAgCO,MAAMA,wBAIHC;IAGN,YAAmBC,MAAuD,CAAE;QACxE,MAAMC,KAAK,AAAkB,cAAlB,OAAOD,SAAwBA,SAASA,OAAO,MAAM;QAKhE,KAAK,CAACC;QACN,IAAI,CAAC,MAAM,GAAGD;IAClB;IAIO,UAAUE,KAAY,EAAW;QACpC,IAAI,AAAuB,cAAvB,OAAO,IAAI,CAAC,MAAM,IAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,WACnD,OAAO;QAEX,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAACA;IACjC;AACJ;AAEO,MAAMC,qBAAqB,CAK9BH,SAEO,IAAIF,gBAA0CE"}
package/registry.js CHANGED
@@ -1,38 +1,23 @@
1
- /**
2
- * TODO: refactor this to use a proper DI container
3
- */
4
-
5
1
  class HandlerRegistry {
6
- handlers = new Map();
7
- constructor() {
8
- /**
9
- * We don't want this class to be constructed outside the static create() method
10
- */
11
- }
12
- static create() {
13
- return new HandlerRegistry();
14
- }
15
- register(handler, options) {
16
- if (this.handlers.has(handler.name)) {
17
- if (options?.silent) {
18
- return;
19
- }
20
- /**
21
- * This should only happen during the development phase.
22
- */
23
- throw new Error(`Handler "${handler.name}" is already registered.`);
2
+ constructor(){
3
+ this.handlers = new Map();
4
+ }
5
+ static create() {
6
+ return new HandlerRegistry();
7
+ }
8
+ register(handler, options) {
9
+ if (this.handlers.has(handler.name)) {
10
+ if (options?.silent) return;
11
+ throw new Error(`Handler "${handler.name}" is already registered.`);
12
+ }
13
+ this.handlers.set(handler.name, handler);
24
14
  }
25
- this.handlers.set(handler.name, handler);
26
- }
27
- getHandler(event, context) {
28
- for (const handler of this.handlers.values()) {
29
- if (handler.canUse(event, context)) {
30
- return handler;
31
- }
15
+ getHandler(event, context) {
16
+ for (const handler of this.handlers.values())if (handler.canUse(event, context)) return handler;
17
+ throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
32
18
  }
33
- throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);
34
- }
35
19
  }
36
- export const registry = HandlerRegistry.create();
20
+ const registry = HandlerRegistry.create();
21
+ export { registry };
37
22
 
38
23
  //# sourceMappingURL=registry.js.map
package/registry.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["HandlerRegistry","handlers","Map","constructor","create","register","handler","options","has","name","silent","Error","set","getHandler","event","context","values","canUse","JSON","stringify","registry"],"sources":["registry.ts"],"sourcesContent":["/**\n * TODO: refactor this to use a proper DI container\n */\nimport type { HandlerEvent, SourceHandler } from \"~/types.js\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\n\ninterface RegisterOptions {\n silent?: boolean;\n}\n\nclass HandlerRegistry {\n private readonly handlers = new Map<string, SourceHandler>();\n\n private constructor() {\n /**\n * We don't want this class to be constructed outside the static create() method\n */\n }\n\n public static create() {\n return new HandlerRegistry();\n }\n\n public register(handler: SourceHandler<any>, options?: RegisterOptions) {\n if (this.handlers.has(handler.name)) {\n if (options?.silent) {\n return;\n }\n /**\n * This should only happen during the development phase.\n */\n throw new Error(`Handler \"${handler.name}\" is already registered.`);\n }\n this.handlers.set(handler.name, handler);\n }\n\n public getHandler(event: HandlerEvent, context: LambdaContext): SourceHandler {\n for (const handler of this.handlers.values()) {\n if (handler.canUse(event, context)) {\n return handler;\n }\n }\n throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);\n }\n}\n\nexport type { HandlerRegistry };\n\nexport const registry = HandlerRegistry.create();\n"],"mappings":"AAAA;AACA;AACA;;AAQA,MAAMA,eAAe,CAAC;EACDC,QAAQ,GAAG,IAAIC,GAAG,CAAwB,CAAC;EAEpDC,WAAWA,CAAA,EAAG;IAClB;AACR;AACA;EAFQ;EAKJ,OAAcC,MAAMA,CAAA,EAAG;IACnB,OAAO,IAAIJ,eAAe,CAAC,CAAC;EAChC;EAEOK,QAAQA,CAACC,OAA2B,EAAEC,OAAyB,EAAE;IACpE,IAAI,IAAI,CAACN,QAAQ,CAACO,GAAG,CAACF,OAAO,CAACG,IAAI,CAAC,EAAE;MACjC,IAAIF,OAAO,EAAEG,MAAM,EAAE;QACjB;MACJ;MACA;AACZ;AACA;MACY,MAAM,IAAIC,KAAK,CAAC,YAAYL,OAAO,CAACG,IAAI,0BAA0B,CAAC;IACvE;IACA,IAAI,CAACR,QAAQ,CAACW,GAAG,CAACN,OAAO,CAACG,IAAI,EAAEH,OAAO,CAAC;EAC5C;EAEOO,UAAUA,CAACC,KAAmB,EAAEC,OAAsB,EAAiB;IAC1E,KAAK,MAAMT,OAAO,IAAI,IAAI,CAACL,QAAQ,CAACe,MAAM,CAAC,CAAC,EAAE;MAC1C,IAAIV,OAAO,CAACW,MAAM,CAACH,KAAK,EAAEC,OAAO,CAAC,EAAE;QAChC,OAAOT,OAAO;MAClB;IACJ;IACA,MAAM,IAAIK,KAAK,CAAC,sCAAsCO,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC,EAAE,CAAC;EAClF;AACJ;AAIA,OAAO,MAAMM,QAAQ,GAAGpB,eAAe,CAACI,MAAM,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"registry.js","sources":["../src/registry.ts"],"sourcesContent":["/**\n * TODO: refactor this to use a proper DI container\n */\nimport type { HandlerEvent, SourceHandler } from \"~/types.js\";\nimport type { Context as LambdaContext } from \"@webiny/aws-sdk/types/index.js\";\n\ninterface RegisterOptions {\n silent?: boolean;\n}\n\nclass HandlerRegistry {\n private readonly handlers = new Map<string, SourceHandler>();\n\n private constructor() {\n /**\n * We don't want this class to be constructed outside the static create() method\n */\n }\n\n public static create() {\n return new HandlerRegistry();\n }\n\n public register(handler: SourceHandler<any>, options?: RegisterOptions) {\n if (this.handlers.has(handler.name)) {\n if (options?.silent) {\n return;\n }\n /**\n * This should only happen during the development phase.\n */\n throw new Error(`Handler \"${handler.name}\" is already registered.`);\n }\n this.handlers.set(handler.name, handler);\n }\n\n public getHandler(event: HandlerEvent, context: LambdaContext): SourceHandler {\n for (const handler of this.handlers.values()) {\n if (handler.canUse(event, context)) {\n return handler;\n }\n }\n throw new Error(`There is no handler for the event: ${JSON.stringify(event)}`);\n }\n}\n\nexport type { HandlerRegistry };\n\nexport const registry = HandlerRegistry.create();\n"],"names":["HandlerRegistry","Map","handler","options","Error","event","context","JSON","registry"],"mappings":"AAUA,MAAMA;IAGF,aAAsB;aAFL,QAAQ,GAAG,IAAIC;IAMhC;IAEA,OAAc,SAAS;QACnB,OAAO,IAAID;IACf;IAEO,SAASE,OAA2B,EAAEC,OAAyB,EAAE;QACpE,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACD,QAAQ,IAAI,GAAG;YACjC,IAAIC,SAAS,QACT;YAKJ,MAAM,IAAIC,MAAM,CAAC,SAAS,EAAEF,QAAQ,IAAI,CAAC,wBAAwB,CAAC;QACtE;QACA,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA,QAAQ,IAAI,EAAEA;IACpC;IAEO,WAAWG,KAAmB,EAAEC,OAAsB,EAAiB;QAC1E,KAAK,MAAMJ,WAAW,IAAI,CAAC,QAAQ,CAAC,MAAM,GACtC,IAAIA,QAAQ,MAAM,CAACG,OAAOC,UACtB,OAAOJ;QAGf,MAAM,IAAIE,MAAM,CAAC,mCAAmC,EAAEG,KAAK,SAAS,CAACF,QAAQ;IACjF;AACJ;AAIO,MAAMG,WAAWR,gBAAgB,MAAM"}