@worktif/runtime 0.3.0-edge.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/LICENSE +101 -0
- package/README.md +495 -0
- package/out/dist/bin/index.js +212 -0
- package/out/dist/bin/purenow.js +218 -0
- package/out/dist/bin/templates/runtime-web/cdk/.gitignore.template +25 -0
- package/out/dist/bin/templates/runtime-web/cdk/README.md.template +267 -0
- package/out/dist/bin/templates/runtime-web/cdk/bin/app.ts.template +173 -0
- package/out/dist/bin/templates/runtime-web/cdk/cdk.json.template +79 -0
- package/out/dist/bin/templates/runtime-web/cdk/package.json.template +28 -0
- package/out/dist/bin/templates/runtime-web/cdk/tsconfig.json.template +38 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/.env.example +15 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/README.md +118 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/gitignore.template +64 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/package.json +34 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/purenow.config.ts +105 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/app.tsx +35 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/handlers/users/index.ts +17 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/handlers/users/users.handlers.ts +222 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/index.tsx +71 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/about-page.tsx +65 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/home-page.tsx +55 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/users-page.tsx +66 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/routes.tsx +61 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/services/index.ts +17 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/services/users.service.ts +133 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/ties/index.ts +17 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/ties/users.ties.ts +53 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/tsconfig.json +53 -0
- package/out/dist/lib/index.d.ts +4 -0
- package/out/dist/lib/index.js +4 -0
- package/out/dist/lib/lib/index.d.ts +3 -0
- package/out/dist/lib/lib/runtime-web/index.d.ts +17 -0
- package/out/dist/lib/lib/runtime-web/pipelines/browser-pipeline.d.ts +110 -0
- package/out/dist/lib/lib/runtime-web/pipelines/index.d.ts +2 -0
- package/out/dist/lib/lib/runtime-web/pureweb.d.ts +65 -0
- package/out/dist/lib/lib/runtime-web/types/config.types.d.ts +301 -0
- package/out/dist/lib/lib/runtime-web/types/http.types.d.ts +171 -0
- package/out/dist/lib/lib/runtime-web/types/index.d.ts +14 -0
- package/out/dist/lib/lib/runtime-web/types/infra.types.d.ts +225 -0
- package/out/dist/lib/lib/runtime-web/types/lambda.types.d.ts +175 -0
- package/out/dist/lib/lib/runtime-web/types/microservice.types.d.ts +70 -0
- package/out/dist/lib/lib/runtime-web/types/runtime.types.d.ts +55 -0
- package/out/dist/lib/utils/index.d.ts +2 -0
- package/out/dist/lib/utils/types/index.d.ts +3 -0
- package/out/dist/lib/utils/types/runtime.config.types.d.ts +71 -0
- package/out/dist/src/bin/index.d.ts +5 -0
- package/out/dist/src/bin/index.unix.d.ts +5 -0
- package/out/dist/src/bin/purenow-runtime-cli.d.ts +31 -0
- package/out/dist/src/bin/services/index.d.ts +8 -0
- package/out/dist/src/bin/services/purenow-runtime-deployment.strategy.d.ts +37 -0
- package/out/dist/src/bin/services/purenow-runtime-stacks-deploy.service.d.ts +58 -0
- package/out/dist/src/bin/services/purenow-runtime-stacks-deploy.service.types.d.ts +18 -0
- package/out/dist/src/bin/services/runtime-web-cli-extensions.d.ts +2 -0
- package/out/dist/src/bin/services/template.service.d.ts +53 -0
- package/out/dist/src/bin/services/utils/index.d.ts +2 -0
- package/out/dist/src/bin/utils/errors.d.ts +68 -0
- package/out/dist/src/lib/runtime-web/index.d.ts +17 -0
- package/out/dist/src/lib/runtime-web/pipelines/browser-pipeline.d.ts +110 -0
- package/out/dist/src/lib/runtime-web/pipelines/index.d.ts +2 -0
- package/out/dist/src/lib/runtime-web/pureweb.d.ts +65 -0
- package/out/dist/src/lib/runtime-web/types/config.types.d.ts +301 -0
- package/out/dist/src/lib/runtime-web/types/http.types.d.ts +171 -0
- package/out/dist/src/lib/runtime-web/types/index.d.ts +14 -0
- package/out/dist/src/lib/runtime-web/types/infra.types.d.ts +225 -0
- package/out/dist/src/lib/runtime-web/types/lambda.types.d.ts +175 -0
- package/out/dist/src/lib/runtime-web/types/microservice.types.d.ts +70 -0
- package/out/dist/src/lib/runtime-web/types/runtime.types.d.ts +55 -0
- package/package.json +133 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
A serverless web application powered by [Purenow](https://github.com/worktif/purenow).
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
- Node.js >= 18.0.0
|
|
10
|
+
- AWS CLI configured with credentials
|
|
11
|
+
- Yarn or npm
|
|
12
|
+
|
|
13
|
+
### Installation
|
|
14
|
+
|
|
15
|
+
Install dependencies:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install
|
|
19
|
+
# or
|
|
20
|
+
yarn install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Development
|
|
24
|
+
|
|
25
|
+
Start the local development server:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm run dev
|
|
29
|
+
# or
|
|
30
|
+
yarn dev
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The application will be available at `http://localhost:3000`.
|
|
34
|
+
|
|
35
|
+
### Building
|
|
36
|
+
|
|
37
|
+
Build all targets (React, Lambda, CDK):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm run build
|
|
41
|
+
# or
|
|
42
|
+
yarn build
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Deployment
|
|
46
|
+
|
|
47
|
+
Deploy to AWS:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Deploy to dev stage (default)
|
|
51
|
+
npm run deploy:dev
|
|
52
|
+
|
|
53
|
+
# Deploy to staging
|
|
54
|
+
npm run deploy:staging
|
|
55
|
+
|
|
56
|
+
# Deploy to production
|
|
57
|
+
npm run deploy:prod
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Environment Diagnostics
|
|
61
|
+
|
|
62
|
+
Check your development environment and project configuration:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm run doctor
|
|
66
|
+
# or
|
|
67
|
+
yarn doctor
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Project Information
|
|
71
|
+
|
|
72
|
+
Display version and configuration information:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm run info
|
|
76
|
+
# or
|
|
77
|
+
yarn info
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Project Structure
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
.
|
|
84
|
+
├── src/
|
|
85
|
+
│ ├── index.tsx # Application entry point
|
|
86
|
+
│ ├── App.tsx # Root component
|
|
87
|
+
│ ├── routes.tsx # Route configuration
|
|
88
|
+
│ └── pages/ # Page components
|
|
89
|
+
│ ├── HomePage.tsx
|
|
90
|
+
│ └── AboutPage.tsx
|
|
91
|
+
├── public/
|
|
92
|
+
│ └── index.html # HTML template
|
|
93
|
+
├── purenow.config.ts # Purenow configuration
|
|
94
|
+
├── tsconfig.json # TypeScript configuration
|
|
95
|
+
└── package.json # Project dependencies
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Configuration
|
|
100
|
+
|
|
101
|
+
Edit `purenow.config.ts` to customize:
|
|
102
|
+
|
|
103
|
+
- Project name
|
|
104
|
+
- Deployment stages (dev, staging, prod)
|
|
105
|
+
- AWS regions and profiles
|
|
106
|
+
- Custom domains
|
|
107
|
+
- Feature flags (SEO, manifest, warmup)
|
|
108
|
+
|
|
109
|
+
## Learn More
|
|
110
|
+
|
|
111
|
+
- [Purenow Documentation](https://github.com/worktif/purenow)
|
|
112
|
+
- [React Router v7](https://reactrouter.com/)
|
|
113
|
+
- [AWS Lambda](https://aws.amazon.com/lambda/)
|
|
114
|
+
- [AWS CDK](https://aws.amazon.com/cdk/)
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
Elastic License 2.0
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Purenow build outputs
|
|
2
|
+
out/
|
|
3
|
+
dist/
|
|
4
|
+
build/
|
|
5
|
+
.logs/
|
|
6
|
+
.serverless/
|
|
7
|
+
|
|
8
|
+
# AWS CDK
|
|
9
|
+
cdk.out/
|
|
10
|
+
cdk.context.json
|
|
11
|
+
|
|
12
|
+
# Environment variables
|
|
13
|
+
.env
|
|
14
|
+
.env.local
|
|
15
|
+
.env.development.local
|
|
16
|
+
.env.test.local
|
|
17
|
+
.env.production.local
|
|
18
|
+
|
|
19
|
+
# Dependencies
|
|
20
|
+
node_modules/
|
|
21
|
+
.pnp
|
|
22
|
+
.pnp.js
|
|
23
|
+
|
|
24
|
+
# Testing
|
|
25
|
+
coverage/
|
|
26
|
+
.nyc_output/
|
|
27
|
+
|
|
28
|
+
# Production
|
|
29
|
+
/build
|
|
30
|
+
|
|
31
|
+
# Misc
|
|
32
|
+
.DS_Store
|
|
33
|
+
*.log
|
|
34
|
+
npm-debug.log*
|
|
35
|
+
yarn-debug.log*
|
|
36
|
+
yarn-error.log*
|
|
37
|
+
.pnpm-debug.log*
|
|
38
|
+
|
|
39
|
+
# TypeScript
|
|
40
|
+
*.tsbuildinfo
|
|
41
|
+
.tsbuildinfo
|
|
42
|
+
|
|
43
|
+
# IDE
|
|
44
|
+
.idea/
|
|
45
|
+
.vscode/
|
|
46
|
+
*.swp
|
|
47
|
+
*.swo
|
|
48
|
+
*~
|
|
49
|
+
|
|
50
|
+
# OS
|
|
51
|
+
Thumbs.db
|
|
52
|
+
.Spotlight-V100
|
|
53
|
+
.Trashes
|
|
54
|
+
|
|
55
|
+
# Temporary files
|
|
56
|
+
.tmp/
|
|
57
|
+
tmp/
|
|
58
|
+
temp/
|
|
59
|
+
|
|
60
|
+
# Cache
|
|
61
|
+
.cache/
|
|
62
|
+
.parcel-cache/
|
|
63
|
+
.eslintcache
|
|
64
|
+
.stylelintcache
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{projectName}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "Serverless web runtime powered by Purenow",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "purenow dev",
|
|
8
|
+
"build": "purenow build",
|
|
9
|
+
"deploy": "purenow deploy",
|
|
10
|
+
"deploy:dev": "purenow deploy --stage dev",
|
|
11
|
+
"deploy:staging": "purenow deploy --stage staging",
|
|
12
|
+
"deploy:prod": "purenow deploy --stage prod",
|
|
13
|
+
"doctor": "purenow doctor",
|
|
14
|
+
"info": "purenow info"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@worktif/purenow": "^0.3.0-edge.0",
|
|
18
|
+
"react": "^19.1.1",
|
|
19
|
+
"react-dom": "^19.1.1",
|
|
20
|
+
"react-router": "^7.7.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^22.15.29",
|
|
24
|
+
"@types/react": "^19.1.6",
|
|
25
|
+
"@types/react-dom": "^19.1.6",
|
|
26
|
+
"typescript": "^5.8.2",
|
|
27
|
+
"tsx": "^4.21.0",
|
|
28
|
+
"aws-cdk-lib": "^2.172.0",
|
|
29
|
+
"constructs": "^10.4.2"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.0.0"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Elastic License 2.0
|
|
3
|
+
* Copyright (C) 2025–present Raman Marozau, Work Target Insight Function. All rights reserved.
|
|
4
|
+
* Contact: raman@worktif.com
|
|
5
|
+
*
|
|
6
|
+
* This file is part of the Licensed Work: worktif.purenow.cdk <worktif_purenow_cdk>.
|
|
7
|
+
* Use of this software is governed by the Elastic License 2.0; see the LICENSE file
|
|
8
|
+
* or https://www.elastic.co/licensing/elastic-license for details.
|
|
9
|
+
*
|
|
10
|
+
* Re-licensing notice:
|
|
11
|
+
* This file was previously distributed under the Business Source License 1.1 (BUSL-1.1).
|
|
12
|
+
* As of 2025-09-22, it is re-licensed under Elastic License 2.0.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: Elastic-2.0
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { PurenowCliConfig } from '@worktif/purenow';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Purenow CLI Configuration
|
|
21
|
+
*
|
|
22
|
+
* This file defines the configuration for your Purenow application,
|
|
23
|
+
* including deployment stages, paths, and feature flags.
|
|
24
|
+
*/
|
|
25
|
+
const config: PurenowCliConfig = {
|
|
26
|
+
/**
|
|
27
|
+
* Project name used for AWS resource naming
|
|
28
|
+
*/
|
|
29
|
+
projectName: '{{PROJECT_NAME}}',
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Deployment stages configuration
|
|
33
|
+
* Each stage can have its own AWS region, profile, and domain settings
|
|
34
|
+
* Note: Region is resolved from AWS SDK default provider chain (env vars, ~/.aws/config)
|
|
35
|
+
* The awsRegion value here is used as a fallback if no region is configured
|
|
36
|
+
*/
|
|
37
|
+
stages: [
|
|
38
|
+
{
|
|
39
|
+
name: 'dev',
|
|
40
|
+
awsRegion: '{{REGION}}', // Fallback region if not configured in AWS
|
|
41
|
+
awsProfile: 'default', // Optional: AWS CLI profile name
|
|
42
|
+
// domain: 'example.com', // Optional: Custom domain
|
|
43
|
+
// subdomain: 'dev', // Optional: Subdomain prefix
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'staging',
|
|
47
|
+
awsRegion: 'us-east-1', // Fallback region if not configured in AWS
|
|
48
|
+
awsProfile: 'default',
|
|
49
|
+
// domain: 'example.com',
|
|
50
|
+
// subdomain: 'staging',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'prod',
|
|
54
|
+
awsRegion: 'us-east-1', // Fallback region if not configured in AWS
|
|
55
|
+
awsProfile: 'default',
|
|
56
|
+
// domain: 'example.com',
|
|
57
|
+
// subdomain: 'www',
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Project paths configuration
|
|
63
|
+
*/
|
|
64
|
+
paths: {
|
|
65
|
+
srcDir: 'src',
|
|
66
|
+
reactEntry: 'src/index.tsx',
|
|
67
|
+
outDir: 'out/dist',
|
|
68
|
+
cdkDir: 'cdk', // Optional: CDK infrastructure directory
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Infrastructure mode
|
|
73
|
+
* - 'cdk': Use AWS CDK for infrastructure (recommended)
|
|
74
|
+
* - 'auto': Automatic infrastructure management
|
|
75
|
+
*/
|
|
76
|
+
infraMode: 'cdk',
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Optional feature flags
|
|
80
|
+
*/
|
|
81
|
+
features: {
|
|
82
|
+
/**
|
|
83
|
+
* Enable SEO metadata storage in DynamoDB
|
|
84
|
+
*/
|
|
85
|
+
enableSeo: false,
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Enable web app manifest generation
|
|
89
|
+
*/
|
|
90
|
+
enableManifest: true,
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Enable Lambda warmup to reduce cold starts
|
|
94
|
+
*/
|
|
95
|
+
enableWarmup: false,
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A configuration setting that determines whether the cache should be cleared on deployment.
|
|
99
|
+
* When set to true, the cache will be cleared every time a deployment occurs.
|
|
100
|
+
*/
|
|
101
|
+
clearCacheOnDeploy: true,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export default config;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Elastic License 2.0
|
|
3
|
+
* Copyright (C) 2025–present Raman Marozau, Work Target Insight Function. All rights reserved.
|
|
4
|
+
* Contact: raman@worktif.com
|
|
5
|
+
*
|
|
6
|
+
* This file is part of the Licensed Work: worktif.purenow.cdk <worktif_purenow_cdk>.
|
|
7
|
+
* Use of this software is governed by the Elastic License 2.0; see the LICENSE file
|
|
8
|
+
* or https://www.elastic.co/licensing/elastic-license for details.
|
|
9
|
+
*
|
|
10
|
+
* Re-licensing notice:
|
|
11
|
+
* This file was previously distributed under the Business Source License 1.1 (BUSL-1.1).
|
|
12
|
+
* As of 2025-09-22, it is re-licensed under Elastic License 2.0.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: Elastic-2.0
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import * as React from 'react';
|
|
18
|
+
import { PurenowRouterProvider } from '@worktif/purenow';
|
|
19
|
+
|
|
20
|
+
interface AppProps {
|
|
21
|
+
router: any;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Root application component that wraps the router provider
|
|
26
|
+
*/
|
|
27
|
+
const App: React.FC<AppProps> = ({ router }) => {
|
|
28
|
+
return (
|
|
29
|
+
<div className="app">
|
|
30
|
+
<PurenowRouterProvider router={router}/>
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default App;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Elastic License 2.0
|
|
3
|
+
* Copyright (C) 2025–present Raman Marozau, Work Target Insight Function. All rights reserved.
|
|
4
|
+
* Contact: raman@worktif.com
|
|
5
|
+
*
|
|
6
|
+
* This file is part of the Licensed Work: React Serverless <react-serverless>.
|
|
7
|
+
* Use of this software is governed by the Elastic License 2.0; see the LICENSE file
|
|
8
|
+
* or https://www.elastic.co/licensing/elastic-license for details.
|
|
9
|
+
*
|
|
10
|
+
* Re-licensing notice:
|
|
11
|
+
* This file was previously distributed under the Business Source License 1.1 (BUSL-1.1).
|
|
12
|
+
* As of 2025-09-15, it is re-licensed under Elastic License 2.0.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: Elastic-2.0
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export * from './users.handlers';
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Elastic License 2.0
|
|
3
|
+
* Copyright (C) 2025–present Raman Marozau, Work Target Insight Function. All rights reserved.
|
|
4
|
+
* Contact: raman@worktif.com
|
|
5
|
+
*
|
|
6
|
+
* This file is part of the Licensed Work: worktif.purenow.cdk <worktif_purenow_cdk>.
|
|
7
|
+
* Use of this software is governed by the Elastic License 2.0; see the LICENSE file
|
|
8
|
+
* or https://www.elastic.co/licensing/elastic-license for details.
|
|
9
|
+
*
|
|
10
|
+
* SPDX-License-Identifier: Elastic-2.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { LambdaDefinition } from '@worktif/purenow';
|
|
14
|
+
|
|
15
|
+
import { UsersService } from '../../services/users.service';
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create User Handler
|
|
20
|
+
*
|
|
21
|
+
* Creates a new user via POST /api/users
|
|
22
|
+
*
|
|
23
|
+
* Request body:
|
|
24
|
+
* ```json
|
|
25
|
+
* {
|
|
26
|
+
* "email": "user@example.com",
|
|
27
|
+
* "name": "John Doe",
|
|
28
|
+
* "password": "securepassword123"
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const createUserHandler: LambdaDefinition = {
|
|
33
|
+
id: 'create',
|
|
34
|
+
ties: [UsersService],
|
|
35
|
+
handler: (deps) => async (event: any, context: any) => {
|
|
36
|
+
try {
|
|
37
|
+
const body = JSON.parse(event.body || '{}');
|
|
38
|
+
const { email, name, password } = body;
|
|
39
|
+
|
|
40
|
+
if (!email || !name || !password) {
|
|
41
|
+
return {
|
|
42
|
+
statusCode: 400,
|
|
43
|
+
headers: { 'Content-Type': 'application/json' },
|
|
44
|
+
body: JSON.stringify({ error: 'Email, name, and password are required' }),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const user = await (deps as { usersService: UsersService }).usersService.createUser({ email, name, password });
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
statusCode: 201,
|
|
52
|
+
headers: { 'Content-Type': 'application/json' },
|
|
53
|
+
body: JSON.stringify(user),
|
|
54
|
+
};
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return {
|
|
57
|
+
statusCode: 500,
|
|
58
|
+
headers: { 'Content-Type': 'application/json' },
|
|
59
|
+
body: JSON.stringify({
|
|
60
|
+
error: 'User creation failed',
|
|
61
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
http: {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
path: '/api/users',
|
|
69
|
+
auth: 'none',
|
|
70
|
+
cors: true,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get User Handler
|
|
76
|
+
*
|
|
77
|
+
* Retrieves a user by ID via GET /api/users/{id}
|
|
78
|
+
*/
|
|
79
|
+
export const getUserHandler: LambdaDefinition = {
|
|
80
|
+
id: 'get',
|
|
81
|
+
ties: [UsersService],
|
|
82
|
+
handler: (deps) => async (event: any, context: any) => {
|
|
83
|
+
try {
|
|
84
|
+
const userId = event.pathParameters?.id;
|
|
85
|
+
|
|
86
|
+
if (!userId) {
|
|
87
|
+
return {
|
|
88
|
+
statusCode: 400,
|
|
89
|
+
headers: { 'Content-Type': 'application/json' },
|
|
90
|
+
body: JSON.stringify({ error: 'User ID is required' }),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const user = await (deps as { usersService: UsersService }).usersService.getUser(userId);
|
|
95
|
+
|
|
96
|
+
if (!user) {
|
|
97
|
+
return {
|
|
98
|
+
statusCode: 404,
|
|
99
|
+
headers: { 'Content-Type': 'application/json' },
|
|
100
|
+
body: JSON.stringify({ error: 'User not found' }),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
statusCode: 200,
|
|
106
|
+
headers: { 'Content-Type': 'application/json' },
|
|
107
|
+
body: JSON.stringify(user),
|
|
108
|
+
};
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return {
|
|
111
|
+
statusCode: 500,
|
|
112
|
+
headers: { 'Content-Type': 'application/json' },
|
|
113
|
+
body: JSON.stringify({
|
|
114
|
+
error: 'Failed to retrieve user',
|
|
115
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
116
|
+
}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
http: {
|
|
121
|
+
method: 'GET',
|
|
122
|
+
path: '/api/users/{id}',
|
|
123
|
+
auth: 'jwt',
|
|
124
|
+
cors: true,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Update User Handler
|
|
130
|
+
*
|
|
131
|
+
* Updates a user via PUT /api/users/{id}
|
|
132
|
+
*/
|
|
133
|
+
export const updateUserHandler: LambdaDefinition = {
|
|
134
|
+
id: 'update',
|
|
135
|
+
ties: [UsersService],
|
|
136
|
+
handler: (deps) => async (event: any, context: any) => {
|
|
137
|
+
try {
|
|
138
|
+
const userId = event.pathParameters?.id;
|
|
139
|
+
const body = JSON.parse(event.body || '{}');
|
|
140
|
+
|
|
141
|
+
if (!userId) {
|
|
142
|
+
return {
|
|
143
|
+
statusCode: 400,
|
|
144
|
+
headers: { 'Content-Type': 'application/json' },
|
|
145
|
+
body: JSON.stringify({ error: 'User ID is required' }),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const user = await (deps as { usersService: UsersService }).usersService.updateUser(userId, body);
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
statusCode: 200,
|
|
153
|
+
headers: { 'Content-Type': 'application/json' },
|
|
154
|
+
body: JSON.stringify(user),
|
|
155
|
+
};
|
|
156
|
+
} catch (error) {
|
|
157
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
158
|
+
const statusCode = message === 'User not found' ? 404 : 500;
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
statusCode,
|
|
162
|
+
headers: { 'Content-Type': 'application/json' },
|
|
163
|
+
body: JSON.stringify({
|
|
164
|
+
error: statusCode === 404 ? 'User not found' : 'Failed to update user',
|
|
165
|
+
message,
|
|
166
|
+
}),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
http: {
|
|
171
|
+
method: 'PUT',
|
|
172
|
+
path: '/api/users/{id}',
|
|
173
|
+
auth: 'jwt',
|
|
174
|
+
cors: true,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Delete User Handler
|
|
180
|
+
*
|
|
181
|
+
* Deletes a user via DELETE /api/users/{id}
|
|
182
|
+
*/
|
|
183
|
+
export const deleteUserHandler: LambdaDefinition = {
|
|
184
|
+
id: 'delete',
|
|
185
|
+
ties: [UsersService],
|
|
186
|
+
handler: (deps) => async (event: any, context: any) => {
|
|
187
|
+
try {
|
|
188
|
+
const userId = event.pathParameters?.id;
|
|
189
|
+
|
|
190
|
+
if (!userId) {
|
|
191
|
+
return {
|
|
192
|
+
statusCode: 400,
|
|
193
|
+
headers: { 'Content-Type': 'application/json' },
|
|
194
|
+
body: JSON.stringify({ error: 'User ID is required' }),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
await (deps as { usersService: UsersService }).usersService.deleteUser(userId);
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
statusCode: 204,
|
|
202
|
+
headers: { 'Content-Type': 'application/json' },
|
|
203
|
+
body: '',
|
|
204
|
+
};
|
|
205
|
+
} catch (error) {
|
|
206
|
+
return {
|
|
207
|
+
statusCode: 500,
|
|
208
|
+
headers: { 'Content-Type': 'application/json' },
|
|
209
|
+
body: JSON.stringify({
|
|
210
|
+
error: 'Failed to delete user',
|
|
211
|
+
message: error instanceof Error ? error.message : 'Unknown error',
|
|
212
|
+
}),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
http: {
|
|
217
|
+
method: 'DELETE',
|
|
218
|
+
path: '/api/users/{id}',
|
|
219
|
+
auth: 'jwt',
|
|
220
|
+
cors: true,
|
|
221
|
+
},
|
|
222
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Elastic License 2.0
|
|
3
|
+
* Copyright (C) 2025–present Raman Marozau, Work Target Insight Function. All rights reserved.
|
|
4
|
+
* Contact: raman@worktif.com
|
|
5
|
+
*
|
|
6
|
+
* This file is part of the Licensed Work: worktif.purenow.cdk <worktif_purenow_cdk>.
|
|
7
|
+
* Use of this software is governed by the Elastic License 2.0; see the LICENSE file
|
|
8
|
+
* or https://www.elastic.co/licensing/elastic-license for details.
|
|
9
|
+
*
|
|
10
|
+
* SPDX-License-Identifier: Elastic-2.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Runtime Web Core Example Application
|
|
15
|
+
*
|
|
16
|
+
* This is the main entry point for the example application.
|
|
17
|
+
* It demonstrates how to configure and use the Runtime Web Core layer.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import * as React from 'react';
|
|
21
|
+
import { ErrorBoundary, pureweb, purenowRouter, Stage } from '@worktif/purenow';
|
|
22
|
+
|
|
23
|
+
// Import Ties classes
|
|
24
|
+
import { UsersTies } from './ties';
|
|
25
|
+
|
|
26
|
+
// Import Lambda handlers
|
|
27
|
+
import { createUserHandler, deleteUserHandler, getUserHandler, updateUserHandler } from './handlers/users';
|
|
28
|
+
|
|
29
|
+
import App from './App';
|
|
30
|
+
|
|
31
|
+
// Router
|
|
32
|
+
import { routes } from './routes';
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Start the application
|
|
37
|
+
*
|
|
38
|
+
* The purenow() function automatically detects the execution context:
|
|
39
|
+
* - Browser: Hydrates React app with client-side routing
|
|
40
|
+
* - Lambda: Executes handlers with DI injection
|
|
41
|
+
* - CDK: Synthesizes CloudFormation templates
|
|
42
|
+
*/
|
|
43
|
+
pureweb({
|
|
44
|
+
// React application factory
|
|
45
|
+
app: ({ router }: any) => <App router={router}/>,
|
|
46
|
+
|
|
47
|
+
// Router instance
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
router: purenowRouter({
|
|
50
|
+
router: routes,
|
|
51
|
+
defaults: {
|
|
52
|
+
HydrateFallback: () => <div>Loading...</div>,
|
|
53
|
+
errorBoundary: <ErrorBoundary>asd</ErrorBoundary>,
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
|
|
57
|
+
// Service name (used for AWS resource naming)
|
|
58
|
+
serviceName: 'runtime-web-example',
|
|
59
|
+
|
|
60
|
+
// Deployment stage
|
|
61
|
+
stage: 'dev' as Stage,
|
|
62
|
+
|
|
63
|
+
// Microservice registry
|
|
64
|
+
register: {
|
|
65
|
+
// Users microservice
|
|
66
|
+
users: {
|
|
67
|
+
ties: [UsersTies],
|
|
68
|
+
lambdas: [createUserHandler, getUserHandler, updateUserHandler, deleteUserHandler],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|