equipped 4.0.0-alpha-10

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 (100) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/lib/bull/index.d.ts +37 -0
  3. package/lib/bull/index.js +93 -0
  4. package/lib/cache/cache.d.ts +7 -0
  5. package/lib/cache/cache.js +6 -0
  6. package/lib/cache/types/redis-cache.d.ts +11 -0
  7. package/lib/cache/types/redis-cache.js +40 -0
  8. package/lib/emails/index.d.ts +14 -0
  9. package/lib/emails/index.js +13 -0
  10. package/lib/enums/index.d.ts +19 -0
  11. package/lib/enums/index.js +29 -0
  12. package/lib/enums/types.d.ts +36 -0
  13. package/lib/enums/types.js +22 -0
  14. package/lib/errors/customError.d.ts +14 -0
  15. package/lib/errors/customError.js +12 -0
  16. package/lib/errors/index.d.ts +10 -0
  17. package/lib/errors/index.js +26 -0
  18. package/lib/errors/types/accessTokenExpired.d.ts +5 -0
  19. package/lib/errors/types/accessTokenExpired.js +12 -0
  20. package/lib/errors/types/accountNotVerifiedError.d.ts +5 -0
  21. package/lib/errors/types/accountNotVerifiedError.js +12 -0
  22. package/lib/errors/types/badRequestError.d.ts +5 -0
  23. package/lib/errors/types/badRequestError.js +12 -0
  24. package/lib/errors/types/invalidToken.d.ts +5 -0
  25. package/lib/errors/types/invalidToken.js +12 -0
  26. package/lib/errors/types/notAuthenticatedError.d.ts +5 -0
  27. package/lib/errors/types/notAuthenticatedError.js +12 -0
  28. package/lib/errors/types/notAuthorizedError.d.ts +5 -0
  29. package/lib/errors/types/notAuthorizedError.js +12 -0
  30. package/lib/errors/types/notFoundError.d.ts +5 -0
  31. package/lib/errors/types/notFoundError.js +12 -0
  32. package/lib/errors/types/refreshTokenMisusedError.d.ts +5 -0
  33. package/lib/errors/types/refreshTokenMisusedError.js +12 -0
  34. package/lib/errors/types/validationError.d.ts +10 -0
  35. package/lib/errors/types/validationError.js +12 -0
  36. package/lib/events/events.d.ts +17 -0
  37. package/lib/events/events.js +26 -0
  38. package/lib/events/rabbit.d.ts +4 -0
  39. package/lib/events/rabbit.js +44 -0
  40. package/lib/exit.d.ts +1 -0
  41. package/lib/exit.js +25 -0
  42. package/lib/express/app.d.ts +16 -0
  43. package/lib/express/app.js +127 -0
  44. package/lib/express/controllers/index.d.ts +13 -0
  45. package/lib/express/controllers/index.js +76 -0
  46. package/lib/express/controllers/request.d.ts +31 -0
  47. package/lib/express/controllers/request.js +48 -0
  48. package/lib/express/index.d.ts +5 -0
  49. package/lib/express/index.js +20 -0
  50. package/lib/express/middlewares/errorHandler.d.ts +1 -0
  51. package/lib/express/middlewares/errorHandler.js +22 -0
  52. package/lib/express/middlewares/index.d.ts +4 -0
  53. package/lib/express/middlewares/index.js +20 -0
  54. package/lib/express/middlewares/notFoundHandler.d.ts +1 -0
  55. package/lib/express/middlewares/notFoundHandler.js +8 -0
  56. package/lib/express/middlewares/parseAuthUser.d.ts +1 -0
  57. package/lib/express/middlewares/parseAuthUser.js +15 -0
  58. package/lib/express/middlewares/requireAuthUser.d.ts +2 -0
  59. package/lib/express/middlewares/requireAuthUser.js +11 -0
  60. package/lib/express/middlewares/requireRefreshUser.d.ts +2 -0
  61. package/lib/express/middlewares/requireRefreshUser.js +14 -0
  62. package/lib/express/statusCodes.d.ts +16 -0
  63. package/lib/express/statusCodes.js +17 -0
  64. package/lib/index.d.ts +18 -0
  65. package/lib/index.js +45 -0
  66. package/lib/instance.d.ts +43 -0
  67. package/lib/instance.js +115 -0
  68. package/lib/listeners/emitter.d.ts +20 -0
  69. package/lib/listeners/emitter.js +132 -0
  70. package/lib/listeners/index.d.ts +1 -0
  71. package/lib/listeners/index.js +17 -0
  72. package/lib/logger/index.d.ts +16 -0
  73. package/lib/logger/index.js +25 -0
  74. package/lib/mongoose/changeStreams.d.ts +25 -0
  75. package/lib/mongoose/changeStreams.js +93 -0
  76. package/lib/mongoose/index.d.ts +4 -0
  77. package/lib/mongoose/index.js +24 -0
  78. package/lib/mongoose/query.d.ts +60 -0
  79. package/lib/mongoose/query.js +97 -0
  80. package/lib/storage/index.d.ts +18 -0
  81. package/lib/storage/index.js +2 -0
  82. package/lib/structure/baseEntity.d.ts +5 -0
  83. package/lib/structure/baseEntity.js +21 -0
  84. package/lib/structure/baseMapper.d.ts +4 -0
  85. package/lib/structure/baseMapper.js +6 -0
  86. package/lib/structure/index.d.ts +2 -0
  87. package/lib/structure/index.js +18 -0
  88. package/lib/utils/auth.d.ts +28 -0
  89. package/lib/utils/auth.js +65 -0
  90. package/lib/utils/authUser.d.ts +10 -0
  91. package/lib/utils/authUser.js +2 -0
  92. package/lib/utils/media.d.ts +2 -0
  93. package/lib/utils/media.js +14 -0
  94. package/lib/utils/tokens.d.ts +15 -0
  95. package/lib/utils/tokens.js +78 -0
  96. package/lib/utils/utils.d.ts +4 -0
  97. package/lib/utils/utils.js +16 -0
  98. package/lib/validations/index.d.ts +146 -0
  99. package/lib/validations/index.js +103 -0
  100. package/package.json +80 -0
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Hash = exports.validateReq = exports.validate = exports.Validation = exports.Schema = void 0;
27
+ const bcrypt = __importStar(require("bcryptjs"));
28
+ const Validate = __importStar(require("valleyed"));
29
+ const errors_1 = require("../errors");
30
+ const instance_1 = require("../instance");
31
+ const isNotTruncated = (error) => Validate.makeRule((file) => {
32
+ const val = file;
33
+ error = error ?? `is larger than allowed limit of ${instance_1.Instance.get().settings.maxFileUploadSizeInMb}mb`;
34
+ const valid = val ? !val.isTruncated : true;
35
+ return valid ? Validate.isValid(val) : Validate.isInvalid([error], val);
36
+ });
37
+ const isValidPhone = (error) => Validate.makeRule((value) => {
38
+ const phone = value;
39
+ const { code = '', number = '' } = phone ?? {};
40
+ const isValidCode = Validate.isString()(code).valid &&
41
+ code.startsWith('+') &&
42
+ Validate.isNumber()(parseInt(code.slice(1))).valid;
43
+ const isValidNumber = Validate.isNumber()(parseInt(number)).valid;
44
+ if (!isValidCode)
45
+ return Validate.isInvalid([error ?? 'invalid phone code'], phone);
46
+ if (!isValidNumber)
47
+ return Validate.isInvalid([error ?? 'invalid phone number'], phone);
48
+ return Validate.isValid(phone);
49
+ });
50
+ const file = Validate.v.file;
51
+ Validate.v.file = (...args) => file(...args).addRule(isNotTruncated());
52
+ exports.Schema = Validate.v;
53
+ exports.Validation = { ...Validate, isNotTruncated, isValidPhone };
54
+ const validate = (data, rules) => {
55
+ const errors = Object.entries(data)
56
+ .map(([key, value]) => ({
57
+ key,
58
+ validity: exports.Validation.Validator.and(value, [rules[key].rules], {
59
+ required: rules[key].required,
60
+ nullable: rules[key].nullable
61
+ })
62
+ }));
63
+ const failed = errors.some(({ validity }) => !validity.valid);
64
+ if (failed)
65
+ throw new errors_1.ValidationError(errors
66
+ .filter(({ validity }) => !validity.valid)
67
+ .map(({ key, validity }) => ({ field: key, messages: validity.errors })));
68
+ return data;
69
+ };
70
+ exports.validate = validate;
71
+ const validateReq = (schema, value) => {
72
+ const validity = exports.Validation.v.object(schema).parse(value);
73
+ if (validity.valid)
74
+ return validity.value;
75
+ const errorsObject = validity.errors
76
+ .map((error) => {
77
+ const splitKey = ': ';
78
+ const [field, ...rest] = error.split(splitKey);
79
+ return { field, message: rest.join(splitKey) };
80
+ }).reduce(((acc, cur) => {
81
+ if (acc[cur.field])
82
+ acc[cur.field].push(cur.message);
83
+ else
84
+ acc[cur.field] = [cur.message];
85
+ return acc;
86
+ }), {});
87
+ throw new errors_1.ValidationError(Object.entries(errorsObject)
88
+ .map(([key, value]) => ({ field: key, messages: value })));
89
+ };
90
+ exports.validateReq = validateReq;
91
+ const hash = async (password) => {
92
+ password = password.trim();
93
+ if (!password)
94
+ return '';
95
+ return await bcrypt.hash(password, instance_1.Instance.get().settings.hashSaltRounds);
96
+ };
97
+ const compare = async (plainPassword, hashed) => {
98
+ plainPassword = plainPassword.trim();
99
+ if (!plainPassword && plainPassword === hashed)
100
+ return true;
101
+ return await bcrypt.compare(plainPassword, hashed);
102
+ };
103
+ exports.Hash = { hash, compare };
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "equipped",
3
+ "version": "4.0.0-alpha-10",
4
+ "private": false,
5
+ "description": "",
6
+ "main": "lib/index.js",
7
+ "scripts": {
8
+ "build": "tsc --project tsconfig.json",
9
+ "lint": "eslint src/ --ext .ts,.js --fix",
10
+ "pub": "yarn lint && yarn build && yarn publish --access public",
11
+ "release": "standard-version",
12
+ "prepare": "husky install",
13
+ "test": "echo"
14
+ },
15
+ "author": "",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "@commitlint/cli": "^17.4.3",
19
+ "@commitlint/config-conventional": "^17.4.3",
20
+ "@types/amqplib": "^0.10.1",
21
+ "@types/bcryptjs": "^2.4.2",
22
+ "@types/bull": "^3.15.9",
23
+ "@types/cors": "^2.8.13",
24
+ "@types/express": "^4.17.17",
25
+ "@types/express-fileupload": "^1.4.1",
26
+ "@types/jsonwebtoken": "^9.0.1",
27
+ "@types/morgan": "^1.9.4",
28
+ "@types/node": "^18.13.0",
29
+ "@types/pug": "^2.0.6",
30
+ "@typescript-eslint/eslint-plugin": "^5.52.0",
31
+ "@typescript-eslint/parser": "^5.52.0",
32
+ "eslint": "^8.34.0",
33
+ "eslint-plugin-promise": "^6.1.1",
34
+ "husky": "^8.0.3",
35
+ "standard-version": "^9.5.0",
36
+ "typescript": "^4.9.5"
37
+ },
38
+ "dependencies": {
39
+ "amqplib": "^0.10.3",
40
+ "axios": "^1.3.3",
41
+ "bcryptjs": "^2.4.3",
42
+ "bull": "^4.10.4",
43
+ "compression": "^1.7.4",
44
+ "cookie-parser": "^1.4.6",
45
+ "cors": "^2.8.5",
46
+ "dotenv": "^16.0.3",
47
+ "express": "^4.18.2",
48
+ "express-fileupload": "^1.4.0",
49
+ "express-rate-limit": "^6.7.0",
50
+ "express-slow-down": "^1.5.0",
51
+ "jsonwebtoken": "^9.0.0",
52
+ "jwks-rsa": "^3.0.1",
53
+ "mongoose": "^6.9.1",
54
+ "morgan": "^1.10.0",
55
+ "music-metadata": "^7",
56
+ "path-to-regexp": "^6.2.1",
57
+ "pug": "^3.0.2",
58
+ "redis": "^4.6.4",
59
+ "socket.io": "4.6.0",
60
+ "valleyed": "^4.0.5"
61
+ },
62
+ "repository": {
63
+ "url": "git://github.com/kevinand11/equipped.git"
64
+ },
65
+ "publishConfig": {
66
+ "registry": "https://registry.npmjs.org/"
67
+ },
68
+ "commitlint": {
69
+ "extends": [
70
+ "@commitlint/config-conventional"
71
+ ]
72
+ },
73
+ "files": [
74
+ "LICENSE",
75
+ "CHANGELOG.md",
76
+ "README.md",
77
+ "lib"
78
+ ],
79
+ "standard-version": {}
80
+ }