@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/README.md CHANGED
@@ -1,58 +1,167 @@
1
1
  # @incloodsolutions/devkit
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@incloodsolutions/devkit.svg?style=for-the-badge)](https://www.npmjs.com/package/@incloodsolutions/devkit)
4
- [![npm dm](https://img.shields.io/npm/dm/@incloodsolutions/devkit.svg?style=for-the-badge)](https://www.npmjs.com/package/@incloodsolutions/devkit)
5
- [![downloads](https://img.shields.io/npm/dt/@incloodsolutions/devkit.svg?style=for-the-badge)](https://www.npmjs.com/package/@incloodsolutions/devkit)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@incloodsolutions/devkit.svg?style=for-the-badge)](https://www.npmjs.com/package/@incloodsolutions/devkit)
6
5
  [![license](https://img.shields.io/npm/l/@incloodsolutions/devkit.svg?style=for-the-badge)](https://www.npmjs.com/package/@incloodsolutions/devkit)
7
6
 
8
- A comprehensive development toolkit for Node.js and TypeScript applications. It provides reusable development utilities, configuration helpers, AWS CDK constructs and stacks, build tooling, project scaffolding, and other resources to simplify modern application development and infrastructure management.
7
+ Opinionated **AWS CDK v2 constructs** with sensible defaults for building serverless
8
+ applications. Each construct wraps one or more `aws-cdk-lib` resources, applies defaults
9
+ (ARM64, current Node.js runtime, source maps, stage-based timeouts, CloudFormation
10
+ outputs), and exposes the underlying resource for further customisation.
11
+
12
+ > For a one-line index of every construct and type in this package (and the other
13
+ > toolkits), see [`../docs/AI-INDEX.md`](../docs/AI-INDEX.md). Every construct, its props
14
+ > interface, and the created resource fields carry inline TSDoc comments describing the
15
+ > applied defaults.
9
16
 
10
17
  ---
11
18
 
12
- ## 📦 Installation
19
+ ## Installation
13
20
 
14
21
  ```bash
15
- npm install @incloodsolutions/devkit
16
- # or
17
- yarn add @incloodsolutions/devkit
22
+ npm install @incloodsolutions/devkit aws-cdk-lib constructs
18
23
  ```
19
24
 
20
- ## 🚀 Usage
25
+ Depends on `aws-cdk-lib`, `constructs`, `esbuild`, and
26
+ [`@incloodsolutions/toolkit`](../toolkit).
27
+
28
+ > **Scope note.** Only the AWS CDK constructs and their types are currently exported. The
29
+ > `src/utility`, `src/lint`, `src/prettier`, and `src/aws/cli` folders are placeholders and
30
+ > export nothing yet, despite what older documentation suggested.
31
+
32
+ ## Common props
33
+
34
+ Every construct constructor is `new XxxConstruct(scope, id, props)`. `props` is based on
35
+ `IBaseCdkConstructProps`:
21
36
 
22
37
  ```typescript
23
- import { EnvironmentHelper } from "@incloodsolutions/devkit";
38
+ interface IBaseCdkConstructProps<TOptions = any> {
39
+ readonly stage?: AppEnvironmentType; // 'production' | 'staging' | 'qa' | ...
40
+ readonly options?: TOptions; // the service-specific options (see each construct)
41
+ readonly stackName?: string;
42
+ readonly appName?: string;
43
+ readonly enableDebug?: boolean;
44
+ }
45
+ ```
46
+
47
+ The created resource is exposed as a public readonly field (`.function`, `.api`, `.table`,
48
+ `.topic`, `.queue`, `.layer`, `.distribution`, ...).
49
+
50
+ ## Modular imports (tree-shaking)
51
+
52
+ **There is no package-root import.** `import ... from '@incloodsolutions/devkit'` does not
53
+ resolve — you must import a specific subpath. Every construct is published as its own
54
+ subpath, so a stack that uses one construct does not bundle the code for all seventeen:
24
55
 
25
- // Example usage
26
- const env = EnvironmentHelper.load();
56
+ ```typescript
57
+ import { BaseLambdaConstruct } from '@incloodsolutions/devkit/aws-cdk/lambda';
58
+ import { BaseDynamoDBConstruct } from '@incloodsolutions/devkit/aws-cdk/dynamo-db';
59
+ import type { IBaseCdkConstructProps } from '@incloodsolutions/devkit/aws-types';
27
60
  ```
28
61
 
29
- ## Features
30
-
31
- - ⚙️ Node.js development utilities
32
- - 📝 Configuration management
33
- - 🏗️ AWS CDK constructs
34
- - ☁️ Reusable AWS CDK stacks
35
- - 🛠️ Infrastructure helpers
36
- - 🔐 IAM, Route53, ACM, Lambda, API Gateway, S3 & DynamoDB utilities
37
- - 🏷️ Resource naming & tagging helpers
38
- - 📁 Project templates & scaffolding
39
- - 🧩 Build & release utilities
40
- - 🔧 Development tooling and helpers
41
- - 💙 First-class TypeScript support
42
-
43
- ## 🎯 Goals
44
-
45
- - Reduce development and infrastructure boilerplate
46
- - Standardise project structure and configuration
47
- - Promote reusable infrastructure components
48
- - Simplify AWS CDK development
49
- - Improve developer productivity
50
- - Encourage consistency across projects
51
- - Provide sensible defaults while remaining extensible
52
-
53
- ## 📚 Part of the IncloodSolutions Toolkit Ecosystem
54
-
55
- - **@incloodsolutions/toolkit** Core utilities and shared helpers
56
- - **@incloodsolutions/node-toolkit** Node.js runtime and backend utilities
57
- - **@incloodsolutions/toolkit-react** React utilities and components
58
- - **@incloodsolutions/devkit** Development tooling, configuration, AWS CDK constructs, stacks, and infrastructure utilities
62
+ | Subpath | Contents |
63
+ | ------- | -------- |
64
+ | `.../aws` · `.../aws-cdk` | all `Base*` constructs |
65
+ | `.../aws-cdk/<name>` | one construct — `api-gateway`, `api-gateway-v2`, `api-gateway-websocket`, `cloudfront`, `cloudwatch`, `dynamo-db`, `event-bridge`, `lambda`, `lambda-authorizer`, `lambda-authorizer-v2`, `lambda-layer`, `role-policy`, `s3`, `s3-deployment`, `sns`, `sqs`, `vpc` |
66
+ | `.../aws-types` | `IBaseConstruct`, `IBaseCdkConstructProps` |
67
+
68
+ Every subpath resolves ESM (`import`), CommonJS (`require`), and its own `.d.ts`.
69
+ `aws-cdk-lib` and `constructs` stay external in every bundle.
70
+
71
+ ## Constructs
72
+
73
+ | Construct | Wraps | Notable defaults |
74
+ | --------- | ----- | ---------------- |
75
+ | `BaseLambdaConstruct` | `aws-lambda.Function` | Node.js 24, ARM64, 1024 MB, `Code.fromAsset('dist')`, handler `lambda.handler`, timeout 30 s (prod) / 15 s, `--enable-source-maps`, injects `NODE_ENV` from `stage`, validates env vars for duplicates. Exposes `.function`. |
76
+ | `BaseLambdaLayerConstruct` | `aws-lambda.LayerVersion` | Create new or import via `fromExistingLayerArn` / `fromExistingLayerAttribute`. Exposes `.layer` / `.existingLayer`. |
77
+ | `BaseApiGatewayConstruct` | `aws-apigateway.RestApi` | REST API with Lambda proxy integration and permissive CORS. |
78
+ | `BaseApiGatewayV2Construct` | `aws-apigatewayv2.HttpApi` | HTTP API; takes `handlerFunctions` and `routeOptions`. Exposes `.api`. |
79
+ | `BaseApiGatewayWebSocketConstruct` | `aws-apigatewayv2.WebSocketApi` + `WebSocketStage` | Lambda route integrations for `$connect` / `$disconnect` / custom routes. |
80
+ | `BaseLambdaAuthoriserConstruct` | `aws-apigateway.TokenAuthorizer` | REST API token authorizer backed by a Lambda. |
81
+ | `BaseLambdaAuthoriserV2Construct` | `aws-apigatewayv2-authorizers.HttpLambdaAuthorizer` | HTTP API Lambda authorizer. |
82
+ | `BaseDynamoDBConstruct` | `aws-dynamodb.Table` | Create new or import (`fromExistingTableArn` / `Name` / `Attributes`); `globalSecondaryIndexes` / `localSecondaryIndexes`. Exposes `.table` / `.existingTable`. |
83
+ | `BaseS3Construct` | `aws-s3.Bucket` | Bucket with defaults. |
84
+ | `BaseS3DeploymentConstruct` | S3 `Bucket` + CloudFront `Distribution` + `BucketDeployment` | Static-site deploy; toggles `withS3Bucket` / `withCloudfront`; `bucketDeploymentOptions.sources` required. |
85
+ | `BaseCloudfrontConstruct` | `aws-cloudfront.Distribution` | Distribution with `ViewerProtocolPolicy` default. |
86
+ | `BaseCloudwatchLogGroupConstruct` | `aws-logs.LogGroup` | Log group with retention. |
87
+ | `BaseSnsConstruct` | `aws-sns.Topic` | Optional `targetFunctions` as `LambdaSubscription`. Exposes `.topic`. |
88
+ | `BaseSqsConstruct` | `aws-sqs.Queue` | Optional Lambda `EventSourceMapping`. Exposes `.queue`. |
89
+ | `BaseEventBridgeConstruct` | `aws-events.Rule` | Rule with a Lambda target. |
90
+ | `BaseVpcConstruct` | `aws-ec2.Vpc` | VPC with defaults. |
91
+ | `BaseRolePolicyConstruct` | `aws-iam.Role` + `PolicyStatement` / `ManagedPolicy` | IAM role and policy helper. |
92
+
93
+ ## Types
94
+
95
+ | Symbol | Summary |
96
+ | ------ | ------- |
97
+ | `IBaseConstruct` | extends `IBaseEnableDebug`. |
98
+ | `IBaseCdkConstructProps<TOptions>` | shared construct props (see above). |
99
+
100
+ ## Usage
101
+
102
+ ```typescript
103
+ import { Stack, StackProps } from 'aws-cdk-lib';
104
+ import { Construct } from 'constructs';
105
+ import { BaseLambdaConstruct } from '@incloodsolutions/devkit/aws-cdk/lambda';
106
+ import { BaseApiGatewayV2Construct } from '@incloodsolutions/devkit/aws-cdk/api-gateway-v2';
107
+ import { BaseDynamoDBConstruct } from '@incloodsolutions/devkit/aws-cdk/dynamo-db';
108
+
109
+ export class ApiStack extends Stack {
110
+ constructor(scope: Construct, id: string, props?: StackProps) {
111
+ super(scope, id, props);
112
+
113
+ const table = new BaseDynamoDBConstruct(this, 'Table', {
114
+ stage: 'production',
115
+ stackName: this.stackName,
116
+ options: { tableOptions: { partitionKey: { name: 'id', type: AttributeType.STRING } } },
117
+ });
118
+
119
+ const handler = new BaseLambdaConstruct(this, 'Handler', {
120
+ stage: 'production',
121
+ stackName: this.stackName,
122
+ options: { lambdaOptions: { environment: { TABLE_NAME: table.table.tableName } } },
123
+ });
124
+
125
+ table.table.grantReadWriteData(handler.function);
126
+
127
+ new BaseApiGatewayV2Construct(this, 'Api', {
128
+ stage: 'production',
129
+ stackName: this.stackName,
130
+ options: {
131
+ handlerFunctions: [handler.function],
132
+ routeOptions: [{ path: '/{proxy+}' }],
133
+ },
134
+ });
135
+ }
136
+ }
137
+ ```
138
+
139
+ ## Development
140
+
141
+ ```bash
142
+ npm install
143
+ npm run build # tsup: bundles ESM + CJS and a single dist/index.d.ts
144
+ npm run format # prettier --write (tabs, single quotes, trailing commas)
145
+ npm run lint # eslint --fix
146
+ npm test # vitest run — synthesises every construct and asserts its CloudFormation
147
+ npm run test:watch # vitest in watch mode
148
+ npm run package # build, then npm pack a tarball
149
+ ```
150
+
151
+ [`test/constructs.spec.ts`](./test/constructs.spec.ts) instantiates each `Base*` construct
152
+ in a throwaway `Stack` and checks the output with `aws-cdk-lib/assertions` (`Template`).
153
+ Nothing is deployed and no AWS credentials are used. Its header comment records the
154
+ constructs that need extra props or currently throw.
155
+ [`test/esm-bundle.spec.ts`](./test/esm-bundle.spec.ts) guards that every subpath entry is
156
+ built, loads as ESM, and keeps `aws-cdk-lib` / `constructs` external.
157
+
158
+ > The whole build is `tsup` (`dts: true`), pinned to `typescript@^6`. There is **no root
159
+ > export** and no `main`/`module`/`types` fields — every module and every construct is a
160
+ > `./*` subpath in `exports` (see [Modular imports](#modular-imports-tree-shaking)),
161
+ > configured by the `entry` map in `tsup.config.ts` and `exports` + `typesVersions` in
162
+ > `package.json`. The `index` bundle is still built as the test aggregation point but is
163
+ > not reachable by the package name.
164
+
165
+ ## License
166
+
167
+ MIT © Inclood Solutions
@@ -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.cjs.map
77
+ //# sourceMappingURL=api-gateway-v2.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":";;;;;;;;;;AAsDO,IAAM,yBAAA,GAAN,cACEA,oBAAA,CAET;AAAA,EAzDA;AAyDA,IAAA,MAAA,CAAA,IAAA,EAAA,2BAAA,CAAA;AAAA;AAAA;AAAA,EAEU,GAAA;AAAA;AAAA,EAGT,WAAA,GAAc,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOd,WAAA,CACC,KAAA,EACA,EAAA,EACA,KAAA,EACC;AACD,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,WAA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AgB;AAAA,MACnC,KAAA,EAAO,KAAK,GAAA,CAAI;AAAA,KAChB,CAAA;AAAA,EACF;AACD","file":"api-gateway-v2.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 {\n\tAddRoutesOptions,\n\tCorsHttpMethod,\n\tHttpApi,\n\tHttpApiProps,\n} 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<\n\tIBaseCdkConstructProps<{\n\t\t/** HTTP API configuration options */\n\t\treadonly gatewayOptions: HttpApiProps;\n\n\t\t/** Route definitions passed directly to `addRoutes` */\n\t\treadonly routeOptions: Partial<AddRoutesOptions>[];\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {\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 * 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\n\textends Construct\n\timplements IBaseConstruct\n{\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(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops: IApiGatewayV2ConstructProps,\n\t) {\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:\n\t\t\t\tprops?.options?.gatewayOptions?.description ||\n\t\t\t\t'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:\n\t\t\t\t\tprops.options?.gatewayOptions?.corsPreflight?.allowMethods ||\n\t\t\t\t\tObject.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}\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 '../aws-types.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 '../aws-types.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.js.map
75
+ //# sourceMappingURL=api-gateway-v2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/aws/cdk/constructs/api-gateway-v2-construct.ts"],"names":[],"mappings":";;;;;;;;AAsDO,IAAM,yBAAA,GAAN,cACE,SAAA,CAET;AAAA,EAzDA;AAyDA,IAAA,MAAA,CAAA,IAAA,EAAA,2BAAA,CAAA;AAAA;AAAA;AAAA,EAEU,GAAA;AAAA;AAAA,EAGT,WAAA,GAAc,KAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOd,WAAA,CACC,KAAA,EACA,EAAA,EACA,KAAA,EACC;AACD,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,cAAc,KAAA,CAAM,WAAA;AAEzB,IAAA,IAAA,CAAK,GAA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AAA,CAAK,GAAA,CAAI,kBAAA,CAAmB,aAAA,CAAc,OAAO,CAAA;AAKjD,IAAA,IAAI,SAAA,CAAU,MAAM,cAAA,EAAgB;AAAA,MACnC,KAAA,EAAO,KAAK,GAAA,CAAI;AAAA,KAChB,CAAA;AAAA,EACF;AACD","file":"api-gateway-v2.js","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 {\n\tAddRoutesOptions,\n\tCorsHttpMethod,\n\tHttpApi,\n\tHttpApiProps,\n} 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<\n\tIBaseCdkConstructProps<{\n\t\t/** HTTP API configuration options */\n\t\treadonly gatewayOptions: HttpApiProps;\n\n\t\t/** Route definitions passed directly to `addRoutes` */\n\t\treadonly routeOptions: Partial<AddRoutesOptions>[];\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {\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 * 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\n\textends Construct\n\timplements IBaseConstruct\n{\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(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops: IApiGatewayV2ConstructProps,\n\t) {\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:\n\t\t\t\tprops?.options?.gatewayOptions?.description ||\n\t\t\t\t'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:\n\t\t\t\t\tprops.options?.gatewayOptions?.corsPreflight?.allowMethods ||\n\t\t\t\t\tObject.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}\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
+
8
+ var __defProp = Object.defineProperty;
9
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var BaseApiGatewayWebSocketConstruct = class extends constructs.Construct {
11
+ static {
12
+ __name(this, "BaseApiGatewayWebSocketConstruct");
13
+ }
14
+ /** The created WebSocket API instance */
15
+ socketApi;
16
+ /**
17
+ * @param scope Parent construct
18
+ * @param id Unique construct identifier
19
+ * @param props Configuration for API, stage, and route handlers
20
+ */
21
+ constructor(scope, id, props) {
22
+ super(scope, id);
23
+ this.socketApi = new awsApigatewayv2.WebSocketApi(this, id, {
24
+ ...props.options.webSocketApiOptions,
25
+ /**
26
+ * Route for connection establishment ($connect)
27
+ */
28
+ connectRouteOptions: {
29
+ ...props.handlers.connect?.option,
30
+ integration: new awsApigatewayv2Integrations.WebSocketLambdaIntegration(
31
+ "connectIntegration",
32
+ props.handlers.connect.function
33
+ )
34
+ },
35
+ /**
36
+ * Route for disconnection events ($disconnect)
37
+ */
38
+ disconnectRouteOptions: {
39
+ ...props.handlers.disconnect?.option,
40
+ integration: new awsApigatewayv2Integrations.WebSocketLambdaIntegration(
41
+ "disconnectIntegration",
42
+ props.handlers.disconnect.function
43
+ )
44
+ },
45
+ /**
46
+ * Default route for unmatched messages ($default)
47
+ */
48
+ defaultRouteOptions: {
49
+ ...props.handlers.default?.option,
50
+ integration: new awsApigatewayv2Integrations.WebSocketLambdaIntegration(
51
+ "defaultIntegration",
52
+ props.handlers.default.function
53
+ )
54
+ }
55
+ });
56
+ this.socketApi.addRoute("notifications", {
57
+ ...props.handlers.message?.option,
58
+ /** Lambda integration for message handling */
59
+ integration: new awsApigatewayv2Integrations.WebSocketLambdaIntegration(
60
+ "routes",
61
+ props.handlers.message.function
62
+ )
63
+ });
64
+ const webSocketStage = new awsApigatewayv2.WebSocketStage(this, `${id}_stage`, {
65
+ ...props.options?.webSocketStageOptions,
66
+ webSocketApi: this.socketApi,
67
+ autoDeploy: true
68
+ });
69
+ new awsCdkLib.CfnOutput(this, "WebSocketURL", {
70
+ value: webSocketStage.url
71
+ });
72
+ }
73
+ };
74
+
75
+ exports.BaseApiGatewayWebSocketConstruct = BaseApiGatewayWebSocketConstruct;
76
+ //# sourceMappingURL=api-gateway-websocket.cjs.map
77
+ //# sourceMappingURL=api-gateway-websocket.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/aws/cdk/constructs/api-gateway-websocket-construct.ts"],"names":["Construct","WebSocketApi","WebSocketLambdaIntegration","WebSocketStage","CfnOutput"],"mappings":";;;;;;;;;AA6EO,IAAM,gCAAA,GAAN,cAA+CA,oBAAA,CAAU;AAAA,EA7EhE;AA6EgE,IAAA,MAAA,CAAA,IAAA,EAAA,kCAAA,CAAA;AAAA;AAAA;AAAA,EAEtD,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,WAAA,CACC,KAAA,EACA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AA;AAAA,MAClB,cAAc,IAAA,CAAK,SAAA;AAAA,MACnB,UAAA,EAAY;AAAA,KACZ,CAAA;AAKD,IAAA,IAAIC,mBAAA,CAAU,MAAM,cAAA,EAAgB;AAAA,MACnC,OAAO,cAAA,CAAe;AAAA,KACtB,CAAA;AAAA,EACF;AACD","file":"api-gateway-websocket.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { CfnOutput } from 'aws-cdk-lib';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { WebSocketLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';\nimport {\n\tWebSocketApi,\n\tWebSocketApiProps,\n\tWebSocketRouteOptions,\n\tWebSocketStage,\n\tWebSocketStageProps,\n} from 'aws-cdk-lib/aws-apigatewayv2';\n\nimport { IBaseCdkConstructProps } from '../../types';\n\n/**\n * Props for BaseApiGatewayWebSocketConstruct\n *\n * Provides configuration for:\n * - WebSocket API (API Gateway v2)\n * - WebSocket stage\n * - Route handlers for lifecycle events\n */\ninterface IApiGatewayWebsocketConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** WebSocket API configuration options */\n\t\treadonly webSocketApiOptions: WebSocketApiProps;\n\n\t\t/** WebSocket stage configuration options */\n\t\treadonly webSocketStageOptions: WebSocketStageProps;\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {\n\t/**\n\t * Lambda handlers mapped to WebSocket lifecycle routes\n\t *\n\t * Includes:\n\t * - $connect\n\t * - $disconnect\n\t * - $default\n\t * - custom message route\n\t */\n\treadonly handlers: {\n\t\t/** Handler for connection establishment ($connect) */\n\t\treadonly connect: {\n\t\t\toption: WebSocketRouteOptions;\n\t\t\tfunction: Function;\n\t\t};\n\n\t\t/** Handler for unmatched routes ($default) */\n\t\treadonly default: {\n\t\t\toption: WebSocketRouteOptions;\n\t\t\tfunction: Function;\n\t\t};\n\n\t\t/** Handler for custom message route (e.g. 'notifications') */\n\t\treadonly message: {\n\t\t\toption: WebSocketRouteOptions;\n\t\t\tfunction: Function;\n\t\t};\n\n\t\t/** Handler for disconnection events ($disconnect) */\n\t\treadonly disconnect: {\n\t\t\toption: WebSocketRouteOptions;\n\t\t\tfunction: Function;\n\t\t};\n\t};\n}\n\n/**\n * CDK construct for WebSocket API Gateway\n *\n * Responsibilities:\n * - Creates a WebSocket API with lifecycle route integrations\n * - Registers a custom message route\n * - Deploys a stage with auto-deploy enabled\n * - Exposes WebSocket endpoint URL as a CloudFormation output\n */\nexport class BaseApiGatewayWebSocketConstruct extends Construct {\n\t/** The created WebSocket API instance */\n\treadonly socketApi: WebSocketApi;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for API, stage, and route handlers\n\t */\n\tconstructor(\n\t\tscope: Construct,\n\t\tid: string,\n\t\tprops: IApiGatewayWebsocketConstructProps,\n\t) {\n\t\tsuper(scope, id);\n\n\t\tthis.socketApi = new WebSocketApi(this, id, {\n\t\t\t...props.options.webSocketApiOptions,\n\n\t\t\t/**\n\t\t\t * Route for connection establishment ($connect)\n\t\t\t */\n\t\t\tconnectRouteOptions: {\n\t\t\t\t...props.handlers.connect?.option,\n\t\t\t\tintegration: new WebSocketLambdaIntegration(\n\t\t\t\t\t'connectIntegration',\n\t\t\t\t\tprops.handlers.connect.function,\n\t\t\t\t),\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Route for disconnection events ($disconnect)\n\t\t\t */\n\t\t\tdisconnectRouteOptions: {\n\t\t\t\t...props.handlers.disconnect?.option,\n\t\t\t\tintegration: new WebSocketLambdaIntegration(\n\t\t\t\t\t'disconnectIntegration',\n\t\t\t\t\tprops.handlers.disconnect.function,\n\t\t\t\t),\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Default route for unmatched messages ($default)\n\t\t\t */\n\t\t\tdefaultRouteOptions: {\n\t\t\t\t...props.handlers.default?.option,\n\t\t\t\tintegration: new WebSocketLambdaIntegration(\n\t\t\t\t\t'defaultIntegration',\n\t\t\t\t\tprops.handlers.default.function,\n\t\t\t\t),\n\t\t\t},\n\t\t});\n\n\t\t/**\n\t\t * Custom message route (e.g. \"notifications\")\n\t\t */\n\t\tthis.socketApi.addRoute('notifications', {\n\t\t\t...props.handlers.message?.option,\n\n\t\t\t/** Lambda integration for message handling */\n\t\t\tintegration: new WebSocketLambdaIntegration(\n\t\t\t\t'routes',\n\t\t\t\tprops.handlers.message.function,\n\t\t\t),\n\t\t});\n\n\t\t/**\n\t\t * WebSocket stage deployment\n\t\t * Auto-deploy ensures changes are immediately available\n\t\t */\n\t\tconst webSocketStage = new WebSocketStage(this, `${id}_stage`, {\n\t\t\t...props.options?.webSocketStageOptions,\n\t\t\twebSocketApi: this.socketApi,\n\t\t\tautoDeploy: true,\n\t\t});\n\n\t\t/**\n\t\t * CloudFormation output exposing WebSocket endpoint URL\n\t\t */\n\t\tnew CfnOutput(this, 'WebSocketURL', {\n\t\t\tvalue: webSocketStage.url,\n\t\t});\n\t}\n}\n"]}