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