@incloodsolutions/devkit 0.0.2 → 0.0.3

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 (153) hide show
  1. package/dist/aws/cdk/constructs/api-gateway-construct.cjs +95 -0
  2. package/dist/aws/cdk/constructs/api-gateway-construct.cjs.map +1 -0
  3. package/dist/aws/cdk/constructs/api-gateway-construct.d.cts +80 -0
  4. package/dist/aws/cdk/constructs/api-gateway-construct.d.ts +80 -0
  5. package/dist/aws/cdk/constructs/api-gateway-construct.js +93 -0
  6. package/dist/aws/cdk/constructs/api-gateway-construct.js.map +1 -0
  7. package/dist/aws/cdk/constructs/api-gateway-v2-construct.cjs +77 -0
  8. package/dist/aws/cdk/constructs/api-gateway-v2-construct.cjs.map +1 -0
  9. package/dist/aws/cdk/constructs/api-gateway-v2-construct.d.cts +55 -0
  10. package/dist/aws/cdk/constructs/api-gateway-v2-construct.d.ts +55 -0
  11. package/dist/aws/cdk/constructs/api-gateway-v2-construct.js +75 -0
  12. package/dist/aws/cdk/constructs/api-gateway-v2-construct.js.map +1 -0
  13. package/dist/aws/cdk/constructs/api-gateway-websocket-construct.cjs +65 -0
  14. package/dist/aws/cdk/constructs/api-gateway-websocket-construct.cjs.map +1 -0
  15. package/dist/aws/cdk/constructs/api-gateway-websocket-construct.d.cts +73 -0
  16. package/dist/aws/cdk/constructs/api-gateway-websocket-construct.d.ts +73 -0
  17. package/dist/aws/cdk/constructs/api-gateway-websocket-construct.js +63 -0
  18. package/dist/aws/cdk/constructs/api-gateway-websocket-construct.js.map +1 -0
  19. package/dist/aws/cdk/constructs/cloudfront-construct.cjs +68 -0
  20. package/dist/aws/cdk/constructs/cloudfront-construct.cjs.map +1 -0
  21. package/dist/aws/cdk/constructs/cloudfront-construct.d.cts +36 -0
  22. package/dist/aws/cdk/constructs/cloudfront-construct.d.ts +36 -0
  23. package/dist/aws/cdk/constructs/cloudfront-construct.js +66 -0
  24. package/dist/aws/cdk/constructs/cloudfront-construct.js.map +1 -0
  25. package/dist/aws/cdk/constructs/cloudwatch-construct.cjs +43 -0
  26. package/dist/aws/cdk/constructs/cloudwatch-construct.cjs.map +1 -0
  27. package/dist/aws/cdk/constructs/cloudwatch-construct.d.cts +36 -0
  28. package/dist/aws/cdk/constructs/cloudwatch-construct.d.ts +36 -0
  29. package/dist/aws/cdk/constructs/cloudwatch-construct.js +41 -0
  30. package/dist/aws/cdk/constructs/cloudwatch-construct.js.map +1 -0
  31. package/dist/aws/cdk/constructs/dynamo-db-construct.cjs +113 -0
  32. package/dist/aws/cdk/constructs/dynamo-db-construct.cjs.map +1 -0
  33. package/dist/aws/cdk/constructs/dynamo-db-construct.d.cts +53 -0
  34. package/dist/aws/cdk/constructs/dynamo-db-construct.d.ts +53 -0
  35. package/dist/aws/cdk/constructs/dynamo-db-construct.js +111 -0
  36. package/dist/aws/cdk/constructs/dynamo-db-construct.js.map +1 -0
  37. package/dist/aws/cdk/constructs/event-bridge-construct.cjs +47 -0
  38. package/dist/aws/cdk/constructs/event-bridge-construct.cjs.map +1 -0
  39. package/dist/aws/cdk/constructs/event-bridge-construct.d.cts +41 -0
  40. package/dist/aws/cdk/constructs/event-bridge-construct.d.ts +41 -0
  41. package/dist/aws/cdk/constructs/event-bridge-construct.js +45 -0
  42. package/dist/aws/cdk/constructs/event-bridge-construct.js.map +1 -0
  43. package/dist/aws/cdk/constructs/index.cjs +881 -0
  44. package/dist/aws/cdk/constructs/index.cjs.map +1 -0
  45. package/dist/aws/cdk/constructs/index.d.cts +34 -0
  46. package/dist/aws/cdk/constructs/index.d.ts +34 -0
  47. package/dist/aws/cdk/constructs/index.js +863 -0
  48. package/dist/aws/cdk/constructs/index.js.map +1 -0
  49. package/dist/aws/cdk/constructs/lambda-authorizer-construct.cjs +37 -0
  50. package/dist/aws/cdk/constructs/lambda-authorizer-construct.cjs.map +1 -0
  51. package/dist/aws/cdk/constructs/lambda-authorizer-construct.d.cts +44 -0
  52. package/dist/aws/cdk/constructs/lambda-authorizer-construct.d.ts +44 -0
  53. package/dist/aws/cdk/constructs/lambda-authorizer-construct.js +35 -0
  54. package/dist/aws/cdk/constructs/lambda-authorizer-construct.js.map +1 -0
  55. package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.cjs +47 -0
  56. package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.cjs.map +1 -0
  57. package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.d.cts +45 -0
  58. package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.d.ts +45 -0
  59. package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.js +45 -0
  60. package/dist/aws/cdk/constructs/lambda-authorizer-v2-construct.js.map +1 -0
  61. package/dist/aws/cdk/constructs/lambda-construct.cjs +82 -0
  62. package/dist/aws/cdk/constructs/lambda-construct.cjs.map +1 -0
  63. package/dist/aws/cdk/constructs/lambda-construct.d.cts +37 -0
  64. package/dist/aws/cdk/constructs/lambda-construct.d.ts +37 -0
  65. package/dist/aws/cdk/constructs/lambda-construct.js +80 -0
  66. package/dist/aws/cdk/constructs/lambda-construct.js.map +1 -0
  67. package/dist/aws/cdk/constructs/lambda-layer-construct.cjs +72 -0
  68. package/dist/aws/cdk/constructs/lambda-layer-construct.cjs.map +1 -0
  69. package/dist/aws/cdk/constructs/lambda-layer-construct.d.cts +52 -0
  70. package/dist/aws/cdk/constructs/lambda-layer-construct.d.ts +52 -0
  71. package/dist/aws/cdk/constructs/lambda-layer-construct.js +70 -0
  72. package/dist/aws/cdk/constructs/lambda-layer-construct.js.map +1 -0
  73. package/dist/aws/cdk/constructs/role-policy-construct.cjs +53 -0
  74. package/dist/aws/cdk/constructs/role-policy-construct.cjs.map +1 -0
  75. package/dist/aws/cdk/constructs/role-policy-construct.d.cts +44 -0
  76. package/dist/aws/cdk/constructs/role-policy-construct.d.ts +44 -0
  77. package/dist/aws/cdk/constructs/role-policy-construct.js +51 -0
  78. package/dist/aws/cdk/constructs/role-policy-construct.js.map +1 -0
  79. package/dist/aws/cdk/constructs/s3-construct.cjs +38 -0
  80. package/dist/aws/cdk/constructs/s3-construct.cjs.map +1 -0
  81. package/dist/aws/cdk/constructs/s3-construct.d.cts +36 -0
  82. package/dist/aws/cdk/constructs/s3-construct.d.ts +36 -0
  83. package/dist/aws/cdk/constructs/s3-construct.js +36 -0
  84. package/dist/aws/cdk/constructs/s3-construct.js.map +1 -0
  85. package/dist/aws/cdk/constructs/s3-deployment-construct.cjs +168 -0
  86. package/dist/aws/cdk/constructs/s3-deployment-construct.cjs.map +1 -0
  87. package/dist/aws/cdk/constructs/s3-deployment-construct.d.cts +72 -0
  88. package/dist/aws/cdk/constructs/s3-deployment-construct.d.ts +72 -0
  89. package/dist/aws/cdk/constructs/s3-deployment-construct.js +166 -0
  90. package/dist/aws/cdk/constructs/s3-deployment-construct.js.map +1 -0
  91. package/dist/aws/cdk/constructs/sns-construct.cjs +43 -0
  92. package/dist/aws/cdk/constructs/sns-construct.cjs.map +1 -0
  93. package/dist/aws/cdk/constructs/sns-construct.d.cts +45 -0
  94. package/dist/aws/cdk/constructs/sns-construct.d.ts +45 -0
  95. package/dist/aws/cdk/constructs/sns-construct.js +41 -0
  96. package/dist/aws/cdk/constructs/sns-construct.js.map +1 -0
  97. package/dist/aws/cdk/constructs/sqs-construct.cjs +55 -0
  98. package/dist/aws/cdk/constructs/sqs-construct.cjs.map +1 -0
  99. package/dist/aws/cdk/constructs/sqs-construct.d.cts +52 -0
  100. package/dist/aws/cdk/constructs/sqs-construct.d.ts +52 -0
  101. package/dist/aws/cdk/constructs/sqs-construct.js +53 -0
  102. package/dist/aws/cdk/constructs/sqs-construct.js.map +1 -0
  103. package/dist/aws/cdk/constructs/vpc-construct.cjs +33 -0
  104. package/dist/aws/cdk/constructs/vpc-construct.cjs.map +1 -0
  105. package/dist/aws/cdk/constructs/vpc-construct.d.cts +34 -0
  106. package/dist/aws/cdk/constructs/vpc-construct.d.ts +34 -0
  107. package/dist/aws/cdk/constructs/vpc-construct.js +31 -0
  108. package/dist/aws/cdk/constructs/vpc-construct.js.map +1 -0
  109. package/dist/aws/cdk/index.cjs +881 -0
  110. package/dist/aws/cdk/index.cjs.map +1 -0
  111. package/dist/aws/cdk/index.d.cts +34 -0
  112. package/dist/aws/cdk/index.d.ts +34 -0
  113. package/dist/aws/cdk/index.js +863 -0
  114. package/dist/aws/cdk/index.js.map +1 -0
  115. package/dist/aws/cli/index.cjs +4 -0
  116. package/dist/aws/cli/index.cjs.map +1 -0
  117. package/dist/aws/cli/index.d.cts +2 -0
  118. package/dist/aws/cli/index.d.ts +2 -0
  119. package/dist/aws/cli/index.js +3 -0
  120. package/dist/aws/cli/index.js.map +1 -0
  121. package/dist/aws/index.cjs +881 -0
  122. package/dist/aws/index.cjs.map +1 -0
  123. package/dist/aws/index.d.cts +34 -0
  124. package/dist/aws/index.d.ts +34 -0
  125. package/dist/aws/index.js +863 -0
  126. package/dist/aws/index.js.map +1 -0
  127. package/dist/aws/types/index.cjs +4 -0
  128. package/dist/aws/types/index.cjs.map +1 -0
  129. package/dist/aws/types/index.d.cts +18 -0
  130. package/dist/aws/types/index.d.ts +18 -0
  131. package/dist/aws/types/index.js +3 -0
  132. package/dist/aws/types/index.js.map +1 -0
  133. package/dist/index.d.cts +34 -755
  134. package/dist/index.d.ts +34 -755
  135. package/dist/lint/index.cjs +4 -0
  136. package/dist/lint/index.cjs.map +1 -0
  137. package/dist/lint/index.d.cts +2 -0
  138. package/dist/lint/index.d.ts +2 -0
  139. package/dist/lint/index.js +3 -0
  140. package/dist/lint/index.js.map +1 -0
  141. package/dist/prettier/index.cjs +4 -0
  142. package/dist/prettier/index.cjs.map +1 -0
  143. package/dist/prettier/index.d.cts +2 -0
  144. package/dist/prettier/index.d.ts +2 -0
  145. package/dist/prettier/index.js +3 -0
  146. package/dist/prettier/index.js.map +1 -0
  147. package/dist/utility/index.cjs +4 -0
  148. package/dist/utility/index.cjs.map +1 -0
  149. package/dist/utility/index.d.cts +2 -0
  150. package/dist/utility/index.d.ts +2 -0
  151. package/dist/utility/index.js +3 -0
  152. package/dist/utility/index.js.map +1 -0
  153. package/package.json +7 -2
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+
3
+ var constructs = require('constructs');
4
+ var awsCdkLib = require('aws-cdk-lib');
5
+ var awsApigateway = require('aws-cdk-lib/aws-apigateway');
6
+ var toolkit = require('@incloodsolutions/toolkit');
7
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var BaseApiGatewayConstruct = class _BaseApiGatewayConstruct extends constructs.Construct {
11
+ static {
12
+ __name(this, "BaseApiGatewayConstruct");
13
+ }
14
+ /** The created REST API instance */
15
+ api;
16
+ /** Enables debug logging for route creation */
17
+ enableDebug = false;
18
+ /**
19
+ * @param scope Parent construct
20
+ * @param id Unique construct identifier
21
+ * @param props Configuration for API, routes, and Lambda handler
22
+ */
23
+ constructor(scope, id, props) {
24
+ super(scope, id);
25
+ this.enableDebug = props.enableDebug;
26
+ this.api = new awsApigateway.RestApi(this, id, {
27
+ ...props?.options?.gatewayOptions,
28
+ /** Default API description if not provided */
29
+ description: props?.options?.gatewayOptions?.description || "This is a REST API using CDK",
30
+ /**
31
+ * CORS configuration
32
+ * Falls back to allowing all origins, methods, and standard headers
33
+ */
34
+ defaultCorsPreflightOptions: {
35
+ ...props?.options?.gatewayOptions?.defaultCorsPreflightOptions,
36
+ /** Allow all origins by default */
37
+ allowOrigins: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowOrigins || awsApigateway.Cors.ALL_ORIGINS,
38
+ /** Allow all HTTP methods by default */
39
+ allowMethods: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowMethods || awsApigateway.Cors.ALL_METHODS,
40
+ /** Merge default headers with user-defined headers */
41
+ allowHeaders: [
42
+ ...props.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowHeaders,
43
+ "Content-Type",
44
+ "Accept",
45
+ "X-Amz-Date",
46
+ "Authorization",
47
+ "X-Api-Key",
48
+ "X-Amz-Security-Token",
49
+ "X-Amz-User-Agent"
50
+ ]
51
+ },
52
+ /** Minimum payload size (in bytes) before compression is applied */
53
+ minCompressionSize: props?.options?.gatewayOptions?.minCompressionSize || awsCdkLib.Size.bytes(1)
54
+ });
55
+ if (props?.options?.routeOptions?.length && props?.handlerFunction) {
56
+ const integration = new awsApigateway.LambdaIntegration(props.handlerFunction);
57
+ this.addRoutes(this.api.root, props.options.routeOptions, integration);
58
+ }
59
+ this.api.applyRemovalPolicy(awsCdkLib.RemovalPolicy.DESTROY);
60
+ new awsCdkLib.CfnOutput(this, "ApiGateway", {
61
+ value: this.api.url
62
+ });
63
+ }
64
+ /**
65
+ * Recursively attaches routes to the API Gateway
66
+ *
67
+ * Behaviour:
68
+ * - Creates a resource for each route segment
69
+ * - Attaches method + Lambda integration
70
+ * - Traverses child routes for nested paths
71
+ *
72
+ * @param parent Parent API resource
73
+ * @param routes Route definitions
74
+ * @param integration Lambda integration applied to each route
75
+ * @param previousPath Accumulated path (used for debug logging)
76
+ * @private
77
+ */
78
+ addRoutes(parent, routes, integration, previousPath) {
79
+ routes.forEach((route) => {
80
+ const currentPath = `${previousPath || ""}/${route.name}`;
81
+ const resource = parent.addResource(route.name);
82
+ resource.addMethod(route.method, integration);
83
+ if (route?.children.length) {
84
+ this.addRoutes(resource, route.children, integration, currentPath);
85
+ }
86
+ if (this.enableDebug) {
87
+ toolkit.printLog(_BaseApiGatewayConstruct.name, `Route created: ${route.method} ${currentPath}`);
88
+ }
89
+ });
90
+ }
91
+ };
92
+
93
+ exports.BaseApiGatewayConstruct = BaseApiGatewayConstruct;
94
+ //# sourceMappingURL=api-gateway-construct.cjs.map
95
+ //# sourceMappingURL=api-gateway-construct.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/aws/cdk/constructs/api-gateway-construct.ts"],"names":["Construct","RestApi","Cors","Size","LambdaIntegration","RemovalPolicy","CfnOutput","printLog"],"mappings":";;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AkB,MAAM,MAAM,CAAA,CAAA,EAAI,WAAW,CAAA,CAAE,CAAA;AAAA,MACvF;AAAA,IACD,CAAC,CAAA;AAAA,EACF;AACD","file":"api-gateway-construct.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { HttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';\nimport { CfnOutput, RemovalPolicy, Size } from 'aws-cdk-lib';\nimport { Cors, IResource, LambdaIntegration, RestApi, RestApiProps } from 'aws-cdk-lib/aws-apigateway';\n\nimport { printLog } from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps, IBaseConstruct } from '../../types';\n\n\n/**\n * Route definition for API Gateway resources\n *\n * Supports hierarchical route structures using `children`\n */\ninterface IRouteOption {\n\t/** Path segment (e.g. 'users', 'orders') */\n\tname: string;\n\n\t/** HTTP method for the route */\n\tmethod: `${HttpMethod}`;\n\n\t/** Nested routes under this path */\n\tchildren?: IRouteOption[];\n}\n\n/**\n * Props for BaseApiGatewayConstruct\n *\n * Provides configuration for:\n * - REST API (API Gateway v1)\n * - Route definitions\n * - Lambda handler\n */\ninterface IApiGatewayConstructProps extends Omit<IBaseCdkConstructProps<{\n\t/** REST API configuration options */\n\treadonly gatewayOptions: RestApiProps;\n\n\t/** Route definitions used to build API resources */\n\treadonly routeOptions: IRouteOption[];\n}>, 'appName' | 'stage' | 'stackName'> {\n\t/**\n\t * Lambda function handling all API routes\n\t *\n\t * Note:\n\t * A single Lambda integration is reused across all routes\n\t */\n\treadonly handlerFunction: Function;\n}\n\n/**\n * CDK construct for REST API Gateway with Lambda integration\n *\n * Responsibilities:\n * - Creates a REST API with configurable options\n * - Applies default CORS and compression settings when not provided\n * - Recursively builds API resources from route definitions\n * - Exposes API base URL as a CloudFormation output\n */\nexport class BaseApiGatewayConstruct extends Construct implements IBaseConstruct {\n\t/** The created REST API instance */\n\treadonly api: RestApi;\n\n\t/** Enables debug logging for route creation */\n\tenableDebug = false;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for API, routes, and Lambda handler\n\t */\n\tconstructor(scope: Construct, id: string, props: IApiGatewayConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.enableDebug = props.enableDebug;\n\n\t\tthis.api = new RestApi(this, id, {\n\t\t\t...props?.options?.gatewayOptions,\n\n\t\t\t/** Default API description if not provided */\n\t\t\tdescription: props?.options?.gatewayOptions?.description || 'This is a REST API using CDK',\n\n\t\t\t/**\n\t\t\t * CORS configuration\n\t\t\t * Falls back to allowing all origins, methods, and standard headers\n\t\t\t */\n\t\t\tdefaultCorsPreflightOptions: {\n\t\t\t\t...props?.options?.gatewayOptions?.defaultCorsPreflightOptions,\n\n\t\t\t\t/** Allow all origins by default */\n\t\t\t\tallowOrigins: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowOrigins || Cors.ALL_ORIGINS,\n\n\t\t\t\t/** Allow all HTTP methods by default */\n\t\t\t\tallowMethods: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowMethods || Cors.ALL_METHODS,\n\n\t\t\t\t/** Merge default headers with user-defined headers */\n\t\t\t\tallowHeaders: [\n\t\t\t\t\t...props.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowHeaders,\n\t\t\t\t\t'Content-Type',\n\t\t\t\t\t'Accept',\n\t\t\t\t\t'X-Amz-Date',\n\t\t\t\t\t'Authorization',\n\t\t\t\t\t'X-Api-Key',\n\t\t\t\t\t'X-Amz-Security-Token',\n\t\t\t\t\t'X-Amz-User-Agent'\n\t\t\t\t]\n\t\t\t},\n\n\t\t\t/** Minimum payload size (in bytes) before compression is applied */\n\t\t\tminCompressionSize: props?.options?.gatewayOptions?.minCompressionSize || Size.bytes(1),\n\t\t});\n\n\t\t/**\n\t\t * Register routes if provided\n\t\t */\n\t\tif (props?.options?.routeOptions?.length && props?.handlerFunction) {\n\t\t\tconst integration = new LambdaIntegration(props.handlerFunction);\n\n\t\t\t/**\n\t\t\t * Attach routes recursively starting from API root\n\t\t\t */\n\t\t\tthis.addRoutes(this.api.root, props.options.routeOptions, integration);\n\t\t}\n\n\t\t/**\n\t\t * Apply removal policy (useful for non-production environments)\n\t\t */\n\t\tthis.api.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing API base URL\n\t\t */\n\t\tnew CfnOutput(this, 'ApiGateway', {\n\t\t\tvalue: this.api.url\n\t\t});\n\t}\n\n\t/**\n\t * Recursively attaches routes to the API Gateway\n\t *\n\t * Behaviour:\n\t * - Creates a resource for each route segment\n\t * - Attaches method + Lambda integration\n\t * - Traverses child routes for nested paths\n\t *\n\t * @param parent Parent API resource\n\t * @param routes Route definitions\n\t * @param integration Lambda integration applied to each route\n\t * @param previousPath Accumulated path (used for debug logging)\n\t * @private\n\t */\n\tprivate addRoutes(\n\t\tparent: IResource,\n\t\troutes: IRouteOption[],\n\t\tintegration: LambdaIntegration,\n\t\tpreviousPath?: string\n\t) {\n\t\troutes.forEach(route => {\n\t\t\tconst currentPath = `${previousPath || ''}/${route.name}`;\n\n\t\t\tconst resource = parent.addResource(route.name);\n\n\t\t\t/** Attach HTTP method with Lambda integration */\n\t\t\tresource.addMethod(route.method, integration);\n\n\t\t\t/** Recursively process child routes */\n\t\t\tif (route?.children.length) {\n\t\t\t\tthis.addRoutes(resource, route.children, integration, currentPath);\n\t\t\t}\n\n\t\t\t/** Optional debug logging */\n\t\t\tif (this.enableDebug) {\n\t\t\t\tprintLog(BaseApiGatewayConstruct.name, `Route created: ${route.method} ${currentPath}`);\n\t\t\t}\n\t\t});\n\t}\n}"]}
@@ -0,0 +1,80 @@
1
+ import { Construct } from 'constructs';
2
+ import { Function } from 'aws-cdk-lib/aws-lambda';
3
+ import { HttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';
4
+ import { RestApi, RestApiProps } from 'aws-cdk-lib/aws-apigateway';
5
+ import { IBaseConstruct, IBaseCdkConstructProps } from '../../types/index.cjs';
6
+ import '@incloodsolutions/toolkit';
7
+
8
+ /**
9
+ * Route definition for API Gateway resources
10
+ *
11
+ * Supports hierarchical route structures using `children`
12
+ */
13
+ interface IRouteOption {
14
+ /** Path segment (e.g. 'users', 'orders') */
15
+ name: string;
16
+ /** HTTP method for the route */
17
+ method: `${HttpMethod}`;
18
+ /** Nested routes under this path */
19
+ children?: IRouteOption[];
20
+ }
21
+ /**
22
+ * Props for BaseApiGatewayConstruct
23
+ *
24
+ * Provides configuration for:
25
+ * - REST API (API Gateway v1)
26
+ * - Route definitions
27
+ * - Lambda handler
28
+ */
29
+ interface IApiGatewayConstructProps extends Omit<IBaseCdkConstructProps<{
30
+ /** REST API configuration options */
31
+ readonly gatewayOptions: RestApiProps;
32
+ /** Route definitions used to build API resources */
33
+ readonly routeOptions: IRouteOption[];
34
+ }>, 'appName' | 'stage' | 'stackName'> {
35
+ /**
36
+ * Lambda function handling all API routes
37
+ *
38
+ * Note:
39
+ * A single Lambda integration is reused across all routes
40
+ */
41
+ readonly handlerFunction: Function;
42
+ }
43
+ /**
44
+ * CDK construct for REST API Gateway with Lambda integration
45
+ *
46
+ * Responsibilities:
47
+ * - Creates a REST API with configurable options
48
+ * - Applies default CORS and compression settings when not provided
49
+ * - Recursively builds API resources from route definitions
50
+ * - Exposes API base URL as a CloudFormation output
51
+ */
52
+ declare class BaseApiGatewayConstruct extends Construct implements IBaseConstruct {
53
+ /** The created REST API instance */
54
+ readonly api: RestApi;
55
+ /** Enables debug logging for route creation */
56
+ enableDebug: boolean;
57
+ /**
58
+ * @param scope Parent construct
59
+ * @param id Unique construct identifier
60
+ * @param props Configuration for API, routes, and Lambda handler
61
+ */
62
+ constructor(scope: Construct, id: string, props: IApiGatewayConstructProps);
63
+ /**
64
+ * Recursively attaches routes to the API Gateway
65
+ *
66
+ * Behaviour:
67
+ * - Creates a resource for each route segment
68
+ * - Attaches method + Lambda integration
69
+ * - Traverses child routes for nested paths
70
+ *
71
+ * @param parent Parent API resource
72
+ * @param routes Route definitions
73
+ * @param integration Lambda integration applied to each route
74
+ * @param previousPath Accumulated path (used for debug logging)
75
+ * @private
76
+ */
77
+ private addRoutes;
78
+ }
79
+
80
+ export { BaseApiGatewayConstruct };
@@ -0,0 +1,80 @@
1
+ import { Construct } from 'constructs';
2
+ import { Function } from 'aws-cdk-lib/aws-lambda';
3
+ import { HttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';
4
+ import { RestApi, RestApiProps } from 'aws-cdk-lib/aws-apigateway';
5
+ import { IBaseConstruct, IBaseCdkConstructProps } from '../../types/index.js';
6
+ import '@incloodsolutions/toolkit';
7
+
8
+ /**
9
+ * Route definition for API Gateway resources
10
+ *
11
+ * Supports hierarchical route structures using `children`
12
+ */
13
+ interface IRouteOption {
14
+ /** Path segment (e.g. 'users', 'orders') */
15
+ name: string;
16
+ /** HTTP method for the route */
17
+ method: `${HttpMethod}`;
18
+ /** Nested routes under this path */
19
+ children?: IRouteOption[];
20
+ }
21
+ /**
22
+ * Props for BaseApiGatewayConstruct
23
+ *
24
+ * Provides configuration for:
25
+ * - REST API (API Gateway v1)
26
+ * - Route definitions
27
+ * - Lambda handler
28
+ */
29
+ interface IApiGatewayConstructProps extends Omit<IBaseCdkConstructProps<{
30
+ /** REST API configuration options */
31
+ readonly gatewayOptions: RestApiProps;
32
+ /** Route definitions used to build API resources */
33
+ readonly routeOptions: IRouteOption[];
34
+ }>, 'appName' | 'stage' | 'stackName'> {
35
+ /**
36
+ * Lambda function handling all API routes
37
+ *
38
+ * Note:
39
+ * A single Lambda integration is reused across all routes
40
+ */
41
+ readonly handlerFunction: Function;
42
+ }
43
+ /**
44
+ * CDK construct for REST API Gateway with Lambda integration
45
+ *
46
+ * Responsibilities:
47
+ * - Creates a REST API with configurable options
48
+ * - Applies default CORS and compression settings when not provided
49
+ * - Recursively builds API resources from route definitions
50
+ * - Exposes API base URL as a CloudFormation output
51
+ */
52
+ declare class BaseApiGatewayConstruct extends Construct implements IBaseConstruct {
53
+ /** The created REST API instance */
54
+ readonly api: RestApi;
55
+ /** Enables debug logging for route creation */
56
+ enableDebug: boolean;
57
+ /**
58
+ * @param scope Parent construct
59
+ * @param id Unique construct identifier
60
+ * @param props Configuration for API, routes, and Lambda handler
61
+ */
62
+ constructor(scope: Construct, id: string, props: IApiGatewayConstructProps);
63
+ /**
64
+ * Recursively attaches routes to the API Gateway
65
+ *
66
+ * Behaviour:
67
+ * - Creates a resource for each route segment
68
+ * - Attaches method + Lambda integration
69
+ * - Traverses child routes for nested paths
70
+ *
71
+ * @param parent Parent API resource
72
+ * @param routes Route definitions
73
+ * @param integration Lambda integration applied to each route
74
+ * @param previousPath Accumulated path (used for debug logging)
75
+ * @private
76
+ */
77
+ private addRoutes;
78
+ }
79
+
80
+ export { BaseApiGatewayConstruct };
@@ -0,0 +1,93 @@
1
+ import { Construct } from 'constructs';
2
+ import { Size, RemovalPolicy, CfnOutput } from 'aws-cdk-lib';
3
+ import { RestApi, Cors, LambdaIntegration } from 'aws-cdk-lib/aws-apigateway';
4
+ import { printLog } from '@incloodsolutions/toolkit';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var BaseApiGatewayConstruct = class _BaseApiGatewayConstruct extends Construct {
9
+ static {
10
+ __name(this, "BaseApiGatewayConstruct");
11
+ }
12
+ /** The created REST API instance */
13
+ api;
14
+ /** Enables debug logging for route creation */
15
+ enableDebug = false;
16
+ /**
17
+ * @param scope Parent construct
18
+ * @param id Unique construct identifier
19
+ * @param props Configuration for API, routes, and Lambda handler
20
+ */
21
+ constructor(scope, id, props) {
22
+ super(scope, id);
23
+ this.enableDebug = props.enableDebug;
24
+ this.api = new RestApi(this, id, {
25
+ ...props?.options?.gatewayOptions,
26
+ /** Default API description if not provided */
27
+ description: props?.options?.gatewayOptions?.description || "This is a REST API using CDK",
28
+ /**
29
+ * CORS configuration
30
+ * Falls back to allowing all origins, methods, and standard headers
31
+ */
32
+ defaultCorsPreflightOptions: {
33
+ ...props?.options?.gatewayOptions?.defaultCorsPreflightOptions,
34
+ /** Allow all origins by default */
35
+ allowOrigins: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowOrigins || Cors.ALL_ORIGINS,
36
+ /** Allow all HTTP methods by default */
37
+ allowMethods: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowMethods || Cors.ALL_METHODS,
38
+ /** Merge default headers with user-defined headers */
39
+ allowHeaders: [
40
+ ...props.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowHeaders,
41
+ "Content-Type",
42
+ "Accept",
43
+ "X-Amz-Date",
44
+ "Authorization",
45
+ "X-Api-Key",
46
+ "X-Amz-Security-Token",
47
+ "X-Amz-User-Agent"
48
+ ]
49
+ },
50
+ /** Minimum payload size (in bytes) before compression is applied */
51
+ minCompressionSize: props?.options?.gatewayOptions?.minCompressionSize || Size.bytes(1)
52
+ });
53
+ if (props?.options?.routeOptions?.length && props?.handlerFunction) {
54
+ const integration = new LambdaIntegration(props.handlerFunction);
55
+ this.addRoutes(this.api.root, props.options.routeOptions, integration);
56
+ }
57
+ this.api.applyRemovalPolicy(RemovalPolicy.DESTROY);
58
+ new CfnOutput(this, "ApiGateway", {
59
+ value: this.api.url
60
+ });
61
+ }
62
+ /**
63
+ * Recursively attaches routes to the API Gateway
64
+ *
65
+ * Behaviour:
66
+ * - Creates a resource for each route segment
67
+ * - Attaches method + Lambda integration
68
+ * - Traverses child routes for nested paths
69
+ *
70
+ * @param parent Parent API resource
71
+ * @param routes Route definitions
72
+ * @param integration Lambda integration applied to each route
73
+ * @param previousPath Accumulated path (used for debug logging)
74
+ * @private
75
+ */
76
+ addRoutes(parent, routes, integration, previousPath) {
77
+ routes.forEach((route) => {
78
+ const currentPath = `${previousPath || ""}/${route.name}`;
79
+ const resource = parent.addResource(route.name);
80
+ resource.addMethod(route.method, integration);
81
+ if (route?.children.length) {
82
+ this.addRoutes(resource, route.children, integration, currentPath);
83
+ }
84
+ if (this.enableDebug) {
85
+ printLog(_BaseApiGatewayConstruct.name, `Route created: ${route.method} ${currentPath}`);
86
+ }
87
+ });
88
+ }
89
+ };
90
+
91
+ export { BaseApiGatewayConstruct };
92
+ //# sourceMappingURL=api-gateway-construct.js.map
93
+ //# sourceMappingURL=api-gateway-construct.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/aws/cdk/constructs/api-gateway-construct.ts"],"names":[],"mappings":";;;;;;;AA4DO,IAAM,uBAAA,GAAN,MAAM,wBAAA,SAAgC,SAAA,CAAoC;AAAA,EA5DjF;AA4DiF,IAAA,MAAA,CAAA,IAAA,EAAA,yBAAA,CAAA;AAAA;AAAA;AAAA,EAEvE,GAAA;AAAA;AAAA,EAGT,WAAA,GAAc,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOd,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAAkC;AAC3E,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,cAAc,KAAA,CAAM,WAAA;AAEzB,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,OAAA,CAAQ,IAAA,EAAM,EAAA,EAAI;AAAA,MAChC,GAAG,OAAO,OAAA,EAAS,cAAA;AAAA;AAAA,MAGnB,WAAA,EAAa,KAAA,EAAO,OAAA,EAAS,cAAA,EAAgB,WAAA,IAAe,8BAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM5D,2BAAA,EAA6B;AAAA,QAC5B,GAAG,KAAA,EAAO,OAAA,EAAS,cAAA,EAAgB,2BAAA;AAAA;AAAA,QAGnC,cAAc,KAAA,EAAO,OAAA,EAAS,cAAA,EAAgB,2BAAA,EAA6B,gBAAgB,IAAA,CAAK,WAAA;AAAA;AAAA,QAGhG,cAAc,KAAA,EAAO,OAAA,EAAS,cAAA,EAAgB,2BAAA,EAA6B,gBAAgB,IAAA,CAAK,WAAA;AAAA;AAAA,QAGhG,YAAA,EAAc;AAAA,UACb,GAAG,K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C,MAAA,IAAI,KAAA,EAAO,SAAS,MAAA,EAAQ;AAC3B,QAAA,IAAA,CAAK,SAAA,CAAU,QAAA,EAAU,KAAA,CAAM,QAAA,EAAU,aAAa,WAAW,CAAA;AAAA,MAClE;AAGA,MAAA,IAAI,KAAK,WAAA,EAAa;AACrB,QAAA,QAAA,CAAS,yBAAwB,IAAA,EAAM,CAAA,eAAA,EAAkB,MAAM,MAAM,CAAA,CAAA,EAAI,WAAW,CAAA,CAAE,CAAA;AAAA,MACvF;AAAA,IACD,CAAC,CAAA;AAAA,EACF;AACD","file":"api-gateway-construct.js","sourcesContent":["import { Construct } from 'constructs';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { HttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';\nimport { CfnOutput, RemovalPolicy, Size } from 'aws-cdk-lib';\nimport { Cors, IResource, LambdaIntegration, RestApi, RestApiProps } from 'aws-cdk-lib/aws-apigateway';\n\nimport { printLog } from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps, IBaseConstruct } from '../../types';\n\n\n/**\n * Route definition for API Gateway resources\n *\n * Supports hierarchical route structures using `children`\n */\ninterface IRouteOption {\n\t/** Path segment (e.g. 'users', 'orders') */\n\tname: string;\n\n\t/** HTTP method for the route */\n\tmethod: `${HttpMethod}`;\n\n\t/** Nested routes under this path */\n\tchildren?: IRouteOption[];\n}\n\n/**\n * Props for BaseApiGatewayConstruct\n *\n * Provides configuration for:\n * - REST API (API Gateway v1)\n * - Route definitions\n * - Lambda handler\n */\ninterface IApiGatewayConstructProps extends Omit<IBaseCdkConstructProps<{\n\t/** REST API configuration options */\n\treadonly gatewayOptions: RestApiProps;\n\n\t/** Route definitions used to build API resources */\n\treadonly routeOptions: IRouteOption[];\n}>, 'appName' | 'stage' | 'stackName'> {\n\t/**\n\t * Lambda function handling all API routes\n\t *\n\t * Note:\n\t * A single Lambda integration is reused across all routes\n\t */\n\treadonly handlerFunction: Function;\n}\n\n/**\n * CDK construct for REST API Gateway with Lambda integration\n *\n * Responsibilities:\n * - Creates a REST API with configurable options\n * - Applies default CORS and compression settings when not provided\n * - Recursively builds API resources from route definitions\n * - Exposes API base URL as a CloudFormation output\n */\nexport class BaseApiGatewayConstruct extends Construct implements IBaseConstruct {\n\t/** The created REST API instance */\n\treadonly api: RestApi;\n\n\t/** Enables debug logging for route creation */\n\tenableDebug = false;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for API, routes, and Lambda handler\n\t */\n\tconstructor(scope: Construct, id: string, props: IApiGatewayConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.enableDebug = props.enableDebug;\n\n\t\tthis.api = new RestApi(this, id, {\n\t\t\t...props?.options?.gatewayOptions,\n\n\t\t\t/** Default API description if not provided */\n\t\t\tdescription: props?.options?.gatewayOptions?.description || 'This is a REST API using CDK',\n\n\t\t\t/**\n\t\t\t * CORS configuration\n\t\t\t * Falls back to allowing all origins, methods, and standard headers\n\t\t\t */\n\t\t\tdefaultCorsPreflightOptions: {\n\t\t\t\t...props?.options?.gatewayOptions?.defaultCorsPreflightOptions,\n\n\t\t\t\t/** Allow all origins by default */\n\t\t\t\tallowOrigins: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowOrigins || Cors.ALL_ORIGINS,\n\n\t\t\t\t/** Allow all HTTP methods by default */\n\t\t\t\tallowMethods: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowMethods || Cors.ALL_METHODS,\n\n\t\t\t\t/** Merge default headers with user-defined headers */\n\t\t\t\tallowHeaders: [\n\t\t\t\t\t...props.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowHeaders,\n\t\t\t\t\t'Content-Type',\n\t\t\t\t\t'Accept',\n\t\t\t\t\t'X-Amz-Date',\n\t\t\t\t\t'Authorization',\n\t\t\t\t\t'X-Api-Key',\n\t\t\t\t\t'X-Amz-Security-Token',\n\t\t\t\t\t'X-Amz-User-Agent'\n\t\t\t\t]\n\t\t\t},\n\n\t\t\t/** Minimum payload size (in bytes) before compression is applied */\n\t\t\tminCompressionSize: props?.options?.gatewayOptions?.minCompressionSize || Size.bytes(1),\n\t\t});\n\n\t\t/**\n\t\t * Register routes if provided\n\t\t */\n\t\tif (props?.options?.routeOptions?.length && props?.handlerFunction) {\n\t\t\tconst integration = new LambdaIntegration(props.handlerFunction);\n\n\t\t\t/**\n\t\t\t * Attach routes recursively starting from API root\n\t\t\t */\n\t\t\tthis.addRoutes(this.api.root, props.options.routeOptions, integration);\n\t\t}\n\n\t\t/**\n\t\t * Apply removal policy (useful for non-production environments)\n\t\t */\n\t\tthis.api.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing API base URL\n\t\t */\n\t\tnew CfnOutput(this, 'ApiGateway', {\n\t\t\tvalue: this.api.url\n\t\t});\n\t}\n\n\t/**\n\t * Recursively attaches routes to the API Gateway\n\t *\n\t * Behaviour:\n\t * - Creates a resource for each route segment\n\t * - Attaches method + Lambda integration\n\t * - Traverses child routes for nested paths\n\t *\n\t * @param parent Parent API resource\n\t * @param routes Route definitions\n\t * @param integration Lambda integration applied to each route\n\t * @param previousPath Accumulated path (used for debug logging)\n\t * @private\n\t */\n\tprivate addRoutes(\n\t\tparent: IResource,\n\t\troutes: IRouteOption[],\n\t\tintegration: LambdaIntegration,\n\t\tpreviousPath?: string\n\t) {\n\t\troutes.forEach(route => {\n\t\t\tconst currentPath = `${previousPath || ''}/${route.name}`;\n\n\t\t\tconst resource = parent.addResource(route.name);\n\n\t\t\t/** Attach HTTP method with Lambda integration */\n\t\t\tresource.addMethod(route.method, integration);\n\n\t\t\t/** Recursively process child routes */\n\t\t\tif (route?.children.length) {\n\t\t\t\tthis.addRoutes(resource, route.children, integration, currentPath);\n\t\t\t}\n\n\t\t\t/** Optional debug logging */\n\t\t\tif (this.enableDebug) {\n\t\t\t\tprintLog(BaseApiGatewayConstruct.name, `Route created: ${route.method} ${currentPath}`);\n\t\t\t}\n\t\t});\n\t}\n}"]}
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var constructs = require('constructs');
4
+ var awsCdkLib = require('aws-cdk-lib');
5
+ var awsApigatewayv2Integrations = require('aws-cdk-lib/aws-apigatewayv2-integrations');
6
+ var awsApigatewayv2 = require('aws-cdk-lib/aws-apigatewayv2');
7
+ var toolkit = require('@incloodsolutions/toolkit');
8
+
9
+ var __defProp = Object.defineProperty;
10
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
+ var BaseApiGatewayV2Construct = class extends constructs.Construct {
12
+ static {
13
+ __name(this, "BaseApiGatewayV2Construct");
14
+ }
15
+ /** The created HTTP API instance */
16
+ api;
17
+ /** Enables debug logging (if used externally) */
18
+ enableDebug = false;
19
+ /**
20
+ * @param scope Parent construct
21
+ * @param id Unique construct identifier
22
+ * @param props Configuration for API, routes, and handlers
23
+ */
24
+ constructor(scope, id, props) {
25
+ super(scope, id);
26
+ this.enableDebug = props.enableDebug;
27
+ this.api = new awsApigatewayv2.HttpApi(this, id, {
28
+ ...props?.options?.gatewayOptions,
29
+ /** Default API description if not provided */
30
+ description: props?.options?.gatewayOptions?.description || "This is an Http API using CDK",
31
+ /**
32
+ * CORS configuration
33
+ * Falls back to allowing all methods and standard headers if not explicitly defined
34
+ */
35
+ corsPreflight: {
36
+ ...props.options?.gatewayOptions?.corsPreflight,
37
+ /** Allow all HTTP methods by default */
38
+ allowMethods: props.options?.gatewayOptions?.corsPreflight?.allowMethods || Object.values(awsApigatewayv2.CorsHttpMethod),
39
+ /** Merge default headers with user-defined headers */
40
+ allowHeaders: [
41
+ "Content-Type",
42
+ "Accept",
43
+ "X-Amz-Date",
44
+ "Authorization",
45
+ "X-Api-Key",
46
+ "X-Amz-Security-Token",
47
+ "X-Amz-User-Agent",
48
+ ...props.options?.gatewayOptions?.corsPreflight?.allowHeaders || []
49
+ ]
50
+ }
51
+ });
52
+ if (!props?.handlerFunctions?.length) {
53
+ throw new toolkit.CustomException("Construct requires atleast one function");
54
+ }
55
+ if (props?.options?.routeOptions?.length) {
56
+ props.handlerFunctions.forEach((handlerFunc) => {
57
+ props?.options?.routeOptions.forEach((route) => {
58
+ this.api.addRoutes({
59
+ ...route,
60
+ /**
61
+ * Lambda integration for each route
62
+ */
63
+ integration: new awsApigatewayv2Integrations.HttpLambdaIntegration("routes", handlerFunc)
64
+ });
65
+ });
66
+ });
67
+ }
68
+ this.api.applyRemovalPolicy(awsCdkLib.RemovalPolicy.DESTROY);
69
+ new awsCdkLib.CfnOutput(this, "ApiGatewayV2", {
70
+ value: this.api.url
71
+ });
72
+ }
73
+ };
74
+
75
+ exports.BaseApiGatewayV2Construct = BaseApiGatewayV2Construct;
76
+ //# sourceMappingURL=api-gateway-v2-construct.cjs.map
77
+ //# sourceMappingURL=api-gateway-v2-construct.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/aws/cdk/constructs/api-gateway-v2-construct.ts"],"names":["Construct","HttpApi","CorsHttpMethod","CustomException","HttpLambdaIntegration","RemovalPolicy","CfnOutput"],"mappings":";;;;;;;;;;AA+CO,IAAM,yBAAA,GAAN,cAAwCA,oBAAA,CAAoC;AAAA,EA/CnF;AA+CmF,IAAA,MAAA,CAAA,IAAA,EAAA,2BAAA,CAAA;AAAA;AAAA;AAAA,EAEzE,GAAA;AAAA;AAAA,EAGT,WAAA,GAAc,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOd,WAAA,CAAY,KAAA,EAAkB,EAAA,EAAY,KAAA,EAAoC;AAC7E,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,cAAc,KAAA,CAAM,WAAA;AAEzB,IAAA,IAAA,CAAK,GAAA,GAAM,IAAIC,uBAAA,CAAQ,IAAA,EAAM,EAAA,EAAI;AAAA,MAChC,GAAG,OAAO,OAAA,EAAS,cAAA;AAAA;AAAA,MAGnB,WAAA,EAAa,KAAA,EAAO,OAAA,EAAS,cAAA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CAAI;AAAA,KAChB,CAAA;AAAA,EACF;AACD","file":"api-gateway-v2-construct.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { CfnOutput, RemovalPolicy } from 'aws-cdk-lib';\nimport { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';\nimport { AddRoutesOptions, CorsHttpMethod, HttpApi, HttpApiProps } from 'aws-cdk-lib/aws-apigatewayv2';\n\nimport { CustomException } from '@incloodsolutions/toolkit';\nimport { IBaseCdkConstructProps, IBaseConstruct } from '../../types';\n\n/**\n * Properties for configuring the API Gateway v2 construct\n *\n * Extends base CDK construct props and provides configuration for:\n * - HTTP API (Api Gateway v2)\n * - Route definitions\n * - Lambda handlers\n */\ninterface IApiGatewayV2ConstructProps extends Omit<IBaseCdkConstructProps<{\n\t/** HTTP API configuration options */\n\treadonly gatewayOptions: HttpApiProps;\n\n\t/** Route definitions passed directly to `addRoutes` */\n\treadonly routeOptions: Partial<AddRoutesOptions>[];\n}>, 'appName' | 'stage' | 'stackName'> {\n\t/**\n\t * Lambda functions used as route handlers\n\t *\n\t * Note:\n\t * Each handler is paired with each route during route creation\n\t */\n\treadonly handlerFunctions: Function[];\n}\n\n\n/**\n * CDK construct for creating an API Gateway v2 (HTTP API)\n *\n * Responsibilities:\n * - Creates an HTTP API with optional custom configuration\n * - Applies default CORS configuration when not provided\n * - Attaches routes with Lambda integrations\n * - Exposes API URL as a CloudFormation output\n *\n * Behaviour:\n * - Each route is registered for every provided handler function\n * - Throws if no handler functions are supplied\n */\nexport class BaseApiGatewayV2Construct extends Construct implements IBaseConstruct {\n\t/** The created HTTP API instance */\n\treadonly api: HttpApi;\n\n\t/** Enables debug logging (if used externally) */\n\tenableDebug = false;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for API, routes, and handlers\n\t */\n\tconstructor(scope: Construct, id: string, props: IApiGatewayV2ConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.enableDebug = props.enableDebug;\n\n\t\tthis.api = new HttpApi(this, id, {\n\t\t\t...props?.options?.gatewayOptions,\n\n\t\t\t/** Default API description if not provided */\n\t\t\tdescription: props?.options?.gatewayOptions?.description || 'This is an Http API using CDK',\n\n\t\t\t/**\n\t\t\t * CORS configuration\n\t\t\t * Falls back to allowing all methods and standard headers if not explicitly defined\n\t\t\t */\n\t\t\tcorsPreflight: {\n\t\t\t\t...props.options?.gatewayOptions?.corsPreflight,\n\n\t\t\t\t/** Allow all HTTP methods by default */\n\t\t\t\tallowMethods: props.options?.gatewayOptions?.corsPreflight?.allowMethods || Object.values(CorsHttpMethod),\n\n\t\t\t\t/** Merge default headers with user-defined headers */\n\t\t\t\tallowHeaders: [\n\t\t\t\t\t'Content-Type',\n\t\t\t\t\t'Accept',\n\t\t\t\t\t'X-Amz-Date',\n\t\t\t\t\t'Authorization',\n\t\t\t\t\t'X-Api-Key',\n\t\t\t\t\t'X-Amz-Security-Token',\n\t\t\t\t\t'X-Amz-User-Agent',\n\t\t\t\t\t...props.options?.gatewayOptions?.corsPreflight?.allowHeaders || []\n\t\t\t\t]\n\t\t\t}\n\t\t});\n\n\t\t/**\n\t\t * Ensure at least one handler function is provided\n\t\t */\n\t\tif (!props?.handlerFunctions?.length) {\n\t\t\tthrow new CustomException('Construct requires atleast one function');\n\t\t}\n\n\t\t/**\n\t\t * Register routes with Lambda integrations\n\t\t */\n\t\tif (props?.options?.routeOptions?.length) {\n\t\t\tprops.handlerFunctions.forEach(handlerFunc => {\n\t\t\t\tprops?.options?.routeOptions.forEach(route => {\n\t\t\t\t\tthis.api.addRoutes({\n\t\t\t\t\t\t...route,\n\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Lambda integration for each route\n\t\t\t\t\t\t */\n\t\t\t\t\t\tintegration: new HttpLambdaIntegration('routes', handlerFunc)\n\t\t\t\t\t} as AddRoutesOptions);\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Apply removal policy (useful for non-production environments)\n\t\t */\n\t\tthis.api.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing the API base URL\n\t\t */\n\t\tnew CfnOutput(this, 'ApiGatewayV2', {\n\t\t\tvalue: this.api.url,\n\t\t});\n\t}\n}"]}
@@ -0,0 +1,55 @@
1
+ import { Construct } from 'constructs';
2
+ import { Function } from 'aws-cdk-lib/aws-lambda';
3
+ import { HttpApi, HttpApiProps, AddRoutesOptions } from 'aws-cdk-lib/aws-apigatewayv2';
4
+ import { IBaseConstruct, IBaseCdkConstructProps } from '../../types/index.cjs';
5
+ import '@incloodsolutions/toolkit';
6
+
7
+ /**
8
+ * Properties for configuring the API Gateway v2 construct
9
+ *
10
+ * Extends base CDK construct props and provides configuration for:
11
+ * - HTTP API (Api Gateway v2)
12
+ * - Route definitions
13
+ * - Lambda handlers
14
+ */
15
+ interface IApiGatewayV2ConstructProps extends Omit<IBaseCdkConstructProps<{
16
+ /** HTTP API configuration options */
17
+ readonly gatewayOptions: HttpApiProps;
18
+ /** Route definitions passed directly to `addRoutes` */
19
+ readonly routeOptions: Partial<AddRoutesOptions>[];
20
+ }>, 'appName' | 'stage' | 'stackName'> {
21
+ /**
22
+ * Lambda functions used as route handlers
23
+ *
24
+ * Note:
25
+ * Each handler is paired with each route during route creation
26
+ */
27
+ readonly handlerFunctions: Function[];
28
+ }
29
+ /**
30
+ * CDK construct for creating an API Gateway v2 (HTTP API)
31
+ *
32
+ * Responsibilities:
33
+ * - Creates an HTTP API with optional custom configuration
34
+ * - Applies default CORS configuration when not provided
35
+ * - Attaches routes with Lambda integrations
36
+ * - Exposes API URL as a CloudFormation output
37
+ *
38
+ * Behaviour:
39
+ * - Each route is registered for every provided handler function
40
+ * - Throws if no handler functions are supplied
41
+ */
42
+ declare class BaseApiGatewayV2Construct extends Construct implements IBaseConstruct {
43
+ /** The created HTTP API instance */
44
+ readonly api: HttpApi;
45
+ /** Enables debug logging (if used externally) */
46
+ enableDebug: boolean;
47
+ /**
48
+ * @param scope Parent construct
49
+ * @param id Unique construct identifier
50
+ * @param props Configuration for API, routes, and handlers
51
+ */
52
+ constructor(scope: Construct, id: string, props: IApiGatewayV2ConstructProps);
53
+ }
54
+
55
+ export { BaseApiGatewayV2Construct };
@@ -0,0 +1,55 @@
1
+ import { Construct } from 'constructs';
2
+ import { Function } from 'aws-cdk-lib/aws-lambda';
3
+ import { HttpApi, HttpApiProps, AddRoutesOptions } from 'aws-cdk-lib/aws-apigatewayv2';
4
+ import { IBaseConstruct, IBaseCdkConstructProps } from '../../types/index.js';
5
+ import '@incloodsolutions/toolkit';
6
+
7
+ /**
8
+ * Properties for configuring the API Gateway v2 construct
9
+ *
10
+ * Extends base CDK construct props and provides configuration for:
11
+ * - HTTP API (Api Gateway v2)
12
+ * - Route definitions
13
+ * - Lambda handlers
14
+ */
15
+ interface IApiGatewayV2ConstructProps extends Omit<IBaseCdkConstructProps<{
16
+ /** HTTP API configuration options */
17
+ readonly gatewayOptions: HttpApiProps;
18
+ /** Route definitions passed directly to `addRoutes` */
19
+ readonly routeOptions: Partial<AddRoutesOptions>[];
20
+ }>, 'appName' | 'stage' | 'stackName'> {
21
+ /**
22
+ * Lambda functions used as route handlers
23
+ *
24
+ * Note:
25
+ * Each handler is paired with each route during route creation
26
+ */
27
+ readonly handlerFunctions: Function[];
28
+ }
29
+ /**
30
+ * CDK construct for creating an API Gateway v2 (HTTP API)
31
+ *
32
+ * Responsibilities:
33
+ * - Creates an HTTP API with optional custom configuration
34
+ * - Applies default CORS configuration when not provided
35
+ * - Attaches routes with Lambda integrations
36
+ * - Exposes API URL as a CloudFormation output
37
+ *
38
+ * Behaviour:
39
+ * - Each route is registered for every provided handler function
40
+ * - Throws if no handler functions are supplied
41
+ */
42
+ declare class BaseApiGatewayV2Construct extends Construct implements IBaseConstruct {
43
+ /** The created HTTP API instance */
44
+ readonly api: HttpApi;
45
+ /** Enables debug logging (if used externally) */
46
+ enableDebug: boolean;
47
+ /**
48
+ * @param scope Parent construct
49
+ * @param id Unique construct identifier
50
+ * @param props Configuration for API, routes, and handlers
51
+ */
52
+ constructor(scope: Construct, id: string, props: IApiGatewayV2ConstructProps);
53
+ }
54
+
55
+ export { BaseApiGatewayV2Construct };
@@ -0,0 +1,75 @@
1
+ import { Construct } from 'constructs';
2
+ import { RemovalPolicy, CfnOutput } from 'aws-cdk-lib';
3
+ import { HttpLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
4
+ import { HttpApi, CorsHttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';
5
+ import { CustomException } from '@incloodsolutions/toolkit';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var BaseApiGatewayV2Construct = class extends Construct {
10
+ static {
11
+ __name(this, "BaseApiGatewayV2Construct");
12
+ }
13
+ /** The created HTTP API instance */
14
+ api;
15
+ /** Enables debug logging (if used externally) */
16
+ enableDebug = false;
17
+ /**
18
+ * @param scope Parent construct
19
+ * @param id Unique construct identifier
20
+ * @param props Configuration for API, routes, and handlers
21
+ */
22
+ constructor(scope, id, props) {
23
+ super(scope, id);
24
+ this.enableDebug = props.enableDebug;
25
+ this.api = new HttpApi(this, id, {
26
+ ...props?.options?.gatewayOptions,
27
+ /** Default API description if not provided */
28
+ description: props?.options?.gatewayOptions?.description || "This is an Http API using CDK",
29
+ /**
30
+ * CORS configuration
31
+ * Falls back to allowing all methods and standard headers if not explicitly defined
32
+ */
33
+ corsPreflight: {
34
+ ...props.options?.gatewayOptions?.corsPreflight,
35
+ /** Allow all HTTP methods by default */
36
+ allowMethods: props.options?.gatewayOptions?.corsPreflight?.allowMethods || Object.values(CorsHttpMethod),
37
+ /** Merge default headers with user-defined headers */
38
+ allowHeaders: [
39
+ "Content-Type",
40
+ "Accept",
41
+ "X-Amz-Date",
42
+ "Authorization",
43
+ "X-Api-Key",
44
+ "X-Amz-Security-Token",
45
+ "X-Amz-User-Agent",
46
+ ...props.options?.gatewayOptions?.corsPreflight?.allowHeaders || []
47
+ ]
48
+ }
49
+ });
50
+ if (!props?.handlerFunctions?.length) {
51
+ throw new CustomException("Construct requires atleast one function");
52
+ }
53
+ if (props?.options?.routeOptions?.length) {
54
+ props.handlerFunctions.forEach((handlerFunc) => {
55
+ props?.options?.routeOptions.forEach((route) => {
56
+ this.api.addRoutes({
57
+ ...route,
58
+ /**
59
+ * Lambda integration for each route
60
+ */
61
+ integration: new HttpLambdaIntegration("routes", handlerFunc)
62
+ });
63
+ });
64
+ });
65
+ }
66
+ this.api.applyRemovalPolicy(RemovalPolicy.DESTROY);
67
+ new CfnOutput(this, "ApiGatewayV2", {
68
+ value: this.api.url
69
+ });
70
+ }
71
+ };
72
+
73
+ export { BaseApiGatewayV2Construct };
74
+ //# sourceMappingURL=api-gateway-v2-construct.js.map
75
+ //# sourceMappingURL=api-gateway-v2-construct.js.map