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,10 +1,14 @@
1
1
  // {{headerComment}}
2
- export class _ControllerFactory {
2
+ import { Controller } from "tsoa";
3
3
 
4
- constructor() {}
4
+ export class _ControllerFactory extends Controller {
5
+
6
+ constructor() {
7
+ super();
8
+ }
5
9
 
6
10
  protected isObjectId(id: string): boolean {
7
11
  return /^[0-9a-fA-F]{24}$/.test(id);
8
12
  }
9
-
13
+
10
14
  }
@@ -12,7 +12,7 @@ export default class Authentication {
12
12
  public middleware = (req: Request, res: Response, next: NextFunction) => {
13
13
  try {
14
14
  // gate keeper
15
- log.info("Authentication.middleware", req.headers["x-auth-index"], req.headers.authorization);
15
+ // log.info("Authentication.middleware", req.headers["x-auth-index"], req.headers.authorization);
16
16
  const token = req.headers.authorization?.split(" ")[1];
17
17
  const accessTokenIndex = req.headers["x-auth-index"]?.toString();
18
18
 
@@ -26,9 +26,6 @@ export default class Authentication {
26
26
 
27
27
  // verify token
28
28
  const tokenData = this.JWTService.verifyToken(token, accessTokenIndex);
29
-
30
- // set req.user to the decoded token
31
- log.info("tokenValid", tokenData);
32
29
  req.user = tokenData;
33
30
  next();
34
31
  }
@@ -40,7 +37,6 @@ export default class Authentication {
40
37
  response.send(res, 400, { message: e?.message});
41
38
  }
42
39
  else {
43
- log.errorNoExit(e);
44
40
  response.send(res, 500, { message: e?.message});
45
41
  }
46
42
  }
@@ -0,0 +1,24 @@
1
+ // {{headerComment}}
2
+ import { Request } from "express";
3
+ import VexResponseError from "../_types/VexResponseError.gen";
4
+
5
+ /**
6
+ * Called by tsoa-generated routes for every @Security decorator.
7
+ * securityName matches the key in tsoa.json securityDefinitions.
8
+ */
9
+ export async function expressAuthentication(
10
+ request: Request,
11
+ securityName: string,
12
+ _scopes?: string[]
13
+ ): Promise<unknown> {
14
+
15
+ if (securityName === "BearerAuth" && !request.headers["authorization"]) {
16
+ throw new VexResponseError(401, null, "Missing Authorization header");
17
+ }
18
+
19
+ if (securityName === "AuthIndex" && !request.headers["x-auth-index"]) {
20
+ throw new VexResponseError(401, null, "Missing X-Auth-Index header");
21
+ }
22
+
23
+ return {};
24
+ }
@@ -1,25 +1,26 @@
1
- APP_HOST=http://localhost
2
- APP_PORT=3000
3
- MONGODB_URI=mongodb://localhost:27017/veryExpressDB
4
- SQL_URI=postgresql://username:password@localhost:5432/mydatabase
5
- SQL_CA=""
6
-
7
- LOGIN_SUCCESS_REDIRECT_PATH=/logincallback
8
- LOGIN_FAILED_REDIRECT_PATH=/logincallback
9
-
10
- # OAUTH
11
- OAUTH_GOOGLE_CLIENTID=
12
- OAUTH_GOOGLE_CLIENTSECRET=
13
- OAUTH_GITHUB_CLIENTID=
14
- OAUTH_GITHUB_CLIENTSECRET=
15
- # OAUTH_MICROSOFT_CLIENTID=
16
- # OAUTH_MICROSOFT_CLIENTSECRET=
17
- # OAUTH_APPLE_CLIENTID=
18
- # OAUTH_APPLE_CLIENTSECRET=
19
-
20
- # JWT token
21
- ACCESS_TOKEN_EXPIRE_TIME='5m'
22
- REFRESH_TOKEN_EXPIRE_TIME='15m'
23
- SESSION_COOKIE_SECRET='my-session-cookie-secret'
24
- JWT_ALGORITHM='HS256'
1
+ APP_HOST=http://localhost
2
+ APP_PORT=3000
3
+ MONGODB_URI=mongodb://localhost:27017/veryExpressDB
4
+ SQL_URI=postgresql://username:password@localhost:5432/mydatabase
5
+ SQL_CA=""
6
+ SQL_SYNCHRONIZE=true
7
+
8
+ LOGIN_SUCCESS_REDIRECT_PATH=/logincallback
9
+ LOGIN_FAILED_REDIRECT_PATH=/logincallback
10
+
11
+ # OAUTH
12
+ OAUTH_GOOGLE_CLIENTID=
13
+ OAUTH_GOOGLE_CLIENTSECRET=
14
+ OAUTH_GITHUB_CLIENTID=
15
+ OAUTH_GITHUB_CLIENTSECRET=
16
+ # OAUTH_MICROSOFT_CLIENTID=
17
+ # OAUTH_MICROSOFT_CLIENTSECRET=
18
+ # OAUTH_APPLE_CLIENTID=
19
+ # OAUTH_APPLE_CLIENTSECRET=
20
+
21
+ # JWT token
22
+ ACCESS_TOKEN_EXPIRE_TIME='5m'
23
+ REFRESH_TOKEN_EXPIRE_TIME='15m'
24
+ SESSION_COOKIE_SECRET='my-session-cookie-secret'
25
+ JWT_ALGORITHM='HS256'
25
26
  JWT_SECRET0='my-secret-key0'
@@ -1,54 +1,50 @@
1
- {
2
- "main": "index.js",
3
- "scripts": {
4
- "build": "tsc -p . && node scripts/build.js",
5
- "start": "node dist/server.js",
6
- "dev": "nodemon --watch src --exec ts-node src/server.ts",
7
- "docker-build": "docker build -t very-express .",
8
- "docker-start": "docker run -p 3000:3000 very-express"
9
- },
10
- "dependencies": {
11
- "@types/pg": "^8.20.0",
12
- "cookie": "^0.6.0",
13
- "cookie-parser": "^1.4.6",
14
- "dotenv": "^16.4.4",
15
- "express": "^4.18.2",
16
- "express-validator": "^7.0.1",
17
- "helmet": "^7.1.0",
18
- "js-yaml": "^4.1.0",
19
- "jsonwebtoken": "^9.0.2",
20
- "knex": "^3.2.9",
21
- "mongo-ts-querystring": "^1.0.4",
22
- "mongodb": "^5.6.0",
23
- "mongoose": "^7.4.0",
24
- "mysql2": "^3.22.0",
25
- "passport": "^0.7.0",
26
- "passport-github": "^1.1.0",
27
- "passport-google-oauth20": "^2.0.0",
28
- "passport-jwt": "^4.0.1",
29
- "pg": "^8.20.0",
30
- "swagger-ui-express": "^5.0.0"
31
- },
32
- "devDependencies": {
33
- "@types/cookie-parser": "^1.4.7",
34
- "@types/crypto-js": "^4.1.2",
35
- "@types/dotenv": "^8.2.0",
36
- "@types/express": "^4.17.17",
37
- "@types/express-validator": "^3.0.0",
38
- "@types/js-yaml": "^4.0.9",
39
- "@types/jsonwebtoken": "^9.0.7",
40
- "@types/mongodb": "^4.0.7",
41
- "@types/ms": "^2.1.0",
42
- "@types/node": "^20.4.2",
43
- "@types/passport": "^1.0.16",
44
- "@types/passport-github": "^1.1.12",
45
- "@types/passport-google-oauth20": "^2.0.14",
46
- "@types/sequelize": "^4.28.15",
47
- "@types/swagger-ui-express": "^4.1.6",
48
- "@types/ws": "^8.5.5",
49
- "nodemon": "^2.0.22",
50
- "strip-json-comments": "^5.0.1",
51
- "ts-node": "^10.9.1",
52
- "typescript": "^5.1.6"
53
- }
54
- }
1
+ {
2
+ "main": "index.js",
3
+ "scripts": {
4
+ "build": "npm run openapi && tsc -p . && node scripts/build.js",
5
+ "start": "node dist/server.js",
6
+ "dev": "nodemon --watch src --ext ts --ignore src/system/_routes/tsoa_routes.ts --ignore src/openapi/ --exec \"tsoa spec-and-routes && ts-node src/server.ts\"",
7
+ "openapi": "tsoa spec-and-routes",
8
+ "docker-build": "docker build -t very-express .",
9
+ "docker-start": "docker run -p 3000:3000 very-express"
10
+ },
11
+ "dependencies": {
12
+ "cookie": "^0.6.0",
13
+ "cookie-parser": "^1.4.6",
14
+ "dotenv": "^16.4.4",
15
+ "express": "^4.18.2",
16
+ "helmet": "^7.1.0",
17
+ "js-yaml": "^4.1.0",
18
+ "jsonwebtoken": "^9.0.2",
19
+ "passport": "^0.7.0",
20
+ "passport-github": "^1.1.0",
21
+ "passport-google-oauth20": "^2.0.0",
22
+ "passport-jwt": "^4.0.1",
23
+ "pg": "^8.20.0",
24
+ "reflect-metadata": "^0.2.2",
25
+ "swagger-ui-express": "^5.0.0",
26
+ "tsoa": "^7.0.0-alpha.0",
27
+ "typeorm": "^0.3.20"
28
+ },
29
+ "devDependencies": {
30
+ "@types/cookie-parser": "^1.4.7",
31
+ "@types/crypto-js": "^4.1.2",
32
+ "@types/dotenv": "^8.2.0",
33
+ "@types/express": "^4.17.17",
34
+ "@types/js-yaml": "^4.0.9",
35
+ "@types/jsonwebtoken": "^9.0.7",
36
+ "@types/mongodb": "^4.0.7",
37
+ "@types/ms": "^2.1.0",
38
+ "@types/node": "^20.4.2",
39
+ "@types/passport": "^1.0.16",
40
+ "@types/passport-github": "^1.1.12",
41
+ "@types/passport-google-oauth20": "^2.0.14",
42
+ "@types/pg": "^8.11.0",
43
+ "@types/swagger-ui-express": "^4.1.6",
44
+ "@types/ws": "^8.5.5",
45
+ "nodemon": "^2.0.22",
46
+ "strip-json-comments": "^5.0.1",
47
+ "ts-node": "^10.9.1",
48
+ "typescript": "^5.1.6"
49
+ }
50
+ }
@@ -0,0 +1,48 @@
1
+ // {{headerComment}}
2
+ import { Model, Document, FilterQuery } from "mongoose";
3
+ import { IVexRepository } from "../_types/IVexRepository.gen";
4
+ import { Select, Filter, Join } from "../_types/VexRequest.gen";
5
+
6
+ export class MongooseRepositoryAdapter<T extends Document> implements IVexRepository<T> {
7
+ constructor(private model: Model<T>) {}
8
+
9
+ public get native(): Model<T> {
10
+ return this.model;
11
+ }
12
+
13
+ find(filter: Filter, join?: Join, select?: Select): Promise<T[]> {
14
+ // TODO: handle join and select
15
+ return this.model.find((filter || {}) as FilterQuery<T>).exec();
16
+ }
17
+
18
+ findOne(filter: Filter, join?: Join, select?: Select): Promise<T | null> {
19
+ // TODO: handle join and select
20
+ return this.model.findOne(filter as FilterQuery<T>).exec();
21
+ }
22
+
23
+ findOneWhere(filter: Filter, join?: Join, select?: Select): Promise<T | null> {
24
+ // TODO: handle join and select
25
+ return this.model.findOne(filter as FilterQuery<T>).exec();
26
+ }
27
+
28
+ async create(data: Partial<T>): Promise<T> {
29
+ const doc = new this.model(data);
30
+ return doc.save();
31
+ }
32
+
33
+ replace(id: string | number, data: Partial<T>): Promise<T | null> {
34
+ return this.model.findByIdAndUpdate(id, data, { new: true, overwrite: true }).exec();
35
+ }
36
+
37
+ update(id: string | number, data: Partial<T>): Promise<T | null> {
38
+ return this.model.findByIdAndUpdate(id, { $set: data }, { new: true }).exec();
39
+ }
40
+
41
+ async delete(id: string | number): Promise<void> {
42
+ await this.model.findByIdAndDelete(id).exec();
43
+ }
44
+
45
+ async deleteWhere(filter: Record<string, unknown>): Promise<void> {
46
+ await this.model.deleteOne(filter as FilterQuery<T>).exec();
47
+ }
48
+ }
@@ -0,0 +1,59 @@
1
+ // {{headerComment}}
2
+ import { Repository, ObjectLiteral, FindOptionsWhere, DeepPartial } from "typeorm";
3
+ import { IVexRepository } from "../_types/IVexRepository.gen";
4
+ import { Select, Filter, Join } from "../_types/VexRequest.gen";
5
+
6
+ export class TypeOrmRepositoryAdapter<T extends ObjectLiteral> implements IVexRepository<T> {
7
+ constructor(private repo: Repository<T>) {}
8
+
9
+ public get native(): Repository<T> {
10
+ return this.repo;
11
+ }
12
+
13
+ find(filter: Filter, join?: Join, select?: Select): Promise<T[]> {
14
+ return this.repo.find({
15
+ select,
16
+ where: filter as FindOptionsWhere<T>,
17
+ relations: join
18
+ });
19
+ }
20
+
21
+ findOne(filter: Filter, join?: Join, select?: Select): Promise<T | null> {
22
+ return this.repo.findOne({
23
+ select,
24
+ where: filter as FindOptionsWhere<T>,
25
+ relations: join
26
+ });
27
+ }
28
+
29
+ findOneWhere(filter: Filter, join?: Join, select?: Select): Promise<T | null> {
30
+ return this.repo.findOne({
31
+ select,
32
+ where: filter as FindOptionsWhere<T>,
33
+ relations: join
34
+ });
35
+ }
36
+
37
+ async create(data: Partial<T>): Promise<T> {
38
+ return this.repo.save(this.repo.create(data as DeepPartial<T>));
39
+ }
40
+
41
+ async replace(id: string | number, data: Partial<T>): Promise<T | null> {
42
+ const existing = await this.findOne({ _id: id });
43
+ if (!existing) return null;
44
+ return this.repo.save(this.repo.merge(existing, data as DeepPartial<T>));
45
+ }
46
+
47
+ async update(id: string | number, data: Partial<T>): Promise<T | null> {
48
+ await this.repo.update({ _id: id } as unknown as FindOptionsWhere<T>, data as any);
49
+ return this.findOne({ _id: id });
50
+ }
51
+
52
+ async delete(id: string | number): Promise<void> {
53
+ await this.repo.delete({ _id: id } as unknown as FindOptionsWhere<T>);
54
+ }
55
+
56
+ async deleteWhere(filter: Record<string, unknown>): Promise<void> {
57
+ await this.repo.delete(filter as FindOptionsWhere<T>);
58
+ }
59
+ }
@@ -0,0 +1,14 @@
1
+ // {{headerComment}}
2
+ import { VexDbConnector } from "./VexDbConnector.gen";
3
+ import dotenv from "dotenv";
4
+
5
+ dotenv.config();
6
+
7
+ const VexDb = new VexDbConnector({
8
+ sqlUrl: process.env.SQL_URI ?? undefined,
9
+ sqlCa: process.env.SQL_CA ?? undefined,
10
+ mongoUrl: process.env.MONGO_URI ?? undefined,
11
+ recordAccessLog: false,
12
+ });
13
+
14
+ export default VexDb;