@incloodsolutions/devkit 0.0.2 → 0.0.4

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 (128) hide show
  1. package/README.md +150 -41
  2. package/dist/aws-cdk/api-gateway-v2.cjs +77 -0
  3. package/dist/aws-cdk/api-gateway-v2.cjs.map +1 -0
  4. package/dist/aws-cdk/api-gateway-v2.d.cts +55 -0
  5. package/dist/aws-cdk/api-gateway-v2.d.ts +55 -0
  6. package/dist/aws-cdk/api-gateway-v2.js +75 -0
  7. package/dist/aws-cdk/api-gateway-v2.js.map +1 -0
  8. package/dist/aws-cdk/api-gateway-websocket.cjs +77 -0
  9. package/dist/aws-cdk/api-gateway-websocket.cjs.map +1 -0
  10. package/dist/aws-cdk/api-gateway-websocket.d.cts +73 -0
  11. package/dist/aws-cdk/api-gateway-websocket.d.ts +73 -0
  12. package/dist/aws-cdk/api-gateway-websocket.js +75 -0
  13. package/dist/aws-cdk/api-gateway-websocket.js.map +1 -0
  14. package/dist/aws-cdk/api-gateway.cjs +98 -0
  15. package/dist/aws-cdk/api-gateway.cjs.map +1 -0
  16. package/dist/aws-cdk/api-gateway.d.cts +80 -0
  17. package/dist/aws-cdk/api-gateway.d.ts +80 -0
  18. package/dist/aws-cdk/api-gateway.js +96 -0
  19. package/dist/aws-cdk/api-gateway.js.map +1 -0
  20. package/dist/aws-cdk/cloudfront.cjs +68 -0
  21. package/dist/aws-cdk/cloudfront.cjs.map +1 -0
  22. package/dist/aws-cdk/cloudfront.d.cts +36 -0
  23. package/dist/aws-cdk/cloudfront.d.ts +36 -0
  24. package/dist/aws-cdk/cloudfront.js +66 -0
  25. package/dist/aws-cdk/cloudfront.js.map +1 -0
  26. package/dist/aws-cdk/cloudwatch.cjs +43 -0
  27. package/dist/aws-cdk/cloudwatch.cjs.map +1 -0
  28. package/dist/aws-cdk/cloudwatch.d.cts +36 -0
  29. package/dist/aws-cdk/cloudwatch.d.ts +36 -0
  30. package/dist/aws-cdk/cloudwatch.js +41 -0
  31. package/dist/aws-cdk/cloudwatch.js.map +1 -0
  32. package/dist/aws-cdk/dynamo-db.cjs +113 -0
  33. package/dist/aws-cdk/dynamo-db.cjs.map +1 -0
  34. package/dist/aws-cdk/dynamo-db.d.cts +53 -0
  35. package/dist/aws-cdk/dynamo-db.d.ts +53 -0
  36. package/dist/aws-cdk/dynamo-db.js +111 -0
  37. package/dist/aws-cdk/dynamo-db.js.map +1 -0
  38. package/dist/aws-cdk/event-bridge.cjs +47 -0
  39. package/dist/aws-cdk/event-bridge.cjs.map +1 -0
  40. package/dist/aws-cdk/event-bridge.d.cts +41 -0
  41. package/dist/aws-cdk/event-bridge.d.ts +41 -0
  42. package/dist/aws-cdk/event-bridge.js +45 -0
  43. package/dist/aws-cdk/event-bridge.js.map +1 -0
  44. package/dist/aws-cdk/lambda-authorizer-v2.cjs +50 -0
  45. package/dist/aws-cdk/lambda-authorizer-v2.cjs.map +1 -0
  46. package/dist/aws-cdk/lambda-authorizer-v2.d.cts +45 -0
  47. package/dist/aws-cdk/lambda-authorizer-v2.d.ts +45 -0
  48. package/dist/aws-cdk/lambda-authorizer-v2.js +48 -0
  49. package/dist/aws-cdk/lambda-authorizer-v2.js.map +1 -0
  50. package/dist/aws-cdk/lambda-authorizer.cjs +37 -0
  51. package/dist/aws-cdk/lambda-authorizer.cjs.map +1 -0
  52. package/dist/aws-cdk/lambda-authorizer.d.cts +44 -0
  53. package/dist/aws-cdk/lambda-authorizer.d.ts +44 -0
  54. package/dist/aws-cdk/lambda-authorizer.js +35 -0
  55. package/dist/aws-cdk/lambda-authorizer.js.map +1 -0
  56. package/dist/aws-cdk/lambda-layer.cjs +69 -0
  57. package/dist/aws-cdk/lambda-layer.cjs.map +1 -0
  58. package/dist/aws-cdk/lambda-layer.d.cts +52 -0
  59. package/dist/aws-cdk/lambda-layer.d.ts +52 -0
  60. package/dist/aws-cdk/lambda-layer.js +67 -0
  61. package/dist/aws-cdk/lambda-layer.js.map +1 -0
  62. package/dist/aws-cdk/lambda.cjs +82 -0
  63. package/dist/aws-cdk/lambda.cjs.map +1 -0
  64. package/dist/aws-cdk/lambda.d.cts +37 -0
  65. package/dist/aws-cdk/lambda.d.ts +37 -0
  66. package/dist/aws-cdk/lambda.js +80 -0
  67. package/dist/aws-cdk/lambda.js.map +1 -0
  68. package/dist/aws-cdk/role-policy.cjs +53 -0
  69. package/dist/aws-cdk/role-policy.cjs.map +1 -0
  70. package/dist/aws-cdk/role-policy.d.cts +44 -0
  71. package/dist/aws-cdk/role-policy.d.ts +44 -0
  72. package/dist/aws-cdk/role-policy.js +51 -0
  73. package/dist/aws-cdk/role-policy.js.map +1 -0
  74. package/dist/aws-cdk/s3-deployment.cjs +177 -0
  75. package/dist/aws-cdk/s3-deployment.cjs.map +1 -0
  76. package/dist/aws-cdk/s3-deployment.d.cts +72 -0
  77. package/dist/aws-cdk/s3-deployment.d.ts +72 -0
  78. package/dist/aws-cdk/s3-deployment.js +175 -0
  79. package/dist/aws-cdk/s3-deployment.js.map +1 -0
  80. package/dist/aws-cdk/s3.cjs +38 -0
  81. package/dist/aws-cdk/s3.cjs.map +1 -0
  82. package/dist/aws-cdk/s3.d.cts +36 -0
  83. package/dist/aws-cdk/s3.d.ts +36 -0
  84. package/dist/aws-cdk/s3.js +36 -0
  85. package/dist/aws-cdk/s3.js.map +1 -0
  86. package/dist/aws-cdk/sns.cjs +43 -0
  87. package/dist/aws-cdk/sns.cjs.map +1 -0
  88. package/dist/aws-cdk/sns.d.cts +45 -0
  89. package/dist/aws-cdk/sns.d.ts +45 -0
  90. package/dist/aws-cdk/sns.js +41 -0
  91. package/dist/aws-cdk/sns.js.map +1 -0
  92. package/dist/aws-cdk/sqs.cjs +55 -0
  93. package/dist/aws-cdk/sqs.cjs.map +1 -0
  94. package/dist/aws-cdk/sqs.d.cts +52 -0
  95. package/dist/aws-cdk/sqs.d.ts +52 -0
  96. package/dist/aws-cdk/sqs.js +53 -0
  97. package/dist/aws-cdk/sqs.js.map +1 -0
  98. package/dist/aws-cdk/vpc.cjs +33 -0
  99. package/dist/aws-cdk/vpc.cjs.map +1 -0
  100. package/dist/aws-cdk/vpc.d.cts +34 -0
  101. package/dist/aws-cdk/vpc.d.ts +34 -0
  102. package/dist/aws-cdk/vpc.js +31 -0
  103. package/dist/aws-cdk/vpc.js.map +1 -0
  104. package/dist/aws-cdk.cjs +905 -0
  105. package/dist/aws-cdk.cjs.map +1 -0
  106. package/dist/aws-cdk.d.cts +34 -0
  107. package/dist/aws-cdk.d.ts +34 -0
  108. package/dist/aws-cdk.js +887 -0
  109. package/dist/aws-cdk.js.map +1 -0
  110. package/dist/aws-types.cjs +4 -0
  111. package/dist/aws-types.cjs.map +1 -0
  112. package/dist/aws-types.d.cts +42 -0
  113. package/dist/aws-types.d.ts +42 -0
  114. package/dist/aws-types.js +3 -0
  115. package/dist/aws-types.js.map +1 -0
  116. package/dist/aws.cjs +905 -0
  117. package/dist/aws.cjs.map +1 -0
  118. package/dist/aws.d.cts +34 -0
  119. package/dist/aws.d.ts +34 -0
  120. package/dist/aws.js +887 -0
  121. package/dist/aws.js.map +1 -0
  122. package/dist/index.cjs +43 -19
  123. package/dist/index.cjs.map +1 -1
  124. package/dist/index.d.cts +34 -755
  125. package/dist/index.d.ts +34 -755
  126. package/dist/index.js +43 -19
  127. package/dist/index.js.map +1 -1
  128. package/package.json +181 -19
