@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.
- package/README.md +150 -41
- package/dist/aws-cdk/api-gateway-v2.cjs +77 -0
- package/dist/aws-cdk/api-gateway-v2.cjs.map +1 -0
- package/dist/aws-cdk/api-gateway-v2.d.cts +55 -0
- package/dist/aws-cdk/api-gateway-v2.d.ts +55 -0
- package/dist/aws-cdk/api-gateway-v2.js +75 -0
- package/dist/aws-cdk/api-gateway-v2.js.map +1 -0
- package/dist/aws-cdk/api-gateway-websocket.cjs +77 -0
- package/dist/aws-cdk/api-gateway-websocket.cjs.map +1 -0
- package/dist/aws-cdk/api-gateway-websocket.d.cts +73 -0
- package/dist/aws-cdk/api-gateway-websocket.d.ts +73 -0
- package/dist/aws-cdk/api-gateway-websocket.js +75 -0
- package/dist/aws-cdk/api-gateway-websocket.js.map +1 -0
- package/dist/aws-cdk/api-gateway.cjs +98 -0
- package/dist/aws-cdk/api-gateway.cjs.map +1 -0
- package/dist/aws-cdk/api-gateway.d.cts +80 -0
- package/dist/aws-cdk/api-gateway.d.ts +80 -0
- package/dist/aws-cdk/api-gateway.js +96 -0
- package/dist/aws-cdk/api-gateway.js.map +1 -0
- package/dist/aws-cdk/cloudfront.cjs +68 -0
- package/dist/aws-cdk/cloudfront.cjs.map +1 -0
- package/dist/aws-cdk/cloudfront.d.cts +36 -0
- package/dist/aws-cdk/cloudfront.d.ts +36 -0
- package/dist/aws-cdk/cloudfront.js +66 -0
- package/dist/aws-cdk/cloudfront.js.map +1 -0
- package/dist/aws-cdk/cloudwatch.cjs +43 -0
- package/dist/aws-cdk/cloudwatch.cjs.map +1 -0
- package/dist/aws-cdk/cloudwatch.d.cts +36 -0
- package/dist/aws-cdk/cloudwatch.d.ts +36 -0
- package/dist/aws-cdk/cloudwatch.js +41 -0
- package/dist/aws-cdk/cloudwatch.js.map +1 -0
- package/dist/aws-cdk/dynamo-db.cjs +113 -0
- package/dist/aws-cdk/dynamo-db.cjs.map +1 -0
- package/dist/aws-cdk/dynamo-db.d.cts +53 -0
- package/dist/aws-cdk/dynamo-db.d.ts +53 -0
- package/dist/aws-cdk/dynamo-db.js +111 -0
- package/dist/aws-cdk/dynamo-db.js.map +1 -0
- package/dist/aws-cdk/event-bridge.cjs +47 -0
- package/dist/aws-cdk/event-bridge.cjs.map +1 -0
- package/dist/aws-cdk/event-bridge.d.cts +41 -0
- package/dist/aws-cdk/event-bridge.d.ts +41 -0
- package/dist/aws-cdk/event-bridge.js +45 -0
- package/dist/aws-cdk/event-bridge.js.map +1 -0
- package/dist/aws-cdk/lambda-authorizer-v2.cjs +50 -0
- package/dist/aws-cdk/lambda-authorizer-v2.cjs.map +1 -0
- package/dist/aws-cdk/lambda-authorizer-v2.d.cts +45 -0
- package/dist/aws-cdk/lambda-authorizer-v2.d.ts +45 -0
- package/dist/aws-cdk/lambda-authorizer-v2.js +48 -0
- package/dist/aws-cdk/lambda-authorizer-v2.js.map +1 -0
- package/dist/aws-cdk/lambda-authorizer.cjs +37 -0
- package/dist/aws-cdk/lambda-authorizer.cjs.map +1 -0
- package/dist/aws-cdk/lambda-authorizer.d.cts +44 -0
- package/dist/aws-cdk/lambda-authorizer.d.ts +44 -0
- package/dist/aws-cdk/lambda-authorizer.js +35 -0
- package/dist/aws-cdk/lambda-authorizer.js.map +1 -0
- package/dist/aws-cdk/lambda-layer.cjs +69 -0
- package/dist/aws-cdk/lambda-layer.cjs.map +1 -0
- package/dist/aws-cdk/lambda-layer.d.cts +52 -0
- package/dist/aws-cdk/lambda-layer.d.ts +52 -0
- package/dist/aws-cdk/lambda-layer.js +67 -0
- package/dist/aws-cdk/lambda-layer.js.map +1 -0
- package/dist/aws-cdk/lambda.cjs +82 -0
- package/dist/aws-cdk/lambda.cjs.map +1 -0
- package/dist/aws-cdk/lambda.d.cts +37 -0
- package/dist/aws-cdk/lambda.d.ts +37 -0
- package/dist/aws-cdk/lambda.js +80 -0
- package/dist/aws-cdk/lambda.js.map +1 -0
- package/dist/aws-cdk/role-policy.cjs +53 -0
- package/dist/aws-cdk/role-policy.cjs.map +1 -0
- package/dist/aws-cdk/role-policy.d.cts +44 -0
- package/dist/aws-cdk/role-policy.d.ts +44 -0
- package/dist/aws-cdk/role-policy.js +51 -0
- package/dist/aws-cdk/role-policy.js.map +1 -0
- package/dist/aws-cdk/s3-deployment.cjs +177 -0
- package/dist/aws-cdk/s3-deployment.cjs.map +1 -0
- package/dist/aws-cdk/s3-deployment.d.cts +72 -0
- package/dist/aws-cdk/s3-deployment.d.ts +72 -0
- package/dist/aws-cdk/s3-deployment.js +175 -0
- package/dist/aws-cdk/s3-deployment.js.map +1 -0
- package/dist/aws-cdk/s3.cjs +38 -0
- package/dist/aws-cdk/s3.cjs.map +1 -0
- package/dist/aws-cdk/s3.d.cts +36 -0
- package/dist/aws-cdk/s3.d.ts +36 -0
- package/dist/aws-cdk/s3.js +36 -0
- package/dist/aws-cdk/s3.js.map +1 -0
- package/dist/aws-cdk/sns.cjs +43 -0
- package/dist/aws-cdk/sns.cjs.map +1 -0
- package/dist/aws-cdk/sns.d.cts +45 -0
- package/dist/aws-cdk/sns.d.ts +45 -0
- package/dist/aws-cdk/sns.js +41 -0
- package/dist/aws-cdk/sns.js.map +1 -0
- package/dist/aws-cdk/sqs.cjs +55 -0
- package/dist/aws-cdk/sqs.cjs.map +1 -0
- package/dist/aws-cdk/sqs.d.cts +52 -0
- package/dist/aws-cdk/sqs.d.ts +52 -0
- package/dist/aws-cdk/sqs.js +53 -0
- package/dist/aws-cdk/sqs.js.map +1 -0
- package/dist/aws-cdk/vpc.cjs +33 -0
- package/dist/aws-cdk/vpc.cjs.map +1 -0
- package/dist/aws-cdk/vpc.d.cts +34 -0
- package/dist/aws-cdk/vpc.d.ts +34 -0
- package/dist/aws-cdk/vpc.js +31 -0
- package/dist/aws-cdk/vpc.js.map +1 -0
- package/dist/aws-cdk.cjs +905 -0
- package/dist/aws-cdk.cjs.map +1 -0
- package/dist/aws-cdk.d.cts +34 -0
- package/dist/aws-cdk.d.ts +34 -0
- package/dist/aws-cdk.js +887 -0
- package/dist/aws-cdk.js.map +1 -0
- package/dist/aws-types.cjs +4 -0
- package/dist/aws-types.cjs.map +1 -0
- package/dist/aws-types.d.cts +42 -0
- package/dist/aws-types.d.ts +42 -0
- package/dist/aws-types.js +3 -0
- package/dist/aws-types.js.map +1 -0
- package/dist/aws.cjs +905 -0
- package/dist/aws.cjs.map +1 -0
- package/dist/aws.d.cts +34 -0
- package/dist/aws.d.ts +34 -0
- package/dist/aws.js +887 -0
- package/dist/aws.js.map +1 -0
- package/dist/index.cjs +43 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -755
- package/dist/index.d.ts +34 -755
- package/dist/index.js +43 -19
- package/dist/index.js.map +1 -1
- package/package.json +181 -19
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { WebSocketApi, WebSocketApiProps, WebSocketStageProps, WebSocketRouteOptions } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
4
|
+
import { IBaseCdkConstructProps } from '../aws-types.cjs';
|
|
5
|
+
import '@incloodsolutions/toolkit';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for BaseApiGatewayWebSocketConstruct
|
|
9
|
+
*
|
|
10
|
+
* Provides configuration for:
|
|
11
|
+
* - WebSocket API (API Gateway v2)
|
|
12
|
+
* - WebSocket stage
|
|
13
|
+
* - Route handlers for lifecycle events
|
|
14
|
+
*/
|
|
15
|
+
interface IApiGatewayWebsocketConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
16
|
+
/** WebSocket API configuration options */
|
|
17
|
+
readonly webSocketApiOptions: WebSocketApiProps;
|
|
18
|
+
/** WebSocket stage configuration options */
|
|
19
|
+
readonly webSocketStageOptions: WebSocketStageProps;
|
|
20
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
21
|
+
/**
|
|
22
|
+
* Lambda handlers mapped to WebSocket lifecycle routes
|
|
23
|
+
*
|
|
24
|
+
* Includes:
|
|
25
|
+
* - $connect
|
|
26
|
+
* - $disconnect
|
|
27
|
+
* - $default
|
|
28
|
+
* - custom message route
|
|
29
|
+
*/
|
|
30
|
+
readonly handlers: {
|
|
31
|
+
/** Handler for connection establishment ($connect) */
|
|
32
|
+
readonly connect: {
|
|
33
|
+
option: WebSocketRouteOptions;
|
|
34
|
+
function: Function;
|
|
35
|
+
};
|
|
36
|
+
/** Handler for unmatched routes ($default) */
|
|
37
|
+
readonly default: {
|
|
38
|
+
option: WebSocketRouteOptions;
|
|
39
|
+
function: Function;
|
|
40
|
+
};
|
|
41
|
+
/** Handler for custom message route (e.g. 'notifications') */
|
|
42
|
+
readonly message: {
|
|
43
|
+
option: WebSocketRouteOptions;
|
|
44
|
+
function: Function;
|
|
45
|
+
};
|
|
46
|
+
/** Handler for disconnection events ($disconnect) */
|
|
47
|
+
readonly disconnect: {
|
|
48
|
+
option: WebSocketRouteOptions;
|
|
49
|
+
function: Function;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* CDK construct for WebSocket API Gateway
|
|
55
|
+
*
|
|
56
|
+
* Responsibilities:
|
|
57
|
+
* - Creates a WebSocket API with lifecycle route integrations
|
|
58
|
+
* - Registers a custom message route
|
|
59
|
+
* - Deploys a stage with auto-deploy enabled
|
|
60
|
+
* - Exposes WebSocket endpoint URL as a CloudFormation output
|
|
61
|
+
*/
|
|
62
|
+
declare class BaseApiGatewayWebSocketConstruct extends Construct {
|
|
63
|
+
/** The created WebSocket API instance */
|
|
64
|
+
readonly socketApi: WebSocketApi;
|
|
65
|
+
/**
|
|
66
|
+
* @param scope Parent construct
|
|
67
|
+
* @param id Unique construct identifier
|
|
68
|
+
* @param props Configuration for API, stage, and route handlers
|
|
69
|
+
*/
|
|
70
|
+
constructor(scope: Construct, id: string, props: IApiGatewayWebsocketConstructProps);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { BaseApiGatewayWebSocketConstruct };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { WebSocketApi, WebSocketApiProps, WebSocketStageProps, WebSocketRouteOptions } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
4
|
+
import { IBaseCdkConstructProps } from '../aws-types.js';
|
|
5
|
+
import '@incloodsolutions/toolkit';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Props for BaseApiGatewayWebSocketConstruct
|
|
9
|
+
*
|
|
10
|
+
* Provides configuration for:
|
|
11
|
+
* - WebSocket API (API Gateway v2)
|
|
12
|
+
* - WebSocket stage
|
|
13
|
+
* - Route handlers for lifecycle events
|
|
14
|
+
*/
|
|
15
|
+
interface IApiGatewayWebsocketConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
16
|
+
/** WebSocket API configuration options */
|
|
17
|
+
readonly webSocketApiOptions: WebSocketApiProps;
|
|
18
|
+
/** WebSocket stage configuration options */
|
|
19
|
+
readonly webSocketStageOptions: WebSocketStageProps;
|
|
20
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
21
|
+
/**
|
|
22
|
+
* Lambda handlers mapped to WebSocket lifecycle routes
|
|
23
|
+
*
|
|
24
|
+
* Includes:
|
|
25
|
+
* - $connect
|
|
26
|
+
* - $disconnect
|
|
27
|
+
* - $default
|
|
28
|
+
* - custom message route
|
|
29
|
+
*/
|
|
30
|
+
readonly handlers: {
|
|
31
|
+
/** Handler for connection establishment ($connect) */
|
|
32
|
+
readonly connect: {
|
|
33
|
+
option: WebSocketRouteOptions;
|
|
34
|
+
function: Function;
|
|
35
|
+
};
|
|
36
|
+
/** Handler for unmatched routes ($default) */
|
|
37
|
+
readonly default: {
|
|
38
|
+
option: WebSocketRouteOptions;
|
|
39
|
+
function: Function;
|
|
40
|
+
};
|
|
41
|
+
/** Handler for custom message route (e.g. 'notifications') */
|
|
42
|
+
readonly message: {
|
|
43
|
+
option: WebSocketRouteOptions;
|
|
44
|
+
function: Function;
|
|
45
|
+
};
|
|
46
|
+
/** Handler for disconnection events ($disconnect) */
|
|
47
|
+
readonly disconnect: {
|
|
48
|
+
option: WebSocketRouteOptions;
|
|
49
|
+
function: Function;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* CDK construct for WebSocket API Gateway
|
|
55
|
+
*
|
|
56
|
+
* Responsibilities:
|
|
57
|
+
* - Creates a WebSocket API with lifecycle route integrations
|
|
58
|
+
* - Registers a custom message route
|
|
59
|
+
* - Deploys a stage with auto-deploy enabled
|
|
60
|
+
* - Exposes WebSocket endpoint URL as a CloudFormation output
|
|
61
|
+
*/
|
|
62
|
+
declare class BaseApiGatewayWebSocketConstruct extends Construct {
|
|
63
|
+
/** The created WebSocket API instance */
|
|
64
|
+
readonly socketApi: WebSocketApi;
|
|
65
|
+
/**
|
|
66
|
+
* @param scope Parent construct
|
|
67
|
+
* @param id Unique construct identifier
|
|
68
|
+
* @param props Configuration for API, stage, and route handlers
|
|
69
|
+
*/
|
|
70
|
+
constructor(scope: Construct, id: string, props: IApiGatewayWebsocketConstructProps);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { BaseApiGatewayWebSocketConstruct };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { WebSocketLambdaIntegration } from 'aws-cdk-lib/aws-apigatewayv2-integrations';
|
|
4
|
+
import { WebSocketApi, WebSocketStage } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var BaseApiGatewayWebSocketConstruct = class extends Construct {
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "BaseApiGatewayWebSocketConstruct");
|
|
11
|
+
}
|
|
12
|
+
/** The created WebSocket API instance */
|
|
13
|
+
socketApi;
|
|
14
|
+
/**
|
|
15
|
+
* @param scope Parent construct
|
|
16
|
+
* @param id Unique construct identifier
|
|
17
|
+
* @param props Configuration for API, stage, and route handlers
|
|
18
|
+
*/
|
|
19
|
+
constructor(scope, id, props) {
|
|
20
|
+
super(scope, id);
|
|
21
|
+
this.socketApi = new WebSocketApi(this, id, {
|
|
22
|
+
...props.options.webSocketApiOptions,
|
|
23
|
+
/**
|
|
24
|
+
* Route for connection establishment ($connect)
|
|
25
|
+
*/
|
|
26
|
+
connectRouteOptions: {
|
|
27
|
+
...props.handlers.connect?.option,
|
|
28
|
+
integration: new WebSocketLambdaIntegration(
|
|
29
|
+
"connectIntegration",
|
|
30
|
+
props.handlers.connect.function
|
|
31
|
+
)
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Route for disconnection events ($disconnect)
|
|
35
|
+
*/
|
|
36
|
+
disconnectRouteOptions: {
|
|
37
|
+
...props.handlers.disconnect?.option,
|
|
38
|
+
integration: new WebSocketLambdaIntegration(
|
|
39
|
+
"disconnectIntegration",
|
|
40
|
+
props.handlers.disconnect.function
|
|
41
|
+
)
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Default route for unmatched messages ($default)
|
|
45
|
+
*/
|
|
46
|
+
defaultRouteOptions: {
|
|
47
|
+
...props.handlers.default?.option,
|
|
48
|
+
integration: new WebSocketLambdaIntegration(
|
|
49
|
+
"defaultIntegration",
|
|
50
|
+
props.handlers.default.function
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
this.socketApi.addRoute("notifications", {
|
|
55
|
+
...props.handlers.message?.option,
|
|
56
|
+
/** Lambda integration for message handling */
|
|
57
|
+
integration: new WebSocketLambdaIntegration(
|
|
58
|
+
"routes",
|
|
59
|
+
props.handlers.message.function
|
|
60
|
+
)
|
|
61
|
+
});
|
|
62
|
+
const webSocketStage = new WebSocketStage(this, `${id}_stage`, {
|
|
63
|
+
...props.options?.webSocketStageOptions,
|
|
64
|
+
webSocketApi: this.socketApi,
|
|
65
|
+
autoDeploy: true
|
|
66
|
+
});
|
|
67
|
+
new CfnOutput(this, "WebSocketURL", {
|
|
68
|
+
value: webSocketStage.url
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { BaseApiGatewayWebSocketConstruct };
|
|
74
|
+
//# sourceMappingURL=api-gateway-websocket.js.map
|
|
75
|
+
//# sourceMappingURL=api-gateway-websocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/api-gateway-websocket-construct.ts"],"names":[],"mappings":";;;;;;;AA6EO,IAAM,gCAAA,GAAN,cAA+C,SAAA,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,EAAA,EACA,KAAA,EACC;AACD,IAAA,KAAA,CAAM,OAAO,EAAE,CAAA;AAEf,IAAA,IAAA,CAAK,SAAA,GAAY,IAAI,YAAA,CAAa,IAAA,EAAM,EAAA,EAAI;AAAA,MAC3C,GAAG,MAAM,OAAA,CAAQ,mBAAA;AAAA;AAAA;AAAA;AAAA,MAKjB,mBAAA,EAAqB;AAAA,QACpB,GAAG,KAAA,CAAM,QAAA,CAAS,OAAA,EAAS,MAAA;AAAA,QAC3B,aAAa,IAAI,0BAAA;AAAA,UAChB,oBAAA;AAAA,UACA,KAAA,CAAM,SAAS,OAAA,CAAQ;AAAA;AACxB,OACD;AAAA;AAAA;AAAA;AAAA,MAKA,sBAAA,EAAwB;AAAA,QACvB,GAAG,KAAA,CAAM,QAAA,CAAS,UAAA,EAAY,MAAA;AAAA,QAC9B,aAAa,IAAI,0BAAA;AAAA,UAChB,uBAAA;AAAA,UACA,KAAA,CAAM,SAAS,UAAA,CAAW;AAAA;AAC3B,OACD;AAAA;AAAA;AAAA;AAAA,MAKA,mBAAA,EAAqB;AAAA,QACpB,GAAG,KAAA,CAAM,QAAA,CAAS,OAAA,EAAS,MAAA;AAAA,QAC3B,aAAa,IAAI,0BAAA;AAAA,UAChB,oBAAA;AAAA,UACA,KAAA,CAAM,SAAS,OAAA,CAAQ;AAAA;AACxB;AACD,KACA,CAAA;AAKD,IAAA,IAAA,CAAK,SAAA,CAAU,SAAS,eAAA,EAAiB;AAAA,MACxC,GAAG,KAAA,CAAM,QAAA,CAAS,OAAA,EAAS,MAAA;AAAA;AAAA,MAG3B,aAAa,IAAI,0BAAA;AAAA,QAChB,QAAA;AAAA,QACA,KAAA,CAAM,SAAS,OAAA,CAAQ;AAAA;AACxB,KACA,CAAA;AAMD,IAAA,MAAM,iBAAiB,IAAI,cAAA,CAAe,IAAA,EAAM,CAAA,EAAG,EAAE,CAAA,MAAA,CAAA,EAAU;AAAA,MAC9D,GAAG,MAAM,OAAA,EAAS,qBAAA;AAAA,MAClB,cAAc,IAAA,CAAK,SAAA;AAAA,MACnB,UAAA,EAAY;AAAA,KACZ,CAAA;AAKD,IAAA,IAAI,SAAA,CAAU,MAAM,cAAA,EAAgB;AAAA,MACnC,OAAO,cAAA,CAAe;AAAA,KACtB,CAAA;AAAA,EACF;AACD","file":"api-gateway-websocket.js","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"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constructs = require('constructs');
|
|
4
|
+
var awsCdkLib = require('aws-cdk-lib');
|
|
5
|
+
var awsApigateway = require('aws-cdk-lib/aws-apigateway');
|
|
6
|
+
var toolkit = require('@incloodsolutions/toolkit');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var BaseApiGatewayConstruct = class _BaseApiGatewayConstruct extends constructs.Construct {
|
|
11
|
+
static {
|
|
12
|
+
__name(this, "BaseApiGatewayConstruct");
|
|
13
|
+
}
|
|
14
|
+
/** The created REST API instance */
|
|
15
|
+
api;
|
|
16
|
+
/** Enables debug logging for route creation */
|
|
17
|
+
enableDebug = false;
|
|
18
|
+
/**
|
|
19
|
+
* @param scope Parent construct
|
|
20
|
+
* @param id Unique construct identifier
|
|
21
|
+
* @param props Configuration for API, routes, and Lambda handler
|
|
22
|
+
*/
|
|
23
|
+
constructor(scope, id, props) {
|
|
24
|
+
super(scope, id);
|
|
25
|
+
this.enableDebug = props.enableDebug;
|
|
26
|
+
this.api = new awsApigateway.RestApi(this, id, {
|
|
27
|
+
...props?.options?.gatewayOptions,
|
|
28
|
+
/** Default API description if not provided */
|
|
29
|
+
description: props?.options?.gatewayOptions?.description || "This is a REST API using CDK",
|
|
30
|
+
/**
|
|
31
|
+
* CORS configuration
|
|
32
|
+
* Falls back to allowing all origins, methods, and standard headers
|
|
33
|
+
*/
|
|
34
|
+
defaultCorsPreflightOptions: {
|
|
35
|
+
...props?.options?.gatewayOptions?.defaultCorsPreflightOptions,
|
|
36
|
+
/** Allow all origins by default */
|
|
37
|
+
allowOrigins: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowOrigins || awsApigateway.Cors.ALL_ORIGINS,
|
|
38
|
+
/** Allow all HTTP methods by default */
|
|
39
|
+
allowMethods: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowMethods || awsApigateway.Cors.ALL_METHODS,
|
|
40
|
+
/** Merge default headers with user-defined headers */
|
|
41
|
+
allowHeaders: [
|
|
42
|
+
...props.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowHeaders,
|
|
43
|
+
"Content-Type",
|
|
44
|
+
"Accept",
|
|
45
|
+
"X-Amz-Date",
|
|
46
|
+
"Authorization",
|
|
47
|
+
"X-Api-Key",
|
|
48
|
+
"X-Amz-Security-Token",
|
|
49
|
+
"X-Amz-User-Agent"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
/** Minimum payload size (in bytes) before compression is applied */
|
|
53
|
+
minCompressionSize: props?.options?.gatewayOptions?.minCompressionSize || awsCdkLib.Size.bytes(1)
|
|
54
|
+
});
|
|
55
|
+
if (props?.options?.routeOptions?.length && props?.handlerFunction) {
|
|
56
|
+
const integration = new awsApigateway.LambdaIntegration(props.handlerFunction);
|
|
57
|
+
this.addRoutes(this.api.root, props.options.routeOptions, integration);
|
|
58
|
+
}
|
|
59
|
+
this.api.applyRemovalPolicy(awsCdkLib.RemovalPolicy.DESTROY);
|
|
60
|
+
new awsCdkLib.CfnOutput(this, "ApiGateway", {
|
|
61
|
+
value: this.api.url
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Recursively attaches routes to the API Gateway
|
|
66
|
+
*
|
|
67
|
+
* Behaviour:
|
|
68
|
+
* - Creates a resource for each route segment
|
|
69
|
+
* - Attaches method + Lambda integration
|
|
70
|
+
* - Traverses child routes for nested paths
|
|
71
|
+
*
|
|
72
|
+
* @param parent Parent API resource
|
|
73
|
+
* @param routes Route definitions
|
|
74
|
+
* @param integration Lambda integration applied to each route
|
|
75
|
+
* @param previousPath Accumulated path (used for debug logging)
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
addRoutes(parent, routes, integration, previousPath) {
|
|
79
|
+
routes.forEach((route) => {
|
|
80
|
+
const currentPath = `${previousPath || ""}/${route.name}`;
|
|
81
|
+
const resource = parent.addResource(route.name);
|
|
82
|
+
resource.addMethod(route.method, integration);
|
|
83
|
+
if (route?.children.length) {
|
|
84
|
+
this.addRoutes(resource, route.children, integration, currentPath);
|
|
85
|
+
}
|
|
86
|
+
if (this.enableDebug) {
|
|
87
|
+
toolkit.printLog(
|
|
88
|
+
_BaseApiGatewayConstruct.name,
|
|
89
|
+
`Route created: ${route.method} ${currentPath}`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
exports.BaseApiGatewayConstruct = BaseApiGatewayConstruct;
|
|
97
|
+
//# sourceMappingURL=api-gateway.cjs.map
|
|
98
|
+
//# sourceMappingURL=api-gateway.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/api-gateway-construct.ts"],"names":["Construct","RestApi","Cors","Size","LambdaIntegration","RemovalPolicy","CfnOutput","printLog"],"mappings":"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","file":"api-gateway.cjs","sourcesContent":["import { Construct } from 'constructs';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { HttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';\nimport { CfnOutput, RemovalPolicy, Size } from 'aws-cdk-lib';\nimport {\n\tCors,\n\tIResource,\n\tLambdaIntegration,\n\tRestApi,\n\tRestApiProps,\n} from 'aws-cdk-lib/aws-apigateway';\n\nimport { printLog } from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps, IBaseConstruct } from '../../types';\n\n/**\n * Route definition for API Gateway resources\n *\n * Supports hierarchical route structures using `children`\n */\ninterface IRouteOption {\n\t/** Path segment (e.g. 'users', 'orders') */\n\tname: string;\n\n\t/** HTTP method for the route */\n\tmethod: `${HttpMethod}`;\n\n\t/** Nested routes under this path */\n\tchildren?: IRouteOption[];\n}\n\n/**\n * Props for BaseApiGatewayConstruct\n *\n * Provides configuration for:\n * - REST API (API Gateway v1)\n * - Route definitions\n * - Lambda handler\n */\ninterface IApiGatewayConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** REST API configuration options */\n\t\treadonly gatewayOptions: RestApiProps;\n\n\t\t/** Route definitions used to build API resources */\n\t\treadonly routeOptions: IRouteOption[];\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {\n\t/**\n\t * Lambda function handling all API routes\n\t *\n\t * Note:\n\t * A single Lambda integration is reused across all routes\n\t */\n\treadonly handlerFunction: Function;\n}\n\n/**\n * CDK construct for REST API Gateway with Lambda integration\n *\n * Responsibilities:\n * - Creates a REST API with configurable options\n * - Applies default CORS and compression settings when not provided\n * - Recursively builds API resources from route definitions\n * - Exposes API base URL as a CloudFormation output\n */\nexport class BaseApiGatewayConstruct\n\textends Construct\n\timplements IBaseConstruct\n{\n\t/** The created REST API instance */\n\treadonly api: RestApi;\n\n\t/** Enables debug logging for route creation */\n\tenableDebug = false;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for API, routes, and Lambda handler\n\t */\n\tconstructor(scope: Construct, id: string, props: IApiGatewayConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.enableDebug = props.enableDebug;\n\n\t\tthis.api = new RestApi(this, id, {\n\t\t\t...props?.options?.gatewayOptions,\n\n\t\t\t/** Default API description if not provided */\n\t\t\tdescription:\n\t\t\t\tprops?.options?.gatewayOptions?.description ||\n\t\t\t\t'This is a REST API using CDK',\n\n\t\t\t/**\n\t\t\t * CORS configuration\n\t\t\t * Falls back to allowing all origins, methods, and standard headers\n\t\t\t */\n\t\t\tdefaultCorsPreflightOptions: {\n\t\t\t\t...props?.options?.gatewayOptions?.defaultCorsPreflightOptions,\n\n\t\t\t\t/** Allow all origins by default */\n\t\t\t\tallowOrigins:\n\t\t\t\t\tprops?.options?.gatewayOptions?.defaultCorsPreflightOptions\n\t\t\t\t\t\t?.allowOrigins || Cors.ALL_ORIGINS,\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?.defaultCorsPreflightOptions\n\t\t\t\t\t\t?.allowMethods || Cors.ALL_METHODS,\n\n\t\t\t\t/** Merge default headers with user-defined headers */\n\t\t\t\tallowHeaders: [\n\t\t\t\t\t...props.options?.gatewayOptions?.defaultCorsPreflightOptions\n\t\t\t\t\t\t?.allowHeaders,\n\t\t\t\t\t'Content-Type',\n\t\t\t\t\t'Accept',\n\t\t\t\t\t'X-Amz-Date',\n\t\t\t\t\t'Authorization',\n\t\t\t\t\t'X-Api-Key',\n\t\t\t\t\t'X-Amz-Security-Token',\n\t\t\t\t\t'X-Amz-User-Agent',\n\t\t\t\t],\n\t\t\t},\n\n\t\t\t/** Minimum payload size (in bytes) before compression is applied */\n\t\t\tminCompressionSize:\n\t\t\t\tprops?.options?.gatewayOptions?.minCompressionSize || Size.bytes(1),\n\t\t});\n\n\t\t/**\n\t\t * Register routes if provided\n\t\t */\n\t\tif (props?.options?.routeOptions?.length && props?.handlerFunction) {\n\t\t\tconst integration = new LambdaIntegration(props.handlerFunction);\n\n\t\t\t/**\n\t\t\t * Attach routes recursively starting from API root\n\t\t\t */\n\t\t\tthis.addRoutes(this.api.root, props.options.routeOptions, integration);\n\t\t}\n\n\t\t/**\n\t\t * Apply removal policy (useful for non-production environments)\n\t\t */\n\t\tthis.api.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing API base URL\n\t\t */\n\t\tnew CfnOutput(this, 'ApiGateway', {\n\t\t\tvalue: this.api.url,\n\t\t});\n\t}\n\n\t/**\n\t * Recursively attaches routes to the API Gateway\n\t *\n\t * Behaviour:\n\t * - Creates a resource for each route segment\n\t * - Attaches method + Lambda integration\n\t * - Traverses child routes for nested paths\n\t *\n\t * @param parent Parent API resource\n\t * @param routes Route definitions\n\t * @param integration Lambda integration applied to each route\n\t * @param previousPath Accumulated path (used for debug logging)\n\t * @private\n\t */\n\tprivate addRoutes(\n\t\tparent: IResource,\n\t\troutes: IRouteOption[],\n\t\tintegration: LambdaIntegration,\n\t\tpreviousPath?: string,\n\t) {\n\t\troutes.forEach((route) => {\n\t\t\tconst currentPath = `${previousPath || ''}/${route.name}`;\n\n\t\t\tconst resource = parent.addResource(route.name);\n\n\t\t\t/** Attach HTTP method with Lambda integration */\n\t\t\tresource.addMethod(route.method, integration);\n\n\t\t\t/** Recursively process child routes */\n\t\t\tif (route?.children.length) {\n\t\t\t\tthis.addRoutes(resource, route.children, integration, currentPath);\n\t\t\t}\n\n\t\t\t/** Optional debug logging */\n\t\t\tif (this.enableDebug) {\n\t\t\t\tprintLog(\n\t\t\t\t\tBaseApiGatewayConstruct.name,\n\t\t\t\t\t`Route created: ${route.method} ${currentPath}`,\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { HttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
4
|
+
import { RestApi, RestApiProps } from 'aws-cdk-lib/aws-apigateway';
|
|
5
|
+
import { IBaseConstruct, IBaseCdkConstructProps } from '../aws-types.cjs';
|
|
6
|
+
import '@incloodsolutions/toolkit';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Route definition for API Gateway resources
|
|
10
|
+
*
|
|
11
|
+
* Supports hierarchical route structures using `children`
|
|
12
|
+
*/
|
|
13
|
+
interface IRouteOption {
|
|
14
|
+
/** Path segment (e.g. 'users', 'orders') */
|
|
15
|
+
name: string;
|
|
16
|
+
/** HTTP method for the route */
|
|
17
|
+
method: `${HttpMethod}`;
|
|
18
|
+
/** Nested routes under this path */
|
|
19
|
+
children?: IRouteOption[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Props for BaseApiGatewayConstruct
|
|
23
|
+
*
|
|
24
|
+
* Provides configuration for:
|
|
25
|
+
* - REST API (API Gateway v1)
|
|
26
|
+
* - Route definitions
|
|
27
|
+
* - Lambda handler
|
|
28
|
+
*/
|
|
29
|
+
interface IApiGatewayConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
30
|
+
/** REST API configuration options */
|
|
31
|
+
readonly gatewayOptions: RestApiProps;
|
|
32
|
+
/** Route definitions used to build API resources */
|
|
33
|
+
readonly routeOptions: IRouteOption[];
|
|
34
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
35
|
+
/**
|
|
36
|
+
* Lambda function handling all API routes
|
|
37
|
+
*
|
|
38
|
+
* Note:
|
|
39
|
+
* A single Lambda integration is reused across all routes
|
|
40
|
+
*/
|
|
41
|
+
readonly handlerFunction: Function;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* CDK construct for REST API Gateway with Lambda integration
|
|
45
|
+
*
|
|
46
|
+
* Responsibilities:
|
|
47
|
+
* - Creates a REST API with configurable options
|
|
48
|
+
* - Applies default CORS and compression settings when not provided
|
|
49
|
+
* - Recursively builds API resources from route definitions
|
|
50
|
+
* - Exposes API base URL as a CloudFormation output
|
|
51
|
+
*/
|
|
52
|
+
declare class BaseApiGatewayConstruct extends Construct implements IBaseConstruct {
|
|
53
|
+
/** The created REST API instance */
|
|
54
|
+
readonly api: RestApi;
|
|
55
|
+
/** Enables debug logging for route creation */
|
|
56
|
+
enableDebug: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* @param scope Parent construct
|
|
59
|
+
* @param id Unique construct identifier
|
|
60
|
+
* @param props Configuration for API, routes, and Lambda handler
|
|
61
|
+
*/
|
|
62
|
+
constructor(scope: Construct, id: string, props: IApiGatewayConstructProps);
|
|
63
|
+
/**
|
|
64
|
+
* Recursively attaches routes to the API Gateway
|
|
65
|
+
*
|
|
66
|
+
* Behaviour:
|
|
67
|
+
* - Creates a resource for each route segment
|
|
68
|
+
* - Attaches method + Lambda integration
|
|
69
|
+
* - Traverses child routes for nested paths
|
|
70
|
+
*
|
|
71
|
+
* @param parent Parent API resource
|
|
72
|
+
* @param routes Route definitions
|
|
73
|
+
* @param integration Lambda integration applied to each route
|
|
74
|
+
* @param previousPath Accumulated path (used for debug logging)
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
private addRoutes;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { BaseApiGatewayConstruct };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { HttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
4
|
+
import { RestApi, RestApiProps } from 'aws-cdk-lib/aws-apigateway';
|
|
5
|
+
import { IBaseConstruct, IBaseCdkConstructProps } from '../aws-types.js';
|
|
6
|
+
import '@incloodsolutions/toolkit';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Route definition for API Gateway resources
|
|
10
|
+
*
|
|
11
|
+
* Supports hierarchical route structures using `children`
|
|
12
|
+
*/
|
|
13
|
+
interface IRouteOption {
|
|
14
|
+
/** Path segment (e.g. 'users', 'orders') */
|
|
15
|
+
name: string;
|
|
16
|
+
/** HTTP method for the route */
|
|
17
|
+
method: `${HttpMethod}`;
|
|
18
|
+
/** Nested routes under this path */
|
|
19
|
+
children?: IRouteOption[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Props for BaseApiGatewayConstruct
|
|
23
|
+
*
|
|
24
|
+
* Provides configuration for:
|
|
25
|
+
* - REST API (API Gateway v1)
|
|
26
|
+
* - Route definitions
|
|
27
|
+
* - Lambda handler
|
|
28
|
+
*/
|
|
29
|
+
interface IApiGatewayConstructProps extends Omit<IBaseCdkConstructProps<{
|
|
30
|
+
/** REST API configuration options */
|
|
31
|
+
readonly gatewayOptions: RestApiProps;
|
|
32
|
+
/** Route definitions used to build API resources */
|
|
33
|
+
readonly routeOptions: IRouteOption[];
|
|
34
|
+
}>, 'appName' | 'stage' | 'stackName'> {
|
|
35
|
+
/**
|
|
36
|
+
* Lambda function handling all API routes
|
|
37
|
+
*
|
|
38
|
+
* Note:
|
|
39
|
+
* A single Lambda integration is reused across all routes
|
|
40
|
+
*/
|
|
41
|
+
readonly handlerFunction: Function;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* CDK construct for REST API Gateway with Lambda integration
|
|
45
|
+
*
|
|
46
|
+
* Responsibilities:
|
|
47
|
+
* - Creates a REST API with configurable options
|
|
48
|
+
* - Applies default CORS and compression settings when not provided
|
|
49
|
+
* - Recursively builds API resources from route definitions
|
|
50
|
+
* - Exposes API base URL as a CloudFormation output
|
|
51
|
+
*/
|
|
52
|
+
declare class BaseApiGatewayConstruct extends Construct implements IBaseConstruct {
|
|
53
|
+
/** The created REST API instance */
|
|
54
|
+
readonly api: RestApi;
|
|
55
|
+
/** Enables debug logging for route creation */
|
|
56
|
+
enableDebug: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* @param scope Parent construct
|
|
59
|
+
* @param id Unique construct identifier
|
|
60
|
+
* @param props Configuration for API, routes, and Lambda handler
|
|
61
|
+
*/
|
|
62
|
+
constructor(scope: Construct, id: string, props: IApiGatewayConstructProps);
|
|
63
|
+
/**
|
|
64
|
+
* Recursively attaches routes to the API Gateway
|
|
65
|
+
*
|
|
66
|
+
* Behaviour:
|
|
67
|
+
* - Creates a resource for each route segment
|
|
68
|
+
* - Attaches method + Lambda integration
|
|
69
|
+
* - Traverses child routes for nested paths
|
|
70
|
+
*
|
|
71
|
+
* @param parent Parent API resource
|
|
72
|
+
* @param routes Route definitions
|
|
73
|
+
* @param integration Lambda integration applied to each route
|
|
74
|
+
* @param previousPath Accumulated path (used for debug logging)
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
private addRoutes;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { BaseApiGatewayConstruct };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import { Size, RemovalPolicy, CfnOutput } from 'aws-cdk-lib';
|
|
3
|
+
import { RestApi, Cors, LambdaIntegration } from 'aws-cdk-lib/aws-apigateway';
|
|
4
|
+
import { printLog } from '@incloodsolutions/toolkit';
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var BaseApiGatewayConstruct = class _BaseApiGatewayConstruct extends Construct {
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "BaseApiGatewayConstruct");
|
|
11
|
+
}
|
|
12
|
+
/** The created REST API instance */
|
|
13
|
+
api;
|
|
14
|
+
/** Enables debug logging for route creation */
|
|
15
|
+
enableDebug = false;
|
|
16
|
+
/**
|
|
17
|
+
* @param scope Parent construct
|
|
18
|
+
* @param id Unique construct identifier
|
|
19
|
+
* @param props Configuration for API, routes, and Lambda handler
|
|
20
|
+
*/
|
|
21
|
+
constructor(scope, id, props) {
|
|
22
|
+
super(scope, id);
|
|
23
|
+
this.enableDebug = props.enableDebug;
|
|
24
|
+
this.api = new RestApi(this, id, {
|
|
25
|
+
...props?.options?.gatewayOptions,
|
|
26
|
+
/** Default API description if not provided */
|
|
27
|
+
description: props?.options?.gatewayOptions?.description || "This is a REST API using CDK",
|
|
28
|
+
/**
|
|
29
|
+
* CORS configuration
|
|
30
|
+
* Falls back to allowing all origins, methods, and standard headers
|
|
31
|
+
*/
|
|
32
|
+
defaultCorsPreflightOptions: {
|
|
33
|
+
...props?.options?.gatewayOptions?.defaultCorsPreflightOptions,
|
|
34
|
+
/** Allow all origins by default */
|
|
35
|
+
allowOrigins: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowOrigins || Cors.ALL_ORIGINS,
|
|
36
|
+
/** Allow all HTTP methods by default */
|
|
37
|
+
allowMethods: props?.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowMethods || Cors.ALL_METHODS,
|
|
38
|
+
/** Merge default headers with user-defined headers */
|
|
39
|
+
allowHeaders: [
|
|
40
|
+
...props.options?.gatewayOptions?.defaultCorsPreflightOptions?.allowHeaders,
|
|
41
|
+
"Content-Type",
|
|
42
|
+
"Accept",
|
|
43
|
+
"X-Amz-Date",
|
|
44
|
+
"Authorization",
|
|
45
|
+
"X-Api-Key",
|
|
46
|
+
"X-Amz-Security-Token",
|
|
47
|
+
"X-Amz-User-Agent"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
/** Minimum payload size (in bytes) before compression is applied */
|
|
51
|
+
minCompressionSize: props?.options?.gatewayOptions?.minCompressionSize || Size.bytes(1)
|
|
52
|
+
});
|
|
53
|
+
if (props?.options?.routeOptions?.length && props?.handlerFunction) {
|
|
54
|
+
const integration = new LambdaIntegration(props.handlerFunction);
|
|
55
|
+
this.addRoutes(this.api.root, props.options.routeOptions, integration);
|
|
56
|
+
}
|
|
57
|
+
this.api.applyRemovalPolicy(RemovalPolicy.DESTROY);
|
|
58
|
+
new CfnOutput(this, "ApiGateway", {
|
|
59
|
+
value: this.api.url
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Recursively attaches routes to the API Gateway
|
|
64
|
+
*
|
|
65
|
+
* Behaviour:
|
|
66
|
+
* - Creates a resource for each route segment
|
|
67
|
+
* - Attaches method + Lambda integration
|
|
68
|
+
* - Traverses child routes for nested paths
|
|
69
|
+
*
|
|
70
|
+
* @param parent Parent API resource
|
|
71
|
+
* @param routes Route definitions
|
|
72
|
+
* @param integration Lambda integration applied to each route
|
|
73
|
+
* @param previousPath Accumulated path (used for debug logging)
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
addRoutes(parent, routes, integration, previousPath) {
|
|
77
|
+
routes.forEach((route) => {
|
|
78
|
+
const currentPath = `${previousPath || ""}/${route.name}`;
|
|
79
|
+
const resource = parent.addResource(route.name);
|
|
80
|
+
resource.addMethod(route.method, integration);
|
|
81
|
+
if (route?.children.length) {
|
|
82
|
+
this.addRoutes(resource, route.children, integration, currentPath);
|
|
83
|
+
}
|
|
84
|
+
if (this.enableDebug) {
|
|
85
|
+
printLog(
|
|
86
|
+
_BaseApiGatewayConstruct.name,
|
|
87
|
+
`Route created: ${route.method} ${currentPath}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { BaseApiGatewayConstruct };
|
|
95
|
+
//# sourceMappingURL=api-gateway.js.map
|
|
96
|
+
//# sourceMappingURL=api-gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/aws/cdk/constructs/api-gateway-construct.ts"],"names":[],"mappings":"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","file":"api-gateway.js","sourcesContent":["import { Construct } from 'constructs';\nimport { Function } from 'aws-cdk-lib/aws-lambda';\nimport { HttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';\nimport { CfnOutput, RemovalPolicy, Size } from 'aws-cdk-lib';\nimport {\n\tCors,\n\tIResource,\n\tLambdaIntegration,\n\tRestApi,\n\tRestApiProps,\n} from 'aws-cdk-lib/aws-apigateway';\n\nimport { printLog } from '@incloodsolutions/toolkit';\n\nimport { IBaseCdkConstructProps, IBaseConstruct } from '../../types';\n\n/**\n * Route definition for API Gateway resources\n *\n * Supports hierarchical route structures using `children`\n */\ninterface IRouteOption {\n\t/** Path segment (e.g. 'users', 'orders') */\n\tname: string;\n\n\t/** HTTP method for the route */\n\tmethod: `${HttpMethod}`;\n\n\t/** Nested routes under this path */\n\tchildren?: IRouteOption[];\n}\n\n/**\n * Props for BaseApiGatewayConstruct\n *\n * Provides configuration for:\n * - REST API (API Gateway v1)\n * - Route definitions\n * - Lambda handler\n */\ninterface IApiGatewayConstructProps extends Omit<\n\tIBaseCdkConstructProps<{\n\t\t/** REST API configuration options */\n\t\treadonly gatewayOptions: RestApiProps;\n\n\t\t/** Route definitions used to build API resources */\n\t\treadonly routeOptions: IRouteOption[];\n\t}>,\n\t'appName' | 'stage' | 'stackName'\n> {\n\t/**\n\t * Lambda function handling all API routes\n\t *\n\t * Note:\n\t * A single Lambda integration is reused across all routes\n\t */\n\treadonly handlerFunction: Function;\n}\n\n/**\n * CDK construct for REST API Gateway with Lambda integration\n *\n * Responsibilities:\n * - Creates a REST API with configurable options\n * - Applies default CORS and compression settings when not provided\n * - Recursively builds API resources from route definitions\n * - Exposes API base URL as a CloudFormation output\n */\nexport class BaseApiGatewayConstruct\n\textends Construct\n\timplements IBaseConstruct\n{\n\t/** The created REST API instance */\n\treadonly api: RestApi;\n\n\t/** Enables debug logging for route creation */\n\tenableDebug = false;\n\n\t/**\n\t * @param scope Parent construct\n\t * @param id Unique construct identifier\n\t * @param props Configuration for API, routes, and Lambda handler\n\t */\n\tconstructor(scope: Construct, id: string, props: IApiGatewayConstructProps) {\n\t\tsuper(scope, id);\n\n\t\tthis.enableDebug = props.enableDebug;\n\n\t\tthis.api = new RestApi(this, id, {\n\t\t\t...props?.options?.gatewayOptions,\n\n\t\t\t/** Default API description if not provided */\n\t\t\tdescription:\n\t\t\t\tprops?.options?.gatewayOptions?.description ||\n\t\t\t\t'This is a REST API using CDK',\n\n\t\t\t/**\n\t\t\t * CORS configuration\n\t\t\t * Falls back to allowing all origins, methods, and standard headers\n\t\t\t */\n\t\t\tdefaultCorsPreflightOptions: {\n\t\t\t\t...props?.options?.gatewayOptions?.defaultCorsPreflightOptions,\n\n\t\t\t\t/** Allow all origins by default */\n\t\t\t\tallowOrigins:\n\t\t\t\t\tprops?.options?.gatewayOptions?.defaultCorsPreflightOptions\n\t\t\t\t\t\t?.allowOrigins || Cors.ALL_ORIGINS,\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?.defaultCorsPreflightOptions\n\t\t\t\t\t\t?.allowMethods || Cors.ALL_METHODS,\n\n\t\t\t\t/** Merge default headers with user-defined headers */\n\t\t\t\tallowHeaders: [\n\t\t\t\t\t...props.options?.gatewayOptions?.defaultCorsPreflightOptions\n\t\t\t\t\t\t?.allowHeaders,\n\t\t\t\t\t'Content-Type',\n\t\t\t\t\t'Accept',\n\t\t\t\t\t'X-Amz-Date',\n\t\t\t\t\t'Authorization',\n\t\t\t\t\t'X-Api-Key',\n\t\t\t\t\t'X-Amz-Security-Token',\n\t\t\t\t\t'X-Amz-User-Agent',\n\t\t\t\t],\n\t\t\t},\n\n\t\t\t/** Minimum payload size (in bytes) before compression is applied */\n\t\t\tminCompressionSize:\n\t\t\t\tprops?.options?.gatewayOptions?.minCompressionSize || Size.bytes(1),\n\t\t});\n\n\t\t/**\n\t\t * Register routes if provided\n\t\t */\n\t\tif (props?.options?.routeOptions?.length && props?.handlerFunction) {\n\t\t\tconst integration = new LambdaIntegration(props.handlerFunction);\n\n\t\t\t/**\n\t\t\t * Attach routes recursively starting from API root\n\t\t\t */\n\t\t\tthis.addRoutes(this.api.root, props.options.routeOptions, integration);\n\t\t}\n\n\t\t/**\n\t\t * Apply removal policy (useful for non-production environments)\n\t\t */\n\t\tthis.api.applyRemovalPolicy(RemovalPolicy.DESTROY);\n\n\t\t/**\n\t\t * CloudFormation output exposing API base URL\n\t\t */\n\t\tnew CfnOutput(this, 'ApiGateway', {\n\t\t\tvalue: this.api.url,\n\t\t});\n\t}\n\n\t/**\n\t * Recursively attaches routes to the API Gateway\n\t *\n\t * Behaviour:\n\t * - Creates a resource for each route segment\n\t * - Attaches method + Lambda integration\n\t * - Traverses child routes for nested paths\n\t *\n\t * @param parent Parent API resource\n\t * @param routes Route definitions\n\t * @param integration Lambda integration applied to each route\n\t * @param previousPath Accumulated path (used for debug logging)\n\t * @private\n\t */\n\tprivate addRoutes(\n\t\tparent: IResource,\n\t\troutes: IRouteOption[],\n\t\tintegration: LambdaIntegration,\n\t\tpreviousPath?: string,\n\t) {\n\t\troutes.forEach((route) => {\n\t\t\tconst currentPath = `${previousPath || ''}/${route.name}`;\n\n\t\t\tconst resource = parent.addResource(route.name);\n\n\t\t\t/** Attach HTTP method with Lambda integration */\n\t\t\tresource.addMethod(route.method, integration);\n\n\t\t\t/** Recursively process child routes */\n\t\t\tif (route?.children.length) {\n\t\t\t\tthis.addRoutes(resource, route.children, integration, currentPath);\n\t\t\t}\n\n\t\t\t/** Optional debug logging */\n\t\t\tif (this.enableDebug) {\n\t\t\t\tprintLog(\n\t\t\t\t\tBaseApiGatewayConstruct.name,\n\t\t\t\t\t`Route created: ${route.method} ${currentPath}`,\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
|