soul-cli 0.6.1 → 0.7.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.
- package/.all-contributorsrc +73 -0
- package/.editorconfig +26 -0
- package/.env.sample +9 -0
- package/.eslintignore +2 -0
- package/.eslintrc.js +24 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/workflows/npm-publish.yml +23 -0
- package/.husky/pre-commit +5 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +21 -0
- package/README.md +188 -1
- package/docs/api/root-examples.md +41 -0
- package/docs/api/rows-examples.md +225 -0
- package/docs/api/tables-examples.md +217 -0
- package/docs/api-examples.md +62 -0
- package/docs/auth-db-diagram.png +0 -0
- package/docs/auth.md +135 -0
- package/docs/extensions-examples.md +167 -0
- package/docs/logo.png +0 -0
- package/docs/soul-studio.png +0 -0
- package/docs/ws/rows-examples.md +122 -0
- package/docs/ws-examples.md +42 -0
- package/package.json +17 -2
- package/src/cli.js +59 -1
- package/src/commands.js +22 -0
- package/src/config/index.js +48 -3
- package/src/constants/api.js +26 -0
- package/src/constants/auth.js +5 -0
- package/src/constants/index.js +13 -0
- package/src/constants/messages.js +41 -0
- package/src/constants/roles.js +3 -0
- package/src/constants/tables.js +47 -0
- package/src/controllers/auth/common.js +16 -0
- package/src/controllers/auth/index.js +5 -0
- package/src/controllers/auth/tables.js +96 -0
- package/src/controllers/auth/token.js +243 -0
- package/src/controllers/auth/user.js +394 -0
- package/src/controllers/auth.test.js +372 -0
- package/src/controllers/rows.js +48 -55
- package/src/controllers/rows.test.js +146 -40
- package/src/controllers/tables.test.js +58 -28
- package/src/db/schema.js +118 -0
- package/src/index.js +33 -4
- package/src/middlewares/api.js +79 -0
- package/src/middlewares/auth.js +85 -0
- package/src/middlewares/broadcast.js +1 -1
- package/src/middlewares/validation.js +3 -2
- package/src/routes/auth.js +29 -0
- package/src/routes/rows.js +17 -5
- package/src/routes/tables.js +26 -4
- package/src/schemas/auth.js +67 -0
- package/src/schemas/index.js +6 -1
- package/src/schemas/rows.js +20 -0
- package/src/schemas/tables.js +18 -2
- package/src/server.js +3 -2
- package/src/services/authService.js +78 -0
- package/src/services/index.js +2 -1
- package/src/services/rowService.js +36 -7
- package/src/services/tableService.js +127 -1
- package/src/swagger/index.js +67 -0
- package/src/swagger/swagger.json +292 -60
- package/src/tests/index.js +4 -5
- package/src/tests/testData.js +23 -10
- package/src/utils/index.js +78 -0
- /package/{src/services/.gitkeep → docs/extensions/api-examples.js} +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const bcrypt = require('bcrypt');
|
|
2
|
+
const jwt = require('jsonwebtoken');
|
|
3
|
+
|
|
4
|
+
const { passwordStrength } = require('check-password-strength');
|
|
5
|
+
|
|
6
|
+
const hashPassword = async (password, saltRounds) => {
|
|
7
|
+
const salt = await bcrypt.genSalt(saltRounds);
|
|
8
|
+
const hashedPassword = await bcrypt.hash(password, saltRounds);
|
|
9
|
+
return { hashedPassword, salt };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const comparePasswords = async (plainPassword, hashedPassword) => {
|
|
13
|
+
const isMatch = await bcrypt.compare(plainPassword, hashedPassword);
|
|
14
|
+
return isMatch;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const checkPasswordStrength = (password) => {
|
|
18
|
+
const value = passwordStrength(password).value;
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const generateToken = async (payload, secret, expiresIn) => {
|
|
23
|
+
return jwt.sign(payload, secret, { expiresIn });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const decodeToken = async (token, secret) => {
|
|
27
|
+
try {
|
|
28
|
+
const decoded = jwt.verify(token, secret);
|
|
29
|
+
return decoded;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw new Error('Invalid token');
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const toBoolean = (value) => {
|
|
36
|
+
if (typeof value === 'boolean') {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (typeof value === 'string') {
|
|
41
|
+
const lowerCaseValue = value.toLowerCase();
|
|
42
|
+
if (lowerCaseValue === 'true') {
|
|
43
|
+
return true;
|
|
44
|
+
} else if (lowerCaseValue === 'false') {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (typeof value === 'number') {
|
|
50
|
+
if (value === 1) {
|
|
51
|
+
return true;
|
|
52
|
+
} else if (value === 0) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw new Error('Invalid value. Cannot convert to boolean.');
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const removeFields = async (rows, fields) => {
|
|
61
|
+
const newPayload = rows.map((row) => {
|
|
62
|
+
fields.map((field) => {
|
|
63
|
+
delete row[field];
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return newPayload;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
hashPassword,
|
|
72
|
+
comparePasswords,
|
|
73
|
+
checkPasswordStrength,
|
|
74
|
+
generateToken,
|
|
75
|
+
decodeToken,
|
|
76
|
+
toBoolean,
|
|
77
|
+
removeFields,
|
|
78
|
+
};
|
|
File without changes
|