very-express 0.5.26 → 0.6.0-alpha

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.
Files changed (60) hide show
  1. package/.eslintrc.json +36 -37
  2. package/.gitattributes +2 -2
  3. package/.github/copilot-instructions.md +107 -84
  4. package/.github/workflows/npm-start.yml +23 -23
  5. package/LICENSE +21 -21
  6. package/README.md +75 -75
  7. package/dist/index.js +1040 -1149
  8. package/dist/templates/_controllers/_ControllerFactory.ts +7 -3
  9. package/dist/templates/_middlewares/Authentication.ts +1 -5
  10. package/dist/templates/_middlewares/tsoaAuthentication.ts +24 -0
  11. package/dist/templates/_projectSettings/env +25 -24
  12. package/dist/templates/_projectSettings/package.json +50 -54
  13. package/dist/templates/_services/MongooseRepositoryAdapter.ts +48 -0
  14. package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +59 -0
  15. package/dist/templates/_services/VexDb.ts +14 -0
  16. package/dist/templates/_services/VexDbConnector.ts +108 -163
  17. package/dist/templates/_services/VexSystem.ts +25 -42
  18. package/dist/templates/_services/auth/JWTService.ts +26 -13
  19. package/dist/templates/_services/oauth/OAuthProfileMap.ts +6 -14
  20. package/dist/templates/_services/oauth/OAuthStrategyService.ts +70 -51
  21. package/dist/templates/_types/IVexRepository.ts +18 -0
  22. package/dist/templates/_types/VexRequest.ts +11 -0
  23. package/dist/templates/_types/VexResponse.ts +25 -0
  24. package/dist/templates/_types/VexResponseError.ts +4 -3
  25. package/dist/templates/_types/responseObject.ts +1 -1
  26. package/dist/templates/_utils/common.ts +50 -16
  27. package/dist/templates/_utils/hash.ts +6 -5
  28. package/dist/templates/_utils/index.ts +2 -1
  29. package/dist/templates/_utils/logger.ts +15 -14
  30. package/dist/templates/_utils/processTimer.ts +1 -0
  31. package/dist/templates/_utils/response.ts +4 -3
  32. package/dist/templates/_utils/validator.ts +1 -0
  33. package/dist/templates/jsonSchema/Session.json +34 -31
  34. package/dist/templates/jsonSchema/User.json +50 -85
  35. package/dist/templates/jsonSchema/UserAuthProfiles.json +48 -0
  36. package/dist/templates/root/Dockerfile +19 -19
  37. package/dist/templates/root/README.md +38 -38
  38. package/dist/templates/root/public/css/style.css +7 -7
  39. package/dist/templates/root/public/js/login.js +58 -58
  40. package/dist/templates/root/public/js/logincallback.js +18 -18
  41. package/dist/templates/root/public/js/mytokens.js +10 -10
  42. package/dist/templates/root/public/js/refreshtokens.js +22 -22
  43. package/dist/templates/root/scripts/build.js +38 -38
  44. package/dist/templates/root/tsconfig.json +29 -27
  45. package/docs/ForeignKey.md +43 -43
  46. package/docs/appGenerated/auth.md +22 -22
  47. package/docs/developmentNote.md +22 -22
  48. package/docs/releaseNote/v0-5-0.md +17 -17
  49. package/docs/roadMap/futurePlan.md +9 -9
  50. package/docs/roadMap/released.md +49 -49
  51. package/docs/roadMap/v0-6-0.md +15 -15
  52. package/docs/vexJsonSchema.md +55 -55
  53. package/package.json +59 -58
  54. package/scripts/build.js +13 -13
  55. package/scripts/bump-version.js +86 -86
  56. package/scripts/copyTsTemplates.js +30 -30
  57. package/scripts/merge.js +124 -124
  58. package/tsconfig.json +121 -121
  59. package/vex.config.json +37 -36
  60. package/dist/templates/_types/VexResponsePayloadError.ts +0 -20
