very-express 0.4.14 → 0.5.1

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 (38) hide show
  1. package/dist/index.js +702 -524
  2. package/dist/templates/_middlewares/Authentication.ts +45 -0
  3. package/dist/templates/_plugins/auth/JWTKeyStore.ts +71 -0
  4. package/dist/templates/_plugins/auth/jwt.ts +57 -0
  5. package/dist/templates/_plugins/auth/oauthVerify.ts +83 -0
  6. package/dist/templates/_plugins/auth/profileMapping.ts +69 -0
  7. package/dist/templates/_plugins/auth/token.ts +25 -0
  8. package/dist/templates/_roles/_RoleFactory.ts +2 -2
  9. package/dist/templates/_routes/oauth/OAuthRouteFactory.ts +88 -0
  10. package/dist/templates/_services/VexDbConnector.ts +20 -3
  11. package/dist/templates/_types/response/index.ts +10 -0
  12. package/dist/templates/_types/response/responseCode.ts +13 -0
  13. package/dist/templates/_types/response/responseMsg.ts +23 -0
  14. package/dist/templates/_types/response/responseStatusToCode.ts +70 -0
  15. package/dist/templates/_utils/common.ts +39 -3
  16. package/dist/templates/_utils/index.ts +6 -2
  17. package/dist/templates/_utils/logger.ts +5 -5
  18. package/dist/templates/_utils/processTimer.ts +6 -0
  19. package/dist/templates/_utils/response.ts +25 -11
  20. package/dist/templates/jsonSchema/User.json +41 -14
  21. package/dist/templates/root/.env +10 -1
  22. package/dist/templates/root/Dockerfile +20 -0
  23. package/dist/templates/root/README.md +5 -0
  24. package/dist/templates/root/package.json +13 -4
  25. package/dist/templates/root/scripts/build.js +39 -0
  26. package/docs/ForeignKey.md +40 -0
  27. package/docs/releaseNote/v0-5-0.md +18 -0
  28. package/docs/roadMap/v0-6-0.md +9 -1
  29. package/docs/roadMap/v0-7-0.md +3 -2
  30. package/docs/vexJsonSchema.md +5 -4
  31. package/package.json +4 -14
  32. package/scripts/copyTsTemplates.js +6 -0
  33. package/vex.config.json +4 -6
  34. package/dist/templates/_plugins/PassportGoogle.ts +0 -84
  35. package/dist/templates/_plugins/oauthVerify.ts +0 -39
  36. package/dist/templates/_types/responseMsg.ts +0 -20
  37. package/docs/roadMap/v0-5-0.md +0 -20
  38. /package/.github/workflows/{npm-publish.yml → npm-start.yml} +0 -0
