pangea-server 3.3.53 → 3.3.55
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/auth/access-token.class.d.ts +1 -1
- package/dist/auth/auth.helpers.js +4 -5
- package/dist/database/db-client.js +2 -3
- package/dist/database/decorators/columns/column.js +18 -9
- package/dist/database/decorators/columns/date.columns.js +3 -4
- package/dist/database/decorators/columns/general.columns.js +20 -11
- package/dist/database/decorators/columns/json.columns.js +19 -10
- package/dist/database/decorators/columns/number.columns.js +2 -3
- package/dist/database/decorators/columns/string.columns.js +19 -10
- package/dist/database/decorators/index.js +17 -7
- package/dist/database/decorators/relations.js +17 -7
- package/dist/database/decorators/table.js +18 -9
- package/dist/database/seed.helpers.js +4 -5
- package/dist/helpers/env.helpers.js +4 -5
- package/dist/helpers/gemini.helpers.d.ts +0 -1
- package/dist/helpers/gemini.helpers.js +1 -2
- package/dist/helpers/html-sanitize.helpers.js +3 -4
- package/dist/helpers/mailer.helpers.d.ts +0 -1
- package/dist/helpers/print.helpers.js +4 -5
- package/dist/helpers/random.helpers.js +3 -4
- package/dist/main.js +1 -2
- package/dist/middlewares/delay-request.middleware.js +1 -2
- package/dist/middlewares/handle-error.middleware.js +1 -2
- package/dist/router/app-router.class.d.ts +5 -5
- package/dist/router/app-router.class.js +1 -2
- package/dist/router/call-controller.js +1 -2
- package/dist/types/global.types.d.ts +0 -1
- package/dist/validator/validate-request.js +1 -2
- package/package.json +2 -2
- package/dist/authentication/access-token.class.d.ts +0 -13
- package/dist/authentication/access-token.class.js +0 -28
- package/dist/authentication/authentication.helpers.d.ts +0 -17
- package/dist/authentication/authentication.helpers.js +0 -73
- package/dist/authentication/authentication.types.d.ts +0 -11
- package/dist/authentication/authentication.types.js +0 -2
- package/dist/authentication/base-auth.class.d.ts +0 -11
- package/dist/authentication/base-auth.class.js +0 -35
- package/dist/authentication/index.d.ts +0 -4
- package/dist/authentication/index.js +0 -20
- package/dist/helpers/file.helpers.d.ts +0 -21
- package/dist/helpers/file.helpers.js +0 -73
- package/dist/helpers/hashing.helpers.d.ts +0 -2
- package/dist/helpers/hashing.helpers.js +0 -16
- package/dist/helpers/password.helpers.d.ts +0 -4
- package/dist/helpers/password.helpers.js +0 -16
- package/dist/types/error.types.d.ts +0 -4
- package/dist/types/error.types.js +0 -2
|
@@ -5,7 +5,7 @@ export declare class AccessToken {
|
|
|
5
5
|
constructor(privateKey: string);
|
|
6
6
|
getKey(userCtor: UserCtor): string;
|
|
7
7
|
createToken(userCtor: UserCtor, id: ModelId): string;
|
|
8
|
-
verifyToken(token: string): Record<string,
|
|
8
|
+
verifyToken(token: string): Record<string, ModelId>;
|
|
9
9
|
getTokenData(userCtor: UserCtor, user: User): {
|
|
10
10
|
accessToken: string;
|
|
11
11
|
user: User;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.login = login;
|
|
4
|
+
exports.validateAccessToken = validateAccessToken;
|
|
5
|
+
exports.getUserFromToken = getUserFromToken;
|
|
6
|
+
exports.getUsersFromToken = getUsersFromToken;
|
|
4
7
|
// helpers
|
|
5
8
|
const helpers_1 = require("../helpers");
|
|
6
9
|
async function login(authHeader, db, accessToken, userCtor, extraWhere = {}) {
|
|
@@ -20,14 +23,12 @@ async function login(authHeader, db, accessToken, userCtor, extraWhere = {}) {
|
|
|
20
23
|
helpers_1.AppError.ThrowInvalidCredentials();
|
|
21
24
|
return accessToken.getTokenData(userCtor, user);
|
|
22
25
|
}
|
|
23
|
-
exports.login = login;
|
|
24
26
|
async function validateAccessToken(authHeader, db, accessToken, userCtor) {
|
|
25
27
|
const user = await getUserFromToken(authHeader, db, accessToken, userCtor);
|
|
26
28
|
if (!user)
|
|
27
29
|
helpers_1.AppError.ThrowUnauthorized();
|
|
28
30
|
return accessToken.getTokenData(userCtor, user);
|
|
29
31
|
}
|
|
30
|
-
exports.validateAccessToken = validateAccessToken;
|
|
31
32
|
function getUserFromToken(authHeader, db, accessToken, userCtor) {
|
|
32
33
|
try {
|
|
33
34
|
const token = getBearerToken(authHeader);
|
|
@@ -42,7 +43,6 @@ function getUserFromToken(authHeader, db, accessToken, userCtor) {
|
|
|
42
43
|
return null;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
exports.getUserFromToken = getUserFromToken;
|
|
46
46
|
async function getUsersFromToken(authHeader, db, accessToken, authMap) {
|
|
47
47
|
try {
|
|
48
48
|
const token = getBearerToken(authHeader);
|
|
@@ -61,7 +61,6 @@ async function getUsersFromToken(authHeader, db, accessToken, authMap) {
|
|
|
61
61
|
return Object.fromEntries(Object.keys(authMap).map((type) => [type, null]));
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
exports.getUsersFromToken = getUsersFromToken;
|
|
65
64
|
// internal functions
|
|
66
65
|
function getBearerToken(authHeader) {
|
|
67
66
|
if (!authHeader)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.initDatabase = initDatabase;
|
|
4
|
+
exports.getDbClient = getDbClient;
|
|
4
5
|
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
5
6
|
// helpers
|
|
6
7
|
const helpers_1 = require("../helpers");
|
|
@@ -47,13 +48,11 @@ function initDatabase(models, seeds, config = {}) {
|
|
|
47
48
|
}
|
|
48
49
|
return { connectDatabase, disconnectDatabase };
|
|
49
50
|
}
|
|
50
|
-
exports.initDatabase = initDatabase;
|
|
51
51
|
function getDbClient() {
|
|
52
52
|
if (!dbClient)
|
|
53
53
|
throw new Error('DbClient instance is not initialized');
|
|
54
54
|
return dbClient;
|
|
55
55
|
}
|
|
56
|
-
exports.getDbClient = getDbClient;
|
|
57
56
|
// internal functions
|
|
58
57
|
function logQuery(sql, timing) {
|
|
59
58
|
(0, helpers_1.printInfo)('query', sql);
|
|
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Column =
|
|
36
|
+
exports.Column = Column;
|
|
27
37
|
const seq = __importStar(require("sequelize-typescript"));
|
|
28
38
|
function Column(type, options = {}) {
|
|
29
39
|
const { nullable = false, defaultValue, index, unique = false, hideByDefault, get, set, ...restOptions } = options;
|
|
@@ -44,4 +54,3 @@ function Column(type, options = {}) {
|
|
|
44
54
|
model.AddHiddenAttribute(propertyName);
|
|
45
55
|
};
|
|
46
56
|
}
|
|
47
|
-
exports.Column = Column;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ColDatetime = ColDatetime;
|
|
4
|
+
exports.ColDate = ColDate;
|
|
5
|
+
exports.ColTime = ColTime;
|
|
4
6
|
const column_1 = require("./column");
|
|
5
7
|
function ColDatetime(options) {
|
|
6
8
|
return (0, column_1.Column)('DATE', options);
|
|
7
9
|
}
|
|
8
|
-
exports.ColDatetime = ColDatetime;
|
|
9
10
|
function ColDate(options) {
|
|
10
11
|
return (0, column_1.Column)('DATEONLY', options);
|
|
11
12
|
}
|
|
12
|
-
exports.ColDate = ColDate;
|
|
13
13
|
function ColTime(options) {
|
|
14
14
|
return (0, column_1.Column)('TIME', options);
|
|
15
15
|
}
|
|
16
|
-
exports.ColTime = ColTime;
|
|
@@ -15,28 +15,38 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
36
|
+
exports.ColBool = ColBool;
|
|
37
|
+
exports.ColForeignKey = ColForeignKey;
|
|
38
|
+
exports.ColVirtual = ColVirtual;
|
|
27
39
|
const seq = __importStar(require("sequelize-typescript"));
|
|
28
40
|
const column_1 = require("./column");
|
|
29
41
|
function ColBool(options) {
|
|
30
42
|
return (0, column_1.Column)('BOOLEAN', options);
|
|
31
43
|
}
|
|
32
|
-
exports.ColBool = ColBool;
|
|
33
44
|
function ColForeignKey(getModelFn, options) {
|
|
34
45
|
return function (target, propertyName) {
|
|
35
46
|
(0, column_1.Column)('INTEGER', { ...options, index: true, onUpdate: 'RESTRICT', onDelete: 'RESTRICT' })(target, propertyName);
|
|
36
47
|
seq.ForeignKey(getModelFn)(target, propertyName);
|
|
37
48
|
};
|
|
38
49
|
}
|
|
39
|
-
exports.ColForeignKey = ColForeignKey;
|
|
40
50
|
function ColVirtual(options) {
|
|
41
51
|
let get;
|
|
42
52
|
let set;
|
|
@@ -51,4 +61,3 @@ function ColVirtual(options) {
|
|
|
51
61
|
}
|
|
52
62
|
return seq.Column({ type: seq.DataType.VIRTUAL, ...(get && { get }), ...(set && { set }) });
|
|
53
63
|
}
|
|
54
|
-
exports.ColVirtual = ColVirtual;
|
|
@@ -15,15 +15,26 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
36
|
+
exports.ColJson = ColJson;
|
|
37
|
+
exports.ColStrArray = ColStrArray;
|
|
27
38
|
const seq = __importStar(require("sequelize-typescript"));
|
|
28
39
|
const column_1 = require("./column");
|
|
29
40
|
function ColJson(options) {
|
|
@@ -41,7 +52,6 @@ function ColJson(options) {
|
|
|
41
52
|
})(target, propertyName);
|
|
42
53
|
};
|
|
43
54
|
}
|
|
44
|
-
exports.ColJson = ColJson;
|
|
45
55
|
function ColStrArray() {
|
|
46
56
|
return function (target, propertyName) {
|
|
47
57
|
(0, column_1.Column)(seq.DataType.TEXT('long'), {
|
|
@@ -56,4 +66,3 @@ function ColStrArray() {
|
|
|
56
66
|
})(target, propertyName);
|
|
57
67
|
};
|
|
58
68
|
}
|
|
59
|
-
exports.ColStrArray = ColStrArray;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ColInt = ColInt;
|
|
4
|
+
exports.ColDouble = ColDouble;
|
|
4
5
|
const column_1 = require("./column");
|
|
5
6
|
function ColInt(options) {
|
|
6
7
|
return getNumColumn('INTEGER', options);
|
|
7
8
|
}
|
|
8
|
-
exports.ColInt = ColInt;
|
|
9
9
|
function ColDouble(options) {
|
|
10
10
|
return getNumColumn('DOUBLE', options);
|
|
11
11
|
}
|
|
12
|
-
exports.ColDouble = ColDouble;
|
|
13
12
|
// internal functions
|
|
14
13
|
function getNumColumn(type, options = {}) {
|
|
15
14
|
const { min, max, ...restOptions } = options;
|
|
@@ -15,15 +15,26 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
36
|
+
exports.ColStr = ColStr;
|
|
37
|
+
exports.ColText = ColText;
|
|
27
38
|
const seq = __importStar(require("sequelize-typescript"));
|
|
28
39
|
const column_1 = require("./column");
|
|
29
40
|
// resources
|
|
@@ -31,11 +42,9 @@ const resources_1 = require("../../../resources");
|
|
|
31
42
|
function ColStr(options) {
|
|
32
43
|
return getStrColumn(seq.DataType.STRING(getLength(255, options.maxLength)), options);
|
|
33
44
|
}
|
|
34
|
-
exports.ColStr = ColStr;
|
|
35
45
|
function ColText(options) {
|
|
36
46
|
return getStrColumn('TEXT', options);
|
|
37
47
|
}
|
|
38
|
-
exports.ColText = ColText;
|
|
39
48
|
// internal functions
|
|
40
49
|
function getStrColumn(type, options = {}) {
|
|
41
50
|
return (0, column_1.Column)(type, {
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.rel = exports.col = exports.Table = void 0;
|
|
27
37
|
const str = __importStar(require("./columns/string.columns"));
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.HasMany = exports.HasOne = exports.BelongsTo = void 0;
|
|
27
37
|
const seq = __importStar(require("sequelize-typescript"));
|
|
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Table =
|
|
36
|
+
exports.Table = Table;
|
|
27
37
|
const seq = __importStar(require("sequelize-typescript"));
|
|
28
38
|
// helpers
|
|
29
39
|
const pangea_helpers_1 = require("pangea-helpers");
|
|
@@ -52,4 +62,3 @@ function Table(tableName, options = {}) {
|
|
|
52
62
|
seq.Scopes(() => ({ withHiddenAttributes: { attributes: { include: hiddenAttributes } } }))(target);
|
|
53
63
|
};
|
|
54
64
|
}
|
|
55
|
-
exports.Table = Table;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.dropTables = dropTables;
|
|
4
|
+
exports.emptyTables = emptyTables;
|
|
5
|
+
exports.syncTables = syncTables;
|
|
6
|
+
exports.seedTables = seedTables;
|
|
4
7
|
const db_client_1 = require("./db-client");
|
|
5
8
|
const db_class_1 = require("./db.class");
|
|
6
9
|
// helpers
|
|
@@ -11,19 +14,16 @@ async function dropTables() {
|
|
|
11
14
|
await dbClient.drop();
|
|
12
15
|
(0, helpers_1.printSuccess)('database', 'tables dropped');
|
|
13
16
|
}
|
|
14
|
-
exports.dropTables = dropTables;
|
|
15
17
|
async function emptyTables() {
|
|
16
18
|
(0, helpers_1.printInfo)('database', 'emptying tables...');
|
|
17
19
|
const dbClient = (0, db_client_1.getDbClient)();
|
|
18
20
|
await dbClient.truncate({ truncate: true, cascade: true });
|
|
19
21
|
(0, helpers_1.printSuccess)('database', 'tables emptied');
|
|
20
22
|
}
|
|
21
|
-
exports.emptyTables = emptyTables;
|
|
22
23
|
async function syncTables() {
|
|
23
24
|
const dbClient = (0, db_client_1.getDbClient)();
|
|
24
25
|
await dbClient.sync();
|
|
25
26
|
}
|
|
26
|
-
exports.syncTables = syncTables;
|
|
27
27
|
async function seedTables(models, seeds) {
|
|
28
28
|
(0, helpers_1.printInfo)('database', 'seeding tables...');
|
|
29
29
|
const modelsToSeed = Object.values(models)
|
|
@@ -45,4 +45,3 @@ async function seedTables(models, seeds) {
|
|
|
45
45
|
}
|
|
46
46
|
(0, helpers_1.printSuccess)('database', 'tables seeded');
|
|
47
47
|
}
|
|
48
|
-
exports.seedTables = seedTables;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getEnvStr = getEnvStr;
|
|
4
|
+
exports.getEnvInt = getEnvInt;
|
|
5
|
+
exports.getEnvFloat = getEnvFloat;
|
|
6
|
+
exports.getEnvBool = getEnvBool;
|
|
4
7
|
const dotenv_1 = require("dotenv");
|
|
5
8
|
// init dotenv
|
|
6
9
|
(0, dotenv_1.config)();
|
|
@@ -16,17 +19,13 @@ function __getEnv(key, raiseException) {
|
|
|
16
19
|
function getEnvStr(key, raiseException = true) {
|
|
17
20
|
return __getEnv(key, raiseException);
|
|
18
21
|
}
|
|
19
|
-
exports.getEnvStr = getEnvStr;
|
|
20
22
|
function getEnvInt(key, raiseException = true) {
|
|
21
23
|
return parseInt(__getEnv(key, raiseException));
|
|
22
24
|
}
|
|
23
|
-
exports.getEnvInt = getEnvInt;
|
|
24
25
|
function getEnvFloat(key, raiseException = true) {
|
|
25
26
|
return parseFloat(__getEnv(key, raiseException));
|
|
26
27
|
}
|
|
27
|
-
exports.getEnvFloat = getEnvFloat;
|
|
28
28
|
function getEnvBool(key, raiseException = false) {
|
|
29
29
|
const value = __getEnv(key, raiseException);
|
|
30
30
|
return value.toLowerCase() === 'true';
|
|
31
31
|
}
|
|
32
|
-
exports.getEnvBool = getEnvBool;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateIaText =
|
|
3
|
+
exports.generateIaText = generateIaText;
|
|
4
4
|
// helpers
|
|
5
5
|
const helpers_1 = require("../helpers");
|
|
6
6
|
async function generateIaText(content) {
|
|
@@ -18,4 +18,3 @@ async function generateIaText(content) {
|
|
|
18
18
|
const response = await ai.models.generateContent({ model: 'gemini-2.5-flash-lite', contents });
|
|
19
19
|
return response.text;
|
|
20
20
|
}
|
|
21
|
-
exports.generateIaText = generateIaText;
|
|
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.sanitizeHtml = sanitizeHtml;
|
|
7
|
+
exports.removeHtmlTags = removeHtmlTags;
|
|
8
|
+
exports.getHtmlSanitized = getHtmlSanitized;
|
|
7
9
|
const jsdom_1 = require("jsdom");
|
|
8
10
|
const dompurify_1 = __importDefault(require("dompurify"));
|
|
9
11
|
// resources
|
|
@@ -15,11 +17,9 @@ const domPurify = (0, dompurify_1.default)(window);
|
|
|
15
17
|
function sanitizeHtml(html) {
|
|
16
18
|
return domPurify.sanitize(html);
|
|
17
19
|
}
|
|
18
|
-
exports.sanitizeHtml = sanitizeHtml;
|
|
19
20
|
function removeHtmlTags(html) {
|
|
20
21
|
return domPurify.sanitize(html, { ALLOWED_TAGS: [] });
|
|
21
22
|
}
|
|
22
|
-
exports.removeHtmlTags = removeHtmlTags;
|
|
23
23
|
function getHtmlSanitized(html, maxLength = 'extraLong') {
|
|
24
24
|
const htmlLength = html ? removeHtmlTags(html).length : 0;
|
|
25
25
|
const finalMaxLength = typeof maxLength === 'number' ? maxLength : resources_1.STRING_LENGTHS[maxLength];
|
|
@@ -27,4 +27,3 @@ function getHtmlSanitized(html, maxLength = 'extraLong') {
|
|
|
27
27
|
error_helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'INVALID_INPUT_DATA' });
|
|
28
28
|
return html ? sanitizeHtml(html) : null;
|
|
29
29
|
}
|
|
30
|
-
exports.getHtmlSanitized = getHtmlSanitized;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.printInfo = printInfo;
|
|
4
|
+
exports.printSuccess = printSuccess;
|
|
5
|
+
exports.printWarning = printWarning;
|
|
6
|
+
exports.printDanger = printDanger;
|
|
4
7
|
function printInfo(label, msg) {
|
|
5
8
|
const finalLabel = label || 'info';
|
|
6
9
|
console.log(`\x1b[34m[${finalLabel}]\x1b[0m`, msg);
|
|
7
10
|
}
|
|
8
|
-
exports.printInfo = printInfo;
|
|
9
11
|
function printSuccess(label, msg) {
|
|
10
12
|
const finalLabel = label || 'success';
|
|
11
13
|
console.log(`\x1b[32m[${finalLabel}]\x1b[0m`, msg);
|
|
12
14
|
}
|
|
13
|
-
exports.printSuccess = printSuccess;
|
|
14
15
|
function printWarning(label, warning) {
|
|
15
16
|
const finalLabel = label || 'warning';
|
|
16
17
|
const msg = warning instanceof Error ? `${warning.name}: ${warning.message}` : warning;
|
|
17
18
|
console.warn(`\x1b[33m[${finalLabel}]\x1b[0m`, msg);
|
|
18
19
|
}
|
|
19
|
-
exports.printWarning = printWarning;
|
|
20
20
|
function printDanger(label, danger, config) {
|
|
21
21
|
const { printError } = config || {};
|
|
22
22
|
const finalLabel = label || 'danger';
|
|
@@ -26,4 +26,3 @@ function printDanger(label, danger, config) {
|
|
|
26
26
|
if (isError && printError)
|
|
27
27
|
console.error(danger);
|
|
28
28
|
}
|
|
29
|
-
exports.printDanger = printDanger;
|
|
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getRandomString = getRandomString;
|
|
7
|
+
exports.getRandomNumber = getRandomNumber;
|
|
8
|
+
exports.generateBarcode = generateBarcode;
|
|
7
9
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
10
|
// resources
|
|
9
11
|
const resources_1 = require("../resources");
|
|
@@ -11,16 +13,13 @@ function getRandomString(length) {
|
|
|
11
13
|
const buffer = crypto_1.default.randomBytes(getSize(length));
|
|
12
14
|
return buffer.toString('hex');
|
|
13
15
|
}
|
|
14
|
-
exports.getRandomString = getRandomString;
|
|
15
16
|
function getRandomNumber(length) {
|
|
16
17
|
const buffer = crypto_1.default.randomBytes(getSize(length));
|
|
17
18
|
return [...buffer].map((b) => b % 10).join('');
|
|
18
19
|
}
|
|
19
|
-
exports.getRandomNumber = getRandomNumber;
|
|
20
20
|
function generateBarcode() {
|
|
21
21
|
return getRandomNumber(12);
|
|
22
22
|
}
|
|
23
|
-
exports.generateBarcode = generateBarcode;
|
|
24
23
|
// internal functions
|
|
25
24
|
function getSize(length = 'short') {
|
|
26
25
|
return typeof length === 'number' ? length : resources_1.RANDOM_STRING_LENGTHS[length];
|
package/dist/main.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.startServer =
|
|
6
|
+
exports.startServer = startServer;
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
|
8
8
|
require("express-async-errors");
|
|
9
9
|
// middlewares
|
|
@@ -30,7 +30,6 @@ async function startServer(config) {
|
|
|
30
30
|
afterDatabaseConnected?.();
|
|
31
31
|
jobs.forEach((job) => job.Init());
|
|
32
32
|
}
|
|
33
|
-
exports.startServer = startServer;
|
|
34
33
|
// internal functions
|
|
35
34
|
function createApp(setRoutes) {
|
|
36
35
|
// app
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.delayRequest =
|
|
3
|
+
exports.delayRequest = delayRequest;
|
|
4
4
|
// helpers
|
|
5
5
|
const helpers_1 = require("../helpers");
|
|
6
6
|
function delayRequest(delayInSeconds = 1) {
|
|
@@ -13,4 +13,3 @@ function delayRequest(delayInSeconds = 1) {
|
|
|
13
13
|
next();
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
exports.delayRequest = delayRequest;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleError =
|
|
3
|
+
exports.handleError = handleError;
|
|
4
4
|
const http_status_codes_1 = require("http-status-codes");
|
|
5
5
|
// helpers
|
|
6
6
|
const helpers_1 = require("../helpers");
|
|
@@ -10,4 +10,3 @@ function handleError(err, _req, res, next) {
|
|
|
10
10
|
res.status(statusCode).json({ error: err });
|
|
11
11
|
next();
|
|
12
12
|
}
|
|
13
|
-
exports.handleError = handleError;
|
|
@@ -8,11 +8,11 @@ export declare function getAppRouter<AM extends AuthMap, AU extends AuthUsers<AM
|
|
|
8
8
|
new (app: App, basePath: string): {
|
|
9
9
|
router: Router;
|
|
10
10
|
setRoute<V extends Validator>(method: ApiMethod, path: string, validate: Validate<V>, ...args: SetRouteArgs<V, AM, BA>): void;
|
|
11
|
-
get<
|
|
12
|
-
post<
|
|
13
|
-
put<
|
|
14
|
-
patch<
|
|
15
|
-
delete<
|
|
11
|
+
get<V extends Validator>(path: string, validate: Validate<V>, ...args: SetRouteArgs<V, AM, BA>): void;
|
|
12
|
+
post<V extends Validator>(path: string, validate: Validate<V>, ...args: SetRouteArgs<V, AM, BA>): void;
|
|
13
|
+
put<V extends Validator>(path: string, validate: Validate<V>, ...args: SetRouteArgs<V, AM, BA>): void;
|
|
14
|
+
patch<V extends Validator>(path: string, validate: Validate<V>, ...args: SetRouteArgs<V, AM, BA>): void;
|
|
15
|
+
delete<V extends Validator>(path: string, validate: Validate<V>, ...args: SetRouteArgs<V, AM, BA>): void;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAppRouter =
|
|
3
|
+
exports.getAppRouter = getAppRouter;
|
|
4
4
|
const express_1 = require("express");
|
|
5
5
|
const call_controller_1 = require("./call-controller");
|
|
6
6
|
function getAppRouter(appVersion, authConfig) {
|
|
@@ -31,4 +31,3 @@ function getAppRouter(appVersion, authConfig) {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
exports.getAppRouter = getAppRouter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.callController =
|
|
3
|
+
exports.callController = callController;
|
|
4
4
|
const http_status_codes_1 = require("http-status-codes");
|
|
5
5
|
// helpers
|
|
6
6
|
const helpers_1 = require("../helpers");
|
|
@@ -55,7 +55,6 @@ function callController(controller, validate, appVersion, authConfig) {
|
|
|
55
55
|
(0, helpers_1.printInfo)(reqId, 'request finished');
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
exports.callController = callController;
|
|
59
58
|
// internal functions
|
|
60
59
|
function hasInstancesAndTotalCount(obj) {
|
|
61
60
|
return typeof obj === 'object' && obj !== null && 'instances' in obj && 'totalCount' in obj;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateRequest =
|
|
3
|
+
exports.validateRequest = validateRequest;
|
|
4
4
|
// helpers
|
|
5
5
|
const helpers_1 = require("../helpers");
|
|
6
6
|
const pangea_helpers_1 = require("pangea-helpers");
|
|
@@ -17,7 +17,6 @@ function validateRequest(validate, req) {
|
|
|
17
17
|
helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'INVALID_INPUT_DATA', originalError: err });
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
exports.validateRequest = validateRequest;
|
|
21
20
|
// internal functions
|
|
22
21
|
function normalizeInput(type, obj) {
|
|
23
22
|
if (!Object.keys(obj).length)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pangea-server",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.55",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"@types/node-cron": "3.0.11",
|
|
78
78
|
"@types/nodemailer": "6.4.17",
|
|
79
79
|
"tsc-alias": "1.8.15",
|
|
80
|
-
"typescript": "5.
|
|
80
|
+
"typescript": "5.9.3",
|
|
81
81
|
"yarn": "1.22.22"
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { User } from '../database';
|
|
2
|
-
import type { UserCtor } from './authentication.types';
|
|
3
|
-
export declare class AccessToken {
|
|
4
|
-
private __privateKey;
|
|
5
|
-
constructor(privateKey: string);
|
|
6
|
-
getKey(userCtor: UserCtor): string;
|
|
7
|
-
createToken(userCtor: UserCtor, id: ModelId): string;
|
|
8
|
-
verifyToken(token: string): Record<string, number>;
|
|
9
|
-
getTokenData(userCtor: UserCtor, user: User): {
|
|
10
|
-
accessToken: string;
|
|
11
|
-
user: User;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AccessToken = void 0;
|
|
7
|
-
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
// helpers
|
|
9
|
-
const pangea_helpers_1 = require("pangea-helpers");
|
|
10
|
-
class AccessToken {
|
|
11
|
-
constructor(privateKey) {
|
|
12
|
-
this.__privateKey = privateKey;
|
|
13
|
-
}
|
|
14
|
-
getKey(userCtor) {
|
|
15
|
-
return `${(0, pangea_helpers_1.getFirstChartInLowercase)(userCtor.name)}Id`;
|
|
16
|
-
}
|
|
17
|
-
createToken(userCtor, id) {
|
|
18
|
-
const key = this.getKey(userCtor);
|
|
19
|
-
return jsonwebtoken_1.default.sign({ [key]: id }, this.__privateKey, { expiresIn: 60 * 60 * 24 * 365 });
|
|
20
|
-
}
|
|
21
|
-
verifyToken(token) {
|
|
22
|
-
return jsonwebtoken_1.default.verify(token, this.__privateKey);
|
|
23
|
-
}
|
|
24
|
-
getTokenData(userCtor, user) {
|
|
25
|
-
return { accessToken: this.createToken(userCtor, user.id), user };
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.AccessToken = AccessToken;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { AccessToken } from './access-token.class';
|
|
2
|
-
import { User } from '../database';
|
|
3
|
-
import type { UserCtor, AuthMap } from './authentication.types';
|
|
4
|
-
type AuthHeader = string | undefined;
|
|
5
|
-
export declare function login<U extends User>(authHeader: AuthHeader, db: Db, accessToken: AccessToken, userCtor: BaseModelCtor<U>, extraWhere?: Where<U>): Promise<{
|
|
6
|
-
accessToken: string;
|
|
7
|
-
user: User;
|
|
8
|
-
}>;
|
|
9
|
-
export declare function validateAccessToken(authHeader: AuthHeader, db: Db, accessToken: AccessToken, userCtor: UserCtor): Promise<{
|
|
10
|
-
accessToken: string;
|
|
11
|
-
user: User;
|
|
12
|
-
}>;
|
|
13
|
-
export declare function getUserFromToken(authHeader: AuthHeader, db: Db, accessToken: AccessToken, userCtor: UserCtor): Promise<User | null> | null;
|
|
14
|
-
export declare function getUsersFromToken(authHeader: AuthHeader, db: Db, accessToken: AccessToken, authMap: AuthMap): Promise<{
|
|
15
|
-
[k: string]: User | null;
|
|
16
|
-
}>;
|
|
17
|
-
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUsersFromToken = exports.getUserFromToken = exports.validateAccessToken = exports.login = void 0;
|
|
4
|
-
// helpers
|
|
5
|
-
const helpers_1 = require("../helpers");
|
|
6
|
-
async function login(authHeader, db, accessToken, userCtor, extraWhere = {}) {
|
|
7
|
-
if (!authHeader?.startsWith('Basic '))
|
|
8
|
-
helpers_1.AppError.ThrowInvalidCredentials();
|
|
9
|
-
const base64 = authHeader.slice(6);
|
|
10
|
-
const decoded = Buffer.from(base64, 'base64').toString('utf-8');
|
|
11
|
-
const [username, password] = decoded.split(':');
|
|
12
|
-
if (!username || !password)
|
|
13
|
-
helpers_1.AppError.ThrowInvalidCredentials();
|
|
14
|
-
const where = { ...extraWhere, username };
|
|
15
|
-
const user = await db.findOneOrNull(userCtor, where, { scopes: ['withHiddenAttributes'] });
|
|
16
|
-
if (!user)
|
|
17
|
-
helpers_1.AppError.ThrowInvalidCredentials();
|
|
18
|
-
const isPasswordValid = await (0, helpers_1.comparePasswords)(password, user.password);
|
|
19
|
-
if (!isPasswordValid)
|
|
20
|
-
helpers_1.AppError.ThrowInvalidCredentials();
|
|
21
|
-
return accessToken.getTokenData(userCtor, user);
|
|
22
|
-
}
|
|
23
|
-
exports.login = login;
|
|
24
|
-
async function validateAccessToken(authHeader, db, accessToken, userCtor) {
|
|
25
|
-
const user = await getUserFromToken(authHeader, db, accessToken, userCtor);
|
|
26
|
-
if (!user)
|
|
27
|
-
helpers_1.AppError.ThrowUnauthorized();
|
|
28
|
-
return accessToken.getTokenData(userCtor, user);
|
|
29
|
-
}
|
|
30
|
-
exports.validateAccessToken = validateAccessToken;
|
|
31
|
-
function getUserFromToken(authHeader, db, accessToken, userCtor) {
|
|
32
|
-
try {
|
|
33
|
-
const token = getBearerToken(authHeader);
|
|
34
|
-
const payload = accessToken.verifyToken(token);
|
|
35
|
-
const key = accessToken.getKey(userCtor);
|
|
36
|
-
const id = payload[key];
|
|
37
|
-
if (!id)
|
|
38
|
-
return null;
|
|
39
|
-
return db.findOneOrNull(userCtor, id);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.getUserFromToken = getUserFromToken;
|
|
46
|
-
async function getUsersFromToken(authHeader, db, accessToken, authMap) {
|
|
47
|
-
try {
|
|
48
|
-
const token = getBearerToken(authHeader);
|
|
49
|
-
const payload = accessToken.verifyToken(token);
|
|
50
|
-
const results = await Promise.all(Object.entries(authMap).map(async ([type, userCtor]) => {
|
|
51
|
-
const key = accessToken.getKey(userCtor);
|
|
52
|
-
const id = payload[key];
|
|
53
|
-
if (!id)
|
|
54
|
-
return [type, null];
|
|
55
|
-
const user = await db.findOneOrNull(userCtor, id);
|
|
56
|
-
return [type, user];
|
|
57
|
-
}));
|
|
58
|
-
return Object.fromEntries(results);
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return Object.fromEntries(Object.keys(authMap).map((type) => [type, null]));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.getUsersFromToken = getUsersFromToken;
|
|
65
|
-
// internal functions
|
|
66
|
-
function getBearerToken(authHeader) {
|
|
67
|
-
if (!authHeader)
|
|
68
|
-
throw new Error('Missing authorization header');
|
|
69
|
-
const [type, token] = authHeader.split(' ');
|
|
70
|
-
if (type !== 'Bearer' || !token)
|
|
71
|
-
throw new Error('Invalid authorization format');
|
|
72
|
-
return token;
|
|
73
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BaseAuth } from './base-auth.class';
|
|
2
|
-
import { User } from '../database';
|
|
3
|
-
export type UserCtor = BaseModelCtor<User>;
|
|
4
|
-
export type AuthMap = Record<string, UserCtor>;
|
|
5
|
-
export type UserType<AM extends AuthMap> = keyof AM;
|
|
6
|
-
export type AuthUsers<AM extends AuthMap> = {
|
|
7
|
-
[K in keyof AM]: InstanceType<AM[K]> | null;
|
|
8
|
-
};
|
|
9
|
-
export interface AuthCtor<AM extends AuthMap, AU extends AuthUsers<AM>, BA extends BaseAuth<AM>> {
|
|
10
|
-
new (authUsers: AU): BA;
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { AuthMap, UserType, AuthUsers } from './authentication.types';
|
|
2
|
-
export declare abstract class BaseAuth<AM extends AuthMap> {
|
|
3
|
-
private __authUsers;
|
|
4
|
-
constructor(authUsers: AuthUsers<AM>);
|
|
5
|
-
free(): void;
|
|
6
|
-
notSetYet(): void;
|
|
7
|
-
notAllowed(): void;
|
|
8
|
-
isUserAuth<T extends UserType<AM>>(type: T): boolean;
|
|
9
|
-
getUserAuth<T extends UserType<AM>>(type: T): NonNullable<AuthUsers<AM>[T]>;
|
|
10
|
-
getUsersAuth<const T extends readonly UserType<AM>[]>(types: T): { [I in keyof T]: InstanceType<AM[T[I]]> | null; };
|
|
11
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseAuth = void 0;
|
|
4
|
-
// helpers
|
|
5
|
-
const helpers_1 = require("../helpers");
|
|
6
|
-
class BaseAuth {
|
|
7
|
-
constructor(authUsers) {
|
|
8
|
-
this.__authUsers = authUsers;
|
|
9
|
-
}
|
|
10
|
-
free() {
|
|
11
|
-
(0, helpers_1.printWarning)('authentication', 'free access');
|
|
12
|
-
}
|
|
13
|
-
notSetYet() {
|
|
14
|
-
(0, helpers_1.printWarning)('authentication', 'auth not set yet');
|
|
15
|
-
}
|
|
16
|
-
notAllowed() {
|
|
17
|
-
helpers_1.AppError.ThrowUnauthorized();
|
|
18
|
-
}
|
|
19
|
-
isUserAuth(type) {
|
|
20
|
-
return !!this.__authUsers[type];
|
|
21
|
-
}
|
|
22
|
-
getUserAuth(type) {
|
|
23
|
-
const user = this.__authUsers[type];
|
|
24
|
-
if (!user)
|
|
25
|
-
helpers_1.AppError.ThrowUnauthorized();
|
|
26
|
-
return user;
|
|
27
|
-
}
|
|
28
|
-
getUsersAuth(types) {
|
|
29
|
-
const users = types.map((type) => this.__authUsers[type]);
|
|
30
|
-
if (users.every((user) => !user))
|
|
31
|
-
helpers_1.AppError.ThrowUnauthorized();
|
|
32
|
-
return users;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.BaseAuth = BaseAuth;
|
|
@@ -1,20 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./access-token.class"), exports);
|
|
18
|
-
__exportStar(require("./authentication.helpers"), exports);
|
|
19
|
-
__exportStar(require("./authentication.types"), exports);
|
|
20
|
-
__exportStar(require("./base-auth.class"), exports);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
type GeneralUploadParamsConfig = {
|
|
2
|
-
folder: string;
|
|
3
|
-
fileType: string;
|
|
4
|
-
};
|
|
5
|
-
export declare abstract class File {
|
|
6
|
-
UploadImage(image: UploadableImage, folder: string, previousFile?: string | null): Promise<string>;
|
|
7
|
-
UploadImages(images: UploadableImage[], folder: string): Promise<string[]>;
|
|
8
|
-
UploadVideo(file: MulterFile, folder: string): Promise<string>;
|
|
9
|
-
UploadVideos(files: MulterFile[], folder: string): Promise<string[]>;
|
|
10
|
-
GenerateUploadUrl(config: GeneralUploadParamsConfig): Promise<{
|
|
11
|
-
url: string;
|
|
12
|
-
fileName: string;
|
|
13
|
-
}>;
|
|
14
|
-
GenerateUploadUrls(folder: string, fileTypes: string[]): Promise<{
|
|
15
|
-
url: string;
|
|
16
|
-
fileName: string;
|
|
17
|
-
}[]>;
|
|
18
|
-
DeleteFile(fileName: string): Promise<void>;
|
|
19
|
-
DeleteFiles(fileNames: string[]): Promise<void[]>;
|
|
20
|
-
}
|
|
21
|
-
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.File = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
11
|
-
// helpers
|
|
12
|
-
const print_helpers_1 = require("./print.helpers");
|
|
13
|
-
const env_helpers_1 = require("./env.helpers");
|
|
14
|
-
const random_helpers_1 = require("./random.helpers");
|
|
15
|
-
const bucketName = (0, env_helpers_1.getEnvStr)('DIGITAL_OCEAN_SPACES_BUCKET');
|
|
16
|
-
const endpointUrl = 'nyc3.digitaloceanspaces.com';
|
|
17
|
-
const s3 = new aws_sdk_1.default.S3({
|
|
18
|
-
endpoint: new aws_sdk_1.default.Endpoint(endpointUrl),
|
|
19
|
-
accessKeyId: (0, env_helpers_1.getEnvStr)('DIGITAL_OCEAN_SPACES_ACCESS_KEY'),
|
|
20
|
-
secretAccessKey: (0, env_helpers_1.getEnvStr)('DIGITAL_OCEAN_SPACES_SECRET_KEY'),
|
|
21
|
-
});
|
|
22
|
-
class File {
|
|
23
|
-
async UploadImage(image, folder, previousFile) {
|
|
24
|
-
if (previousFile)
|
|
25
|
-
await this.DeleteFile(previousFile);
|
|
26
|
-
const isString = typeof image === 'string';
|
|
27
|
-
const buffer = isString ? await promises_1.default.readFile(path_1.default.join(process.cwd(), image)) : image.buffer;
|
|
28
|
-
const fileType = isString ? 'image/png' : image.mimetype;
|
|
29
|
-
return uploadFile(buffer, { folder, fileType });
|
|
30
|
-
}
|
|
31
|
-
UploadImages(images, folder) {
|
|
32
|
-
return Promise.all(images.map((image) => this.UploadImage(image, folder)));
|
|
33
|
-
}
|
|
34
|
-
async UploadVideo(file, folder) {
|
|
35
|
-
const stream = fs_1.default.createReadStream(file.path);
|
|
36
|
-
try {
|
|
37
|
-
return await uploadFile(stream, { folder, fileType: file.mimetype });
|
|
38
|
-
}
|
|
39
|
-
finally {
|
|
40
|
-
promises_1.default.unlink(file.path);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
UploadVideos(files, folder) {
|
|
44
|
-
return Promise.all(files.map((file) => this.UploadVideo(file, folder)));
|
|
45
|
-
}
|
|
46
|
-
async GenerateUploadUrl(config) {
|
|
47
|
-
const params = { ...getGeneralUploadParams(config), Expires: 60 };
|
|
48
|
-
const url = await s3.getSignedUrlPromise('putObject', params);
|
|
49
|
-
return { url, fileName: params.Key };
|
|
50
|
-
}
|
|
51
|
-
async GenerateUploadUrls(folder, fileTypes) {
|
|
52
|
-
return Promise.all(fileTypes.map((fileType) => this.GenerateUploadUrl({ folder, fileType })));
|
|
53
|
-
}
|
|
54
|
-
async DeleteFile(fileName) {
|
|
55
|
-
await s3.deleteObject({ Bucket: bucketName, Key: fileName }).promise();
|
|
56
|
-
(0, print_helpers_1.printInfo)('file', `file deleted from ${fileName}`);
|
|
57
|
-
}
|
|
58
|
-
DeleteFiles(fileNames) {
|
|
59
|
-
return Promise.all(fileNames.map((fileName) => this.DeleteFile(fileName)));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.File = File;
|
|
63
|
-
// internal functions
|
|
64
|
-
function getGeneralUploadParams(config) {
|
|
65
|
-
const fileName = `${config.folder}/${(0, random_helpers_1.getRandomString)('short')}`;
|
|
66
|
-
return { Bucket: bucketName, Key: fileName, ContentType: config.fileType, ACL: 'public-read' };
|
|
67
|
-
}
|
|
68
|
-
async function uploadFile(body, config) {
|
|
69
|
-
const params = { ...getGeneralUploadParams(config), Body: body };
|
|
70
|
-
const res = await s3.upload(params).promise();
|
|
71
|
-
(0, print_helpers_1.printInfo)('file', `file uploaded to ${res.Location}`);
|
|
72
|
-
return params.Key;
|
|
73
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.comparePasswords = exports.hashPassword = void 0;
|
|
7
|
-
const bcrypt_1 = __importDefault(require("bcrypt"));
|
|
8
|
-
async function hashPassword(pass) {
|
|
9
|
-
const saltRounds = 10;
|
|
10
|
-
return await bcrypt_1.default.hash(pass, saltRounds);
|
|
11
|
-
}
|
|
12
|
-
exports.hashPassword = hashPassword;
|
|
13
|
-
async function comparePasswords(plainPass, encryptedPass) {
|
|
14
|
-
return await bcrypt_1.default.compare(plainPass, encryptedPass);
|
|
15
|
-
}
|
|
16
|
-
exports.comparePasswords = comparePasswords;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Password = void 0;
|
|
7
|
-
const bcrypt_1 = __importDefault(require("bcrypt"));
|
|
8
|
-
class Password {
|
|
9
|
-
static Hash(data) {
|
|
10
|
-
return bcrypt_1.default.hash(data, 10);
|
|
11
|
-
}
|
|
12
|
-
static Compare(data, encrypted) {
|
|
13
|
-
return bcrypt_1.default.compare(data, encrypted);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.Password = Password;
|