@fy-stack/app-construct 0.0.128 → 0.0.130
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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/ecs-image-app.d.ts +40 -0
- package/dist/lib/ecs-image-app.d.ts.map +1 -0
- package/dist/lib/ecs-image-app.js +107 -0
- package/dist/lib/image-app-construct.d.ts +18 -1
- package/dist/lib/image-app-construct.d.ts.map +1 -1
- package/dist/lib/image-app-construct.js +15 -2
- package/dist/lib/next-app-router-construct.d.ts +14 -1
- package/dist/lib/next-app-router-construct.d.ts.map +1 -1
- package/dist/lib/next-app-router-construct.js +13 -5
- package/dist/lib/next-pages-export-construct.d.ts +6 -1
- package/dist/lib/next-pages-export-construct.d.ts.map +1 -1
- package/dist/lib/next-pages-export-construct.js +8 -0
- package/dist/lib/node-api-construct.d.ts +14 -1
- package/dist/lib/node-api-construct.d.ts.map +1 -1
- package/dist/lib/node-api-construct.js +11 -3
- package/dist/lib/node-app-construct.d.ts +14 -1
- package/dist/lib/node-app-construct.d.ts.map +1 -1
- package/dist/lib/node-app-construct.js +13 -3
- package/dist/lib/react-static-construct.d.ts +17 -0
- package/dist/lib/react-static-construct.d.ts.map +1 -0
- package/dist/lib/react-static-construct.js +66 -0
- package/dist/lib/static-website-construct.d.ts +21 -0
- package/dist/lib/static-website-construct.d.ts.map +1 -0
- package/dist/lib/static-website-construct.js +71 -0
- package/dist/lib/types.d.ts +6 -4
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { NextAppRouterConstruct } from './lib/next-app-router-construct';
|
|
|
3
3
|
export { NextPagesExportConstruct } from './lib/next-pages-export-construct';
|
|
4
4
|
export { NodeApiConstruct } from './lib/node-api-construct';
|
|
5
5
|
export { NodeAppConstruct } from './lib/node-app-construct';
|
|
6
|
+
export { StaticWebsiteConstruct } from './lib/static-website-construct';
|
|
6
7
|
export type { AppConstruct, AppProperties } from "./lib/types";
|
|
7
8
|
export { lambdaAttach } from "./lib/utils/lambda-attach";
|
|
8
9
|
export { lambdaGrant } from "./lib/utils/lambda-grant";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lambdaGrant = exports.lambdaAttach = exports.NodeAppConstruct = exports.NodeApiConstruct = exports.NextPagesExportConstruct = exports.NextAppRouterConstruct = exports.ImageAppConstruct = void 0;
|
|
3
|
+
exports.lambdaGrant = exports.lambdaAttach = exports.StaticWebsiteConstruct = exports.NodeAppConstruct = exports.NodeApiConstruct = exports.NextPagesExportConstruct = exports.NextAppRouterConstruct = exports.ImageAppConstruct = void 0;
|
|
4
4
|
var image_app_construct_1 = require("./lib/image-app-construct");
|
|
5
5
|
Object.defineProperty(exports, "ImageAppConstruct", { enumerable: true, get: function () { return image_app_construct_1.ImageAppConstruct; } });
|
|
6
6
|
var next_app_router_construct_1 = require("./lib/next-app-router-construct");
|
|
@@ -11,6 +11,8 @@ var node_api_construct_1 = require("./lib/node-api-construct");
|
|
|
11
11
|
Object.defineProperty(exports, "NodeApiConstruct", { enumerable: true, get: function () { return node_api_construct_1.NodeApiConstruct; } });
|
|
12
12
|
var node_app_construct_1 = require("./lib/node-app-construct");
|
|
13
13
|
Object.defineProperty(exports, "NodeAppConstruct", { enumerable: true, get: function () { return node_app_construct_1.NodeAppConstruct; } });
|
|
14
|
+
var static_website_construct_1 = require("./lib/static-website-construct");
|
|
15
|
+
Object.defineProperty(exports, "StaticWebsiteConstruct", { enumerable: true, get: function () { return static_website_construct_1.StaticWebsiteConstruct; } });
|
|
14
16
|
var lambda_attach_1 = require("./lib/utils/lambda-attach");
|
|
15
17
|
Object.defineProperty(exports, "lambdaAttach", { enumerable: true, get: function () { return lambda_attach_1.lambdaAttach; } });
|
|
16
18
|
var lambda_grant_1 = require("./lib/utils/lambda-grant");
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Attachable, Grantable } from '@fy-stack/types';
|
|
2
|
+
import type { HttpRouteIntegration } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
3
|
+
import { BehaviorOptions } from 'aws-cdk-lib/aws-cloudfront';
|
|
4
|
+
import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
5
|
+
import { ITopicSubscription, SubscriptionProps } from 'aws-cdk-lib/aws-sns';
|
|
6
|
+
import { Queue } from 'aws-cdk-lib/aws-sqs';
|
|
7
|
+
import { Construct } from 'constructs';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { AppConstruct, AppProperties } from './types';
|
|
10
|
+
declare const BuildParamsSchema: z.ZodObject<{
|
|
11
|
+
file: z.ZodString;
|
|
12
|
+
cpu: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
memoryLimitMib: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
file: string;
|
|
16
|
+
cpu?: number | undefined;
|
|
17
|
+
memoryLimitMib?: number | undefined;
|
|
18
|
+
}, {
|
|
19
|
+
file: string;
|
|
20
|
+
cpu?: number | undefined;
|
|
21
|
+
memoryLimitMib?: number | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
export declare class EcsImageApp extends Construct implements AppConstruct {
|
|
24
|
+
function: Function;
|
|
25
|
+
queue: Queue | undefined;
|
|
26
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
|
|
27
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
28
|
+
grant(...grantables: Grantable[]): void;
|
|
29
|
+
subscription(props: SubscriptionProps): ITopicSubscription;
|
|
30
|
+
cloudfront(path: string): Record<string, BehaviorOptions>;
|
|
31
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
32
|
+
api(path: string): Record<string, HttpRouteIntegration>;
|
|
33
|
+
static parse(params: unknown): {
|
|
34
|
+
file: string;
|
|
35
|
+
cpu?: number | undefined;
|
|
36
|
+
memoryLimitMib?: number | undefined;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=ecs-image-app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecs-image-app.d.ts","sourceRoot":"","sources":["../../src/lib/ecs-image-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAG,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAEL,eAAe,EAKhB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAEL,QAAQ,EAGT,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAK5E,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAKtD,QAAA,MAAM,iBAAiB;;;;;;;;;;;;EAIrB,CAAA;AAEF,qBAAa,WACX,SAAQ,SACR,YAAW,YAAY;IAEhB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAEpB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAoDjG,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,IAAI;IAIpD,KAAK,CAAC,GAAG,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IAIvC,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB;IAQ1D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAqBzD,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAIvD,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;;;CAG7B"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EcsImageApp = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
6
|
+
const aws_cloudfront_1 = require("aws-cdk-lib/aws-cloudfront");
|
|
7
|
+
const aws_cloudfront_origins_1 = require("aws-cdk-lib/aws-cloudfront-origins");
|
|
8
|
+
const aws_ecs_1 = tslib_1.__importDefault(require("aws-cdk-lib/aws-ecs"));
|
|
9
|
+
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
10
|
+
const aws_lambda_event_sources_1 = require("aws-cdk-lib/aws-lambda-event-sources");
|
|
11
|
+
const aws_sns_subscriptions_1 = require("aws-cdk-lib/aws-sns-subscriptions");
|
|
12
|
+
const aws_sqs_1 = require("aws-cdk-lib/aws-sqs");
|
|
13
|
+
const constructs_1 = require("constructs");
|
|
14
|
+
const zod_1 = require("zod");
|
|
15
|
+
const lambda_api_1 = require("./utils/lambda-api");
|
|
16
|
+
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
17
|
+
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
18
|
+
const BuildParamsSchema = zod_1.z.object({
|
|
19
|
+
file: zod_1.z.string(),
|
|
20
|
+
cpu: zod_1.z.coerce.number().optional(),
|
|
21
|
+
memoryLimitMib: zod_1.z.coerce.number().optional()
|
|
22
|
+
});
|
|
23
|
+
class EcsImageApp extends constructs_1.Construct {
|
|
24
|
+
function;
|
|
25
|
+
queue;
|
|
26
|
+
constructor(scope, id, props) {
|
|
27
|
+
super(scope, id);
|
|
28
|
+
const params = BuildParamsSchema.parse(props.buildParams);
|
|
29
|
+
const cluster = new aws_ecs_1.default.Cluster(this, "AppCluster", {
|
|
30
|
+
vpc: props.vpc,
|
|
31
|
+
});
|
|
32
|
+
const taskDefinition = new aws_ecs_1.default.FargateTaskDefinition(this, "AppTask", {
|
|
33
|
+
cpu: params.cpu ?? 1024,
|
|
34
|
+
memoryLimitMiB: params.memoryLimitMib ?? 4096,
|
|
35
|
+
runtimePlatform: {
|
|
36
|
+
cpuArchitecture: aws_ecs_1.default.CpuArchitecture.X86_64
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
taskDefinition.addContainer("AppImage", {
|
|
40
|
+
image: aws_ecs_1.default.ContainerImage.fromAsset(props.output, {
|
|
41
|
+
file: params.file
|
|
42
|
+
}),
|
|
43
|
+
environment: props.env
|
|
44
|
+
});
|
|
45
|
+
this.function = new aws_lambda_1.Function(this, `AppFunction`, {
|
|
46
|
+
memorySize: 512,
|
|
47
|
+
timeout: aws_cdk_lib_1.Duration.seconds(30),
|
|
48
|
+
code: aws_lambda_1.Code.fromInline(`
|
|
49
|
+
exports.handler = async (event) => {
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
`),
|
|
53
|
+
handler: "index.handler",
|
|
54
|
+
runtime: aws_lambda_1.Runtime.NODEJS_20_X,
|
|
55
|
+
environment: {
|
|
56
|
+
CLUSTER_ARN: cluster.clusterArn,
|
|
57
|
+
TASK_DEFINITION_ARN: taskDefinition.taskDefinitionArn
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (props.queue) {
|
|
61
|
+
this.queue = new aws_sqs_1.Queue(this, 'AppQueue', {
|
|
62
|
+
visibilityTimeout: aws_cdk_lib_1.Duration.seconds(59),
|
|
63
|
+
});
|
|
64
|
+
this.function.addEventSource(new aws_lambda_event_sources_1.SqsEventSource(this.queue, {
|
|
65
|
+
batchSize: props.queue.batchSize,
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
attach(attachable) {
|
|
70
|
+
return (0, lambda_attach_1.lambdaAttach)(this.function, attachable);
|
|
71
|
+
}
|
|
72
|
+
grant(...grantables) {
|
|
73
|
+
return (0, lambda_grant_1.lambdaGrant)(this.function, grantables);
|
|
74
|
+
}
|
|
75
|
+
subscription(props) {
|
|
76
|
+
if (this.queue) {
|
|
77
|
+
return new aws_sns_subscriptions_1.SqsSubscription(this.queue, { ...props, rawMessageDelivery: true });
|
|
78
|
+
}
|
|
79
|
+
return new aws_sns_subscriptions_1.LambdaSubscription(this.function, props);
|
|
80
|
+
}
|
|
81
|
+
cloudfront(path) {
|
|
82
|
+
this.function.addEnvironment('BASE_PATH', path);
|
|
83
|
+
const apiUrl = this.function.addFunctionUrl({
|
|
84
|
+
authType: aws_lambda_1.FunctionUrlAuthType.NONE,
|
|
85
|
+
});
|
|
86
|
+
const apiBehavior = {
|
|
87
|
+
origin: new aws_cloudfront_origins_1.FunctionUrlOrigin(apiUrl),
|
|
88
|
+
cachePolicy: aws_cloudfront_1.CachePolicy.CACHING_DISABLED,
|
|
89
|
+
allowedMethods: aws_cloudfront_1.AllowedMethods.ALLOW_ALL,
|
|
90
|
+
compress: true,
|
|
91
|
+
viewerProtocolPolicy: aws_cloudfront_1.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
92
|
+
originRequestPolicy: aws_cloudfront_1.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
|
|
93
|
+
responseHeadersPolicy: aws_cloudfront_1.ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS,
|
|
94
|
+
};
|
|
95
|
+
return { [`${path}/*`]: apiBehavior };
|
|
96
|
+
}
|
|
97
|
+
cloudfrontPolicy(distributionId) {
|
|
98
|
+
throw new Error("cloudfrontPolicy not implemented");
|
|
99
|
+
}
|
|
100
|
+
api(path) {
|
|
101
|
+
return (0, lambda_api_1.lambdaApi)(this.function, path);
|
|
102
|
+
}
|
|
103
|
+
static parse(params) {
|
|
104
|
+
return BuildParamsSchema.parse(params);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.EcsImageApp = EcsImageApp;
|
|
@@ -5,15 +5,32 @@ import { Function } from 'aws-cdk-lib/aws-lambda';
|
|
|
5
5
|
import { ITopicSubscription, SubscriptionProps } from 'aws-cdk-lib/aws-sns';
|
|
6
6
|
import { Queue } from 'aws-cdk-lib/aws-sqs';
|
|
7
7
|
import { Construct } from 'constructs';
|
|
8
|
+
import { z } from 'zod';
|
|
8
9
|
import { AppConstruct, AppProperties } from './types';
|
|
10
|
+
declare const BuildParamsSchema: z.ZodObject<{
|
|
11
|
+
file: z.ZodOptional<z.ZodString>;
|
|
12
|
+
cmd: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
file?: string | undefined;
|
|
15
|
+
cmd?: string[] | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
file?: string | undefined;
|
|
18
|
+
cmd?: string[] | undefined;
|
|
19
|
+
}>;
|
|
9
20
|
export declare class ImageAppConstruct extends Construct implements AppConstruct {
|
|
10
21
|
function: Function;
|
|
11
22
|
queue: Queue | undefined;
|
|
12
|
-
constructor(scope: Construct, id: string, props: AppProperties);
|
|
23
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
|
|
13
24
|
attach(attachable: Record<string, Attachable>): void;
|
|
14
25
|
grant(...grantables: Grantable[]): void;
|
|
15
26
|
subscription(props: SubscriptionProps): ITopicSubscription;
|
|
16
27
|
cloudfront(path: string): Record<string, BehaviorOptions>;
|
|
28
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
17
29
|
api(path: string): Record<string, HttpRouteIntegration>;
|
|
30
|
+
static parse(params: unknown): {
|
|
31
|
+
file?: string | undefined;
|
|
32
|
+
cmd?: string[] | undefined;
|
|
33
|
+
};
|
|
18
34
|
}
|
|
35
|
+
export {};
|
|
19
36
|
//# sourceMappingURL=image-app-construct.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-app-construct.d.ts","sourceRoot":"","sources":["../../src/lib/image-app-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAG,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAEL,eAAe,EAKhB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAEL,QAAQ,EAIT,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAK5E,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"image-app-construct.d.ts","sourceRoot":"","sources":["../../src/lib/image-app-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAG,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAEL,eAAe,EAKhB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAEL,QAAQ,EAIT,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAK5E,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAKtD,QAAA,MAAM,iBAAiB;;;;;;;;;EAGrB,CAAA;AAEF,qBAAa,iBACX,SAAQ,SACR,YAAW,YAAY;IAEhB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAEpB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IA6BjG,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,IAAI;IAIpD,KAAK,CAAC,GAAG,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IAIvC,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB;IAQ1D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAqBzD,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAIvD,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;;CAG7B"}
|
|
@@ -10,9 +10,14 @@ const aws_lambda_event_sources_1 = require("aws-cdk-lib/aws-lambda-event-sources
|
|
|
10
10
|
const aws_sns_subscriptions_1 = require("aws-cdk-lib/aws-sns-subscriptions");
|
|
11
11
|
const aws_sqs_1 = require("aws-cdk-lib/aws-sqs");
|
|
12
12
|
const constructs_1 = require("constructs");
|
|
13
|
+
const zod_1 = require("zod");
|
|
13
14
|
const lambda_api_1 = require("./utils/lambda-api");
|
|
14
15
|
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
15
16
|
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
17
|
+
const BuildParamsSchema = zod_1.z.object({
|
|
18
|
+
file: zod_1.z.string().optional(),
|
|
19
|
+
cmd: zod_1.z.string().array().optional(),
|
|
20
|
+
});
|
|
16
21
|
class ImageAppConstruct extends constructs_1.Construct {
|
|
17
22
|
function;
|
|
18
23
|
queue;
|
|
@@ -22,9 +27,11 @@ class ImageAppConstruct extends constructs_1.Construct {
|
|
|
22
27
|
memorySize: 512,
|
|
23
28
|
timeout: aws_cdk_lib_1.Duration.seconds(30),
|
|
24
29
|
code: aws_lambda_1.Code.fromAssetImage(props.output, {
|
|
25
|
-
file: props.buildParams
|
|
30
|
+
file: props.buildParams.file,
|
|
26
31
|
platform: aws_ecr_assets_1.Platform.LINUX_AMD64,
|
|
32
|
+
cmd: props.buildParams.cmd,
|
|
27
33
|
}),
|
|
34
|
+
environment: props.env,
|
|
28
35
|
handler: aws_lambda_1.Handler.FROM_IMAGE,
|
|
29
36
|
runtime: aws_lambda_1.Runtime.FROM_IMAGE,
|
|
30
37
|
});
|
|
@@ -45,7 +52,7 @@ class ImageAppConstruct extends constructs_1.Construct {
|
|
|
45
52
|
}
|
|
46
53
|
subscription(props) {
|
|
47
54
|
if (this.queue) {
|
|
48
|
-
return new aws_sns_subscriptions_1.SqsSubscription(this.queue, props);
|
|
55
|
+
return new aws_sns_subscriptions_1.SqsSubscription(this.queue, { ...props, rawMessageDelivery: true });
|
|
49
56
|
}
|
|
50
57
|
return new aws_sns_subscriptions_1.LambdaSubscription(this.function, props);
|
|
51
58
|
}
|
|
@@ -65,8 +72,14 @@ class ImageAppConstruct extends constructs_1.Construct {
|
|
|
65
72
|
};
|
|
66
73
|
return { [`${path}/*`]: apiBehavior };
|
|
67
74
|
}
|
|
75
|
+
cloudfrontPolicy(distributionId) {
|
|
76
|
+
throw new Error("cloudfrontPolicy not implemented");
|
|
77
|
+
}
|
|
68
78
|
api(path) {
|
|
69
79
|
return (0, lambda_api_1.lambdaApi)(this.function, path);
|
|
70
80
|
}
|
|
81
|
+
static parse(params) {
|
|
82
|
+
return BuildParamsSchema.parse(params);
|
|
83
|
+
}
|
|
71
84
|
}
|
|
72
85
|
exports.ImageAppConstruct = ImageAppConstruct;
|
|
@@ -5,16 +5,29 @@ import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
|
5
5
|
import { ITopicSubscription } from 'aws-cdk-lib/aws-sns';
|
|
6
6
|
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
7
7
|
import { Construct } from 'constructs';
|
|
8
|
+
import { z } from 'zod';
|
|
8
9
|
import { AppConstruct, AppProperties } from './types';
|
|
10
|
+
declare const BuildParamsSchema: z.ZodObject<{
|
|
11
|
+
cmd: z.ZodString;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
cmd: string;
|
|
14
|
+
}, {
|
|
15
|
+
cmd: string;
|
|
16
|
+
}>;
|
|
9
17
|
export declare class NextAppRouterConstruct extends Construct implements AppConstruct {
|
|
10
18
|
function: lambda.Function;
|
|
11
19
|
queue: sqs.Queue | undefined;
|
|
12
20
|
private readonly static;
|
|
13
|
-
constructor(scope: Construct, id: string, props: AppProperties);
|
|
21
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
|
|
14
22
|
cloudfront(path: string): Record<string, cloudfront.BehaviorOptions>;
|
|
23
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
15
24
|
api(): Record<string, HttpRouteIntegration>;
|
|
16
25
|
attach(attachable: Record<string, Attachable>): void;
|
|
17
26
|
grant(...grants: Grantable[]): void;
|
|
18
27
|
subscription(): ITopicSubscription;
|
|
28
|
+
static parse(params: unknown): {
|
|
29
|
+
cmd: string;
|
|
30
|
+
};
|
|
19
31
|
}
|
|
32
|
+
export {};
|
|
20
33
|
//# sourceMappingURL=next-app-router-construct.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-app-router-construct.d.ts","sourceRoot":"","sources":["../../src/lib/next-app-router-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAEzD,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAIjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"next-app-router-construct.d.ts","sourceRoot":"","sources":["../../src/lib/next-app-router-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAEzD,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAIjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAItD,QAAA,MAAM,iBAAiB;;;;;;EAErB,CAAA;AAEF,qBAAa,sBAAuB,SAAQ,SAAU,YAAW,YAAY;IACpE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC;IAEpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBAEvB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAgEjG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,eAAe,CAAC;IAmDpE,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAI3C,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,IAAI,kBAAkB;IAIlC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;CAG7B"}
|
|
@@ -12,8 +12,12 @@ const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
|
12
12
|
const s3 = tslib_1.__importStar(require("aws-cdk-lib/aws-s3"));
|
|
13
13
|
const s3Deploy = tslib_1.__importStar(require("aws-cdk-lib/aws-s3-deployment"));
|
|
14
14
|
const constructs_1 = require("constructs");
|
|
15
|
+
const zod_1 = require("zod");
|
|
15
16
|
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
16
17
|
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
18
|
+
const BuildParamsSchema = zod_1.z.object({
|
|
19
|
+
cmd: zod_1.z.string(),
|
|
20
|
+
});
|
|
17
21
|
class NextAppRouterConstruct extends constructs_1.Construct {
|
|
18
22
|
function;
|
|
19
23
|
queue;
|
|
@@ -56,9 +60,7 @@ class NextAppRouterConstruct extends constructs_1.Construct {
|
|
|
56
60
|
};
|
|
57
61
|
Object.assign(environment, props.env);
|
|
58
62
|
const serverOutput = path.join(props.output, "/.next/standalone");
|
|
59
|
-
|
|
60
|
-
throw new Error("command is requires in buildParams");
|
|
61
|
-
fs.writeFileSync(path.join(serverOutput, 'run.sh'), props.buildParams.command);
|
|
63
|
+
fs.writeFileSync(path.join(serverOutput, 'run.sh'), props.buildParams.cmd);
|
|
62
64
|
this.function = new lambda.Function(this, `AppFunction`, {
|
|
63
65
|
runtime: lambda.Runtime.NODEJS_20_X,
|
|
64
66
|
memorySize: 512,
|
|
@@ -84,7 +86,7 @@ class NextAppRouterConstruct extends constructs_1.Construct {
|
|
|
84
86
|
compress: true,
|
|
85
87
|
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
86
88
|
};
|
|
87
|
-
const
|
|
89
|
+
const imageCachePolicy = new cloudfront.CachePolicy(this, "ImagePolicy", {
|
|
88
90
|
queryStringBehavior: cloudfront.CacheQueryStringBehavior.all(),
|
|
89
91
|
maxTtl: cdk.Duration.days(365),
|
|
90
92
|
enableAcceptEncodingGzip: true,
|
|
@@ -104,13 +106,16 @@ class NextAppRouterConstruct extends constructs_1.Construct {
|
|
|
104
106
|
[`${path}/*`]: appBehaviour,
|
|
105
107
|
[`${path}/_next/image`]: {
|
|
106
108
|
...appBehaviour,
|
|
107
|
-
cachePolicy:
|
|
109
|
+
cachePolicy: imageCachePolicy,
|
|
108
110
|
allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
|
|
109
111
|
},
|
|
110
112
|
[`${path}/_next/*`]: staticBehavior,
|
|
111
113
|
[`${path}/*.ico`]: staticBehavior,
|
|
112
114
|
};
|
|
113
115
|
}
|
|
116
|
+
cloudfrontPolicy(distributionId) {
|
|
117
|
+
throw new Error(`cloudfrontPolicy not supported for ${this}`);
|
|
118
|
+
}
|
|
114
119
|
api() {
|
|
115
120
|
throw new Error('api not supported for this construct');
|
|
116
121
|
}
|
|
@@ -123,5 +128,8 @@ class NextAppRouterConstruct extends constructs_1.Construct {
|
|
|
123
128
|
subscription() {
|
|
124
129
|
throw new Error(`subscription not supported for ${this}`);
|
|
125
130
|
}
|
|
131
|
+
static parse(params) {
|
|
132
|
+
return BuildParamsSchema.parse(params);
|
|
133
|
+
}
|
|
126
134
|
}
|
|
127
135
|
exports.NextAppRouterConstruct = NextAppRouterConstruct;
|
|
@@ -3,14 +3,19 @@ import type { HttpRouteIntegration } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
|
3
3
|
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
|
|
4
4
|
import { ITopicSubscription } from 'aws-cdk-lib/aws-sns';
|
|
5
5
|
import { Construct } from 'constructs';
|
|
6
|
+
import { z } from 'zod';
|
|
6
7
|
import { AppConstruct, AppProperties } from './types';
|
|
8
|
+
declare const BuildParamsSchema: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
7
9
|
export declare class NextPagesExportConstruct extends Construct implements AppConstruct {
|
|
8
10
|
private readonly static;
|
|
9
|
-
constructor(scope: Construct, id: string, props: AppProperties);
|
|
11
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
|
|
10
12
|
cloudfront(path: string): Record<string, cloudfront.BehaviorOptions>;
|
|
13
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
11
14
|
api(): Record<string, HttpRouteIntegration>;
|
|
12
15
|
attach(attachable: Record<string, Attachable>): void;
|
|
13
16
|
grant(...grants: Grantable[]): void;
|
|
14
17
|
subscription(): ITopicSubscription;
|
|
18
|
+
static parse(params: unknown): {} | undefined;
|
|
15
19
|
}
|
|
20
|
+
export {};
|
|
16
21
|
//# sourceMappingURL=next-pages-export-construct.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-pages-export-construct.d.ts","sourceRoot":"","sources":["../../src/lib/next-pages-export-construct.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAIzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"next-pages-export-construct.d.ts","sourceRoot":"","sources":["../../src/lib/next-pages-export-construct.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAIzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,iBAAiB,+DAA0B,CAAA;AAEjD,qBAAa,wBAAyB,SAAQ,SAAU,YAAW,YAAY;IAC7E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBAEvB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAiCjG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,eAAe,CAAC;IAmBpE,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAI3C,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,IAAI,kBAAkB;IAIlC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;CAE1B"}
|
|
@@ -9,6 +9,8 @@ const cloudfrontOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfron
|
|
|
9
9
|
const s3 = tslib_1.__importStar(require("aws-cdk-lib/aws-s3"));
|
|
10
10
|
const s3Deploy = tslib_1.__importStar(require("aws-cdk-lib/aws-s3-deployment"));
|
|
11
11
|
const constructs_1 = require("constructs");
|
|
12
|
+
const zod_1 = require("zod");
|
|
13
|
+
const BuildParamsSchema = zod_1.z.object({}).optional();
|
|
12
14
|
class NextPagesExportConstruct extends constructs_1.Construct {
|
|
13
15
|
static;
|
|
14
16
|
constructor(scope, id, props) {
|
|
@@ -54,6 +56,9 @@ class NextPagesExportConstruct extends constructs_1.Construct {
|
|
|
54
56
|
[`${path}/*`]: staticBehavior,
|
|
55
57
|
};
|
|
56
58
|
}
|
|
59
|
+
cloudfrontPolicy(distributionId) {
|
|
60
|
+
throw new Error(`cloudfrontPolicy not supported for ${this}`);
|
|
61
|
+
}
|
|
57
62
|
api() {
|
|
58
63
|
throw new Error('api not supported for this construct');
|
|
59
64
|
}
|
|
@@ -66,5 +71,8 @@ class NextPagesExportConstruct extends constructs_1.Construct {
|
|
|
66
71
|
subscription() {
|
|
67
72
|
throw new Error(`subscription not supported for ${this}`);
|
|
68
73
|
}
|
|
74
|
+
static parse(params) {
|
|
75
|
+
return BuildParamsSchema.parse(params);
|
|
76
|
+
}
|
|
69
77
|
}
|
|
70
78
|
exports.NextPagesExportConstruct = NextPagesExportConstruct;
|
|
@@ -4,11 +4,19 @@ import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
|
4
4
|
import { ITopicSubscription, SubscriptionProps } from 'aws-cdk-lib/aws-sns';
|
|
5
5
|
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
6
6
|
import { Construct } from 'constructs';
|
|
7
|
+
import { z } from 'zod';
|
|
7
8
|
import { AppConstruct, AppProperties } from './types';
|
|
9
|
+
declare const BuildParamsSchema: z.ZodObject<{
|
|
10
|
+
cmd: z.ZodString;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
cmd: string;
|
|
13
|
+
}, {
|
|
14
|
+
cmd: string;
|
|
15
|
+
}>;
|
|
8
16
|
export declare class NodeApiConstruct extends Construct implements AppConstruct {
|
|
9
17
|
function: lambda.Function;
|
|
10
18
|
queue: sqs.Queue | undefined;
|
|
11
|
-
constructor(scope: Construct, id: string, props: AppProperties);
|
|
19
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
|
|
12
20
|
attach(attachable: Record<string, Attachable>): void;
|
|
13
21
|
grant(...grants: Grantable[]): void;
|
|
14
22
|
subscription(props: SubscriptionProps): ITopicSubscription;
|
|
@@ -23,8 +31,13 @@ export declare class NodeApiConstruct extends Construct implements AppConstruct
|
|
|
23
31
|
responseHeadersPolicy: cdk.aws_cloudfront.IResponseHeadersPolicy;
|
|
24
32
|
};
|
|
25
33
|
};
|
|
34
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
26
35
|
api(path: string): {
|
|
27
36
|
[x: string]: cdk.aws_apigatewayv2_integrations.HttpUrlIntegration;
|
|
28
37
|
};
|
|
38
|
+
static parse(params: unknown): {
|
|
39
|
+
cmd: string;
|
|
40
|
+
};
|
|
29
41
|
}
|
|
42
|
+
export {};
|
|
30
43
|
//# sourceMappingURL=node-api-construct.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-api-construct.d.ts","sourceRoot":"","sources":["../../src/lib/node-api-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"node-api-construct.d.ts","sourceRoot":"","sources":["../../src/lib/node-api-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAKtD,QAAA,MAAM,iBAAiB;;;;;;EAErB,CAAA;AAEF,qBAAa,gBAAiB,SAAQ,SAAU,YAAW,YAAY;IAC9D,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC;gBAExB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IA+CjG,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB;IAI1D,UAAU,CAAC,IAAI,EAAE,MAAM;;;;;;;;;;;IAqBvB,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,CAAC,IAAI,EAAE,MAAM;;;IAIhB,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;CAG7B"}
|
|
@@ -11,9 +11,13 @@ const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
|
|
|
11
11
|
const lambdaEventSource = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda-event-sources"));
|
|
12
12
|
const sqs = tslib_1.__importStar(require("aws-cdk-lib/aws-sqs"));
|
|
13
13
|
const constructs_1 = require("constructs");
|
|
14
|
+
const zod_1 = require("zod");
|
|
14
15
|
const lambda_api_1 = require("./utils/lambda-api");
|
|
15
16
|
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
16
17
|
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
18
|
+
const BuildParamsSchema = zod_1.z.object({
|
|
19
|
+
cmd: zod_1.z.string(),
|
|
20
|
+
});
|
|
17
21
|
class NodeApiConstruct extends constructs_1.Construct {
|
|
18
22
|
function;
|
|
19
23
|
queue;
|
|
@@ -30,9 +34,7 @@ class NodeApiConstruct extends constructs_1.Construct {
|
|
|
30
34
|
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
|
|
31
35
|
PORT: '8080',
|
|
32
36
|
});
|
|
33
|
-
|
|
34
|
-
throw new Error("command is requires in buildParams");
|
|
35
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(props.output, 'run.sh'), props.buildParams.command);
|
|
37
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(props.output, 'run.sh'), props.buildParams.cmd);
|
|
36
38
|
this.function = new lambda.Function(this, `AppFunction`, {
|
|
37
39
|
runtime: lambda.Runtime.NODEJS_20_X,
|
|
38
40
|
memorySize: 512,
|
|
@@ -76,8 +78,14 @@ class NodeApiConstruct extends constructs_1.Construct {
|
|
|
76
78
|
};
|
|
77
79
|
return { [`${path}/*`]: apiBehavior };
|
|
78
80
|
}
|
|
81
|
+
cloudfrontPolicy(distributionId) {
|
|
82
|
+
throw new Error(`cloudfrontPolicy not supported for ${this}`);
|
|
83
|
+
}
|
|
79
84
|
api(path) {
|
|
80
85
|
return (0, lambda_api_1.lambdaApi)(this.function, path);
|
|
81
86
|
}
|
|
87
|
+
static parse(params) {
|
|
88
|
+
return BuildParamsSchema.parse(params);
|
|
89
|
+
}
|
|
82
90
|
}
|
|
83
91
|
exports.NodeApiConstruct = NodeApiConstruct;
|
|
@@ -5,15 +5,28 @@ import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
|
5
5
|
import { ITopicSubscription, SubscriptionProps } from 'aws-cdk-lib/aws-sns';
|
|
6
6
|
import * as sqs from 'aws-cdk-lib/aws-sqs';
|
|
7
7
|
import { Construct } from 'constructs';
|
|
8
|
+
import { z } from 'zod';
|
|
8
9
|
import { AppConstruct, AppProperties } from './types';
|
|
10
|
+
declare const BuildParamsSchema: z.ZodObject<{
|
|
11
|
+
handler: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
handler?: string | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
handler?: string | undefined;
|
|
16
|
+
}>;
|
|
9
17
|
export declare class NodeAppConstruct extends Construct implements AppConstruct {
|
|
10
18
|
function: lambda.Function;
|
|
11
19
|
queue: sqs.Queue | undefined;
|
|
12
|
-
constructor(scope: Construct, id: string, props: AppProperties);
|
|
20
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
|
|
13
21
|
attach(attachable: Record<string, Attachable>): void;
|
|
14
22
|
grant(...grants: Grantable[]): void;
|
|
15
23
|
subscription(props: SubscriptionProps): ITopicSubscription;
|
|
16
24
|
cloudfront(path: string): Record<string, BehaviorOptions>;
|
|
25
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
17
26
|
api(path: string): Record<string, HttpRouteIntegration>;
|
|
27
|
+
static parse(params: unknown): {
|
|
28
|
+
handler?: string | undefined;
|
|
29
|
+
};
|
|
18
30
|
}
|
|
31
|
+
export {};
|
|
19
32
|
//# sourceMappingURL=node-app-construct.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-app-construct.d.ts","sourceRoot":"","sources":["../../src/lib/node-app-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"node-app-construct.d.ts","sourceRoot":"","sources":["../../src/lib/node-app-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAItD,QAAA,MAAM,iBAAiB;;;;;;EAErB,CAAA;AAEF,qBAAa,gBAAiB,SAAQ,SAAU,YAAW,YAAY;IAC9D,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC1B,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC;gBAExB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IA8BjG,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB;IAO1D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAIzD,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAWvD,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;;;CAG7B"}
|
|
@@ -3,15 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NodeAppConstruct = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
|
|
6
|
+
const aws_apigatewayv2_integrations_1 = require("aws-cdk-lib/aws-apigatewayv2-integrations");
|
|
6
7
|
const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
|
|
7
8
|
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
8
9
|
const lambdaEventSource = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda-event-sources"));
|
|
9
10
|
const snsSubscriptions = tslib_1.__importStar(require("aws-cdk-lib/aws-sns-subscriptions"));
|
|
10
11
|
const sqs = tslib_1.__importStar(require("aws-cdk-lib/aws-sqs"));
|
|
11
12
|
const constructs_1 = require("constructs");
|
|
13
|
+
const zod_1 = require("zod");
|
|
12
14
|
const lambda_attach_1 = require("./utils/lambda-attach");
|
|
13
15
|
const lambda_grant_1 = require("./utils/lambda-grant");
|
|
14
|
-
const
|
|
16
|
+
const BuildParamsSchema = zod_1.z.object({
|
|
17
|
+
handler: zod_1.z.string().optional(),
|
|
18
|
+
});
|
|
15
19
|
class NodeAppConstruct extends constructs_1.Construct {
|
|
16
20
|
function;
|
|
17
21
|
queue;
|
|
@@ -22,7 +26,7 @@ class NodeAppConstruct extends constructs_1.Construct {
|
|
|
22
26
|
this.function = new lambda.Function(this, `AppFunction`, {
|
|
23
27
|
runtime: lambda.Runtime.NODEJS_20_X,
|
|
24
28
|
memorySize: 512,
|
|
25
|
-
handler: props.buildParams
|
|
29
|
+
handler: props.buildParams.handler ?? "index.handler",
|
|
26
30
|
timeout: cdk.Duration.seconds(30),
|
|
27
31
|
code: lambda.Code.fromAsset(props.output),
|
|
28
32
|
loggingFormat: aws_lambda_1.LoggingFormat.JSON,
|
|
@@ -45,16 +49,22 @@ class NodeAppConstruct extends constructs_1.Construct {
|
|
|
45
49
|
}
|
|
46
50
|
subscription(props) {
|
|
47
51
|
if (this.queue)
|
|
48
|
-
return new snsSubscriptions.SqsSubscription(this.queue, props);
|
|
52
|
+
return new snsSubscriptions.SqsSubscription(this.queue, { ...props, rawMessageDelivery: true });
|
|
49
53
|
return new snsSubscriptions.LambdaSubscription(this.function, props);
|
|
50
54
|
}
|
|
51
55
|
cloudfront(path) {
|
|
52
56
|
throw new Error(`cloudfront not supported for ${this}`);
|
|
53
57
|
}
|
|
58
|
+
cloudfrontPolicy(distributionId) {
|
|
59
|
+
throw new Error(`cloudfrontPolicy not supported for ${this}`);
|
|
60
|
+
}
|
|
54
61
|
api(path) {
|
|
55
62
|
this.function.addEnvironment('BASE_PATH', path);
|
|
56
63
|
const integration = new aws_apigatewayv2_integrations_1.HttpLambdaIntegration('AppIntegration', this.function);
|
|
57
64
|
return { [`${path}/*`]: integration };
|
|
58
65
|
}
|
|
66
|
+
static parse(params) {
|
|
67
|
+
return BuildParamsSchema.parse(params);
|
|
68
|
+
}
|
|
59
69
|
}
|
|
60
70
|
exports.NodeAppConstruct = NodeAppConstruct;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AppConstruct, AppProperties } from './types';
|
|
2
|
+
import { HttpRouteIntegration } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
3
|
+
import { Attachable, Grantable } from '@fy-stack/types';
|
|
4
|
+
import { ITopicSubscription } from 'aws-cdk-lib/aws-sns';
|
|
5
|
+
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
|
|
6
|
+
import { Construct } from 'constructs';
|
|
7
|
+
export declare class ReactStaticConstruct extends Construct implements AppConstruct {
|
|
8
|
+
private readonly static;
|
|
9
|
+
constructor(scope: Construct, id: string, props: AppProperties);
|
|
10
|
+
cloudfront(path: string): Record<string, cloudfront.BehaviorOptions>;
|
|
11
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
12
|
+
api(): Record<string, HttpRouteIntegration>;
|
|
13
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
14
|
+
grant(...grants: Grantable[]): void;
|
|
15
|
+
subscription(): ITopicSubscription;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=react-static-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-static-construct.d.ts","sourceRoot":"","sources":["../../src/lib/react-static-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAIzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,qBAAa,oBAAqB,SAAQ,SAAU,YAAW,YAAY;IACzE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBAEvB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa;IA0B9D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,eAAe,CAAC;IAmBpE,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAI3C,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,IAAI,kBAAkB;CAGnC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReactStaticConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const cloudfront = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront"));
|
|
6
|
+
const cloudfrontOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
|
|
7
|
+
const s3 = tslib_1.__importStar(require("aws-cdk-lib/aws-s3"));
|
|
8
|
+
const s3Deploy = tslib_1.__importStar(require("aws-cdk-lib/aws-s3-deployment"));
|
|
9
|
+
const constructs_1 = require("constructs");
|
|
10
|
+
const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
|
|
11
|
+
class ReactStaticConstruct extends constructs_1.Construct {
|
|
12
|
+
static;
|
|
13
|
+
constructor(scope, id, props) {
|
|
14
|
+
super(scope, id);
|
|
15
|
+
this.static = new s3.Bucket(this, `StaticBucket`, {
|
|
16
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
17
|
+
autoDeleteObjects: true,
|
|
18
|
+
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ACLS,
|
|
19
|
+
publicReadAccess: true,
|
|
20
|
+
websiteIndexDocument: 'index.html',
|
|
21
|
+
websiteErrorDocument: 'index.html',
|
|
22
|
+
cors: [
|
|
23
|
+
{
|
|
24
|
+
allowedHeaders: ['*'],
|
|
25
|
+
allowedOrigins: ['*'],
|
|
26
|
+
allowedMethods: [s3.HttpMethods.GET, s3.HttpMethods.HEAD],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
new s3Deploy.BucketDeployment(this, `StaticDeployment`, {
|
|
31
|
+
destinationBucket: this.static,
|
|
32
|
+
sources: [s3Deploy.Source.asset(props.output),],
|
|
33
|
+
retainOnDelete: false,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
cloudfront(path) {
|
|
37
|
+
const staticOrigin = new cloudfrontOrigin.S3StaticWebsiteOrigin(this.static);
|
|
38
|
+
const staticBehavior = {
|
|
39
|
+
origin: staticOrigin,
|
|
40
|
+
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
|
|
41
|
+
allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
|
|
42
|
+
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD,
|
|
43
|
+
compress: true,
|
|
44
|
+
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
[`${path}/*`]: staticBehavior,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
cloudfrontPolicy(distributionId) {
|
|
51
|
+
throw new Error(`cloudfrontPolicy not supported for ${this}`);
|
|
52
|
+
}
|
|
53
|
+
api() {
|
|
54
|
+
throw new Error('api not supported for this construct');
|
|
55
|
+
}
|
|
56
|
+
attach(attachable) {
|
|
57
|
+
throw new Error('attach not supported for this construct');
|
|
58
|
+
}
|
|
59
|
+
grant(...grants) {
|
|
60
|
+
throw new Error('grant not supported for this construct');
|
|
61
|
+
}
|
|
62
|
+
subscription() {
|
|
63
|
+
throw new Error(`subscription not supported for ${this}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.ReactStaticConstruct = ReactStaticConstruct;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Attachable, Grantable } from '@fy-stack/types';
|
|
2
|
+
import { HttpRouteIntegration } from 'aws-cdk-lib/aws-apigatewayv2';
|
|
3
|
+
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
|
|
4
|
+
import { ITopicSubscription } from 'aws-cdk-lib/aws-sns';
|
|
5
|
+
import { Construct } from 'constructs';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { AppConstruct, AppProperties } from './types';
|
|
8
|
+
declare const BuildParamsSchema: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
9
|
+
export declare class StaticWebsiteConstruct extends Construct implements AppConstruct {
|
|
10
|
+
private readonly static;
|
|
11
|
+
constructor(scope: Construct, id: string, props: AppProperties<z.infer<typeof BuildParamsSchema>>);
|
|
12
|
+
cloudfront(path: string): Record<string, cloudfront.BehaviorOptions>;
|
|
13
|
+
cloudfrontPolicy(distributionId: string): void;
|
|
14
|
+
api(): Record<string, HttpRouteIntegration>;
|
|
15
|
+
attach(attachable: Record<string, Attachable>): void;
|
|
16
|
+
grant(...grants: Grantable[]): void;
|
|
17
|
+
subscription(): ITopicSubscription;
|
|
18
|
+
static parse(params: unknown): {} | undefined;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=static-website-construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-website-construct.d.ts","sourceRoot":"","sources":["../../src/lib/static-website-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC;AAIzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,iBAAiB,+DAA0B,CAAC;AAElD,qBAAa,sBAAuB,SAAQ,SAAU,YAAW,YAAY;IAC3E,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;gBAEvB,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;IA0BjG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,eAAe,CAAC;IAmBpE,gBAAgB,CAAC,cAAc,EAAE,MAAM;IAIvC,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAI3C,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;IAI7C,KAAK,CAAC,GAAG,MAAM,EAAE,SAAS,EAAE;IAI5B,YAAY,IAAI,kBAAkB;IAIlC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO;CAG7B"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StaticWebsiteConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
|
|
6
|
+
const cloudfront = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront"));
|
|
7
|
+
const cloudfrontOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
|
|
8
|
+
const s3 = tslib_1.__importStar(require("aws-cdk-lib/aws-s3"));
|
|
9
|
+
const s3Deploy = tslib_1.__importStar(require("aws-cdk-lib/aws-s3-deployment"));
|
|
10
|
+
const constructs_1 = require("constructs");
|
|
11
|
+
const zod_1 = require("zod");
|
|
12
|
+
const BuildParamsSchema = zod_1.z.object({}).optional();
|
|
13
|
+
class StaticWebsiteConstruct extends constructs_1.Construct {
|
|
14
|
+
static;
|
|
15
|
+
constructor(scope, id, props) {
|
|
16
|
+
super(scope, id);
|
|
17
|
+
this.static = new s3.Bucket(this, `StaticBucket`, {
|
|
18
|
+
removalPolicy: cdk.RemovalPolicy.DESTROY,
|
|
19
|
+
autoDeleteObjects: true,
|
|
20
|
+
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ACLS,
|
|
21
|
+
publicReadAccess: true,
|
|
22
|
+
websiteIndexDocument: 'index.html',
|
|
23
|
+
websiteErrorDocument: 'index.html',
|
|
24
|
+
cors: [
|
|
25
|
+
{
|
|
26
|
+
allowedHeaders: ['*'],
|
|
27
|
+
allowedOrigins: ['*'],
|
|
28
|
+
allowedMethods: [s3.HttpMethods.GET, s3.HttpMethods.HEAD],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
new s3Deploy.BucketDeployment(this, `StaticDeployment`, {
|
|
33
|
+
destinationBucket: this.static,
|
|
34
|
+
sources: [s3Deploy.Source.asset(props.output),],
|
|
35
|
+
retainOnDelete: false,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
cloudfront(path) {
|
|
39
|
+
const staticOrigin = new cloudfrontOrigin.S3StaticWebsiteOrigin(this.static);
|
|
40
|
+
const staticBehavior = {
|
|
41
|
+
origin: staticOrigin,
|
|
42
|
+
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
|
|
43
|
+
allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
|
|
44
|
+
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD,
|
|
45
|
+
compress: true,
|
|
46
|
+
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
[`${path}/*`]: staticBehavior,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
cloudfrontPolicy(distributionId) {
|
|
53
|
+
throw new Error(`cloudfrontPolicy not supported for ${this}`);
|
|
54
|
+
}
|
|
55
|
+
api() {
|
|
56
|
+
throw new Error('api not supported for this construct');
|
|
57
|
+
}
|
|
58
|
+
attach(attachable) {
|
|
59
|
+
throw new Error('attach not supported for this construct');
|
|
60
|
+
}
|
|
61
|
+
grant(...grants) {
|
|
62
|
+
throw new Error('grant not supported for this construct');
|
|
63
|
+
}
|
|
64
|
+
subscription() {
|
|
65
|
+
throw new Error(`subscription not supported for ${this}`);
|
|
66
|
+
}
|
|
67
|
+
static parse(params) {
|
|
68
|
+
return BuildParamsSchema.parse(params);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.StaticWebsiteConstruct = StaticWebsiteConstruct;
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { ApiResource, Attach, CDNResource,
|
|
1
|
+
import type { ApiResource, Attach, CDNResource, EventResource, Grant } from '@fy-stack/types';
|
|
2
|
+
import type { IVpc } from 'aws-cdk-lib/aws-ec2';
|
|
2
3
|
import type { Function } from 'aws-cdk-lib/aws-lambda';
|
|
3
4
|
import { Queue } from 'aws-cdk-lib/aws-sqs';
|
|
4
|
-
export type AppProperties = {
|
|
5
|
+
export type AppProperties<BuildParams = Record<string, unknown>> = {
|
|
5
6
|
queue?: {
|
|
6
7
|
batchSize?: number;
|
|
7
8
|
};
|
|
8
9
|
env?: Record<string, string>;
|
|
9
|
-
buildParams
|
|
10
|
+
buildParams: BuildParams;
|
|
10
11
|
output: string;
|
|
12
|
+
vpc?: IVpc;
|
|
11
13
|
};
|
|
12
|
-
export interface AppConstruct extends Attach, Grant, CDNResource,
|
|
14
|
+
export interface AppConstruct extends Attach, Grant, CDNResource, EventResource, ApiResource {
|
|
13
15
|
function?: Function;
|
|
14
16
|
queue?: Queue;
|
|
15
17
|
}
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,MAAM,MAAM,aAAa,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACjE,KAAK,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,IAAI,CAAA;CACX,CAAC;AAEF,MAAM,WAAW,YAAa,SAAQ,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW;IAC1F,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fy-stack/app-construct",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.130",
|
|
4
|
+
"repository": "https://github.com/festusyuma/fy-stack",
|
|
4
5
|
"dependencies": {
|
|
6
|
+
"@fy-stack/types": "0.0.130",
|
|
5
7
|
"tslib": "^2.3.0",
|
|
6
|
-
"
|
|
8
|
+
"zod": "^3.24.1"
|
|
7
9
|
},
|
|
8
10
|
"peerDependencies": {
|
|
9
|
-
"aws-cdk-lib": "2.
|
|
10
|
-
"constructs": "10.4.2"
|
|
11
|
+
"aws-cdk-lib": "^2.174.1",
|
|
12
|
+
"constructs": "^10.4.2"
|
|
11
13
|
},
|
|
12
14
|
"main": "./dist/index.js",
|
|
13
15
|
"module": "./dist/index.mjs",
|