@@ -1,86 +1,51 @@
1
- {
2
- "type": "object",
3
- "x-documentConfig": {
4
- "methods": [
5
- "get",
6
- "getList",
7
- "post",
8
- "patch"
9
- ],
10
- "documentName": "User"
11
- },
12
- "properties": {
13
- "_id": {
14
- "type": "string",
15
- "x-format": "ObjectId",
16
- "index": true
17
- },
18
- "authProfiles": {
19
- "type": "array",
20
- "items": {
21
- "type": "object",
22
- "properties": {
23
- "provider": {
24
- "type": "string",
25
- "index": true
26
- },
27
- "authId": {
28
- "type": "string",
29
- "index": true
30
- },
31
- "username": {
32
- "type": "string"
33
- },
34
- "password": {
35
- "type": "string"
36
- }
37
- },
38
- "required": []
39
- }
40
- },
41
- "email": {
42
- "type": "string",
43
- "format": "email",
44
- "index": true
45
- },
46
- "name": {
47
- "type": "string",
48
- "maxLength": 64,
49
- "required": true
50
- },
51
- "active": {
52
- "type": "boolean",
53
- "default": true,
54
- "required": true
55
- },
56
- "locale": {
57
- "type": "string",
58
- "maxLength": 8
59
- },
60
- "roles": {
61
- "type": "array",
62
- "x-vexData": "role",
63
- "items": {
64
- "type": "string",
65
- "enum": [
66
- "visitor",
67
- "member",
68
- "admin"
69
- ]
70
- },
71
- "default": [
72
- "visitor"
73
- ]
74
- },
75
- "profileErrors": {
76
- "type": "array",
77
- "items": {
78
- "type": "string"
79
- }
80
- }
81
- },
82
- "required": [
83
- "name",
84
- "active"
85
- ]
1
+ {
2
+ "type": "object",
3
+ "x-documentConfig": {
4
+ "methods": [
5
+ "get",
6
+ "getList",
7
+ "post",
8
+ "patch"
9
+ ],
10
+ "documentName": "User"
11
+ },
12
+ "properties": {
13
+ "_id": {
14
+ "type": "string",
15
+ "x-format": "PrimaryUUID",
16
+ "index": true
17
+ },
18
+ "email": {
19
+ "type": "string",
20
+ "format": "email",
21
+ "index": true
22
+ },
23
+ "name": {
24
+ "type": "string",
25
+ "maxLength": 64,
26
+ "required": true
27
+ },
28
+ "active": {
29
+ "type": "boolean",
30
+ "default": true,
31
+ "required": true
32
+ },
33
+ "roles": {
34
+ "type": "array",
35
+ "items": {
36
+ "type": "string"
37
+ }
38
+ },
39
+ "locale": {
40
+ "type": "string",
41
+ "maxLength": 8
42
+ },
43
+ "profileErrors": {
44
+ "type": "string"
45
+ }
46
+ },
47
+ "required": [
48
+ "name",
49
+ "active"
50
+ ]
86
51
  }
@@ -0,0 +1,48 @@
1
+ {
2
+ "type": "object",
3
+ "x-documentConfig": {
4
+ "methods": [
5
+ "get",
6
+ "getList",
7
+ "post",
8
+ "patch",
9
+ "delete"
10
+ ],
11
+ "documentName": "UserAuthProfiles"
12
+ },
13
+ "properties": {
14
+ "_id": {
15
+ "type": "string",
16
+ "x-format": "PrimaryUUID",
17
+ "index": true
18
+ },
19
+ "userId": {
20
+ "type": "string",
21
+ "x-format": "UUID",
22
+ "index": true,
23
+ "x-foreignKey": {
24
+ "schemaName": "User",
25
+ "fieldName": "_id",
26
+ "relationType": "one-to-many"
27
+ }
28
+ },
29
+ "provider": {
30
+ "type": "string",
31
+ "index": true
32
+ },
33
+ "oauthId": {
34
+ "type": "string",
35
+ "index": true
36
+ },
37
+ "email": {
38
+ "type": "string"
39
+ },
40
+ "username": {
41
+ "type": "string"
42
+ },
43
+ "password": {
44
+ "type": "string",
45
+ "x-hidden": true
46
+ }
47
+ }
48
+ }
@@ -1,20 +1,20 @@
1
- # Use the official Node.js image as the base image
2
- FROM node:14
3
-
4
- # Set the working directory inside the container
5
- WORKDIR /app
6
-
7
- # Copy package.json and package-lock.json to the working directory
8
- COPY package*.json ./
9
-
10
- # Install dependencies
11
- RUN npm install
12
-
13
- # Copy only the /dist directory to the working directory
14
- COPY dist ./dist
15
-
16
- # Expose the port the app runs on
17
- EXPOSE 3000
18
-
19
- # Define the command to run the application
1
+ # Use the official Node.js image as the base image
2
+ FROM node:14
3
+
4
+ # Set the working directory inside the container
5
+ WORKDIR /app
6
+
7
+ # Copy package.json and package-lock.json to the working directory
8
+ COPY package*.json ./
9
+
10
+ # Install dependencies
11
+ RUN npm install
12
+
13
+ # Copy only the /dist directory to the working directory
14
+ COPY dist ./dist
15
+
16
+ # Expose the port the app runs on
17
+ EXPOSE 3000
18
+
19
+ # Define the command to run the application
20
20
  CMD ["npm", "start"]
@@ -1,39 +1,39 @@
1
- # This app is generated by [VeryExpress](https://github.com/Justin26l/VeryExpress)
2
-
3
-
4
- # Quick Start
5
- 1. install `very-express` from npm
6
- `npm install -g very-express` or `npm update -g very-express`
7
-
8
- 2. check configuration file [vex.config.json](./vex.config.json) under project root directory and keep it updated (re-generate the app with very-express).
9
- `vex`
10
-
11
- 3. we should have a express typescript app.
12
- ```
13
- ├── src/
14
- │ └── openapi
15
- │ └── roles (role based access control settings)
16
- │ └── system (very express generated app)
17
- ├── package.json
18
- ├── tsconfig.json
19
- ├── vex.config.json
20
- ├── .env
21
- └── ...
22
- ```
23
-
24
- 4. start the generated express app.
25
- ```
26
- npm i
27
- npm build
28
- npm run start
29
- ```
30
-
31
- 5. start the app in docker.
32
- ```
33
- npm run docker-build
34
- npm run docker-start
35
- ```
36
-
37
- # Resource
38
- - [Documents](https://github.com/Justin26l/VeryExpress/blob/main/README.md)
1
+ # This app is generated by [VeryExpress](https://github.com/Justin26l/VeryExpress)
2
+
3
+
4
+ # Quick Start
5
+ 1. install `very-express` from npm
6
+ `npm install -g very-express` or `npm update -g very-express`
7
+
8
+ 2. check configuration file [vex.config.json](./vex.config.json) under project root directory and keep it updated (re-generate the app with very-express).
9
+ `vex`
10
+
11
+ 3. we should have a express typescript app.
12
+ ```
13
+ ├── src/
14
+ │ └── openapi
15
+ │ └── roles (role based access control settings)
16
+ │ └── system (very express generated app)
17
+ ├── package.json
18
+ ├── tsconfig.json
19
+ ├── vex.config.json
20
+ ├── .env
21
+ └── ...
22
+ ```
23
+
24
+ 4. start the generated express app.
25
+ ```
26
+ npm i
27
+ npm build
28
+ npm run start
29
+ ```
30
+
31
+ 5. start the app in docker.
32
+ ```
33
+ npm run docker-build
34
+ npm run docker-start
35
+ ```
36
+
37
+ # Resource
38
+ - [Documents](https://github.com/Justin26l/VeryExpress/blob/main/README.md)
39
39
  - [VeryExpress Discord](https://discord.gg/PZGMzDp7)
@@ -1,8 +1,8 @@
1
-
2
- pre {
3
- background-color: #f4f4f4;
4
- padding: 20px;
5
- overflow: auto;
6
- border: 1px solid #ccc;
7
- white-space: pre-wrap;
1
+
2
+ pre {
3
+ background-color: #f4f4f4;
4
+ padding: 20px;
5
+ overflow: auto;
6
+ border: 1px solid #ccc;
7
+ white-space: pre-wrap;
8
8
  }
@@ -1,59 +1,59 @@
1
-
2
- document.addEventListener("DOMContentLoaded", function() {
3
- // add event listener to login button
4
- document.querySelector("#localLoginBtn").addEventListener("click", function() {
5
- // call api /auth/local
6
- fetch("/auth/local", {
7
- method: "POST",
8
- headers: {
9
- "Content-Type": "application/json"
10
- },
11
- body: JSON.stringify({
12
- email: document.querySelector("#email").value,
13
- password: document.querySelector("#password").value
14
- })
15
- })
16
- .then(async (res) => {
17
- if(res.status === 302) {
18
- const data = await res.json();
19
- if(data.result?.url){
20
- window.location.href = data.result?.url;
21
- }
22
- else {
23
- alert("Login successful, but no redirect URL provided.");
24
- };
25
- }
26
- else {
27
- const data = await res.json();
28
- alert("Login failed: " + data.message);
29
- }
30
- })
31
- .catch((err) => {
32
- console.error("Error during login:", err);
33
- alert("An error occurred during login. Please try again later.");
34
- });
35
- });
36
-
37
- document.querySelector("#localRegisterBtn").addEventListener("click", function() {
38
- // call api /auth/local
39
- fetch("/auth/register", {
40
- method: "POST",
41
- headers: {
42
- "Content-Type": "application/json"
43
- },
44
- body: JSON.stringify({
45
- email: document.querySelector("#email").value,
46
- password: document.querySelector("#password").value
47
- })
48
- })
49
- .then(async (res) => {
50
- if(res.status === 201) {
51
- alert("Registration successful. You can now log in.");
52
- }
53
- })
54
- .catch((err) => {
55
- console.error("Error during registration:", err);
56
- alert("An error occurred during registration. Please try again later.");
57
- });
58
- });
1
+
2
+ document.addEventListener("DOMContentLoaded", function () {
3
+ // add event listener to login button
4
+ document.querySelector("#localLoginBtn").addEventListener("click", function () {
5
+ // call api /auth/local
6
+ fetch("/api/auth/local", {
7
+ method: "POST",
8
+ headers: {
9
+ "Content-Type": "application/json"
10
+ },
11
+ body: JSON.stringify({
12
+ email: document.querySelector("#email").value,
13
+ password: document.querySelector("#password").value
14
+ })
15
+ })
16
+ .then(async (res) => {
17
+ if (res.status === 301 || res.status === 302) {
18
+ const data = await res.json();
19
+ if (data.result?.url) {
20
+ window.location.href = data.result?.url;
21
+ }
22
+ else {
23
+ alert("Login successful, but no redirect URL provided.");
24
+ }
25
+ }
26
+ else {
27
+ const data = await res.json();
28
+ alert("Login Failed: " + data.message);
29
+ }
30
+ })
31
+ .catch((err) => {
32
+ console.error("Error during login:", err);
33
+ alert("Login Error: " + err.message);
34
+ });
35
+ });
36
+
37
+ document.querySelector("#localRegisterBtn").addEventListener("click", function () {
38
+ // call api /auth/register
39
+ fetch("/api/auth/register", {
40
+ method: "POST",
41
+ headers: {
42
+ "Content-Type": "application/json"
43
+ },
44
+ body: JSON.stringify({
45
+ email: document.querySelector("#email").value,
46
+ password: document.querySelector("#password").value
47
+ })
48
+ })
49
+ .then(async (res) => {
50
+ if (res.status === 201) {
51
+ alert("Registration successful. You can now log in.");
52
+ }
53
+ })
54
+ .catch((err) => {
55
+ console.error("Error during registration:", err);
56
+ alert("An error occurred during registration. Please try again later.");
57
+ });
58
+ });
59
59
  });
@@ -1,19 +1,19 @@
1
-
2
- document.addEventListener("DOMContentLoaded", function() {
3
- console.log('Exchange Tokens from /auth/token');
4
- let sessionCode = new URLSearchParams(location.search).get('code');
5
- fetch(
6
- '/auth/token?code=' + sessionCode, {
7
- method: 'POST'
8
- }
9
- )
10
- .then((res) => res.text())
11
- .then((data) => {
12
- const jsonData = JSON.parse(data);
13
- document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
14
- localStorage.setItem('accessToken', jsonData.result.accessToken);
15
- localStorage.setItem('accessTokenIndex', jsonData.result.accessTokenIndex);
16
- localStorage.setItem('refreshToken', jsonData.result.refreshToken);
17
- localStorage.setItem('refreshTokenIndex', jsonData.result.refreshTokenIndex);
18
- });
1
+
2
+ document.addEventListener("DOMContentLoaded", function() {
3
+ console.log('Exchange Tokens from /api/auth/token');
4
+ let sessionCode = new URLSearchParams(location.search).get('code');
5
+ fetch(
6
+ '/api/auth/token?code=' + sessionCode, {
7
+ method: 'POST'
8
+ }
9
+ )
10
+ .then((res) => res.text())
11
+ .then((data) => {
12
+ const jsonData = JSON.parse(data);
13
+ document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
14
+ localStorage.setItem('accessToken', jsonData.result.accessToken);
15
+ localStorage.setItem('accessTokenIndex', jsonData.result.accessTokenIndex);
16
+ localStorage.setItem('refreshToken', jsonData.result.refreshToken);
17
+ localStorage.setItem('refreshTokenIndex', jsonData.result.refreshTokenIndex);
18
+ });
19
19
  });
@@ -1,11 +1,11 @@
1
- let jsonData = {};
2
-
3
- document.addEventListener("DOMContentLoaded", function () {
4
- jsonData = {
5
- accessToken: localStorage.getItem("accessToken"),
6
- accessTokenIndex: localStorage.getItem("accessTokenIndex"),
7
- refreshToken: localStorage.getItem("refreshToken"),
8
- refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
9
- };
10
- document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
1
+ let jsonData = {};
2
+
3
+ document.addEventListener("DOMContentLoaded", function () {
4
+ jsonData = {
5
+ accessToken: localStorage.getItem("accessToken"),
6
+ accessTokenIndex: localStorage.getItem("accessTokenIndex"),
7
+ refreshToken: localStorage.getItem("refreshToken"),
8
+ refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
9
+ };
10
+ document.querySelector("#tokenData").innerHTML = JSON.stringify(jsonData, null, 2);
11
11
  });
@@ -1,23 +1,23 @@
1
- document.addEventListener("DOMContentLoaded", function () {
2
- jsonPayload = {
3
- refreshToken: localStorage.getItem("refreshToken"),
4
- refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
5
- };
6
-
7
- fetch("/auth/refresh", {
8
- method: "POST",
9
- body: JSON.stringify(jsonPayload),
10
- headers: {
11
- "Content-Type": "application/json",
12
- "Accept": "application/json",
13
- "Authorization": "Bearer " + localStorage.getItem("accessToken"),
14
- "X-Auth-Index": localStorage.getItem("accessTokenIndex")
15
- }
16
- })
17
- .then(res => res.json())
18
- .then((response) => {
19
- localStorage.setItem("accessToken", response.accessToken);
20
- localStorage.setItem("accessTokenIndex", response.accessTokenIndex);
21
- document.querySelector("#tokenData").innerHTML = JSON.stringify(response, null, 2);
22
- });
1
+ document.addEventListener("DOMContentLoaded", function () {
2
+ jsonPayload = {
3
+ refreshToken: localStorage.getItem("refreshToken"),
4
+ refreshTokenIndex: localStorage.getItem("refreshTokenIndex"),
5
+ };
6
+
7
+ fetch("/api/auth/refresh", {
8
+ method: "POST",
9
+ body: JSON.stringify(jsonPayload),
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ "Accept": "application/json",
13
+ "Authorization": "Bearer " + localStorage.getItem("accessToken"),
14
+ "X-Auth-Index": localStorage.getItem("accessTokenIndex")
15
+ }
16
+ })
17
+ .then(res => res.json())
18
+ .then((response) => {
19
+ localStorage.setItem("accessToken", response.accessToken);
20
+ localStorage.setItem("accessTokenIndex", response.accessTokenIndex);
21
+ document.querySelector("#tokenData").innerHTML = JSON.stringify(response, null, 2);
22
+ });
23
23
  });
@@ -1,39 +1,39 @@
1
- // copy openapiDir to tsconfig's outDir
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
-
6
- async function loadStripJsonComments() {
7
- const { default: stripJsonComments } = await import('strip-json-comments');
8
- return stripJsonComments;
9
- }
10
-
11
- async function main() {
12
- // Load strip-json-comments dynamically
13
- const stripJsonComments = await loadStripJsonComments();
14
-
15
- const openapiDir = "{{openapiDir}}";
16
- const tsconfigPath = "tsconfig.json"
17
-
18
- // 1. read tsconfig.json to get outDir
19
- const tsconfigContent = fs.readFileSync(tsconfigPath, 'utf-8');
20
- const tsconfig = JSON.parse(stripJsonComments(tsconfigContent));
21
- const outDir = tsconfig.compilerOptions.outDir;
22
-
23
- // 2. copy ./openapi to outDir
24
- const outDirOpenapi = path.resolve(outDir, 'openapi');
25
- if (!fs.existsSync(outDirOpenapi)) {
26
- fs.mkdirSync(outDirOpenapi, { recursive: true });
27
- }
28
- fs.readdirSync(openapiDir).forEach((file) => {
29
- fs.copyFileSync(path.resolve(openapiDir, file), path.resolve(outDirOpenapi, file));
30
- });
31
- }
32
-
33
-
34
- // Execute the main function
35
- main()
36
- .catch(err => {
37
- console.error(err);
38
- process.exit(1);
1
+ // copy openapiDir to tsconfig's outDir
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ async function loadStripJsonComments() {
7
+ const { default: stripJsonComments } = await import('strip-json-comments');
8
+ return stripJsonComments;
9
+ }
10
+
11
+ async function main() {
12
+ // Load strip-json-comments dynamically
13
+ const stripJsonComments = await loadStripJsonComments();
14
+
15
+ const openapiDir = "{{openapiDir}}";
16
+ const tsconfigPath = "tsconfig.json"
17
+
18
+ // 1. read tsconfig.json to get outDir
19
+ const tsconfigContent = fs.readFileSync(tsconfigPath, 'utf-8');
20
+ const tsconfig = JSON.parse(stripJsonComments(tsconfigContent));
21
+ const outDir = tsconfig.compilerOptions.outDir;
22
+
23
+ // 2. copy ./openapi to outDir
24
+ const outDirOpenapi = path.resolve(outDir, 'openapi');
25
+ if (!fs.existsSync(outDirOpenapi)) {
26
+ fs.mkdirSync(outDirOpenapi, { recursive: true });
27
+ }
28
+ fs.readdirSync(openapiDir).forEach((file) => {
29
+ fs.copyFileSync(path.resolve(openapiDir, file), path.resolve(outDirOpenapi, file));
30
+ });
31
+ }
32
+
33
+
34
+ // Execute the main function
35
+ main()
36
+ .catch(err => {
37
+ console.error(err);
38
+ process.exit(1);
39
39
  });