@aws/nx-plugin 0.26.0 → 0.28.0
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/package.json +1 -1
- package/src/api-connection/generator.js +0 -2
- package/src/api-connection/generator.js.map +1 -1
- package/src/api-connection/schema.d.ts +0 -1
- package/src/api-connection/schema.json +0 -7
- package/src/cloudscape-website/app/generator.js +1 -0
- package/src/cloudscape-website/app/generator.js.map +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/infra/app/generator.js +1 -0
- package/src/infra/app/generator.js.map +1 -1
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +31 -30
- package/src/py/fast-api/generator.js +3 -0
- package/src/py/fast-api/generator.js.map +1 -1
- package/src/py/fast-api/react/__snapshots__/generator.spec.ts.snap +68 -1
- package/src/py/fast-api/react/files/website/components/__apiNameClassName__Provider.tsx.template +27 -1
- package/src/py/fast-api/react/generator.js +7 -17
- package/src/py/fast-api/react/generator.js.map +1 -1
- package/src/py/fast-api/react/schema.d.ts +0 -1
- package/src/py/fast-api/react/schema.json +0 -7
- package/src/py/fast-api/schema.d.ts +1 -0
- package/src/py/fast-api/schema.json +9 -1
- package/src/py/project/generator.js +1 -0
- package/src/py/project/generator.js.map +1 -1
- package/src/py/project/schema.json +7 -2
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +680 -84
- package/src/trpc/backend/files/backend/src/client/index.ts.template +22 -2
- package/src/trpc/backend/files/backend/src/middleware/index.ts.template +2 -3
- package/src/trpc/backend/files/backend/src/router.ts.template +2 -3
- package/src/trpc/backend/generator.js +21 -5
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/backend/schema.d.ts +2 -1
- package/src/trpc/backend/schema.json +10 -2
- package/src/trpc/react/__snapshots__/generator.spec.ts.snap +186 -73
- package/src/trpc/react/files/src/components/__apiNameClassName__ClientProvider.tsx.template +54 -0
- package/src/trpc/react/files/src/hooks/use__apiNameClassName__.tsx.template +2 -2
- package/src/trpc/react/generator.js +13 -69
- package/src/trpc/react/generator.js.map +1 -1
- package/src/trpc/react/schema.d.ts +0 -1
- package/src/trpc/react/schema.json +0 -7
- package/src/ts/lib/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/ts/lib/generator.js +1 -0
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/schema.json +7 -2
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +3 -0
- package/src/ts/mcp-server/generator.js +1 -0
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/mcp-server/schema.json +5 -0
- package/src/utils/api-constructs/api-constructs.d.ts +1 -0
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/app/apis/http/__apiNameKebabCase__.ts.template +53 -2
- package/src/utils/api-constructs/files/app/apis/rest/__apiNameKebabCase__.ts.template +57 -2
- package/src/utils/api-constructs/files/core/api/http/http-api.ts.template +1 -15
- package/src/utils/api-constructs/files/core/api/rest/rest-api.ts.template +0 -14
- package/src/utils/nx.d.ts +4 -0
- package/src/utils/nx.js +9 -1
- package/src/utils/nx.js.map +1 -1
- package/src/api-connection/README.md +0 -0
- package/src/cloudscape-website/app/README.md +0 -289
- package/src/cloudscape-website/cognito-auth/README.md +0 -193
- package/src/infra/app/README.md +0 -200
- package/src/license/README.md +0 -290
- package/src/trpc/backend/README.md +0 -571
- package/src/trpc/backend/files/backend/src/client/sigv4.ts.template +0 -9
- package/src/trpc/react/README.md +0 -330
- package/src/trpc/react/files/src/components/TrpcClients/TrpcApis.tsx.template +0 -1
- package/src/trpc/react/files/src/components/TrpcClients/TrpcClientProviders.tsx.template +0 -10
- package/src/trpc/react/files/src/components/TrpcClients/TrpcProvider.tsx.template +0 -55
- package/src/trpc/react/files/src/components/TrpcClients/index.tsx.template +0 -5
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
# Cloudscape Website App Generator
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
This generator creates a new Cloudscape React application with AWS CDK infrastructure setup. The generated application uses Vite as the build tool and bundler, providing fast development and optimized production builds. The codebase is structured using ES Modules (ESM) for modern JavaScript module system compatibility. It sets up a complete web application using AWS Cloudscape Design System components and configures the necessary build tools and dependencies.
|
|
6
|
-
|
|
7
|
-
## Usage
|
|
8
|
-
|
|
9
|
-
You can generate a new Cloudscape website application in two ways:
|
|
10
|
-
|
|
11
|
-
### 1. Using VSCode IDE
|
|
12
|
-
|
|
13
|
-
First, install the NX Console extension for VSCode:
|
|
14
|
-
|
|
15
|
-
1. Open VSCode
|
|
16
|
-
2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
|
|
17
|
-
3. Search for "Nx Console"
|
|
18
|
-
4. Install [Nx Console](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console)
|
|
19
|
-
|
|
20
|
-
Then generate your application:
|
|
21
|
-
|
|
22
|
-
1. Open the NX Console in VSCode
|
|
23
|
-
2. Click on "Generate"
|
|
24
|
-
3. Search for "ts#cloudscape-website"
|
|
25
|
-
4. Fill in the required parameters in the form
|
|
26
|
-
5. Click "Run"
|
|
27
|
-
|
|
28
|
-
### 2. Using CLI
|
|
29
|
-
|
|
30
|
-
Generate the application:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
nx g @aws/nx-plugin:ts#cloudscape-website my-website --directory=apps/web
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
You can also perform a dry-run to see what files would be generated without actually creating them:
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
nx g @aws/nx-plugin:ts#cloudscape-website my-website --directory=apps/web --dry-run
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Both methods will create a new Cloudscape website application in `apps/web/my-website` with all the necessary configuration and infrastructure code.
|
|
43
|
-
|
|
44
|
-
## Input Parameters
|
|
45
|
-
|
|
46
|
-
| Parameter | Type | Default | Description |
|
|
47
|
-
| -------------- | ------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
48
|
-
| name\* | string | - | The name of the application (required). Must start with a letter and not contain colons. |
|
|
49
|
-
| directory | string | "packages" | The directory to store the application in. |
|
|
50
|
-
| style | string | "css" | The file extension for style files. Options: css, scss, less, tailwind, styled-components, @emotion/styled, styled-jsx, none |
|
|
51
|
-
| unitTestRunner | string | "vitest" | Test runner for unit tests. Options: jest, vitest, none |
|
|
52
|
-
| bundler | string | "vite" | The bundler to use. Options: vite, webpack, rspack |
|
|
53
|
-
| compiler | string | "swc" | The compiler to use. Options: babel, swc |
|
|
54
|
-
| linter | string | "eslint" | The tool for running lint checks. Options: eslint, none |
|
|
55
|
-
| classComponent | boolean | false | Use class components instead of functional components |
|
|
56
|
-
| strict | boolean | true | Creates an application with strict mode and strict type checking |
|
|
57
|
-
| js | boolean | false | Generate JavaScript files instead of TypeScript files |
|
|
58
|
-
| minimal | boolean | false | Generate a React app with minimal setup, no separate test files |
|
|
59
|
-
|
|
60
|
-
\*Required parameter
|
|
61
|
-
|
|
62
|
-
## Expected Output
|
|
63
|
-
|
|
64
|
-
The generator creates two main components:
|
|
65
|
-
|
|
66
|
-
### 1. React Application Code
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
<directory>/<name>/
|
|
70
|
-
├── src/
|
|
71
|
-
│ ├── main.tsx # Application entry point with React setup
|
|
72
|
-
│ ├── config.ts # Application configuration
|
|
73
|
-
│ ├── layouts/ # Layout components
|
|
74
|
-
│ └── pages/ # Page components for routing
|
|
75
|
-
├── public/ # Static assets
|
|
76
|
-
├── tsconfig.json # TypeScript configuration
|
|
77
|
-
├── vite.config.ts # Vite bundler configuration
|
|
78
|
-
├── project.json # Project configuration and build targets
|
|
79
|
-
└── index.html # HTML entry point
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### 2. Infrastructure Code
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
common/constructs/
|
|
86
|
-
├── src/
|
|
87
|
-
| └── index.ts
|
|
88
|
-
| └── app/
|
|
89
|
-
| | ├── index.ts
|
|
90
|
-
| | └── static-websites
|
|
91
|
-
| | └── index.ts
|
|
92
|
-
| | └── <name>.ts # Infrastructure specific to your website
|
|
93
|
-
│ └── core/
|
|
94
|
-
│ └── index.ts
|
|
95
|
-
│ └── static-website.ts # Contains the generic StaticWebsite construct
|
|
96
|
-
├── tsconfig.json # TypeScript configuration
|
|
97
|
-
└── project.json # Project configuration and build targets
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Additionally, it:
|
|
101
|
-
|
|
102
|
-
1. Configures build settings for production deployment
|
|
103
|
-
2. Installs required dependencies:
|
|
104
|
-
- @cloudscape-design/components
|
|
105
|
-
- @cloudscape-design/board-components
|
|
106
|
-
- react-router-dom
|
|
107
|
-
- aws-cdk-lib
|
|
108
|
-
- constructs
|
|
109
|
-
- cdk-app-cli
|
|
110
|
-
|
|
111
|
-
## Infrastructure Architecture
|
|
112
|
-
|
|
113
|
-
```mermaid
|
|
114
|
-
graph TD
|
|
115
|
-
subgraph AWS Cloud
|
|
116
|
-
CF --> WAF
|
|
117
|
-
subgraph ApplicationStack
|
|
118
|
-
CF[CloudFront Distribution] --> S3[S3 Bucket]
|
|
119
|
-
OAC[Origin Access Control] --> S3
|
|
120
|
-
end
|
|
121
|
-
subgraph "WafStack (us-east-1)"
|
|
122
|
-
WAF[WAF Rules]
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
The website construct deploys:
|
|
128
|
-
|
|
129
|
-
1. **CloudFront Distribution**
|
|
130
|
-
|
|
131
|
-
- Global content delivery network
|
|
132
|
-
- Edge caching for static assets
|
|
133
|
-
- HTTPS enabled by default
|
|
134
|
-
|
|
135
|
-
2. **S3 Bucket**
|
|
136
|
-
|
|
137
|
-
- Static website content hosting
|
|
138
|
-
- Private access through CloudFront
|
|
139
|
-
- Versioning enabled
|
|
140
|
-
|
|
141
|
-
3. **WAF (Web Application Firewall)**
|
|
142
|
-
|
|
143
|
-
- Deployed as a seperate stack in us-east-1
|
|
144
|
-
- Web exploit protection
|
|
145
|
-
- Rate limiting
|
|
146
|
-
- IP-based filtering
|
|
147
|
-
|
|
148
|
-
4. **Origin Access Control**
|
|
149
|
-
- Secure S3 bucket access
|
|
150
|
-
- Restricted to CloudFront only
|
|
151
|
-
|
|
152
|
-
## Using the generated Construct
|
|
153
|
-
|
|
154
|
-
After generating the application, you can use the generated construct in your CDK code:
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
import { App, Stack } from 'aws-cdk-lib';
|
|
158
|
-
import { MyWebsite /* Use you website specific name */ } from ':my-org/common-constructs';
|
|
159
|
-
|
|
160
|
-
export class MyWebsiteStack extends Stack {
|
|
161
|
-
constructor(scope: App, id: string) {
|
|
162
|
-
super(scope, id);
|
|
163
|
-
|
|
164
|
-
new MyWebsite(this, 'MyWebsite');
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
The website construct is pre-configured with:
|
|
170
|
-
|
|
171
|
-
- S3 bucket for hosting website content
|
|
172
|
-
- CloudFront distribution with Origin Access Control
|
|
173
|
-
- WAF rules for security (deployed in us-east-1 via seperate stack)
|
|
174
|
-
- Cross-region support for WAF configuration
|
|
175
|
-
|
|
176
|
-
Since all the infrastructure code is generated in your project's `common/constructs` directory, you have full control to customize the implementation. The generated code serves as a starting point that you can adapt to your specific requirements.
|
|
177
|
-
|
|
178
|
-
## Runtime Configuration
|
|
179
|
-
|
|
180
|
-
The generator includes a RuntimeConfig system that bridges your infrastructure and frontend application. This system allows you to:
|
|
181
|
-
|
|
182
|
-
1. **Share Configuration**: Pass runtime configuration from your infrastructure to your React application
|
|
183
|
-
2. **Type Safety**: Configuration is fully typed using TypeScript interfaces
|
|
184
|
-
3. **Context-Based Access**: Access configuration anywhere in your React components using React Context
|
|
185
|
-
|
|
186
|
-
### Infrastructure Usage
|
|
187
|
-
|
|
188
|
-
In your CDK code, you can set runtime configuration using the RuntimeConfig construct:
|
|
189
|
-
|
|
190
|
-
```typescript
|
|
191
|
-
import { RuntimeConfig } from ':my-org/common-constructs';
|
|
192
|
-
|
|
193
|
-
export class MyWebsiteStack extends Stack {
|
|
194
|
-
constructor(scope: App, id: string) {
|
|
195
|
-
super(scope, id);
|
|
196
|
-
|
|
197
|
-
// Get or create the RuntimeConfig instance
|
|
198
|
-
const runtimeConfig = RuntimeConfig.ensure(this);
|
|
199
|
-
|
|
200
|
-
// Set configuration values
|
|
201
|
-
// Be sure to update the IRuntimeConfig interface first with your new definition
|
|
202
|
-
runtimeConfig.config.myFeature = {
|
|
203
|
-
apiEndpoint: 'https://api.example.com',
|
|
204
|
-
region: Stack.of(this).region,
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
### Frontend Usage
|
|
211
|
-
|
|
212
|
-
In your React components, you can access the runtime configuration using the RuntimeConfigContext:
|
|
213
|
-
|
|
214
|
-
```typescript
|
|
215
|
-
import { useRuntimeConfig } from './hooks/useRuntimeConfig';
|
|
216
|
-
|
|
217
|
-
const MyComponent = () => {
|
|
218
|
-
const { myFeature } = useRuntimeConfig();
|
|
219
|
-
|
|
220
|
-
return (
|
|
221
|
-
<div>
|
|
222
|
-
<p>API Endpoint: {myFeature.apiEndpoint}</p>
|
|
223
|
-
<p>Region: {myFeature.region}</p>
|
|
224
|
-
</div>
|
|
225
|
-
);
|
|
226
|
-
};
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
The RuntimeConfigProvider is automatically set up in your application's entry point:
|
|
230
|
-
|
|
231
|
-
```typescript
|
|
232
|
-
import RuntimeConfigProvider from './components/RuntimeConfig';
|
|
233
|
-
|
|
234
|
-
const App = () => (
|
|
235
|
-
<RuntimeConfigProvider>
|
|
236
|
-
<RouterProvider router={router} />
|
|
237
|
-
</RuntimeConfigProvider>
|
|
238
|
-
);
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
This configuration system is particularly useful when:
|
|
242
|
-
|
|
243
|
-
- Integrating with AWS services that require runtime configuration (e.g., Cognito, API Gateway)
|
|
244
|
-
- Managing environment-specific settings
|
|
245
|
-
- Sharing infrastructure outputs with your frontend application
|
|
246
|
-
|
|
247
|
-
## Building the Application
|
|
248
|
-
|
|
249
|
-
### Development Build
|
|
250
|
-
|
|
251
|
-
To run the application in development mode with hot-reload:
|
|
252
|
-
|
|
253
|
-
```bash
|
|
254
|
-
nx serve my-website
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
### Production Build
|
|
258
|
-
|
|
259
|
-
To create a production build:
|
|
260
|
-
|
|
261
|
-
```bash
|
|
262
|
-
nx build my-website
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
All built code is located in the `dist` folder at the root of your workspace. For example, if your application is in `apps/web/my-website`, the built code will be in `dist/apps/web/my-website`.
|
|
266
|
-
|
|
267
|
-
The production build:
|
|
268
|
-
|
|
269
|
-
- Minifies JavaScript and CSS
|
|
270
|
-
- Optimizes assets
|
|
271
|
-
- Generates source maps
|
|
272
|
-
- Creates a deployment-ready bundle
|
|
273
|
-
|
|
274
|
-
## Local development
|
|
275
|
-
|
|
276
|
-
Once you have deployed your application for the first time, we can pull down a copy of the `runtime-config.json` associated with the website so our local website server will operate as expected. To do this run the following command:
|
|
277
|
-
|
|
278
|
-
```bash
|
|
279
|
-
AWS_REGION=<YOUR_REGION> CDK_APP_DIR=<CDK_OUT_DIR>/cdk.out pnpm exec nx run @my-org/website:load:runtime-config
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
- **<YOUR_REGION>:** _the aws region you deployed into i.e: ap-southeast-2_
|
|
283
|
-
- **<CDK_OUT_DIR>:** _the relative path (from the root) to the `cdk.out` directory._
|
|
284
|
-
|
|
285
|
-
For example:
|
|
286
|
-
|
|
287
|
-
```bash
|
|
288
|
-
AWS_REGION=ap-southeast-2 CDK_APP_DIR=./dist/packages/infra/cdk.out pnpm exec nx run @my-org/website:load:runtime-config
|
|
289
|
-
```
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
# Cognito Auth Generator
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
This generator adds AWS Cognito authentication to an existing Cloudscape React application. It sets up the necessary components and infrastructure for user authentication using Amazon Cognito hosted UI, including sign-in, sign-up, and password recovery flows. The generator integrates seamlessly with the Cloudscape Design System components and configures all required AWS resources through CDK.
|
|
6
|
-
|
|
7
|
-
## Prerequisites
|
|
8
|
-
|
|
9
|
-
Before using this generator, ensure your project meets these requirements:
|
|
10
|
-
|
|
11
|
-
1. The project must have a `main.tsx` file in its source directory
|
|
12
|
-
2. The `main.tsx` file must contain a `<RuntimeConfigProvider>` element
|
|
13
|
-
3. The project must be a valid Cloudscape application
|
|
14
|
-
|
|
15
|
-
Example of required `main.tsx` structure:
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
import { RuntimeConfigProvider } from './components/RuntimeConfig';
|
|
19
|
-
|
|
20
|
-
const App = () => <RuntimeConfigProvider>{/* Your app components */}</RuntimeConfigProvider>;
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
If these prerequisites are not met, the generator will fail with an error.
|
|
24
|
-
|
|
25
|
-
## Usage
|
|
26
|
-
|
|
27
|
-
You can add Cognito authentication to your Cloudscape website in two ways:
|
|
28
|
-
|
|
29
|
-
### 1. Using VSCode IDE
|
|
30
|
-
|
|
31
|
-
First, install the NX Console extension for VSCode:
|
|
32
|
-
|
|
33
|
-
1. Open VSCode
|
|
34
|
-
2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
|
|
35
|
-
3. Search for "Nx Console"
|
|
36
|
-
4. Install [Nx Console](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console)
|
|
37
|
-
|
|
38
|
-
Then add authentication:
|
|
39
|
-
|
|
40
|
-
1. Open the NX Console in VSCode
|
|
41
|
-
2. Click on "Generate"
|
|
42
|
-
3. Search for "ts#cloudscape-website#cognito-auth"
|
|
43
|
-
4. Fill in the required parameters:
|
|
44
|
-
- project: Your existing Cloudscape application name
|
|
45
|
-
- allowSignup: Whether to enable self-signup (optional)
|
|
46
|
-
5. Click "Run"
|
|
47
|
-
|
|
48
|
-
### 2. Using CLI
|
|
49
|
-
|
|
50
|
-
Add authentication to your existing Cloudscape application:
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
nx g @aws/nx-plugin:ts#cloudscape-website#cognito-auth --project=my-cloudscape-app --cognito-domain=<your-domain-prefix>
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
Enable self-signup:
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
nx g @aws/nx-plugin:ts#cloudscape-website#cognito-auth --project=my-cloudscape-app --allowSignup=true --cognito-domain=<your-domain-prefix>
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
You can also perform a dry-run to see what files would be generated without actually creating them:
|
|
63
|
-
|
|
64
|
-
```bash
|
|
65
|
-
nx g @aws/nx-plugin:ts#cloudscape-website#cognito-auth --project=my-cloudscape-app --cognito-domain=<your-domain-prefix> --dry-run
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
All methods will add Cognito authentication to your existing Cloudscape website application with all the necessary components and infrastructure code.
|
|
69
|
-
|
|
70
|
-
## Input Parameters
|
|
71
|
-
|
|
72
|
-
| Parameter | Type | Default | Description |
|
|
73
|
-
| --------------- | ------- | ------- | ----------------------------------------------------------- |
|
|
74
|
-
| project\* | string | - | The root directory of the Cloudscape application (required) |
|
|
75
|
-
| cognitoDomain\* | string | - | domain prefix when creating the Cognito Hosted UI |
|
|
76
|
-
| allowSignup | boolean | false | Whether to allow self-signup |
|
|
77
|
-
|
|
78
|
-
\*Required parameter
|
|
79
|
-
|
|
80
|
-
## Expected Output
|
|
81
|
-
|
|
82
|
-
The generator adds authentication-related components and infrastructure:
|
|
83
|
-
|
|
84
|
-
### 1. React Components
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
<directory>/<websiteProject>/
|
|
88
|
-
├── src/
|
|
89
|
-
└── components/
|
|
90
|
-
| └── CognitoAuth/
|
|
91
|
-
| └── index.tsx # Main authentication component
|
|
92
|
-
└── layouts/
|
|
93
|
-
└── App/
|
|
94
|
-
└── index.tsx # Updates this file to add auth support
|
|
95
|
-
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### 2. Infrastructure Code
|
|
99
|
-
|
|
100
|
-
```
|
|
101
|
-
common
|
|
102
|
-
└── constructs/
|
|
103
|
-
└── src/
|
|
104
|
-
└── core/
|
|
105
|
-
└── index.ts # Adds export for identity construct
|
|
106
|
-
└── user-identity.ts # Main identity construct
|
|
107
|
-
└── types/
|
|
108
|
-
└── src/
|
|
109
|
-
└── runtime-config.ts # Updates IRuntimeConfig to add cognitoProps
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
Additionally, it:
|
|
113
|
-
|
|
114
|
-
1. Installs required dependencies:
|
|
115
|
-
- aws-cdk-lib
|
|
116
|
-
- constructs
|
|
117
|
-
- @aws-cdk/aws-cognito-identitypool-alpha
|
|
118
|
-
- react-oidc-context
|
|
119
|
-
- oidc-client-ts
|
|
120
|
-
2. Updates the application's runtime configuration to include Cognito settings
|
|
121
|
-
3. Automatically integrates the authentication component into your website code
|
|
122
|
-
|
|
123
|
-
## Infrastructure Architecture
|
|
124
|
-
|
|
125
|
-
```mermaid
|
|
126
|
-
graph TD
|
|
127
|
-
subgraph AWS Cloud
|
|
128
|
-
UP[Cognito User Pool] --> IP[Identity Pool]
|
|
129
|
-
UP --> CognitoDomain
|
|
130
|
-
UP --> Client[Web Client]
|
|
131
|
-
IP --> IAM[IAM Roles]
|
|
132
|
-
end
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
The infrastructure stack adds:
|
|
136
|
-
|
|
137
|
-
1. **Cognito User Pool**
|
|
138
|
-
|
|
139
|
-
- User directory management
|
|
140
|
-
- Sign-up and sign-in flows
|
|
141
|
-
- MFA configuration
|
|
142
|
-
|
|
143
|
-
2. **Cognito Identity Pool**
|
|
144
|
-
|
|
145
|
-
- Federated identities
|
|
146
|
-
- AWS credentials mapping
|
|
147
|
-
- IAM role assignment
|
|
148
|
-
|
|
149
|
-
3. **Web Client**
|
|
150
|
-
|
|
151
|
-
- User Password and SRP auth flows
|
|
152
|
-
- Token handling
|
|
153
|
-
|
|
154
|
-
4. **Cognito Domain**
|
|
155
|
-
- Domain configured using the cognitoDomain provided
|
|
156
|
-
|
|
157
|
-
## Authentication Components
|
|
158
|
-
|
|
159
|
-
The generator automatically sets up authentication in your application by:
|
|
160
|
-
|
|
161
|
-
1. Importing the CognitoAuth component in main.tsx
|
|
162
|
-
2. Wrapping your application with the CognitoAuth component inside the RuntimeConfigProvider
|
|
163
|
-
3. Configuring authenticated using the Cognito hosted UI
|
|
164
|
-
4. Updating the layout add add a singout button and display the logged in user.
|
|
165
|
-
|
|
166
|
-
No manual setup is required as the generator handles all the necessary component integration.
|
|
167
|
-
|
|
168
|
-
## Runtime Configuration
|
|
169
|
-
|
|
170
|
-
The generator automatically integrates with the RuntimeConfig system to provide Cognito configuration:
|
|
171
|
-
|
|
172
|
-
### Infrastructure Usage
|
|
173
|
-
|
|
174
|
-
```typescript
|
|
175
|
-
import { UserIdentity } from ':my-org/common-constructs';
|
|
176
|
-
import { Stack } from 'aws-cdk-lib';
|
|
177
|
-
import { Construct } from 'constructs';
|
|
178
|
-
|
|
179
|
-
export class MyWebsiteStack extends Stack {
|
|
180
|
-
constructor(scope: Construct, id: string) {
|
|
181
|
-
super(scope, id);
|
|
182
|
-
|
|
183
|
-
// Create the Cognito authentication resources
|
|
184
|
-
new UserIdentity(this, 'Identity');
|
|
185
|
-
|
|
186
|
-
// The runtime config is automatically updated with Cognito settings
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### Frontend Usage
|
|
192
|
-
|
|
193
|
-
The CognitoAuth component automatically uses the runtime configuration.
|
package/src/infra/app/README.md
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
# Infrastructure App Generator
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
This generator creates a new AWS CDK infrastructure application. The generated application includes security best practices through CFN guard checks. The codebase is structured using TypeScript and ES Modules (ESM) for modern development practices.
|
|
6
|
-
|
|
7
|
-
## Usage
|
|
8
|
-
|
|
9
|
-
You can generate a new infrastructure application in two ways:
|
|
10
|
-
|
|
11
|
-
### 1. Using VSCode IDE
|
|
12
|
-
|
|
13
|
-
First, install the NX Console extension for VSCode:
|
|
14
|
-
|
|
15
|
-
1. Open VSCode
|
|
16
|
-
2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
|
|
17
|
-
3. Search for "Nx Console"
|
|
18
|
-
4. Install [Nx Console](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console)
|
|
19
|
-
|
|
20
|
-
Then generate your application:
|
|
21
|
-
|
|
22
|
-
1. Open the NX Console in VSCode
|
|
23
|
-
2. Click on "Generate"
|
|
24
|
-
3. Search for "ts#infra"
|
|
25
|
-
4. Fill in the required parameters in the form
|
|
26
|
-
5. Click "Run"
|
|
27
|
-
|
|
28
|
-
### 2. Using CLI
|
|
29
|
-
|
|
30
|
-
Generate the application:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
nx g @aws/nx-plugin:ts#infra my-infra --directory=apps/infrastructure
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
You can also perform a dry-run to see what files would be generated without actually creating them:
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
nx g @aws/nx-plugin:ts#infra my-infra --directory=apps/infrastructure --dry-run
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Input Parameters
|
|
43
|
-
|
|
44
|
-
| Parameter | Type | Default | Description |
|
|
45
|
-
| -------------- | ------ | --------------- | ---------------------------------------------------------------------------------------- |
|
|
46
|
-
| name\* | string | - | The name of the application (required). Must start with a letter and not contain colons. |
|
|
47
|
-
| ruleSet\* | string | aws_prototyping | cfn guard ruleset to use |
|
|
48
|
-
| directory | string | "packages" | The directory to store the application in. |
|
|
49
|
-
| unitTestRunner | string | "vitest" | Test runner for unit tests. Options: jest, vitest, none |
|
|
50
|
-
|
|
51
|
-
\*Required parameter
|
|
52
|
-
|
|
53
|
-
## Expected Output
|
|
54
|
-
|
|
55
|
-
The generator creates two main components:
|
|
56
|
-
|
|
57
|
-
### 1. Infra app code
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
<directory>/<name>/
|
|
61
|
-
├── src/
|
|
62
|
-
│ └── main.ts # Application entry point with CDK and PDK setup
|
|
63
|
-
│ └── stacks/ # CDK stack definitions
|
|
64
|
-
│ └── application-stack.ts # Main application stack
|
|
65
|
-
├── cdk.json # CDK configuration
|
|
66
|
-
├── tsconfig.json # TypeScript configuration
|
|
67
|
-
└── project.json # Project configuration and build targets
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### 2. Infra library code
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
common/constructs
|
|
74
|
-
└── src
|
|
75
|
-
└── core
|
|
76
|
-
└── cfn-guard.ts # Provides a wrapper around @cdklabs/cdk-validator-cfnguard along with a suppressRule function
|
|
77
|
-
└── cfn-guard-rules
|
|
78
|
-
└── *.guard # cfn guard ruleset definitions
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Additionally, it:
|
|
82
|
-
|
|
83
|
-
1. Configures build settings for CDK synthesis and deployment
|
|
84
|
-
2. Installs required dependencies:
|
|
85
|
-
- aws-cdk-lib
|
|
86
|
-
- aws-cdk
|
|
87
|
-
- @cdklabs/cdk-validator-cfnguard
|
|
88
|
-
- constructs
|
|
89
|
-
- esbuild
|
|
90
|
-
- source-map-support
|
|
91
|
-
- tsx (dev dependency)
|
|
92
|
-
|
|
93
|
-
## Features
|
|
94
|
-
|
|
95
|
-
### 1. Cfn Guard integration
|
|
96
|
-
|
|
97
|
-
The generated application includes Cfn guard integration which ensures security best practices via automated policy checks.
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
import { CfnGuardValidator, RuleSet } from ':e2e-test/common-constructs';
|
|
101
|
-
|
|
102
|
-
const app = new App({
|
|
103
|
-
policyValidationBeta1: [new CfnGuardValidator(RuleSet.AWS_PROTOTYPING)],
|
|
104
|
-
});
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### 2. Build and Deploy Targets
|
|
108
|
-
|
|
109
|
-
The generator configures two main targets in your project.json:
|
|
110
|
-
|
|
111
|
-
1. **Build Target**
|
|
112
|
-
|
|
113
|
-
- Synthesizes CDK templates
|
|
114
|
-
- Caches results for faster subsequent builds
|
|
115
|
-
- Outputs to `dist/<directory>/cdk.out`
|
|
116
|
-
|
|
117
|
-
2. **Deploy Target**
|
|
118
|
-
- Deploys infrastructure to AWS
|
|
119
|
-
- Configures automatic approval for CI/CD pipelines
|
|
120
|
-
- Uses synthesized templates from the build target
|
|
121
|
-
|
|
122
|
-
## Working with the Generated Application
|
|
123
|
-
|
|
124
|
-
### Adding Resources
|
|
125
|
-
|
|
126
|
-
Add AWS resources to your stack in `src/stacks/application-stack.ts`:
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
import * as cdk from 'aws-cdk-lib';
|
|
130
|
-
import { Construct } from 'constructs';
|
|
131
|
-
/* Replace MyWebsite and MyApi with whatever you called them */
|
|
132
|
-
import { UserIdentity, MyWebsite, MyApi } from ':my-org/common-constructs';
|
|
133
|
-
|
|
134
|
-
export class ApplicationStack extends cdk.Stack {
|
|
135
|
-
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
|
|
136
|
-
super(scope, id, props);
|
|
137
|
-
|
|
138
|
-
const identity = new UserIdentity(this, 'UserIdentity');
|
|
139
|
-
const myapi = new MyApi(this, 'MyApi');
|
|
140
|
-
myapi.grantInvokeAccess(identity.identityPool.authenticatedRole);
|
|
141
|
-
new MyWebsite(this, 'Website');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
The generated code serves as a starting point that you can adapt to your specific infrastructure requirements while maintaining security best practices.
|
|
147
|
-
|
|
148
|
-
### Building the Application
|
|
149
|
-
|
|
150
|
-
To create a production build:
|
|
151
|
-
|
|
152
|
-
```bash
|
|
153
|
-
nx build my-infra
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
All built code is located in the `dist` folder at the root of your workspace. For example, if your infrastructure application is in `apps/infrastructure/my-infra`, the built code will be in `dist/apps/infrastructure/my-infra`. This includes:
|
|
157
|
-
|
|
158
|
-
- Compiled TypeScript files
|
|
159
|
-
- CDK synthesized templates in `dist/apps/infrastructure/my-infra/cdk.out`
|
|
160
|
-
- Source maps for debugging
|
|
161
|
-
|
|
162
|
-
### Deploying to AWS
|
|
163
|
-
|
|
164
|
-
To deploy your infrastructure:
|
|
165
|
-
|
|
166
|
-
```bash
|
|
167
|
-
nx deploy my-infra --all
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
This command will deploy your infrastructure to AWS using the account and region configured in your AWS CLI.
|
|
171
|
-
|
|
172
|
-
You can also perform a hotswap deployment if you are only making modifications to existing resources via the following command:
|
|
173
|
-
|
|
174
|
-
```bash
|
|
175
|
-
nx deploy my-infra --hotswap
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
### Cfn Guard Suppressions
|
|
179
|
-
|
|
180
|
-
There may be instances where you want to suppress certain rules on resources. You can do this in two ways:
|
|
181
|
-
|
|
182
|
-
#### Supress a rule on a given construct
|
|
183
|
-
|
|
184
|
-
```typescript
|
|
185
|
-
import { suppressRule } from ':my-org/common-constructs';
|
|
186
|
-
|
|
187
|
-
...
|
|
188
|
-
// suppresses the RULE_NAME for the given construct.
|
|
189
|
-
suppressRule(construct, 'RULE_NAME');
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
#### Supress a rule on a descendant construct
|
|
193
|
-
|
|
194
|
-
```typescript
|
|
195
|
-
import { suppressRule } from ':my-org/common-constructs';
|
|
196
|
-
|
|
197
|
-
...
|
|
198
|
-
// Supresses the RULE_NAME for the construct or any of its descendants if it is an instance of Bucket
|
|
199
|
-
suppressRule(construct, 'RULE_NAME', (construct) => construct instanceof Bucket);
|
|
200
|
-
```
|