@fy-stack/fullstack-construct 0.0.127 → 0.0.129
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 +61 -4
- package/dist/lib/fullstack-construct.d.ts +4 -0
- package/dist/lib/fullstack-construct.d.ts.map +1 -1
- package/dist/lib/fullstack-construct.js +27 -5
- package/dist/lib/types.d.ts +6 -4
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +2 -0
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -1,7 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Fullstack Construct Documentation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## `FullstackConstruct`
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### Example
|
|
6
|
+
```typescript
|
|
7
|
+
import {
|
|
8
|
+
AppGrant,
|
|
9
|
+
AppType,
|
|
10
|
+
FullStackConstruct,
|
|
11
|
+
} from '@fy-stack/fullstack-construct';
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+
new FullStackConstruct(this, 'FullstackApp', {
|
|
14
|
+
appId: `unique-app-id`,
|
|
15
|
+
apps: {
|
|
16
|
+
api: {
|
|
17
|
+
type: AppType.NODE_API,
|
|
18
|
+
output: process.cwd() + '/dist/apps/api',
|
|
19
|
+
buildParams: { command: 'node main.js' },
|
|
20
|
+
attachment: { secrets: true },
|
|
21
|
+
grant: [AppGrant.EVENT, AppGrant.SECRETS],
|
|
22
|
+
},
|
|
23
|
+
eventHandler: {
|
|
24
|
+
type: AppType.NODE_APP,
|
|
25
|
+
output: process.cwd() + '/dist/apps/event-handler',
|
|
26
|
+
buildParams: { handler: 'main.handler' },
|
|
27
|
+
attachment: { secrets: true, queue: { batchSize: 10 } },
|
|
28
|
+
grant: [AppGrant.SECRETS],
|
|
29
|
+
},
|
|
30
|
+
web: {
|
|
31
|
+
type: AppType.NEXT_PAGE_EXPORT,
|
|
32
|
+
output: process.cwd() + '/dist/apps/web',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
secrets: {
|
|
36
|
+
SOME_OTHER_ENV: "envValue"
|
|
37
|
+
},
|
|
38
|
+
events: {
|
|
39
|
+
messages: [
|
|
40
|
+
{ messages: [EventType.DAILY_SPOOL], $resource: 'eventHandler' },
|
|
41
|
+
],
|
|
42
|
+
cron: [
|
|
43
|
+
{
|
|
44
|
+
messages: [EventType.DAILY_SPOOL],
|
|
45
|
+
cron: { hour: '0', minute: '0' },
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
cdn: {
|
|
50
|
+
routes: {
|
|
51
|
+
'/*': { $resource: 'web' },
|
|
52
|
+
},
|
|
53
|
+
domains: [
|
|
54
|
+
{ domain: 'example.com', records: ['*', 'www'] },
|
|
55
|
+
{ domain: 'example.com.ng', records: ['*', 'www'] },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
api: {
|
|
59
|
+
routes: {
|
|
60
|
+
'/*': { $resource: 'api' },
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
```
|
|
@@ -8,9 +8,13 @@ import { SecretsConstruct } from '@fy-stack/secret-construct';
|
|
|
8
8
|
import { StorageConstruct } from '@fy-stack/storage-construct';
|
|
9
9
|
import { Construct } from 'constructs';
|
|
10
10
|
import { FullStackConstructProps } from './types';
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
11
14
|
export declare class FullStackConstruct extends Construct {
|
|
12
15
|
auth?: AuthConstruct;
|
|
13
16
|
storage?: StorageConstruct;
|
|
17
|
+
storagePolicy?: string;
|
|
14
18
|
database?: DatabaseConstruct;
|
|
15
19
|
event?: EventConstruct;
|
|
16
20
|
apps?: Record<string, AppConstruct>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fullstack-construct.d.ts","sourceRoot":"","sources":["../../src/lib/fullstack-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FullStackConstruct = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const apigateway_construct_1 = require("@fy-stack/apigateway-construct");
|
|
5
6
|
const app_construct_1 = require("@fy-stack/app-construct");
|
|
6
7
|
const auth_construct_1 = require("@fy-stack/auth-construct");
|
|
@@ -9,17 +10,24 @@ const database_construct_1 = require("@fy-stack/database-construct");
|
|
|
9
10
|
const event_construct_1 = require("@fy-stack/event-construct");
|
|
10
11
|
const secret_construct_1 = require("@fy-stack/secret-construct");
|
|
11
12
|
const storage_construct_1 = require("@fy-stack/storage-construct");
|
|
13
|
+
const ec2 = tslib_1.__importStar(require("aws-cdk-lib/aws-ec2"));
|
|
12
14
|
const constructs_1 = require("constructs");
|
|
13
15
|
const types_1 = require("./types");
|
|
14
16
|
const AppBuilds = {
|
|
15
17
|
[types_1.AppType.NEXT_APP_ROUTER]: app_construct_1.NextAppRouterConstruct,
|
|
18
|
+
[types_1.AppType.NEXT_PAGE_EXPORT]: app_construct_1.NextPagesExportConstruct,
|
|
16
19
|
[types_1.AppType.NODE_APP]: app_construct_1.NodeAppConstruct,
|
|
17
20
|
[types_1.AppType.NODE_API]: app_construct_1.NodeApiConstruct,
|
|
18
21
|
[types_1.AppType.IMAGE_APP]: app_construct_1.ImageAppConstruct,
|
|
22
|
+
[types_1.AppType.STATIC_WEBSITE]: app_construct_1.StaticWebsiteConstruct,
|
|
19
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
20
27
|
class FullStackConstruct extends constructs_1.Construct {
|
|
21
28
|
auth;
|
|
22
29
|
storage;
|
|
30
|
+
storagePolicy;
|
|
23
31
|
database;
|
|
24
32
|
event;
|
|
25
33
|
apps;
|
|
@@ -28,6 +36,7 @@ class FullStackConstruct extends constructs_1.Construct {
|
|
|
28
36
|
secret;
|
|
29
37
|
constructor(scope, id, props) {
|
|
30
38
|
super(scope, id);
|
|
39
|
+
const vpc = ec2.Vpc.fromLookup(this, 'VPC', props.vpcId ? { vpcId: props.vpcId } : { isDefault: true });
|
|
31
40
|
if (props.auth) {
|
|
32
41
|
this.auth = new auth_construct_1.AuthConstruct(this, props.appId + 'AuthConstruct', {
|
|
33
42
|
groups: props.auth.groups,
|
|
@@ -38,7 +47,10 @@ class FullStackConstruct extends constructs_1.Construct {
|
|
|
38
47
|
}
|
|
39
48
|
/* create secrets for test or production environments */
|
|
40
49
|
if (props.database) {
|
|
41
|
-
this.database = new database_construct_1.DatabaseConstruct(this, 'DatabaseConstruct',
|
|
50
|
+
this.database = new database_construct_1.DatabaseConstruct(this, 'DatabaseConstruct', {
|
|
51
|
+
...props.database,
|
|
52
|
+
vpcId: vpc.vpcId,
|
|
53
|
+
});
|
|
42
54
|
}
|
|
43
55
|
if (props.apps) {
|
|
44
56
|
const apps = {};
|
|
@@ -73,6 +85,7 @@ class FullStackConstruct extends constructs_1.Construct {
|
|
|
73
85
|
if (props.cdn) {
|
|
74
86
|
this.cdn = new cdn_construct_1.CDNConstruct(this, 'CDNConstruct', {
|
|
75
87
|
routes: props.cdn.routes,
|
|
88
|
+
domains: props.cdn.domains,
|
|
76
89
|
resources: { ...this.apps, uploads: this.storage },
|
|
77
90
|
});
|
|
78
91
|
}
|
|
@@ -89,13 +102,22 @@ class FullStackConstruct extends constructs_1.Construct {
|
|
|
89
102
|
secrets: this.secret,
|
|
90
103
|
event: this.event,
|
|
91
104
|
};
|
|
105
|
+
if (this.storage && this.cdn) {
|
|
106
|
+
this.storagePolicy = JSON.stringify(this.storage.cloudfrontPolicy(this.cdn.distribution.distributionId));
|
|
107
|
+
}
|
|
92
108
|
for (const i in props.apps) {
|
|
93
|
-
|
|
109
|
+
const attachments = Object.entries(props.apps[i]?.attachment ?? {})
|
|
94
110
|
.map(([key]) => [key, resources[key]])
|
|
95
|
-
.filter((v) => !!v)
|
|
96
|
-
|
|
111
|
+
.filter((v) => !!v);
|
|
112
|
+
if (attachments.length) {
|
|
113
|
+
this.apps?.[i]?.attach(Object.fromEntries(attachments));
|
|
114
|
+
}
|
|
115
|
+
const grants = props.apps[i]?.grant
|
|
97
116
|
?.map((val) => resources[val])
|
|
98
|
-
.filter((v) => !!v) ?? []
|
|
117
|
+
.filter((v) => !!v) ?? [];
|
|
118
|
+
if (grants.length) {
|
|
119
|
+
this.apps?.[i]?.grant(...grants);
|
|
120
|
+
}
|
|
99
121
|
}
|
|
100
122
|
}
|
|
101
123
|
}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { DatabaseConstructProps } from '@fy-stack/database-construct';
|
|
2
2
|
import { ResourceRef } from '@fy-stack/types';
|
|
3
3
|
import * as events from 'aws-cdk-lib/aws-events';
|
|
4
|
+
import { CDNConstructProps } from '@fy-stack/cdn-construct';
|
|
4
5
|
export declare enum AppType {
|
|
5
6
|
NODE_APP = "nodeApp",
|
|
6
7
|
NODE_API = "nestApi",
|
|
7
8
|
IMAGE_APP = "imageApp",
|
|
8
|
-
NEXT_APP_ROUTER = "nextAppRouter"
|
|
9
|
+
NEXT_APP_ROUTER = "nextAppRouter",
|
|
10
|
+
NEXT_PAGE_EXPORT = "nextPageExport",
|
|
11
|
+
STATIC_WEBSITE = "staticWebsite"
|
|
9
12
|
}
|
|
10
13
|
export type AppAttachment = {
|
|
11
14
|
auth?: boolean;
|
|
@@ -38,6 +41,7 @@ export type AppCron = {
|
|
|
38
41
|
cron: events.CronOptions;
|
|
39
42
|
};
|
|
40
43
|
export type FullStackConstructProps = {
|
|
44
|
+
vpcId?: string;
|
|
41
45
|
appId: string;
|
|
42
46
|
auth?: {
|
|
43
47
|
groups?: string[];
|
|
@@ -51,9 +55,7 @@ export type FullStackConstructProps = {
|
|
|
51
55
|
messages?: AppMessage[];
|
|
52
56
|
cron?: AppCron[];
|
|
53
57
|
};
|
|
54
|
-
cdn?:
|
|
55
|
-
routes: Record<string, ResourceRef>;
|
|
56
|
-
};
|
|
58
|
+
cdn?: Omit<CDNConstructProps, "resources">;
|
|
57
59
|
api?: {
|
|
58
60
|
routes: Record<string, ResourceRef>;
|
|
59
61
|
};
|
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,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,oBAAY,OAAO;IACjB,QAAQ,YAAY;IACpB,QAAQ,YAAY;IACpB,SAAS,aAAa;IACtB,eAAe,kBAAkB;IACjC,gBAAgB,mBAAmB;IACnC,cAAc,kBAAkB;CACjC;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAChC,CAAC;AAEF,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,GAAG,GAAG;IAChB,IAAI,EAAE,OAAO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
|
|
8
8
|
AppType["IMAGE_APP"] = "imageApp";
|
|
9
9
|
AppType["NEXT_APP_ROUTER"] = "nextAppRouter";
|
|
10
|
+
AppType["NEXT_PAGE_EXPORT"] = "nextPageExport";
|
|
11
|
+
AppType["STATIC_WEBSITE"] = "staticWebsite";
|
|
10
12
|
})(AppType || (exports.AppType = AppType = {}));
|
|
11
13
|
var AppGrant;
|
|
12
14
|
(function (AppGrant) {
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fy-stack/fullstack-construct",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.129",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.0",
|
|
6
|
-
"@fy-stack/auth-construct": "0.0.
|
|
7
|
-
"@fy-stack/storage-construct": "0.0.
|
|
8
|
-
"@fy-stack/database-construct": "0.0.
|
|
9
|
-
"@fy-stack/event-construct": "0.0.
|
|
10
|
-
"@fy-stack/secret-construct": "0.0.
|
|
11
|
-
"@fy-stack/cdn-construct": "0.0.
|
|
12
|
-
"@fy-stack/apigateway-construct": "0.0.
|
|
13
|
-
"@fy-stack/types": "0.0.
|
|
14
|
-
"@fy-stack/app-construct": "0.0.
|
|
6
|
+
"@fy-stack/auth-construct": "0.0.129",
|
|
7
|
+
"@fy-stack/storage-construct": "0.0.129",
|
|
8
|
+
"@fy-stack/database-construct": "0.0.129",
|
|
9
|
+
"@fy-stack/event-construct": "0.0.129",
|
|
10
|
+
"@fy-stack/secret-construct": "0.0.129",
|
|
11
|
+
"@fy-stack/cdn-construct": "0.0.129",
|
|
12
|
+
"@fy-stack/apigateway-construct": "0.0.129",
|
|
13
|
+
"@fy-stack/types": "0.0.129",
|
|
14
|
+
"@fy-stack/app-construct": "0.0.129"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"aws-cdk-lib": "2.166.0",
|