@@ -1,84 +0,0 @@
1
- // {{headerComment}}
2
-
3
- import { Router } from "express";
4
- import passport, { PassportStatic, Profile } from "passport";
5
- import { AuthenticateOptionsGoogle, Strategy as GoogleStrategy, StrategyOptions, VerifyCallback } from "passport-google-oauth20";
6
- import { UserModel } from "./../_models/UserModel.gen";
7
-
8
- export type { Profile };
9
-
10
- export interface passportGoogleConfig {
11
- strategyConfig: {
12
- options?: StrategyOptions,
13
- verify: (accessToken: string, refreshToken: string, profile: Profile, done: VerifyCallback) => void
14
- },
15
- authenticateOptionsGoogle?: AuthenticateOptionsGoogle,
16
- }
17
-
18
- /** Provides a router and passport instance for Google OAuth */
19
- export default class PassportGoogle {
20
-
21
- private config: passportGoogleConfig;
22
- public router: Router = Router();
23
- public passport: PassportStatic = passport;
24
-
25
- constructor(config: passportGoogleConfig ) {
26
-
27
- this.config = config;
28
-
29
- this.passport.use(new GoogleStrategy(
30
- this.config.strategyConfig.options || {
31
- clientID: process.env.OAUTH_GOOGLE_CLIENTID || "",
32
- clientSecret: process.env.OAUTH_GOOGLE_CLIENTSECRET || "",
33
- callbackURL: `${process.env.APP_HOST}/auth/google/callback`,
34
- },
35
- this.config.strategyConfig.verify
36
- ));
37
-
38
- // redirect to google login
39
- this.router.get("/auth/google",
40
- this.passport.authenticate("google", this.config.authenticateOptionsGoogle || { scope: ["profile", "email"] })
41
- );
42
-
43
- // back from google login
44
- this.router.get("/auth/google/callback",
45
- this.passport.authenticate("google", { failureRedirect: "/login" }),
46
- (req, res) => {
47
- res.redirect("/profile");
48
- }
49
- );
50
- }
51
-
52
- public passportSerializeUser() {
53
- this.passport.serializeUser(async (user, done) => {
54
- // you can decide what data to store in the session here.
55
- // this data will be used in `deserializeUser` to retrieve the full user object.
56
- // ussually just user's id.
57
-
58
- // store role in session for access control
59
- const DbUser = await UserModel.findById(user);
60
- if (DbUser) {
61
- done(null, DbUser);
62
- } else {
63
- done(new Error("User not found"));
64
- }
65
-
66
- done(null, user);
67
- });
68
- }
69
-
70
- public async passportDeserializeUser() {
71
- this.passport.deserializeUser(async (id, done) => {
72
-
73
- const user = await UserModel.findById(id);
74
- if (user) {
75
- done(null, user);
76
- }
77
- else {
78
- done(new Error("User not found"));
79
- }
80
-
81
- });
82
- }
83
-
84
- }
@@ -1,39 +0,0 @@
1
- // {{headerComment}}
2
-
3
- import { Profile } from "passport";
4
- import { UserModel } from "./../_models/UserModel.gen";
5
-
6
- interface IProfile extends Profile {
7
- [key: string]: any;
8
- }
9
-
10
- export default async function oauthVerify(accessToken: string, refreshToken: string, profile: IProfile, done: (error: any, user?: any) => void) : Promise<void> {
11
- try {
12
-
13
- // find or create user
14
- const existingUser = await UserModel.findOne({ email: profile.emails?.[0].value });
15
-
16
- if( existingUser ){
17
- // log.info('OAuthVerify ExistingUser');
18
- return done(null, existingUser);
19
- }
20
- else {
21
- // log.info('OAuthVerify NewUser');
22
- const newUser = new UserModel({
23
- authProvider: profile.provider,
24
- email: profile.emails?.[0].value || "",
25
- authId: profile.id,
26
- name: profile.displayName,
27
- familyName: profile.name?.familyName,
28
- givenName: profile.name?.givenName,
29
- isActive: true,
30
- locale: profile._json?.locale,
31
- });
32
- newUser.save();
33
- return done(null, newUser);
34
- }
35
- }
36
- catch(err) {
37
- return done(err);
38
- }
39
- }
@@ -1,20 +0,0 @@
1
- export enum responseMsg {
2
- permissionDeny = "Permission Denied",
3
- ok = "OK",
4
- notFound = "Not Found",
5
- queryError = "Query Error",
6
- validateError = "Validation Error",
7
- unexpectedError = "Unexpected Error",
8
- createFail = "Create Fail",
9
- updateFail = "Update Fail",
10
- deleteFail = "Delete Fail",
11
- }
12
-
13
- export interface responseObject<T>{
14
- ret_code : number,
15
- ret_msg : string,
16
- ret_time?: number,
17
- result: T,
18
- }
19
-
20
- export default responseMsg;
@@ -1,20 +0,0 @@
1
- # v0.5.0 Plan
2
-
3
- ### App level foreign-key
4
- - [ ] at JsonSchmea properties item, add attribute `x-foreignKey: "collectionName"`
5
- use this column value to match with target collectionName's "_id" fields.
6
- ```JSON
7
- {
8
- "invoiceId": {
9
- "type" : "string",
10
- "x-foreignKey" : "invoice"
11
- },
12
- "orderId": {
13
- "type" : "string",
14
- "x-foreignKey" : "order"
15
- }
16
- }
17
- ```
18
- - [ ] REST API, to request data with foreign-key collection:
19
- add field name as stringified array into querystring "join"
20
- example `/myDataApi?join=[invoiceId,orderId]`