@mbc-cqrs-serverless/cli 0.1.4-beta.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 +39 -0
- package/templates/.env.local +54 -0
- package/templates/.envrc +3 -0
- package/templates/.eslintrc.js +50 -0
- package/templates/.prettierrc +8 -0
- package/templates/README.md +168 -0
- package/templates/gitignore +46 -0
- package/templates/infra-local/appsync-simulator/.dockerignore +1 -0
- package/templates/infra-local/appsync-simulator/Dockerfile +8 -0
- package/templates/infra-local/appsync-simulator/package-lock.json +7179 -0
- package/templates/infra-local/appsync-simulator/package.json +30 -0
- package/templates/infra-local/appsync-simulator/src/main.ts +61 -0
- package/templates/infra-local/appsync-simulator/src/resolversConfig.ts +19 -0
- package/templates/infra-local/appsync-simulator/src/schema.graphql +28 -0
- package/templates/infra-local/appsync-simulator/src/schema.ts +7 -0
- package/templates/infra-local/appsync-simulator/src/vtl/readVTL.ts +6 -0
- package/templates/infra-local/appsync-simulator/src/vtl/sendMessage.req.vtl +4 -0
- package/templates/infra-local/appsync-simulator/src/vtl/sendMessage.res.vtl +1 -0
- package/templates/infra-local/cognito-local/.dockerignore +1 -0
- package/templates/infra-local/cognito-local/Dockerfile +9 -0
- package/templates/infra-local/cognito-local/db/clients.json +17 -0
- package/templates/infra-local/cognito-local/db/local_2G7noHgW.json +282 -0
- package/templates/infra-local/cognito-local/package-lock.json +2321 -0
- package/templates/infra-local/cognito-local/package.json +17 -0
- package/templates/infra-local/cognito-local/patches/cognito-local+3.23.2.patch +57 -0
- package/templates/infra-local/docker-compose.yml +91 -0
- package/templates/infra-local/elasticmq.conf +23 -0
- package/templates/infra-local/resources.sh +11 -0
- package/templates/infra-local/scripts/trigger_ddb_stream.sh +69 -0
- package/templates/infra-local/serverless.yml +306 -0
- package/templates/jest.config.js +4 -0
- package/templates/nest-cli.json +16 -0
- package/templates/package.json +118 -0
- package/templates/prisma/ddb.ts +232 -0
- package/templates/prisma/dynamodbs/cqrs.json +1 -0
- package/templates/prisma/dynamodbs/cqrs_desc.json +18 -0
- package/templates/prisma/dynamodbs/sequences.json +14 -0
- package/templates/prisma/dynamodbs/tasks.json +18 -0
- package/templates/prisma/schema.prisma +45 -0
- package/templates/src/event-factory.ts +7 -0
- package/templates/src/helpers/get-order.ts +19 -0
- package/templates/src/helpers/index.ts +1 -0
- package/templates/src/main.module.ts +26 -0
- package/templates/src/main.ts +7 -0
- package/templates/src/master/dto/master-attributes.dto.ts +6 -0
- package/templates/src/master/dto/master-command.dto.ts +12 -0
- package/templates/src/master/entity/master-command.entity.ts +13 -0
- package/templates/src/master/entity/master-data-list.entity.ts +13 -0
- package/templates/src/master/entity/master-data.entity.ts +13 -0
- package/templates/src/master/handler/master-rds.handler.ts +59 -0
- package/templates/src/master/master.controller.ts +83 -0
- package/templates/src/master/master.module.ts +19 -0
- package/templates/src/master/master.service.ts +58 -0
- package/templates/src/prisma/index.ts +5 -0
- package/templates/src/prisma/interfaces/index.ts +1 -0
- package/templates/src/prisma/interfaces/prisma-module-options.interface.ts +50 -0
- package/templates/src/prisma/prisma.constants.ts +2 -0
- package/templates/src/prisma/prisma.logging.middleware.ts +20 -0
- package/templates/src/prisma/prisma.module.ts +75 -0
- package/templates/src/prisma/prisma.service.ts +45 -0
- package/templates/src/repl.ts +21 -0
- package/templates/test/api.http +42 -0
- package/templates/test/jest-e2e.json +9 -0
- package/templates/tsconfig.build.json +4 -0
- package/templates/tsconfig.json +25 -0
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mbc-cqrs-serverless/cli",
|
|
3
|
+
"version": "0.1.4-beta.0",
|
|
4
|
+
"description": "a CLI to get started with MBC CQRS serverless framework",
|
|
5
|
+
"bin": {
|
|
6
|
+
"mbc": "./dist/index.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
11
|
+
"templates"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rm -rf dist && tsc",
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/mbc-net/mbc-cqrs-serverless.git"
|
|
20
|
+
},
|
|
21
|
+
"author": "MBC",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/mbc-net/mbc-cqrs-serverless/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://mbc-net.github.io/mbc-cqrs-serverless-doc/",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"commander": "^11.1.0",
|
|
32
|
+
"rimraf": "^5.0.5"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@faker-js/faker": "^8.3.1",
|
|
36
|
+
"@mbc-cqrs-serverless/core": "^0.1.4-beta.0"
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "f9bee15b584659c103ee0439b6b442cff12e0067"
|
|
39
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# AWS_PROFILE=local
|
|
2
|
+
AWS_ACCESS_KEY_ID=local
|
|
3
|
+
AWS_SECRET_ACCESS_KEY=local
|
|
4
|
+
AWS_DEFAULT_REGION=ap-northeast-1
|
|
5
|
+
# running environment
|
|
6
|
+
NODE_ENV=local # local, dev, stg, prod
|
|
7
|
+
# name of application
|
|
8
|
+
APP_NAME=demo
|
|
9
|
+
# set log levels
|
|
10
|
+
LOG_LEVEL=verbose # debug, verbose, info, warn, error, fatal
|
|
11
|
+
# disable event route for API GW integration
|
|
12
|
+
EVENT_SOURCE_DISABLED=false
|
|
13
|
+
# DynamoDB endpoint, useful for local development
|
|
14
|
+
DYNAMODB_ENDPOINT=http://localhost:8000
|
|
15
|
+
DYNAMODB_REGION=ap-northeast-1
|
|
16
|
+
# set the limit size for `attributes` of object in DDB
|
|
17
|
+
ATTRIBUTE_LIMIT_SIZE=389120 # bytes, refer to https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ServiceQuotas.html#limits-attributes
|
|
18
|
+
# S3 endpoint, useful for local development
|
|
19
|
+
S3_ENDPOINT=http://localhost:4566
|
|
20
|
+
S3_REGION=ap-northeast-1
|
|
21
|
+
# save DDB attributes
|
|
22
|
+
S3_BUCKET_NAME=local-bucket
|
|
23
|
+
# Step Function endpoint, useful for local development
|
|
24
|
+
SFN_ENDPOINT=http://localhost:8083
|
|
25
|
+
SFN_REGION=ap-northeast-1
|
|
26
|
+
SFN_COMMAND_ARN=arn:aws:states:ap-northeast-1:101010101010:stateMachine:command
|
|
27
|
+
# SNS endpoint, useful for local development
|
|
28
|
+
SNS_ENDPOINT=http://localhost:4002
|
|
29
|
+
SNS_REGION=ap-northeast-1
|
|
30
|
+
SNS_TOPIC_ARN=arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic
|
|
31
|
+
# Cognito endpoint, useful for local development
|
|
32
|
+
COGNITO_URL=http://localhost:9229
|
|
33
|
+
COGNITO_USER_POOL_ID=local_2G7noHgW
|
|
34
|
+
COGNITO_USER_POLL_CLIENT_ID=dnk8y7ii3wled35p3lw0l2cd7
|
|
35
|
+
COGNITO_REGION=ap-northeast-1
|
|
36
|
+
# AppSync endpoint, useful for local development
|
|
37
|
+
APPSYNC_ENDPOINT=http://localhost:4001/graphql
|
|
38
|
+
APPSYNC_API_KEY=da2-fakeApiId123456
|
|
39
|
+
# SES email endpoint, useful for local development
|
|
40
|
+
SES_ENDPOINT=http://localhost:8005
|
|
41
|
+
SES_REGION=ap-northeast-1
|
|
42
|
+
SES_FROM_EMAIL=email@example.com
|
|
43
|
+
|
|
44
|
+
# This was inserted by `prisma init`:
|
|
45
|
+
# Environment variables declared in this file are automatically made available to Prisma.
|
|
46
|
+
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
|
|
47
|
+
|
|
48
|
+
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
|
|
49
|
+
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
|
50
|
+
|
|
51
|
+
DATABASE_URL="mysql://root:RootCqrs@localhost:3306/cqrs?schema=public&connection_limit=1"
|
|
52
|
+
|
|
53
|
+
# serverless dynamodb local stream
|
|
54
|
+
LOCAL_DDB_MASTER_STREAM=arn:aws:dynamodb:ddblocal:000000000000:table/local-demo-master-command/stream/2024-01-02T02:49:43.692
|
package/templates/.envrc
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
parser: '@typescript-eslint/parser',
|
|
3
|
+
parserOptions: {
|
|
4
|
+
project: 'tsconfig.json',
|
|
5
|
+
tsconfigRootDir: __dirname,
|
|
6
|
+
sourceType: 'module',
|
|
7
|
+
},
|
|
8
|
+
plugins: [
|
|
9
|
+
'@typescript-eslint/eslint-plugin',
|
|
10
|
+
'simple-import-sort',
|
|
11
|
+
'prettier',
|
|
12
|
+
],
|
|
13
|
+
extends: [
|
|
14
|
+
'plugin:@typescript-eslint/recommended',
|
|
15
|
+
'plugin:prettier/recommended',
|
|
16
|
+
'prettier',
|
|
17
|
+
],
|
|
18
|
+
root: true,
|
|
19
|
+
env: {
|
|
20
|
+
node: true,
|
|
21
|
+
jest: true,
|
|
22
|
+
},
|
|
23
|
+
ignorePatterns: [
|
|
24
|
+
'.eslintrc.js',
|
|
25
|
+
'prisma',
|
|
26
|
+
'**/*.spec.ts',
|
|
27
|
+
'**/*.test.ts',
|
|
28
|
+
'infra*',
|
|
29
|
+
],
|
|
30
|
+
rules: {
|
|
31
|
+
'@typescript-eslint/interface-name-prefix': 'off',
|
|
32
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
33
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
34
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
35
|
+
'prettier/prettier': [
|
|
36
|
+
'error',
|
|
37
|
+
{
|
|
38
|
+
semi: false,
|
|
39
|
+
singleQuote: true,
|
|
40
|
+
trailingComma: 'all',
|
|
41
|
+
endOfLine: 'auto',
|
|
42
|
+
tabWidth: 2,
|
|
43
|
+
useTabs: false,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
'simple-import-sort/exports': 'error',
|
|
47
|
+
'simple-import-sort/imports': 'error',
|
|
48
|
+
'no-console': 'error',
|
|
49
|
+
},
|
|
50
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
## Description
|
|
2
|
+
|
|
3
|
+
CQRS framework based on [Nest](https://github.com/nestjs/nest).
|
|
4
|
+
|
|
5
|
+
TechStack:
|
|
6
|
+
|
|
7
|
+
- [Nest](https://github/nestjs/nest)
|
|
8
|
+
- TypeScript
|
|
9
|
+
- AWS Serverless
|
|
10
|
+
|
|
11
|
+
- API GW
|
|
12
|
+
- Lambda
|
|
13
|
+
- Step Functions
|
|
14
|
+
- EventBridge
|
|
15
|
+
- DynamoDB
|
|
16
|
+
|
|
17
|
+
- RDS - PostgreSQL
|
|
18
|
+
- Serverless fw && Localstack for local development
|
|
19
|
+
|
|
20
|
+
## Prepare
|
|
21
|
+
|
|
22
|
+
- [Nodejs](https://nodejs.org/en/download)
|
|
23
|
+
- [JQ cli](https://jqlang.github.io/jq/download/)
|
|
24
|
+
- [AWS cli](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
|
|
25
|
+
- [Docker](https://docs.docker.com/engine/install/)
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
$ cp .env.local .env
|
|
31
|
+
$ npm install
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Running the app
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# development build
|
|
38
|
+
$ npm run build
|
|
39
|
+
|
|
40
|
+
# docker, open in other terminal session
|
|
41
|
+
$ npm run offline:docker
|
|
42
|
+
|
|
43
|
+
# create resources such as S3 buckets
|
|
44
|
+
$ sh infra-local/resources.sh
|
|
45
|
+
|
|
46
|
+
# migrate tables, open in other terminal session
|
|
47
|
+
$ npm run migrate
|
|
48
|
+
|
|
49
|
+
# copy dynamodb stream arn to `.env` file
|
|
50
|
+
# LOCAL_DDB_MASTER_STREAM=arn:aws:dynamodb:ddblocal:000000000000:table/local-demo-master-command/stream/2024-01-02T03:07:49.349
|
|
51
|
+
|
|
52
|
+
# serverless, open in other terminal session
|
|
53
|
+
$ npm run offline:sls
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- After successfully running
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
DEBUG[serverless-offline-sns][adapter]: successfully subscribed queue "http://localhost:9324/101010101010/notification-queue" to topic: "arn:aws:sns:ap-northeast-1:101010101010:CqrsSnsTopic"
|
|
60
|
+
Offline Lambda Server listening on http://localhost:4000
|
|
61
|
+
serverless-offline-aws-eventbridge :: Plugin ready
|
|
62
|
+
serverless-offline-aws-eventbridge :: Mock server running at port: 4010
|
|
63
|
+
Starting Offline SQS at stage dev (ap-northeast-1)
|
|
64
|
+
Starting Offline Dynamodb Streams at stage dev (ap-northeast-1)
|
|
65
|
+
|
|
66
|
+
Starting Offline at stage dev (ap-northeast-1)
|
|
67
|
+
|
|
68
|
+
Offline [http for lambda] listening on http://localhost:3002
|
|
69
|
+
Function names exposed for local invocation by aws-sdk:
|
|
70
|
+
* main: serverless-example-dev-main
|
|
71
|
+
Configuring JWT Authorization: ANY /{proxy+}
|
|
72
|
+
|
|
73
|
+
┌────────────────────────────────────────────────────────────────────────┐
|
|
74
|
+
│ │
|
|
75
|
+
│ ANY | http://localhost:3000/api/public │
|
|
76
|
+
│ POST | http://localhost:3000/2015-03-31/functions/main/invocations │
|
|
77
|
+
│ ANY | http://localhost:3000/swagger-ui/{proxy*} │
|
|
78
|
+
│ POST | http://localhost:3000/2015-03-31/functions/main/invocations │
|
|
79
|
+
│ ANY | http://localhost:3000/{proxy*} │
|
|
80
|
+
│ POST | http://localhost:3000/2015-03-31/functions/main/invocations │
|
|
81
|
+
│ │
|
|
82
|
+
└────────────────────────────────────────────────────────────────────────┘
|
|
83
|
+
|
|
84
|
+
Server ready: http://localhost:3000 🚀
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Helpers
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# prisma command
|
|
92
|
+
$ npx prisma
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Test
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# unit tests
|
|
99
|
+
$ npm run test
|
|
100
|
+
|
|
101
|
+
# e2e tests
|
|
102
|
+
$ npm run test:e2e
|
|
103
|
+
|
|
104
|
+
# test coverage
|
|
105
|
+
$ npm run test:cov
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Before use Keycloak
|
|
109
|
+
|
|
110
|
+
Go to http://localhost:8180/admin/master/console/#/master/clients
|
|
111
|
+
|
|
112
|
+
- create a new client
|
|
113
|
+
|
|
114
|
+
- Client type: `OpenID Connect`
|
|
115
|
+
- Client ID: `hello-world`
|
|
116
|
+
- Valid redirect URIs: `*`
|
|
117
|
+
- Web origins: `*`
|
|
118
|
+
|
|
119
|
+
- go to Client scopes tab, then add new mapper
|
|
120
|
+
|
|
121
|
+
- Mapper type: `Audience`
|
|
122
|
+
- Name: `hello-world`
|
|
123
|
+
- Included Client Audience: `hello-world`
|
|
124
|
+
- Add to access token: `true`
|
|
125
|
+
|
|
126
|
+
- Ref: https://www.keycloak.org/getting-started/getting-started-docker
|
|
127
|
+
|
|
128
|
+
### Update `frontend/aws-export.js`
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
$ cp frontend/aws-export.local.js frontend/src/aws-export.js
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Step function execution
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
$ aws stepfunctions --endpoint-url http://localhost:8083 start-execution --state-machine-arn arn:aws:states:ap-northeast-1:101010101010:stateMachine:foo1
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Endpoints
|
|
141
|
+
|
|
142
|
+
- api gw: http://localhost:3000
|
|
143
|
+
- lambda: http://localhost:4000
|
|
144
|
+
- lambda http: http://localhost:3002
|
|
145
|
+
- step functions: http://localhost:8083
|
|
146
|
+
- dynamodb: http://localhost:8000
|
|
147
|
+
- dynamodb admin: http://localhost:8001
|
|
148
|
+
- sns: http://localhost:4002
|
|
149
|
+
- sqs: http://localhost:9324
|
|
150
|
+
- sqs admin: http://localhost:9325
|
|
151
|
+
- localstack: http://localhost:4566
|
|
152
|
+
- S3
|
|
153
|
+
- appsync: http://localhost:4001
|
|
154
|
+
- cognito: http://localhost:9229
|
|
155
|
+
- eventbridge: http://localhost:4010
|
|
156
|
+
- ses email: http://localhost:8005
|
|
157
|
+
- prisma studio: http://localhost:5000
|
|
158
|
+
- run `npx prisma studio` to open studio web
|
|
159
|
+
|
|
160
|
+
## Nestjs Debug mode
|
|
161
|
+
|
|
162
|
+
Run the following cmd to open nestjs debug mode
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
$ npm run start:repl
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
- Ref: https://docs.nestjs.com/recipes/repl
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# compiled output
|
|
2
|
+
/dist
|
|
3
|
+
/dist_layer
|
|
4
|
+
node_modules
|
|
5
|
+
|
|
6
|
+
# Logs
|
|
7
|
+
logs
|
|
8
|
+
*.log
|
|
9
|
+
npm-debug.log*
|
|
10
|
+
pnpm-debug.log*
|
|
11
|
+
yarn-debug.log*
|
|
12
|
+
yarn-error.log*
|
|
13
|
+
lerna-debug.log*
|
|
14
|
+
|
|
15
|
+
# OS
|
|
16
|
+
.DS_Store
|
|
17
|
+
|
|
18
|
+
# Tests
|
|
19
|
+
/coverage
|
|
20
|
+
/.nyc_output
|
|
21
|
+
|
|
22
|
+
# IDEs and editors
|
|
23
|
+
/.idea
|
|
24
|
+
.project
|
|
25
|
+
.classpath
|
|
26
|
+
.c9/
|
|
27
|
+
*.launch
|
|
28
|
+
.settings/
|
|
29
|
+
*.sublime-workspace
|
|
30
|
+
|
|
31
|
+
# IDE - VSCode
|
|
32
|
+
.vscode/*
|
|
33
|
+
!.vscode/settings.json
|
|
34
|
+
!.vscode/tasks.json
|
|
35
|
+
!.vscode/launch.json
|
|
36
|
+
!.vscode/extensions.json
|
|
37
|
+
|
|
38
|
+
# docker volumn
|
|
39
|
+
docker-data
|
|
40
|
+
|
|
41
|
+
#cognito local
|
|
42
|
+
.cognito
|
|
43
|
+
|
|
44
|
+
.nestjs_repl_history
|
|
45
|
+
|
|
46
|
+
.env
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node_modules
|