@diagramers/cli 1.0.24 → 1.0.25
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/dist/services/template-updater.d.ts +0 -1
- package/dist/services/template-updater.d.ts.map +1 -1
- package/dist/services/template-updater.js +2 -41
- package/dist/services/template-updater.js.map +1 -1
- package/package.json +1 -1
- package/templates/api/certs/auth-app-cert.json +0 -13
- package/templates/api/main.ts +0 -10
- package/templates/api/package.json +0 -70
- package/templates/api/src/assets/css/email-template.css +0 -8
- package/templates/api/src/assets/images/logo_large.png +0 -0
- package/templates/api/src/assets/keys/certificate.pem +0 -22
- package/templates/api/src/assets/keys/private-key.pem +0 -28
- package/templates/api/src/config/config-interface.ts +0 -191
- package/templates/api/src/config/development.ts +0 -145
- package/templates/api/src/config/index.ts +0 -59
- package/templates/api/src/config/production.ts +0 -145
- package/templates/api/src/config/staging.ts +0 -144
- package/templates/api/src/config/uat.ts +0 -144
- package/templates/api/src/controllers/account-controller.ts +0 -162
- package/templates/api/src/entities/audit.ts +0 -12
- package/templates/api/src/entities/base-entity.ts +0 -10
- package/templates/api/src/entities/user.ts +0 -71
- package/templates/api/src/helpers/FrameworkHelper.ts +0 -157
- package/templates/api/src/helpers/auth.ts +0 -971
- package/templates/api/src/helpers/cronHelper.ts +0 -170
- package/templates/api/src/helpers/dbcontext.ts +0 -83
- package/templates/api/src/helpers/encryptionHelper.ts +0 -76
- package/templates/api/src/helpers/enums.ts +0 -258
- package/templates/api/src/helpers/handle-response.ts +0 -49
- package/templates/api/src/helpers/httpHelper.ts +0 -75
- package/templates/api/src/helpers/mailer.ts +0 -152
- package/templates/api/src/helpers/result.ts +0 -47
- package/templates/api/src/helpers/string-helper.ts +0 -27
- package/templates/api/src/routes/account-routes.ts +0 -37
- package/templates/api/src/routes/auth-routes.ts +0 -286
- package/templates/api/src/routes/index.ts +0 -92
- package/templates/api/src/schemas/audit.ts +0 -36
- package/templates/api/src/schemas/otp.ts +0 -52
- package/templates/api/src/schemas/session.ts +0 -57
- package/templates/api/src/schemas/user.ts +0 -125
- package/templates/api/src/server/index.ts +0 -86
- package/templates/api/src/server/socket-server-provider.ts +0 -209
- package/templates/api/src/services/account-service.ts +0 -243
- package/templates/api/src/services/audit-service.ts +0 -56
- package/templates/api/tsconfig.json +0 -16
- package/templates/api/webpack.config.js +0 -66
@@ -1,243 +0,0 @@
|
|
1
|
-
import { ObjectId } from "bson";
|
2
|
-
import * as uuid from 'uuid4';
|
3
|
-
import dbcontext from "../helpers/dbcontext";
|
4
|
-
import { EncryptionHelper } from "../helpers/encryptionHelper";
|
5
|
-
import { AccountStatus, AuditMessageType, ResponseCode } from "../helpers/enums";
|
6
|
-
import { Result } from "../helpers/result";
|
7
|
-
import { UserEntity } from "../schemas/user";
|
8
|
-
import { frameworkHelper } from "../helpers/FrameworkHelper";
|
9
|
-
import { MailHelper } from "../helpers/mailer";
|
10
|
-
import { Config } from "../config";
|
11
|
-
import { AuthHelper } from "../helpers/auth";
|
12
|
-
|
13
|
-
export class AccountService {
|
14
|
-
encryptionHelper: EncryptionHelper;
|
15
|
-
authHelper: AuthHelper;
|
16
|
-
result: Result;
|
17
|
-
className = 'AccountService';
|
18
|
-
|
19
|
-
constructor(result: Result) {
|
20
|
-
this.result = result;
|
21
|
-
this.encryptionHelper = new EncryptionHelper();
|
22
|
-
this.authHelper = new AuthHelper(result);
|
23
|
-
}
|
24
|
-
|
25
|
-
async seedUser(): Promise<Result> {
|
26
|
-
try {
|
27
|
-
this.result.addMessage(AuditMessageType.info, this.className, 'SeedUser', 'Started');
|
28
|
-
const existingAdmin = await dbcontext.UserEntity.findOne({ email: 'admin@tactic.com' });
|
29
|
-
if (existingAdmin) {
|
30
|
-
this.result.Data = existingAdmin._id;
|
31
|
-
this.result.Status = ResponseCode.Ok;
|
32
|
-
return this.result;
|
33
|
-
}
|
34
|
-
const userEntity = new UserEntity({
|
35
|
-
_id: new ObjectId(),
|
36
|
-
email: 'admin@diagrammers.com',
|
37
|
-
username: 'admin@diagrammers.com',
|
38
|
-
name: 'Admin User',
|
39
|
-
emailVerified: true,
|
40
|
-
status: AccountStatus.Active,
|
41
|
-
hashedPassword: this.encryptionHelper.encryptUserLogin('Admin123!'),
|
42
|
-
userType: 'ADMIN',
|
43
|
-
invitationCode: frameworkHelper.generateRandomString(6),
|
44
|
-
identity: uuid()
|
45
|
-
});
|
46
|
-
const createdUser = await dbcontext.UserEntity.create(userEntity);
|
47
|
-
if (createdUser) {
|
48
|
-
this.result.Data = createdUser._id;
|
49
|
-
this.result.Status = ResponseCode.Ok;
|
50
|
-
} else {
|
51
|
-
this.result.Status = ResponseCode.Error;
|
52
|
-
this.result.Errors.push('Failed to seed admin user');
|
53
|
-
}
|
54
|
-
return this.result;
|
55
|
-
} catch (ex) {
|
56
|
-
this.result.addException(this.className, 'SeedUser', ex);
|
57
|
-
return new Result(null, ResponseCode.Error, [ex], [ex.message]);
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
async register(userVM: any): Promise<Result> {
|
62
|
-
try {
|
63
|
-
const userEntity = new UserEntity({
|
64
|
-
email: userVM.email.toLowerCase(),
|
65
|
-
name: userVM.name,
|
66
|
-
username: userVM.email,
|
67
|
-
emailVerified: false,
|
68
|
-
invitationCode: frameworkHelper.generateRandomString(6),
|
69
|
-
status: AccountStatus.PendingConfirmation,
|
70
|
-
hashedPassword: this.encryptionHelper.encryptUserLogin(userVM.password),
|
71
|
-
userType: "NOR",
|
72
|
-
identity: uuid()
|
73
|
-
});
|
74
|
-
const createdUser = await dbcontext.UserEntity.create(userEntity);
|
75
|
-
if (createdUser) {
|
76
|
-
this.result.Data = createdUser._id;
|
77
|
-
const emailView = MailHelper.GetEmailConfirmationTemplate(
|
78
|
-
userEntity.name,
|
79
|
-
`${Config.props.base_site_url}/otp?oobCode=${this.encryptionHelper.encryptUserLogin(userEntity.invitationCode)}&inviteEmail=${this.encryptionHelper.encryptUserLogin(userEntity.email)}&usrStat=${this.encryptionHelper.encryptUserLogin(userEntity.status)}`,
|
80
|
-
'Get Started'
|
81
|
-
);
|
82
|
-
await MailHelper.SendEmail(userVM.email, emailView, `Email Confirmation`);
|
83
|
-
this.result.Status = ResponseCode.Ok;
|
84
|
-
} else {
|
85
|
-
this.result.Status = ResponseCode.Error;
|
86
|
-
this.result.Errors.push('User could not be created');
|
87
|
-
}
|
88
|
-
return this.result;
|
89
|
-
} catch (ex) {
|
90
|
-
this.result.addException(this.className, 'Register', ex);
|
91
|
-
return new Result(null, ResponseCode.Error, [ex], [ex.message]);
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
async checkUserNameAvailability(username: string): Promise<Result> {
|
96
|
-
try {
|
97
|
-
const user = await dbcontext.UserEntity.findOne({ username });
|
98
|
-
if (!user) {
|
99
|
-
return new Result('', ResponseCode.NotExist);
|
100
|
-
} else {
|
101
|
-
return new Result(user._id, ResponseCode.Exist);
|
102
|
-
}
|
103
|
-
} catch (ex) {
|
104
|
-
return new Result(ex.message, ResponseCode.Error);
|
105
|
-
}
|
106
|
-
}
|
107
|
-
|
108
|
-
async confirmEmail(data: any): Promise<Result> {
|
109
|
-
try {
|
110
|
-
const email = this.encryptionHelper.decryptUserLogin(data.email);
|
111
|
-
const code = this.encryptionHelper.decryptUserLogin(data.code);
|
112
|
-
const user = await dbcontext.UserEntity.findOne({ email });
|
113
|
-
if (user && user.invitationCode === code) {
|
114
|
-
user.emailVerified = true;
|
115
|
-
user.status = AccountStatus.Active;
|
116
|
-
await user.save();
|
117
|
-
this.result.Data = user.email;
|
118
|
-
this.result.Status = ResponseCode.Ok;
|
119
|
-
} else {
|
120
|
-
this.result.Status = ResponseCode.Error;
|
121
|
-
this.result.Errors.push('Invalid email confirmation data');
|
122
|
-
}
|
123
|
-
return this.result;
|
124
|
-
} catch (ex) {
|
125
|
-
return new Result(null, ResponseCode.Error, [ex], [ex.message]);
|
126
|
-
}
|
127
|
-
}
|
128
|
-
|
129
|
-
async login(userLoginModel: any): Promise<Result> {
|
130
|
-
try {
|
131
|
-
const encryptedPassword = this.encryptionHelper.encryptUserLogin(userLoginModel.password);
|
132
|
-
const user = await dbcontext.UserEntity.findOne({ email: userLoginModel.email, hashedPassword: encryptedPassword });
|
133
|
-
if (user) {
|
134
|
-
this.result.Data = this.encryptionHelper.encryptUserLogin(JSON.stringify(user));
|
135
|
-
this.result.Status = ResponseCode.Ok;
|
136
|
-
} else {
|
137
|
-
this.result.Status = ResponseCode.Unauthorized;
|
138
|
-
this.result.Errors.push('Invalid login credentials');
|
139
|
-
}
|
140
|
-
return this.result;
|
141
|
-
} catch (ex) {
|
142
|
-
this.result.addException(this.className, 'Login', ex);
|
143
|
-
return this.result;
|
144
|
-
}
|
145
|
-
}
|
146
|
-
|
147
|
-
async getUserByEmail(email: string): Promise<Result> {
|
148
|
-
try {
|
149
|
-
const user = await dbcontext.UserEntity.findOne({ email });
|
150
|
-
if (user) {
|
151
|
-
this.result.Data = user;
|
152
|
-
this.result.Status = ResponseCode.Ok;
|
153
|
-
} else {
|
154
|
-
this.result.Status = ResponseCode.NotExist;
|
155
|
-
}
|
156
|
-
return this.result;
|
157
|
-
} catch (ex) {
|
158
|
-
this.result.addException(this.className, 'GetUserByEmail', ex);
|
159
|
-
return this.result;
|
160
|
-
}
|
161
|
-
}
|
162
|
-
|
163
|
-
// --- Added missing methods as skeletons ---
|
164
|
-
|
165
|
-
async VerifyToken(token: string): Promise<Result> {
|
166
|
-
try {
|
167
|
-
const verified = await this.authHelper.VerifyToken(token);
|
168
|
-
this.result.Data = verified;
|
169
|
-
this.result.Status = ResponseCode.Ok;
|
170
|
-
return this.result;
|
171
|
-
} catch (ex) {
|
172
|
-
this.result.addException(this.className, 'VerifyToken', ex);
|
173
|
-
return new Result(null, ResponseCode.Unauthorized, [ex], ['Invalid token']);
|
174
|
-
}
|
175
|
-
}
|
176
|
-
|
177
|
-
async VerifyMobileVerificationCode(data: any): Promise<Result> {
|
178
|
-
if (data.code === '123456') {
|
179
|
-
this.result.Data = true;
|
180
|
-
this.result.Status = ResponseCode.Ok;
|
181
|
-
} else {
|
182
|
-
this.result.Status = ResponseCode.Unauthorized;
|
183
|
-
this.result.Errors.push('Invalid code');
|
184
|
-
}
|
185
|
-
return this.result;
|
186
|
-
}
|
187
|
-
|
188
|
-
async resetUserPassword(data: any): Promise<Result> {
|
189
|
-
try {
|
190
|
-
const user = await dbcontext.UserEntity.findOne({ email: data.email });
|
191
|
-
if (user) {
|
192
|
-
user.hashedPassword = this.encryptionHelper.encryptUserLogin(data.password);
|
193
|
-
await user.save();
|
194
|
-
this.result.Data = true;
|
195
|
-
this.result.Status = ResponseCode.Ok;
|
196
|
-
} else {
|
197
|
-
this.result.Status = ResponseCode.NotExist;
|
198
|
-
this.result.Errors.push('User not found');
|
199
|
-
}
|
200
|
-
return this.result;
|
201
|
-
} catch (ex) {
|
202
|
-
this.result.addException(this.className, 'resetUserPassword', ex);
|
203
|
-
return new Result(null, ResponseCode.Error, [ex], [ex.message]);
|
204
|
-
}
|
205
|
-
}
|
206
|
-
|
207
|
-
async requestResettUserPassword(data: any): Promise<Result> {
|
208
|
-
try {
|
209
|
-
const user = await dbcontext.UserEntity.findOne({ email: data.email });
|
210
|
-
if (user) {
|
211
|
-
user.invitationCode = frameworkHelper.generateRandomString(6);
|
212
|
-
await user.save();
|
213
|
-
this.result.Data = true;
|
214
|
-
this.result.Status = ResponseCode.Ok;
|
215
|
-
} else {
|
216
|
-
this.result.Status = ResponseCode.NotExist;
|
217
|
-
this.result.Errors.push('User not found');
|
218
|
-
}
|
219
|
-
return this.result;
|
220
|
-
} catch (ex) {
|
221
|
-
this.result.addException(this.className, 'requestResettUserPassword', ex);
|
222
|
-
return new Result(null, ResponseCode.Error, [ex], [ex.message]);
|
223
|
-
}
|
224
|
-
}
|
225
|
-
|
226
|
-
async completeSignup(data: any): Promise<Result> {
|
227
|
-
this.result.Status = ResponseCode.Ok;
|
228
|
-
this.result.Data = true;
|
229
|
-
return this.result;
|
230
|
-
}
|
231
|
-
|
232
|
-
async checkEmailIsExistForBusiness(data: any): Promise<Result> {
|
233
|
-
this.result.Status = ResponseCode.NotExist;
|
234
|
-
this.result.Data = false;
|
235
|
-
return this.result;
|
236
|
-
}
|
237
|
-
|
238
|
-
async checkPhoneIsExistForBusiness(data: any): Promise<Result> {
|
239
|
-
this.result.Status = ResponseCode.NotExist;
|
240
|
-
this.result.Data = false;
|
241
|
-
return this.result;
|
242
|
-
}
|
243
|
-
}
|
@@ -1,56 +0,0 @@
|
|
1
|
-
|
2
|
-
import { Config } from "../config";
|
3
|
-
import { IAudit } from "../entities/audit";
|
4
|
-
import dbcontext from "../helpers/dbcontext";
|
5
|
-
import { AuditMessageType } from "../helpers/enums";
|
6
|
-
export class AuditService {
|
7
|
-
async AddAuditBulk(messages: any, errors: any, additionalInfo: any) {
|
8
|
-
try {
|
9
|
-
var auditDocuments = [];
|
10
|
-
if (Config.props.isDev) {
|
11
|
-
messages.map((message: any) => {
|
12
|
-
auditDocuments.push({
|
13
|
-
type: message.type ? AuditMessageType[message.type] : AuditMessageType[AuditMessageType.unknown],
|
14
|
-
className: message.className ? message.className : '-',
|
15
|
-
methodName: message.methodName ? message.methodName : '-',
|
16
|
-
requestIdentifier: message.requestIdentifier ? message.requestIdentifier : '-',
|
17
|
-
message: message.message ? message.message : message,
|
18
|
-
auditTime: message.auditTime ? message.auditTime : new Date(),
|
19
|
-
additionalInfo: additionalInfo
|
20
|
-
});
|
21
|
-
});
|
22
|
-
}
|
23
|
-
errors.map((error: any) => {
|
24
|
-
auditDocuments.push({
|
25
|
-
type: AuditMessageType[AuditMessageType.exception],
|
26
|
-
className: error.className ? error.className : '-',
|
27
|
-
methodName: error.methodName ? error.methodName : '-',
|
28
|
-
requestIdentifier: error.requestIdentifier ? error.requestIdentifier : '-',
|
29
|
-
message: error.message ? error.message : error,
|
30
|
-
auditTime: error.auditTime ? error.auditTime : new Date(),
|
31
|
-
additionalInfo: additionalInfo
|
32
|
-
});
|
33
|
-
})
|
34
|
-
dbcontext.AuditEntity.insertMany(auditDocuments);
|
35
|
-
}
|
36
|
-
catch (ex) {
|
37
|
-
console.error(ex)
|
38
|
-
}
|
39
|
-
}
|
40
|
-
async AddAuditSingle(type: AuditMessageType, className, methodName, requestIdentifier, message, addInfo = undefined) {
|
41
|
-
try {
|
42
|
-
dbcontext.AuditEntity.create({
|
43
|
-
type: type ? AuditMessageType[type].toString() : AuditMessageType[AuditMessageType.unknown].toString(),
|
44
|
-
className: className,
|
45
|
-
methodName: methodName,
|
46
|
-
requestIdentifier: requestIdentifier,
|
47
|
-
message: message,
|
48
|
-
auditTime: new Date(),
|
49
|
-
additionalInfo: addInfo
|
50
|
-
})
|
51
|
-
}
|
52
|
-
catch (ex) {
|
53
|
-
console.error(ex)
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"module": "CommonJS",
|
4
|
-
"noImplicitReturns": false,
|
5
|
-
"noImplicitAny": false,
|
6
|
-
"moduleResolution": "node",
|
7
|
-
"noUnusedLocals": false,
|
8
|
-
"outDir": "lib",
|
9
|
-
"sourceMap": true,
|
10
|
-
"target": "ES2022",
|
11
|
-
"allowJs": true
|
12
|
-
},
|
13
|
-
"typeRoots": ["node_modules/@types"],
|
14
|
-
"compileOnSave": true,
|
15
|
-
"include": ["src", "src/*/*.hbs", "main.ts","scripts"]
|
16
|
-
}
|
@@ -1,66 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var nodeExternals = require("webpack-node-externals");
|
4
|
-
var path = require("path");
|
5
|
-
const CopyPlugin = require("copy-webpack-plugin");
|
6
|
-
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
7
|
-
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
8
|
-
|
9
|
-
const { env } = require("process");
|
10
|
-
|
11
|
-
module.exports = {
|
12
|
-
entry: "./main.ts",
|
13
|
-
mode: env.NODE_ENV || "development",
|
14
|
-
output: {
|
15
|
-
path: path.resolve(__dirname, "lib"),
|
16
|
-
filename: "[name].js",
|
17
|
-
libraryTarget: "this",
|
18
|
-
},
|
19
|
-
target: "electron-main",
|
20
|
-
module: {
|
21
|
-
rules: [
|
22
|
-
{
|
23
|
-
test: /\.tsx?$/,
|
24
|
-
loader: "ts-loader",
|
25
|
-
options: {
|
26
|
-
transpileOnly: false,
|
27
|
-
compilerOptions: {
|
28
|
-
declaration: true,
|
29
|
-
declarationDir: "./lib"
|
30
|
-
}
|
31
|
-
},
|
32
|
-
},
|
33
|
-
{
|
34
|
-
test: /\.s?css$/,
|
35
|
-
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
|
36
|
-
},
|
37
|
-
],
|
38
|
-
},
|
39
|
-
resolve: {
|
40
|
-
extensions: [".ts", ".tsx", ".js"],
|
41
|
-
fallback: { crypto: false },
|
42
|
-
},
|
43
|
-
node: {
|
44
|
-
__dirname: true,
|
45
|
-
__filename: true,
|
46
|
-
},
|
47
|
-
externals: [nodeExternals()],
|
48
|
-
plugins: [
|
49
|
-
new CopyPlugin({
|
50
|
-
patterns: [
|
51
|
-
{
|
52
|
-
from: "src/assets",
|
53
|
-
to: "assets/",
|
54
|
-
},
|
55
|
-
{
|
56
|
-
from: "certs",
|
57
|
-
to: "certs/",
|
58
|
-
},
|
59
|
-
],
|
60
|
-
}),
|
61
|
-
],
|
62
|
-
optimization: {
|
63
|
-
minimizer: [new CssMinimizerPlugin()],
|
64
|
-
minimize: true,
|
65
|
-
},
|
66
|
-
};
|