@fy-stack/app-construct 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ # app-construct
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build app-construct` to build the library.
@@ -0,0 +1,5 @@
1
+ export { NestApiConstruct } from './lib/nest-api-construct';
2
+ export { NestConstruct } from './lib/nest-construct';
3
+ export { NextAppRouterConstruct } from './lib/next-app-router-construct';
4
+ export type { AppConstruct, AppProperties } from "./lib/types";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NextAppRouterConstruct = exports.NestConstruct = exports.NestApiConstruct = void 0;
4
+ var nest_api_construct_1 = require("./lib/nest-api-construct");
5
+ Object.defineProperty(exports, "NestApiConstruct", { enumerable: true, get: function () { return nest_api_construct_1.NestApiConstruct; } });
6
+ var nest_construct_1 = require("./lib/nest-construct");
7
+ Object.defineProperty(exports, "NestConstruct", { enumerable: true, get: function () { return nest_construct_1.NestConstruct; } });
8
+ var next_app_router_construct_1 = require("./lib/next-app-router-construct");
9
+ Object.defineProperty(exports, "NextAppRouterConstruct", { enumerable: true, get: function () { return next_app_router_construct_1.NextAppRouterConstruct; } });
@@ -0,0 +1,10 @@
1
+ import { Construct } from 'constructs';
2
+ import { NestConstruct } from './nest-construct';
3
+ import { AppProperties } from './types';
4
+ export declare class NestApiConstruct extends NestConstruct {
5
+ constructor(scope: Construct, id: string, props: AppProperties);
6
+ static clean(output: string, name: string, command: string): {
7
+ serverOutput: string;
8
+ };
9
+ }
10
+ //# sourceMappingURL=nest-api-construct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-api-construct.d.ts","sourceRoot":"","sources":["../../src/lib/nest-api-construct.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,qBAAa,gBAAiB,SAAQ,aAAa;gBACrC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa;WAI9C,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;;;CA0BpE"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NestApiConstruct = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_child_process_1 = tslib_1.__importDefault(require("node:child_process"));
6
+ const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
7
+ const nest_construct_1 = require("./nest-construct");
8
+ class NestApiConstruct extends nest_construct_1.NestConstruct {
9
+ constructor(scope, id, props) {
10
+ super(scope, id, { ...props, webLayer: true });
11
+ }
12
+ static clean(output, name, command) {
13
+ const destination = `./dist/${name}`;
14
+ /** Delete previous cleaned files */
15
+ node_fs_1.default.rmSync(destination, { recursive: true, force: true });
16
+ /** Create server and static folders for deployment */
17
+ node_fs_1.default.mkdirSync(destination, { recursive: true });
18
+ /** copy compiled code to be deployed to the server */
19
+ node_fs_1.default.cpSync(output, destination, { recursive: true });
20
+ /** copy start command to script */
21
+ node_fs_1.default.writeFileSync(`${destination}/run.sh`, command);
22
+ console.log(node_child_process_1.default
23
+ .execSync(`npm ci`, {
24
+ stdio: 'pipe',
25
+ cwd: destination,
26
+ })
27
+ .toString());
28
+ return { serverOutput: destination };
29
+ }
30
+ }
31
+ exports.NestApiConstruct = NestApiConstruct;
@@ -0,0 +1,34 @@
1
+ import { Attachable, Grantable } from '@fy-stack/types';
2
+ import * as cdk from 'aws-cdk-lib';
3
+ import * as lambda from 'aws-cdk-lib/aws-lambda';
4
+ import { ITopicSubscription, SubscriptionProps } from 'aws-cdk-lib/aws-sns';
5
+ import * as sqs from 'aws-cdk-lib/aws-sqs';
6
+ import { Construct } from 'constructs';
7
+ import { AppConstruct, AppProperties } from './types';
8
+ interface Props extends AppProperties {
9
+ webLayer?: boolean;
10
+ }
11
+ export declare class NestConstruct extends Construct implements AppConstruct {
12
+ function: lambda.Function;
13
+ queue: sqs.Queue | undefined;
14
+ constructor(scope: Construct, id: string, props: Props);
15
+ attach(attachable: Record<string, Attachable>): void;
16
+ grant(...grants: Grantable[]): void;
17
+ subscription(props: SubscriptionProps): ITopicSubscription;
18
+ cloudfront(path: string): {
19
+ [x: string]: {
20
+ origin: cdk.aws_cloudfront_origins.FunctionUrlOrigin;
21
+ cachePolicy: cdk.aws_cloudfront.ICachePolicy;
22
+ allowedMethods: cdk.aws_cloudfront.AllowedMethods;
23
+ compress: boolean;
24
+ viewerProtocolPolicy: cdk.aws_cloudfront.ViewerProtocolPolicy;
25
+ originRequestPolicy: cdk.aws_cloudfront.IOriginRequestPolicy;
26
+ responseHeadersPolicy: cdk.aws_cloudfront.IResponseHeadersPolicy;
27
+ };
28
+ };
29
+ static clean(output: string, name: string, command: string): {
30
+ serverOutput: string;
31
+ };
32
+ }
33
+ export {};
34
+ //# sourceMappingURL=nest-construct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nest-construct.d.ts","sourceRoot":"","sources":["../../src/lib/nest-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;AAE5E,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAItD,UAAU,KAAM,SAAQ,aAAa;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,aAAc,SAAQ,SAAU,YAAW,YAAY;IAC3D,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,KAAK;IAqDtD,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;;;;;;;;;;;IAqBvB,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;;;CAuB3D"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NestConstruct = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const child_process = tslib_1.__importStar(require("node:child_process"));
6
+ const fs = tslib_1.__importStar(require("node:fs"));
7
+ const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
8
+ const cloudfront = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront"));
9
+ const cloudfrontOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
10
+ const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
11
+ const lambdaEventSource = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda-event-sources"));
12
+ const snsSubscriptions = tslib_1.__importStar(require("aws-cdk-lib/aws-sns-subscriptions"));
13
+ const sqs = tslib_1.__importStar(require("aws-cdk-lib/aws-sqs"));
14
+ const constructs_1 = require("constructs");
15
+ const lambda_attach_1 = require("./utils/lambda-attach");
16
+ const lambda_grant_1 = require("./utils/lambda-grant");
17
+ class NestConstruct extends constructs_1.Construct {
18
+ function;
19
+ queue;
20
+ constructor(scope, id, props) {
21
+ super(scope, id);
22
+ const region = cdk.Stack.of(this).region;
23
+ const { serverOutput } = props.buildPaths;
24
+ if (!serverOutput)
25
+ throw new Error('asset not found');
26
+ const environment = {};
27
+ Object.assign(environment, props.env);
28
+ const layers = [];
29
+ if (props.webLayer) {
30
+ layers.push(lambda.LayerVersion.fromLayerVersionArn(this, 'WebAdapterLayer', `arn:aws:lambda:${region}:753240598075:layer:LambdaAdapterLayerX86:16`));
31
+ Object.assign(environment, {
32
+ AWS_LAMBDA_EXEC_WRAPPER: '/opt/bootstrap',
33
+ AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
34
+ PORT: '8080',
35
+ });
36
+ }
37
+ this.function = new lambda.Function(this, `AppFunction`, {
38
+ runtime: lambda.Runtime.NODEJS_20_X,
39
+ memorySize: 512,
40
+ handler: props.webLayer ? 'run.sh' : 'main.handler',
41
+ layers,
42
+ timeout: cdk.Duration.seconds(30),
43
+ code: lambda.Code.fromAsset(serverOutput),
44
+ environment,
45
+ });
46
+ if (props.queue) {
47
+ this.queue = new sqs.Queue(this, 'AppQueue', {
48
+ visibilityTimeout: cdk.Duration.seconds(59),
49
+ });
50
+ this.function.addEventSource(new lambdaEventSource.SqsEventSource(this.queue, {
51
+ batchSize: props.queue.batchSize,
52
+ }));
53
+ }
54
+ }
55
+ attach(attachable) {
56
+ return (0, lambda_attach_1.lambdaAttach)(this.function, attachable);
57
+ }
58
+ grant(...grants) {
59
+ return (0, lambda_grant_1.lambdaGrant)(this.function, grants);
60
+ }
61
+ subscription(props) {
62
+ if (this.queue)
63
+ return new snsSubscriptions.SqsSubscription(this.queue, props);
64
+ return new snsSubscriptions.LambdaSubscription(this.function, props);
65
+ }
66
+ cloudfront(path) {
67
+ const apiUrl = this.function.addFunctionUrl({
68
+ authType: lambda.FunctionUrlAuthType.NONE,
69
+ });
70
+ const apiBehavior = {
71
+ origin: new cloudfrontOrigin.FunctionUrlOrigin(apiUrl),
72
+ cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
73
+ allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
74
+ compress: true,
75
+ viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
76
+ originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
77
+ responseHeadersPolicy: cloudfront.ResponseHeadersPolicy
78
+ .CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS,
79
+ };
80
+ return { [`${path}/*`]: apiBehavior };
81
+ }
82
+ static clean(output, name, command) {
83
+ const destination = `./dist/${name}`;
84
+ /* Delete previous cleaned files */
85
+ fs.rmSync(destination, { recursive: true, force: true });
86
+ /* Create server and static folders for deployment */
87
+ fs.mkdirSync(destination, { recursive: true });
88
+ /* copy compiled code to be deployed to the server */
89
+ fs.cpSync(output, destination, { recursive: true });
90
+ console.log(child_process
91
+ .execSync(`npm ci`, {
92
+ stdio: 'pipe',
93
+ cwd: destination,
94
+ })
95
+ .toString());
96
+ return { serverOutput: destination };
97
+ }
98
+ }
99
+ exports.NestConstruct = NestConstruct;
@@ -0,0 +1,25 @@
1
+ import { Attach, Attachable, CDNResource, Grant, Grantable } from '@fy-stack/types';
2
+ import * as cdk from 'aws-cdk-lib';
3
+ import * as lambda from 'aws-cdk-lib/aws-lambda';
4
+ import { ITopicSubscription } from 'aws-cdk-lib/aws-sns';
5
+ import * as sqs from 'aws-cdk-lib/aws-sqs';
6
+ import { Construct } from 'constructs';
7
+ import { AppConstruct, AppProperties } from './types';
8
+ export declare class NextAppRouterConstruct extends Construct implements AppConstruct, Attach, Grant, CDNResource {
9
+ function: lambda.Function;
10
+ queue: sqs.Queue | undefined;
11
+ private readonly static;
12
+ constructor(scope: Construct, id: string, props: AppProperties);
13
+ cloudfront(path: string): {
14
+ [x: string]: cdk.aws_cloudfront.BehaviorOptions;
15
+ };
16
+ attach(attachable: Record<string, Attachable>): void;
17
+ grant(...grants: Grantable[]): void;
18
+ subscription(): ITopicSubscription;
19
+ static clean(output: string, name: string, command: string): {
20
+ serverOutput: string;
21
+ staticOutput: string;
22
+ staticPath: string;
23
+ };
24
+ }
25
+ //# sourceMappingURL=next-app-router-construct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-app-router-construct.d.ts","sourceRoot":"","sources":["../../src/lib/next-app-router-construct.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,MAAM,EACN,UAAU,EACV,WAAW,EACX,KAAK,EACL,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAItD,qBAAa,sBACX,SAAQ,SACR,YAAW,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW;IAE5C,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;IAyD9D,UAAU,CAAC,IAAI,EAAE,MAAM;;;IAwCvB,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,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;;;;;CAgC3D"}
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NextAppRouterConstruct = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("node:fs"));
6
+ const cdk = tslib_1.__importStar(require("aws-cdk-lib"));
7
+ const cloudfront = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront"));
8
+ const cloudfrontOrigin = tslib_1.__importStar(require("aws-cdk-lib/aws-cloudfront-origins"));
9
+ const lambda = tslib_1.__importStar(require("aws-cdk-lib/aws-lambda"));
10
+ const s3 = tslib_1.__importStar(require("aws-cdk-lib/aws-s3"));
11
+ const s3Deploy = tslib_1.__importStar(require("aws-cdk-lib/aws-s3-deployment"));
12
+ const constructs_1 = require("constructs");
13
+ const lambda_attach_1 = require("./utils/lambda-attach");
14
+ const lambda_grant_1 = require("./utils/lambda-grant");
15
+ class NextAppRouterConstruct extends constructs_1.Construct {
16
+ function;
17
+ queue;
18
+ static;
19
+ constructor(scope, id, props) {
20
+ super(scope, id);
21
+ const region = cdk.Stack.of(this).region;
22
+ const { serverOutput, staticOutput, staticPath } = props.buildPaths;
23
+ if (!serverOutput || !staticOutput)
24
+ throw new Error('assets not found');
25
+ this.static = new s3.Bucket(this, `StaticBucket`, {
26
+ removalPolicy: cdk.RemovalPolicy.DESTROY,
27
+ autoDeleteObjects: true,
28
+ blockPublicAccess: s3.BlockPublicAccess.BLOCK_ACLS,
29
+ publicReadAccess: true,
30
+ websiteIndexDocument: 'index.html',
31
+ websiteErrorDocument: 'index.html',
32
+ cors: [
33
+ {
34
+ allowedHeaders: ['*'],
35
+ allowedOrigins: ['*'],
36
+ allowedMethods: [s3.HttpMethods.GET, s3.HttpMethods.HEAD],
37
+ },
38
+ ],
39
+ });
40
+ new s3Deploy.BucketDeployment(this, `StaticDeployment`, {
41
+ destinationBucket: this.static,
42
+ sources: [s3Deploy.Source.asset(staticOutput)],
43
+ destinationKeyPrefix: staticPath,
44
+ retainOnDelete: false,
45
+ prune: true,
46
+ });
47
+ const webAdapterLayer = lambda.LayerVersion.fromLayerVersionArn(this, 'WebAdapterLayer', `arn:aws:lambda:${region}:753240598075:layer:LambdaAdapterLayerX86:16`);
48
+ const environment = {
49
+ AWS_LAMBDA_EXEC_WRAPPER: '/opt/bootstrap',
50
+ PORT: '8080',
51
+ AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
52
+ };
53
+ Object.assign(environment, props.env);
54
+ this.function = new lambda.Function(this, `AppFunction`, {
55
+ runtime: lambda.Runtime.NODEJS_20_X,
56
+ memorySize: 512,
57
+ handler: 'run.sh',
58
+ timeout: cdk.Duration.seconds(60),
59
+ code: lambda.Code.fromAsset(serverOutput),
60
+ layers: [webAdapterLayer],
61
+ environment,
62
+ });
63
+ }
64
+ cloudfront(path) {
65
+ const webUrl = this.function.addFunctionUrl({
66
+ authType: lambda.FunctionUrlAuthType.NONE,
67
+ });
68
+ const serverOrigin = new cloudfrontOrigin.FunctionUrlOrigin(webUrl);
69
+ const staticOrigin = new cloudfrontOrigin.S3StaticWebsiteOrigin(this.static);
70
+ const staticBehavior = {
71
+ origin: staticOrigin,
72
+ cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
73
+ allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
74
+ cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD,
75
+ compress: true,
76
+ viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
77
+ };
78
+ const appBehaviour = {
79
+ origin: serverOrigin,
80
+ cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
81
+ allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
82
+ compress: true,
83
+ viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
84
+ originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
85
+ responseHeadersPolicy: cloudfront.ResponseHeadersPolicy
86
+ .CORS_ALLOW_ALL_ORIGINS_WITH_PREFLIGHT_AND_SECURITY_HEADERS,
87
+ };
88
+ return {
89
+ [`${path}/*`]: appBehaviour,
90
+ [`${path}/_next/image/*`]: appBehaviour,
91
+ [`${path}/_next/*`]: staticBehavior,
92
+ [`${path}/*.ico`]: staticBehavior,
93
+ };
94
+ }
95
+ attach(attachable) {
96
+ return (0, lambda_attach_1.lambdaAttach)(this.function, attachable);
97
+ }
98
+ grant(...grants) {
99
+ return (0, lambda_grant_1.lambdaGrant)(this.function, grants);
100
+ }
101
+ subscription() {
102
+ throw new Error(`subscription not supported for ${this}`);
103
+ }
104
+ static clean(output, name, command) {
105
+ const destination = `./dist/${name}`;
106
+ /* Delete previous cleaned files */
107
+ fs.rmSync(destination, { recursive: true, force: true });
108
+ /* Create server and static folders for deployment */
109
+ fs.mkdirSync(`${destination}/server`, { recursive: true });
110
+ fs.mkdirSync(`${destination}/static/_next`, { recursive: true });
111
+ fs.cpSync(`${output}/.next/standalone/`, `${destination}/server`, {
112
+ recursive: true,
113
+ });
114
+ /* Copy public files to static folder */
115
+ fs.cpSync(`${output}/public`, `${destination}/static`, {
116
+ recursive: true,
117
+ });
118
+ /* Copy static files to next static folder */
119
+ fs.cpSync(`${output}/.next/static`, `${destination}/static/_next/static`, {
120
+ recursive: true,
121
+ });
122
+ fs.writeFileSync(`${destination}/server/run.sh`, command);
123
+ return {
124
+ serverOutput: `${destination}/server`,
125
+ staticOutput: `${destination}/static`,
126
+ staticPath: '',
127
+ };
128
+ }
129
+ }
130
+ exports.NextAppRouterConstruct = NextAppRouterConstruct;
@@ -0,0 +1,16 @@
1
+ import { Attach, CDNResource, Event, Grant } from '@fy-stack/types';
2
+ import type { Function } from 'aws-cdk-lib/aws-lambda';
3
+ import { Queue } from 'aws-cdk-lib/aws-sqs';
4
+ export type AppProperties = {
5
+ queue?: {
6
+ batchSize?: number;
7
+ };
8
+ env?: Record<string, string>;
9
+ buildPaths: Record<string, string>;
10
+ output: string;
11
+ };
12
+ export interface AppConstruct extends Attach, Grant, CDNResource, Event {
13
+ function: Function;
14
+ queue?: Queue;
15
+ }
16
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,WAAW,YAAa,SAAQ,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK;IACrE,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { Attachable } from '@fy-stack/types';
2
+ import { Function } from 'aws-cdk-lib/aws-lambda';
3
+ export declare function lambdaAttach(func: Function, attachable: Record<string, Attachable>): void;
4
+ //# sourceMappingURL=lambda-attach.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lambda-attach.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/lambda-attach.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,QAgBlF"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lambdaAttach = lambdaAttach;
4
+ function lambdaAttach(func, attachable) {
5
+ const params = {};
6
+ Object.assign(params, ...Object.entries(attachable)
7
+ .map(([key, val]) => {
8
+ return Object.fromEntries(Object.entries(val?.attachable() ?? {})
9
+ .map(([subKey, subVal]) => [`${key}_${subKey}`, subVal]));
10
+ }));
11
+ for (const i in params) {
12
+ func.addEnvironment(i, params[i]);
13
+ }
14
+ }
@@ -0,0 +1,4 @@
1
+ import { Grantable } from '@fy-stack/types';
2
+ import { Function } from 'aws-cdk-lib/aws-lambda';
3
+ export declare function lambdaGrant(func: Function, grants: Grantable[]): void;
4
+ //# sourceMappingURL=lambda-grant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lambda-grant.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/lambda-grant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,QAI9D"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lambdaGrant = lambdaGrant;
4
+ function lambdaGrant(func, grants) {
5
+ for (const i in grants) {
6
+ grants[i].grantable(func);
7
+ }
8
+ }
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@fy-stack/app-construct",
3
+ "version": "0.0.1",
4
+ "dependencies": {
5
+ "tslib": "^2.3.0"
6
+ },
7
+ "peerDependencies": {
8
+ "aws-cdk-lib": "2.164.1",
9
+ "constructs": "10.4.2",
10
+ "@fy-stack/types": "0.0.1"
11
+ },
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/index.mjs",
14
+ "typings": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist",
17
+ "!**/*.tsbuildinfo"
18
+ ],
19
+ "nx": {
20
+ "name": "app-construct"
21
+ }
22
+ }