package/dist/aws.cjs ADDED
@@ -0,0 +1,905 @@
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
+ var awsApigatewayv2Integrations = require('aws-cdk-lib/aws-apigatewayv2-integrations');
8
+ var awsApigatewayv2 = require('aws-cdk-lib/aws-apigatewayv2');
9
+ var awsCloudfront = require('aws-cdk-lib/aws-cloudfront');
10
+ var awsLogs = require('aws-cdk-lib/aws-logs');
11
+ var awsDynamodb = require('aws-cdk-lib/aws-dynamodb');
12
+ var awsEvents = require('aws-cdk-lib/aws-events');
13
+ var awsEventsTargets = require('aws-cdk-lib/aws-events-targets');
14
+ var awsApigatewayv2Authorizers = require('aws-cdk-lib/aws-apigatewayv2-authorizers');
15
+ var awsLambda = require('aws-cdk-lib/aws-lambda');
16
+ var awsIam = require('aws-cdk-lib/aws-iam');
17
+ var awsS3 = require('aws-cdk-lib/aws-s3');
18
+ var awsCloudfrontOrigins = require('aws-cdk-lib/aws-cloudfront-origins');
19
+ var awsS3Deployment = require('aws-cdk-lib/aws-s3-deployment');
20
+ var awsSns = require('aws-cdk-lib/aws-sns');
21
+ var awsSnsSubscriptions = require('aws-cdk-lib/aws-sns-subscriptions');
22
+ var awsSqs = require('aws-cdk-lib/aws-sqs');
23
+ var awsEc2 = require('aws-cdk-lib/aws-ec2');
24
+
25
+ var __defProp = Object.defineProperty;
26
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
27
+ var BaseApiGatewayConstruct = class _BaseApiGatewayConstruct extends constructs.Construct {
28
+ static {
29
+ __name(this, "BaseApiGatewayConstruct");
30
+ }
31
+ /** The created REST API instance */
32
+ api;
33
+ /** Enables debug logging for route creation */
34
+ enableDebug = false;
35
+ /**
36
+ * @param scope Parent construct
37
+ * @param id Unique construct identifier
38
+ * @param props Configuration for API, routes, and Lambda handler
39
+ */
40
+ constructor(scope, id, props) {
41
+ super(scope, id);
42
+ this.enableDebug = props.enableDebug;
43
+ this.api = new awsApigateway.RestApi(this, id, {
44
+ ...props?.options?.gatewayOptions,
45
+ /** Default API description if not provided */
46
+ description: props?.options?.gatewayOptions?.description || "This is a REST API using CDK",
47
+ /**
48
+ * CORS configuration
49
+ * Falls back to allowing all origins, methods, and standard headers
50
+ */
51
+ defaultCorsPreflightOptions: {
52
+ ...props?.options?.gatewayOptions?.defaultCorsPreflightOptions,
53
+ /** Allow all origins by default */
54
+ allowOrigins: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowOrigins || awsApigateway.Cors.ALL_ORIGINS,
55
+ /** Allow all HTTP methods by default */
56
+ allowMethods: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowMethods || awsApigateway.Cors.ALL_METHODS,
57
+ /** Merge default headers with user-defined headers */
58
+ allowHeaders: [
59
+ ...props.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowHeaders,
60
+ "Content-Type",
61
+ "Accept",
62
+ "X-Amz-Date",
63
+ "Authorization",
64
+ "X-Api-Key",
65
+ "X-Amz-Security-Token",
66
+ "X-Amz-User-Agent"
67
+ ]
68
+ },
69
+ /** Minimum payload size (in bytes) before compression is applied */
70
+ minCompressionSize: props?.options?.gatewayOptions?.minCompressionSize || awsCdkLib.Size.bytes(1)
71
+ });
72
+ if (props?.options?.routeOptions?.length && props?.handlerFunction) {
73
+ const integration = new awsApigateway.LambdaIntegration(props.handlerFunction);
74
+ this.addRoutes(this.api.root, props.options.routeOptions, integration);
75
+ }
76
+ this.api.applyRemovalPolicy(awsCdkLib.RemovalPolicy.DESTROY);
77
+ new awsCdkLib.CfnOutput(this, "ApiGateway", {
78
+ value: this.api.url
79
+ });
80
+ }
81
+ /**
82
+ * Recursively attaches routes to the API Gateway
83
+ *
84
+ * Behaviour:
85
+ * - Creates a resource for each route segment
86
+ * - Attaches method + Lambda integration
87
+ * - Traverses child routes for nested paths
88
+ *
89
+ * @param parent Parent API resource
90
+ * @param routes Route definitions
91
+ * @param integration Lambda integration applied to each route
92
+ * @param previousPath Accumulated path (used for debug logging)
93
+ * @private
94
+ */
95
+ addRoutes(parent, routes, integration, previousPath) {
96
+ routes.forEach((route) => {
97
+ const currentPath = `${previousPath || ""}/${route.name}`;
98
+ const resource = parent.addResource(route.name);
99
+ resource.addMethod(route.method, integration);
100
+ if (route?.children.length) {
101
+ this.addRoutes(resource, route.children, integration, currentPath);
102
+ }
103
+ if (this.enableDebug) {
104
+ toolkit.printLog(
105
+ _BaseApiGatewayConstruct.name,
106
+ `Route created: ${route.method} ${currentPath}`
107
+ );
108
+ }
109
+ });
110
+ }
111
+ };
112
+ var BaseApiGatewayV2Construct = class extends constructs.Construct {
113
+ static {
114
+ __name(this, "BaseApiGatewayV2Construct");
115
+ }
116
+ /** The created HTTP API instance */
117
+ api;
118
+ /** Enables debug logging (if used externally) */
119
+ enableDebug = false;
120
+ /**
121
+ * @param scope Parent construct
122
+ * @param id Unique construct identifier
123
+ * @param props Configuration for API, routes, and handlers
124
+ */
125
+ constructor(scope, id, props) {
126
+ super(scope, id);
127
+ this.enableDebug = props.enableDebug;
128
+ this.api = new awsApigatewayv2.HttpApi(this, id, {
129
+ ...props?.options?.gatewayOptions,
130
+ /** Default API description if not provided */
131
+ description: props?.options?.gatewayOptions?.description || "This is an Http API using CDK",
132
+ /**
133
+ * CORS configuration
134
+ * Falls back to allowing all methods and standard headers if not explicitly defined
135
+ */
136
+ corsPreflight: {
137
+ ...props.options?.gatewayOptions?.corsPreflight,
138
+ /** Allow all HTTP methods by default */
139
+ allowMethods: props.options?.gatewayOptions?.corsPreflight?.allowMethods || Object.values(awsApigatewayv2.CorsHttpMethod),
140
+ /** Merge default headers with user-defined headers */
141
+ allowHeaders: [
142
+ "Content-Type",
143
+ "Accept",
144
+ "X-Amz-Date",
145
+ "Authorization",
146
+ "X-Api-Key",
147
+ "X-Amz-Security-Token",
148
+ "X-Amz-User-Agent",
149
+ ...props.options?.gatewayOptions?.corsPreflight?.allowHeaders || []
150
+ ]
151
+ }
152
+ });
153
+ if (!props?.handlerFunctions?.length) {
154
+ throw new toolkit.CustomException("Construct requires atleast one function");
155
+ }
156
+ if (props?.options?.routeOptions?.length) {
157
+ props.handlerFunctions.forEach((handlerFunc) => {
158
+ props?.options?.routeOptions.forEach((route) => {
159
+ this.api.addRoutes({
160
+ ...route,
161
+ /**
162
+ * Lambda integration for each route
163
+ */
164
+ integration: new awsApigatewayv2Integrations.HttpLambdaIntegration("routes", handlerFunc)
165
+ });
166
+ });
167
+ });
168
+ }
169
+ this.api.applyRemovalPolicy(awsCdkLib.RemovalPolicy.DESTROY);
170
+ new awsCdkLib.CfnOutput(this, "ApiGatewayV2", {
171
+ value: this.api.url
172
+ });
173
+ }
174
+ };
175
+ var BaseApiGatewayWebSocketConstruct = class extends constructs.Construct {
176
+ static {
177
+ __name(this, "BaseApiGatewayWebSocketConstruct");
178
+ }
179
+ /** The created WebSocket API instance */
180
+ socketApi;
181
+ /**
182
+ * @param scope Parent construct
183
+ * @param id Unique construct identifier
184
+ * @param props Configuration for API, stage, and route handlers
185
+ */
186
+ constructor(scope, id, props) {
187
+ super(scope, id);
188
+ this.socketApi = new awsApigatewayv2.WebSocketApi(this, id, {
189
+ ...props.options.webSocketApiOptions,
190
+ /**
191
+ * Route for connection establishment ($connect)
192
+ */
193
+ connectRouteOptions: {
194
+ ...props.handlers.connect?.option,
195
+ integration: new awsApigatewayv2Integrations.WebSocketLambdaIntegration(
196
+ "connectIntegration",
197
+ props.handlers.connect.function
198
+ )
199
+ },
200
+ /**
201
+ * Route for disconnection events ($disconnect)
202
+ */
203
+ disconnectRouteOptions: {
204
+ ...props.handlers.disconnect?.option,
205
+ integration: new awsApigatewayv2Integrations.WebSocketLambdaIntegration(
206
+ "disconnectIntegration",
207
+ props.handlers.disconnect.function
208
+ )
209
+ },
210
+ /**
211
+ * Default route for unmatched messages ($default)
212
+ */
213
+ defaultRouteOptions: {
214
+ ...props.handlers.default?.option,
215
+ integration: new awsApigatewayv2Integrations.WebSocketLambdaIntegration(
216
+ "defaultIntegration",
217
+ props.handlers.default.function
218
+ )
219
+ }
220
+ });
221
+ this.socketApi.addRoute("notifications", {
222
+ ...props.handlers.message?.option,
223
+ /** Lambda integration for message handling */
224
+ integration: new awsApigatewayv2Integrations.WebSocketLambdaIntegration(
225
+ "routes",
226
+ props.handlers.message.function
227
+ )
228
+ });
229
+ const webSocketStage = new awsApigatewayv2.WebSocketStage(this, `${id}_stage`, {
230
+ ...props.options?.webSocketStageOptions,
231
+ webSocketApi: this.socketApi,
232
+ autoDeploy: true
233
+ });
234
+ new awsCdkLib.CfnOutput(this, "WebSocketURL", {
235
+ value: webSocketStage.url
236
+ });
237
+ }
238
+ };
239
+ var BaseCloudfrontConstruct = class extends constructs.Construct {
240
+ static {
241
+ __name(this, "BaseCloudfrontConstruct");
242
+ }
243
+ /** The created CloudFront distribution instance */
244
+ distribution;
245
+ /**
246
+ * @param scope Parent construct
247
+ * @param id Unique construct identifier
248
+ * @param props Configuration for CloudFront distribution
249
+ */
250
+ constructor(scope, id, props) {
251
+ super(scope, id);
252
+ this.distribution = new awsCloudfront.Distribution(this, id, {
253
+ ...props.options?.cloudfrontOptions,
254
+ /**
255
+ * Default behaviour configuration
256
+ * Enforces HTTPS if not explicitly defined
257
+ */
258
+ defaultBehavior: {
259
+ ...props.options?.cloudfrontOptions?.defaultBehavior,
260
+ viewerProtocolPolicy: props.options?.cloudfrontOptions?.defaultBehavior?.viewerProtocolPolicy || awsCloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS
261
+ },
262
+ /**
263
+ * Error response configuration
264
+ *
265
+ * Adds SPA-friendly fallbacks:
266
+ * - 400, 403, 404 responses are redirected to index.html
267
+ */
268
+ errorResponses: [
269
+ ...props.options?.cloudfrontOptions?.errorResponses || [],
270
+ /** Handle 400 errors */
271
+ {
272
+ httpStatus: 400,
273
+ responseHttpStatus: 200,
274
+ responsePagePath: "/index.html",
275
+ ttl: awsCdkLib.Duration.days(1)
276
+ },
277
+ /** Handle 403 errors */
278
+ {
279
+ httpStatus: 403,
280
+ responseHttpStatus: 200,
281
+ responsePagePath: "/index.html",
282
+ ttl: awsCdkLib.Duration.days(1)
283
+ },
284
+ /** Handle 404 errors */
285
+ {
286
+ httpStatus: 404,
287
+ responseHttpStatus: 200,
288
+ responsePagePath: "/index.html",
289
+ ttl: awsCdkLib.Duration.days(1)
290
+ }
291
+ ]
292
+ });
293
+ }
294
+ };
295
+ var BaseCloudwatchLogGroupConstruct = class extends constructs.Construct {
296
+ static {
297
+ __name(this, "BaseCloudwatchLogGroupConstruct");
298
+ }
299
+ /** The created CloudWatch Log Group instance */
300
+ logGroup;
301
+ /**
302
+ * @param scope Parent construct
303
+ * @param id Unique construct identifier
304
+ * @param props Configuration for the log group
305
+ */
306
+ constructor(scope, id, props) {
307
+ super(scope, id);
308
+ this.logGroup = new awsLogs.LogGroup(this, id, {
309
+ ...props.options?.logGroupOptions,
310
+ /**
311
+ * Removal policy applied to the log group
312
+ * Defaults to DESTROY when not explicitly defined
313
+ */
314
+ removalPolicy: props?.options?.logGroupOptions?.removalPolicy || awsCdkLib.RemovalPolicy.DESTROY,
315
+ /**
316
+ * Log retention period
317
+ * Defaults to INFINITE when not explicitly defined
318
+ */
319
+ retention: props?.options?.logGroupOptions?.retention || awsLogs.RetentionDays.INFINITE
320
+ });
321
+ new awsCdkLib.CfnOutput(this, "CloudwatchArn", {
322
+ value: this.logGroup.logGroupArn
323
+ });
324
+ }
325
+ };
326
+ var BaseDynamoDBConstruct = class _BaseDynamoDBConstruct extends constructs.Construct {
327
+ static {
328
+ __name(this, "BaseDynamoDBConstruct");
329
+ }
330
+ /** Newly created DynamoDB table (null if importing existing table) */
331
+ table;
332
+ /** Imported DynamoDB table reference (null if creating new table) */
333
+ existingTable;
334
+ /** Enables debug logging */
335
+ enableDebug = false;
336
+ /**
337
+ * @param scope Parent construct
338
+ * @param id Unique construct identifier
339
+ * @param props Configuration for table creation or import
340
+ */
341
+ constructor(scope, id, props) {
342
+ super(scope, id);
343
+ this.enableDebug = props?.enableDebug;
344
+ if (props.options?.fromExistingTableName) {
345
+ this.table = null;
346
+ this.existingTable = awsDynamodb.Table.fromTableName(
347
+ this,
348
+ `${id}-RefName`,
349
+ props.options.fromExistingTableName
350
+ );
351
+ if (this.enableDebug) {
352
+ toolkit.printLog(
353
+ _BaseDynamoDBConstruct.name,
354
+ `Created Dynamo-DB table from existing using name ${props.options?.fromExistingTableName}`
355
+ );
356
+ }
357
+ } else if (props.options?.fromExistingTableArn) {
358
+ this.table = null;
359
+ this.existingTable = awsDynamodb.Table.fromTableArn(
360
+ this,
361
+ `${id}-RefArn`,
362
+ props.options.fromExistingTableArn
363
+ );
364
+ if (this.enableDebug) {
365
+ toolkit.printLog(
366
+ _BaseDynamoDBConstruct.name,
367
+ `Created Dynamo-DB table from existing using ARN`
368
+ );
369
+ }
370
+ } else if (props.options?.fromExistingTableAttributes) {
371
+ this.table = null;
372
+ this.existingTable = awsDynamodb.Table.fromTableAttributes(
373
+ this,
374
+ `${id}-RefAttributes`,
375
+ props.options.fromExistingTableAttributes
376
+ );
377
+ if (this.enableDebug) {
378
+ toolkit.printLog(
379
+ _BaseDynamoDBConstruct.name,
380
+ `Created Dynamo-DB table from existing attributes`
381
+ );
382
+ }
383
+ } else {
384
+ this.existingTable = null;
385
+ this.table = new awsDynamodb.Table(this, id, {
386
+ ...props.options?.tableOptions,
387
+ /**
388
+ * Billing mode defaults to PAY_PER_REQUEST if not provided
389
+ */
390
+ billingMode: props.options?.tableOptions?.billingMode || awsDynamodb.BillingMode.PAY_PER_REQUEST,
391
+ /**
392
+ * Deletion protection:
393
+ * - Uses explicit value if provided
394
+ * - Defaults to true in production stage
395
+ */
396
+ deletionProtection: props.options?.tableOptions?.deletionProtection === true || props.options?.tableOptions?.deletionProtection === false ? props.options.tableOptions.deletionProtection : props.stage === "production"
397
+ });
398
+ if (props.options?.globalSecondaryIndexes?.length) {
399
+ props.options.globalSecondaryIndexes.forEach((globalIndex) => {
400
+ this.table.addGlobalSecondaryIndex(globalIndex);
401
+ if (this.enableDebug) {
402
+ toolkit.printLog(
403
+ _BaseDynamoDBConstruct.name,
404
+ `Added GSI: ${globalIndex.indexName}`
405
+ );
406
+ }
407
+ });
408
+ }
409
+ if (props.options?.localSecondaryIndexes?.length) {
410
+ props.options.localSecondaryIndexes.forEach((localIndex) => {
411
+ this.table.addLocalSecondaryIndex(localIndex);
412
+ if (this.enableDebug) {
413
+ toolkit.printLog(
414
+ _BaseDynamoDBConstruct.name,
415
+ `Added LSI: ${localIndex.indexName}`
416
+ );
417
+ }
418
+ });
419
+ }
420
+ }
421
+ new awsCdkLib.CfnOutput(this, "DynamoDbArn", {
422
+ value: props.options?.fromExistingTableName || props.options?.fromExistingTableArn ? this.existingTable.tableArn : this.table.tableArn
423
+ });
424
+ }
425
+ };
426
+ var BaseEventBridgeConstruct = class extends constructs.Construct {
427
+ static {
428
+ __name(this, "BaseEventBridgeConstruct");
429
+ }
430
+ /** The created EventBridge rule instance */
431
+ eventSchedule;
432
+ /**
433
+ * @param scope Parent construct
434
+ * @param id Unique construct identifier
435
+ * @param props Configuration for rule and target functions
436
+ */
437
+ constructor(scope, id, props) {
438
+ super(scope, id);
439
+ this.eventSchedule = new awsEvents.Rule(this, id, {
440
+ ...props.options?.eventBridgeOptions,
441
+ /** Default description if not explicitly provided */
442
+ description: props?.options?.eventBridgeOptions?.description || "An Event-bridge rule"
443
+ });
444
+ if (props.options?.targetFunctions?.length) {
445
+ props.options.targetFunctions.forEach((targetFunction) => {
446
+ this.eventSchedule.addTarget(
447
+ /**
448
+ * Lambda target integration
449
+ */
450
+ new awsEventsTargets.LambdaFunction(targetFunction)
451
+ );
452
+ });
453
+ }
454
+ this.eventSchedule.applyRemovalPolicy(awsCdkLib.RemovalPolicy.DESTROY);
455
+ new awsCdkLib.CfnOutput(this, "EventBridgeArn", {
456
+ value: this.eventSchedule.ruleArn
457
+ });
458
+ }
459
+ };
460
+ var BaseLambdaAuthoriserConstruct = class extends constructs.Construct {
461
+ static {
462
+ __name(this, "BaseLambdaAuthoriserConstruct");
463
+ }
464
+ /** The created Token Authorizer instance */
465
+ authoriser;
466
+ /**
467
+ * @param scope Parent construct
468
+ * @param id Unique construct identifier
469
+ * @param props Configuration for authorizer and handler function
470
+ */
471
+ constructor(scope, id, props) {
472
+ super(scope, id);
473
+ this.authoriser = new awsApigateway.TokenAuthorizer(this, id, {
474
+ ...props.options?.authorizerOptions,
475
+ /**
476
+ * Lambda handler responsible for request authorization
477
+ */
478
+ handler: props.handlerFunction
479
+ });
480
+ new awsCdkLib.CfnOutput(this, "LambdaAuthorizerArn", {
481
+ value: this.authoriser.authorizerArn
482
+ });
483
+ }
484
+ };
485
+ var BaseLambdaAuthoriserV2Construct = class extends constructs.Construct {
486
+ static {
487
+ __name(this, "BaseLambdaAuthoriserV2Construct");
488
+ }
489
+ /** The created HTTP Lambda Authorizer instance */
490
+ authoriser;
491
+ /**
492
+ * @param scope Parent construct
493
+ * @param id Unique construct identifier
494
+ * @param props Configuration for authorizer and handler function
495
+ */
496
+ constructor(scope, id, props) {
497
+ super(scope, id);
498
+ this.authoriser = new awsApigatewayv2Authorizers.HttpLambdaAuthorizer(id, props.handlerFunction, {
499
+ ...props?.options?.authorizerOptions,
500
+ /**
501
+ * Identity sources used to extract credentials from incoming requests
502
+ * Defaults to Cookie and Authorization headers
503
+ */
504
+ identitySource: [
505
+ "$request.header.Cookie",
506
+ "$request.header.Authorization",
507
+ ...props?.options?.authorizerOptions?.identitySource
508
+ ],
509
+ /**
510
+ * Supported response types for the authorizer
511
+ * Defaults to IAM and SIMPLE responses
512
+ */
513
+ responseTypes: props?.options?.authorizerOptions?.responseTypes || [
514
+ awsApigatewayv2Authorizers.HttpLambdaResponseType.IAM,
515
+ awsApigatewayv2Authorizers.HttpLambdaResponseType.SIMPLE
516
+ ]
517
+ });
518
+ new awsCdkLib.CfnOutput(this, "LambdaAuthorizerV2_ID", {
519
+ value: this.authoriser.authorizerId
520
+ });
521
+ }
522
+ };
523
+ var BaseLambdaConstruct = class extends constructs.Construct {
524
+ static {
525
+ __name(this, "BaseLambdaConstruct");
526
+ }
527
+ /** The created Lambda function instance */
528
+ function;
529
+ /**
530
+ * @param scope Parent construct
531
+ * @param id Unique construct identifier
532
+ * @param props Configuration for Lambda function
533
+ */
534
+ constructor(scope, id, props) {
535
+ super(scope, id);
536
+ const environment = {
537
+ ...props.options?.lambdaOptions?.environment,
538
+ NODE_ENV: props.stage,
539
+ NODE_OPTIONS: "--enable-source-maps",
540
+ AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1"
541
+ };
542
+ toolkit.detectDuplicateProperties({ data: environment });
543
+ this.function = new awsLambda.Function(this, id, {
544
+ ...props?.options?.lambdaOptions,
545
+ /**
546
+ * Lambda function name
547
+ * Defaults to "<stackName>-handler" if not provided
548
+ */
549
+ functionName: `${props?.options?.lambdaOptions?.functionName || props?.stackName}-handler`,
550
+ /**
551
+ * Function description
552
+ */
553
+ description: props?.options?.lambdaOptions?.description || "A lambda function",
554
+ /**
555
+ * Entry handler for the Lambda function
556
+ */
557
+ handler: props?.options?.lambdaOptions?.handler || "lambda.handler",
558
+ /**
559
+ * Runtime environment
560
+ */
561
+ runtime: props?.options?.lambdaOptions?.runtime || awsLambda.Runtime.NODEJS_24_X,
562
+ /**
563
+ * Execution timeout
564
+ * - 30 seconds in production
565
+ * - 15 seconds otherwise
566
+ */
567
+ timeout: props?.options?.lambdaOptions?.timeout || awsCdkLib.Duration.seconds(
568
+ props.stage === toolkit.AppEnvironmentEnum.PRODUCTION ? 30 : 15
569
+ ),
570
+ /**
571
+ * Memory allocation (in MB)
572
+ */
573
+ memorySize: props?.options?.lambdaOptions?.memorySize || 1024,
574
+ /**
575
+ * CPU architecture
576
+ */
577
+ architecture: props?.options?.lambdaOptions?.architecture || awsLambda.Architecture.ARM_64,
578
+ /**
579
+ * Lambda deployment package source
580
+ */
581
+ code: props?.options?.lambdaOptions?.code || awsLambda.Code.fromAsset("dist"),
582
+ /**
583
+ * Final merged environment variables
584
+ */
585
+ environment
586
+ });
587
+ new awsCdkLib.CfnOutput(this, "LambdaFunctionArn", {
588
+ value: this.function.functionArn
589
+ });
590
+ }
591
+ };
592
+ var BaseLambdaLayerConstruct = class extends constructs.Construct {
593
+ static {
594
+ __name(this, "BaseLambdaLayerConstruct");
595
+ }
596
+ /** Newly created Lambda Layer (null if importing existing layer) */
597
+ layer;
598
+ /** Imported Lambda Layer reference (null if creating new layer) */
599
+ existingLayer;
600
+ /**
601
+ * @param scope Parent construct
602
+ * @param id Unique construct identifier
603
+ * @param props Configuration for layer creation or import
604
+ */
605
+ constructor(scope, id, props) {
606
+ super(scope, id);
607
+ if (props?.options?.fromExistingLayerArn) {
608
+ this.existingLayer = awsLambda.LayerVersion.fromLayerVersionArn(
609
+ this,
610
+ `${id}-Arn`,
611
+ props?.options?.fromExistingLayerArn
612
+ );
613
+ } else if (props?.options?.fromExistingLayerAttribute) {
614
+ this.existingLayer = awsLambda.LayerVersion.fromLayerVersionAttributes(
615
+ this,
616
+ `${id}-Attribute`,
617
+ props?.options?.fromExistingLayerAttribute
618
+ );
619
+ } else {
620
+ this.layer = new awsLambda.LayerVersion(this, id, {
621
+ ...props.options?.layerOptions,
622
+ /**
623
+ * Default layer code asset
624
+ */
625
+ code: props?.options?.layerOptions?.code || awsLambda.Code.fromAsset("./dist-layer"),
626
+ /**
627
+ * Layer description
628
+ */
629
+ description: props?.options?.layerOptions?.description || "Lambda Layer written in NodeJS, NestJS, NodeJS-express, serverless-express",
630
+ /**
631
+ * Supported CPU architectures
632
+ */
633
+ compatibleArchitectures: [awsLambda.Architecture.ARM_64, awsLambda.Architecture.X86_64],
634
+ /**
635
+ * Supported runtimes
636
+ */
637
+ compatibleRuntimes: [
638
+ awsLambda.Runtime.NODEJS_22_X,
639
+ awsLambda.Runtime.NODEJS_24_X,
640
+ awsLambda.Runtime.NODEJS_LATEST
641
+ ]
642
+ });
643
+ }
644
+ new awsCdkLib.CfnOutput(this, "LambdaLayerArn", {
645
+ value: props.options?.fromExistingLayerArn || props.options?.fromExistingLayerAttribute ? this.existingLayer.layerVersionArn : this.layer.layerVersionArn
646
+ });
647
+ }
648
+ };
649
+ var BaseRolePolicyConstruct = class extends constructs.Construct {
650
+ static {
651
+ __name(this, "BaseRolePolicyConstruct");
652
+ }
653
+ /** The created IAM Role instance */
654
+ role;
655
+ /**
656
+ * @param scope Parent construct
657
+ * @param id Unique construct identifier
658
+ * @param props Configuration for role and policies
659
+ */
660
+ constructor(scope, id, props) {
661
+ super(scope, id);
662
+ this.role = new awsIam.Role(this, id, {
663
+ ...props.options?.roleOptions,
664
+ /**
665
+ * Managed policies attached to the role
666
+ * Defaults to AWSLambdaBasicExecutionRole if not provided
667
+ */
668
+ managedPolicies: props.options?.roleOptions?.managedPolicies ? props.options.roleOptions.managedPolicies : [
669
+ awsIam.ManagedPolicy.fromAwsManagedPolicyName(
670
+ "service-role/AWSLambdaBasicExecutionRole"
671
+ )
672
+ ]
673
+ });
674
+ if (props?.policies?.length) {
675
+ props.policies.forEach((policy) => {
676
+ this.role.addToPolicy(
677
+ /**
678
+ * Inline policy statement
679
+ */
680
+ new awsIam.PolicyStatement(policy)
681
+ );
682
+ });
683
+ }
684
+ this.role.applyRemovalPolicy(awsCdkLib.RemovalPolicy.DESTROY);
685
+ new awsCdkLib.CfnOutput(this, "RolePolicyArn", {
686
+ value: this.role.roleArn
687
+ });
688
+ }
689
+ };
690
+ var BaseS3Construct = class extends constructs.Construct {
691
+ static {
692
+ __name(this, "BaseS3Construct");
693
+ }
694
+ /** The created S3 bucket instance */
695
+ bucket;
696
+ /**
697
+ * @param scope Parent construct
698
+ * @param id Unique construct identifier
699
+ * @param props Configuration for S3 bucket
700
+ */
701
+ constructor(scope, id, props) {
702
+ super(scope, id);
703
+ this.bucket = new awsS3.Bucket(this, id, {
704
+ ...props.options?.bucketOptions,
705
+ /**
706
+ * Removal policy applied to the bucket
707
+ * Defaults to DESTROY if not explicitly defined
708
+ */
709
+ removalPolicy: props.options?.bucketOptions?.removalPolicy || awsCdkLib.RemovalPolicy.DESTROY
710
+ });
711
+ new awsCdkLib.CfnOutput(this, "S3BucketArn", {
712
+ value: this.bucket.bucketArn
713
+ });
714
+ }
715
+ };
716
+ var BaseS3DeploymentConstruct = class extends constructs.Construct {
717
+ static {
718
+ __name(this, "BaseS3DeploymentConstruct");
719
+ }
720
+ /** The created or provided S3 bucket */
721
+ bucket;
722
+ /** The created CloudFront distribution */
723
+ distribution;
724
+ /** S3 bucket deployment instance */
725
+ bucketDeployment;
726
+ /**
727
+ * @param scope Parent construct
728
+ * @param id Unique construct identifier
729
+ * @param props Configuration for bucket, distribution, and deployment
730
+ */
731
+ constructor(scope, id, props) {
732
+ super(scope, id);
733
+ if (!props.options?.cloudfrontOptions?.defaultBehavior?.origin && !props?.withS3Bucket && props.withCloudfront) {
734
+ throw new toolkit.CustomException(
735
+ "Cloudfront distribution S3_Bucket origins must be defined!"
736
+ );
737
+ }
738
+ if (!props.options?.bucketDeploymentOptions?.destinationBucket && !props?.withS3Bucket) {
739
+ throw new toolkit.CustomException(
740
+ "Deployment S3_Bucket destination must be defined!"
741
+ );
742
+ }
743
+ if (props?.withS3Bucket) {
744
+ this.bucket = new BaseS3Construct(this, "bucket", {
745
+ enableDebug: props.enableDebug,
746
+ options: { bucketOptions: props.options?.bucketOptions }
747
+ }).bucket;
748
+ }
749
+ if (props?.withCloudfront) {
750
+ const s3Origin = props.options?.cloudfrontOptions?.defaultBehavior?.origin || awsCloudfrontOrigins.S3BucketOrigin.withOriginAccessControl(this.bucket);
751
+ this.distribution = new BaseCloudfrontConstruct(this, "distribution", {
752
+ enableDebug: props.enableDebug,
753
+ options: {
754
+ cloudfrontOptions: {
755
+ ...props.options?.cloudfrontOptions,
756
+ /**
757
+ * Map additional behaviors and ensure origin is assigned
758
+ */
759
+ additionalBehaviors: Object.entries(
760
+ props.options?.cloudfrontOptions?.additionalBehaviors || {}
761
+ ).reduce(
762
+ (behavior, [pattern, behaviorOptions]) => {
763
+ behavior[pattern] = {
764
+ ...behaviorOptions,
765
+ origin: behaviorOptions.origin || s3Origin
766
+ };
767
+ return behavior;
768
+ },
769
+ {}
770
+ ),
771
+ /**
772
+ * Default behavior configuration
773
+ */
774
+ defaultBehavior: {
775
+ ...props.options?.cloudfrontOptions?.defaultBehavior,
776
+ origin: s3Origin
777
+ }
778
+ }
779
+ }
780
+ }).distribution;
781
+ }
782
+ this.bucketDeployment = new awsS3Deployment.BucketDeployment(this, "deployment", {
783
+ ...props.options?.bucketDeploymentOptions,
784
+ /** Target distribution for cache invalidation */
785
+ distribution: props.options?.bucketDeploymentOptions?.distribution || this.distribution,
786
+ /** Paths to invalidate after deployment */
787
+ distributionPaths: props.options?.bucketDeploymentOptions?.distributionPaths || ["/*"],
788
+ /** Destination S3 bucket */
789
+ destinationBucket: props.options?.bucketDeploymentOptions?.destinationBucket || this.bucket
790
+ });
791
+ }
792
+ };
793
+ var BaseSnsConstruct = class extends constructs.Construct {
794
+ static {
795
+ __name(this, "BaseSnsConstruct");
796
+ }
797
+ /** The created SNS topic instance */
798
+ topic;
799
+ /**
800
+ * @param scope Parent construct
801
+ * @param id Unique construct identifier
802
+ * @param props Configuration for topic and subscriptions
803
+ */
804
+ constructor(scope, id, props) {
805
+ super(scope, id);
806
+ this.topic = new awsSns.Topic(this, id, props.options?.topicOptions);
807
+ if (props.options?.targetFunctions?.length) {
808
+ props.options.targetFunctions.forEach((targetFunction) => {
809
+ this.topic.addSubscription(
810
+ /**
811
+ * Lambda subscription target
812
+ */
813
+ new awsSnsSubscriptions.LambdaSubscription(targetFunction)
814
+ );
815
+ });
816
+ }
817
+ this.topic.applyRemovalPolicy(awsCdkLib.RemovalPolicy.DESTROY);
818
+ new awsCdkLib.CfnOutput(this, "SnsTopicArn", {
819
+ value: this.topic.topicArn
820
+ });
821
+ }
822
+ };
823
+ var BaseSqsConstruct = class extends constructs.Construct {
824
+ static {
825
+ __name(this, "BaseSqsConstruct");
826
+ }
827
+ /** The created SQS queue instance */
828
+ queue;
829
+ /**
830
+ * @param scope Parent construct
831
+ * @param id Unique construct identifier
832
+ * @param props Configuration for queue and Lambda consumers
833
+ */
834
+ constructor(scope, id, props) {
835
+ super(scope, id);
836
+ this.queue = new awsSqs.Queue(this, id, {
837
+ ...props?.options?.queueOptions,
838
+ /**
839
+ * Removal policy applied to the queue
840
+ * Defaults to DESTROY if not explicitly defined
841
+ */
842
+ removalPolicy: props?.options?.queueOptions?.removalPolicy || awsCdkLib.RemovalPolicy.DESTROY
843
+ });
844
+ if (props?.targetFunctions?.length) {
845
+ props.targetFunctions.forEach((targetFunction, index) => {
846
+ new awsLambda.EventSourceMapping(this, `${id}-eventSourceMap${index + 1}`, {
847
+ ...props?.options?.eventSourceMappingOptions,
848
+ /** Target Lambda function */
849
+ target: targetFunction,
850
+ /** Source SQS queue ARN */
851
+ eventSourceArn: this.queue.queueArn,
852
+ /**
853
+ * Retry attempts for failed batch processing
854
+ * Defaults to 3 if not explicitly defined
855
+ */
856
+ retryAttempts: props?.options?.eventSourceMappingOptions?.retryAttempts || 3
857
+ });
858
+ });
859
+ }
860
+ new awsCdkLib.CfnOutput(this, "SqsQueueArn", {
861
+ value: this.queue.queueArn
862
+ });
863
+ }
864
+ };
865
+ var BaseVpcConstruct = class extends constructs.Construct {
866
+ static {
867
+ __name(this, "BaseVpcConstruct");
868
+ }
869
+ /** The created VPC instance */
870
+ vpc;
871
+ /**
872
+ * @param scope Parent construct
873
+ * @param id Unique construct identifier
874
+ * @param props Configuration for VPC
875
+ */
876
+ constructor(scope, id, props) {
877
+ super(scope, id);
878
+ this.vpc = new awsEc2.Vpc(this, id, {
879
+ ...props.options.vpcOptions
880
+ });
881
+ new awsCdkLib.CfnOutput(this, "VpcArn", {
882
+ value: this.vpc.vpcArn
883
+ });
884
+ }
885
+ };
886
+
887
+ exports.BaseApiGatewayConstruct = BaseApiGatewayConstruct;
888
+ exports.BaseApiGatewayV2Construct = BaseApiGatewayV2Construct;
889
+ exports.BaseApiGatewayWebSocketConstruct = BaseApiGatewayWebSocketConstruct;
890
+ exports.BaseCloudfrontConstruct = BaseCloudfrontConstruct;
891
+ exports.BaseCloudwatchLogGroupConstruct = BaseCloudwatchLogGroupConstruct;
892
+ exports.BaseDynamoDBConstruct = BaseDynamoDBConstruct;
893
+ exports.BaseEventBridgeConstruct = BaseEventBridgeConstruct;
894
+ exports.BaseLambdaAuthoriserConstruct = BaseLambdaAuthoriserConstruct;
895
+ exports.BaseLambdaAuthoriserV2Construct = BaseLambdaAuthoriserV2Construct;
896
+ exports.BaseLambdaConstruct = BaseLambdaConstruct;
897
+ exports.BaseLambdaLayerConstruct = BaseLambdaLayerConstruct;
898
+ exports.BaseRolePolicyConstruct = BaseRolePolicyConstruct;
899
+ exports.BaseS3Construct = BaseS3Construct;
900
+ exports.BaseS3DeploymentConstruct = BaseS3DeploymentConstruct;
901
+ exports.BaseSnsConstruct = BaseSnsConstruct;
902
+ exports.BaseSqsConstruct = BaseSqsConstruct;
903
+ exports.BaseVpcConstruct = BaseVpcConstruct;
904
+ //# sourceMappingURL=aws.cjs.map
905
+ //# sourceMappingURL=aws.cjs.map