itrm-tools 1.3.17 → 1.3.19
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/api/alegra/AlegraConnectionManager.d.ts +30 -30
- package/dist/api/check/route/CorsCheckApiRouter.js +1 -1
- package/dist/api/check/route/CorsCheckApiRouter.js.map +1 -1
- package/dist/api/check/route/SimpleCheckableAPIRouter.js +4 -1
- package/dist/api/check/route/SimpleCheckableAPIRouter.js.map +1 -1
- package/dist/api/express/ExpressStandardConfiguration.js +7 -2
- package/dist/api/express/ExpressStandardConfiguration.js.map +1 -1
- package/dist/api/request/crud/CrudManager.d.ts +11 -11
- package/dist/api/request/crud/CrudServiceManager.d.ts +28 -28
- package/dist/api/request/crud/CrudServiceManager.js +98 -98
- package/dist/api/request/crud/common/ActivityHistoryManager.d.ts +38 -38
- package/dist/api/request/crud/common/ActivityHistoryManager.js +68 -68
- package/dist/api/request/crud/common/ApplicationManager.d.ts +37 -37
- package/dist/api/request/crud/common/ApplicationManager.js +56 -56
- package/dist/api/request/crud/common/AvailablePlatformManager.d.ts +38 -38
- package/dist/api/request/crud/common/AvailablePlatformManager.js +68 -68
- package/dist/api/request/crud/common/ComponentManager.d.ts +48 -48
- package/dist/api/request/crud/common/ComponentManager.js +62 -62
- package/dist/api/request/crud/common/KeyManager.d.ts +41 -41
- package/dist/api/request/crud/common/KeyManager.js +69 -69
- package/dist/api/request/crud/common/PlatformManager.d.ts +41 -41
- package/dist/api/request/crud/common/PlatformManager.js +59 -59
- package/dist/api/request/crud/common/RoleManager.d.ts +40 -40
- package/dist/api/request/crud/common/RoleManager.js +56 -56
- package/dist/api/request/crud/common/StatusManager.d.ts +32 -32
- package/dist/api/request/crud/common/StatusManager.js +56 -56
- package/dist/api/request/crud/common/TypeManager.d.ts +32 -32
- package/dist/api/request/crud/common/TypeManager.js +56 -56
- package/dist/api/request/crud/common/UserCredentialsManager.d.ts +37 -37
- package/dist/api/request/crud/common/UserCredentialsManager.js +66 -66
- package/dist/api/request/crud/common/UserManager.d.ts +38 -38
- package/dist/api/request/crud/common/UserManager.js +62 -62
- package/dist/api/utils/Response.d.ts +25 -25
- package/dist/api/utils/Response.js +85 -85
- package/dist/cryptography/jwt/JwtUtils.d.ts +18 -18
- package/dist/cryptography/jwt/JwtUtils.js +36 -36
- package/dist/cryptography/password/PasswordUtils.d.ts +6 -6
- package/dist/cryptography/password/PasswordUtils.js +34 -34
- package/dist/index.d.ts +62 -62
- package/dist/index.js +126 -126
- package/dist/types/api.d.ts +21 -21
- package/dist/types/api.js +2 -2
- package/package.json +4 -4
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserManager = void 0;
|
|
4
|
-
const CrudServiceManager_1 = require("../CrudServiceManager");
|
|
5
|
-
class UserManager extends CrudServiceManager_1.CrudServiceManager {
|
|
6
|
-
url;
|
|
7
|
-
constructor(url) {
|
|
8
|
-
super();
|
|
9
|
-
this.url = url;
|
|
10
|
-
}
|
|
11
|
-
find(details) {
|
|
12
|
-
return this.sendFinding(`${this.url}/users?credentialsId=${details.credentialsId}`, details.config);
|
|
13
|
-
}
|
|
14
|
-
findById(details) {
|
|
15
|
-
return this.sendFinding(`${this.url}/users?id=${details.id}`, details.config);
|
|
16
|
-
}
|
|
17
|
-
async count(details) {
|
|
18
|
-
let url = this.buildRequestUrl(`${this.url}/users`, details);
|
|
19
|
-
return (await this.sendCounting(url, details.config)) ?? 0;
|
|
20
|
-
}
|
|
21
|
-
async findAll(details) {
|
|
22
|
-
let users = [];
|
|
23
|
-
let url = this.buildRequestUrl(`${this.url}/users`, details);
|
|
24
|
-
if (details.limit) {
|
|
25
|
-
users = (await this.sendAllFinding(`${url}${url.indexOf('?') !== -1 ? '&' : '?'}limit=${details.limit}&offset=${details.offset}`, details.config)) ?? [];
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
let limit = 5000, offset = 0, isEmpty = false;
|
|
29
|
-
do {
|
|
30
|
-
let values = await this.sendAllFinding(`${url}${url.indexOf('?') !== -1 ? '&' : '?'}limit=${limit}&offset=${offset}`, details.config);
|
|
31
|
-
if (values)
|
|
32
|
-
users = users.concat(values);
|
|
33
|
-
isEmpty = values == undefined || values.length == 0;
|
|
34
|
-
offset += limit;
|
|
35
|
-
} while (!isEmpty);
|
|
36
|
-
}
|
|
37
|
-
return users;
|
|
38
|
-
}
|
|
39
|
-
buildRequestUrl(url, details) {
|
|
40
|
-
let suffix = `${details.id ? `&id=${details.id}` : ""}${details.credentials ? `&credentials=${details.credentials}` : ""}${details.credentialsId ? `&credentialsId=${details.credentialsId}` : ""}`;
|
|
41
|
-
return `${url}?${suffix.substring(1)}`;
|
|
42
|
-
}
|
|
43
|
-
create(details) {
|
|
44
|
-
return this.sendCreation(`${this.url}/users`, {
|
|
45
|
-
statusId: details.statusId,
|
|
46
|
-
credentialsId: details.credentialsId
|
|
47
|
-
}, details.config);
|
|
48
|
-
}
|
|
49
|
-
createMany(details) {
|
|
50
|
-
return this.sendCreationMany(`${this.url}/users`, details.values ?? [], details.config);
|
|
51
|
-
}
|
|
52
|
-
modify(user) {
|
|
53
|
-
return this.sendModification(`${this.url}/users/${user.userId}`, {
|
|
54
|
-
statusId: user.statusId,
|
|
55
|
-
credentialsId: user.credentialsId
|
|
56
|
-
}, user.config);
|
|
57
|
-
}
|
|
58
|
-
destroy(user) {
|
|
59
|
-
return this.sendDestruction(`${this.url}/users/${user.userId}`, user.config);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.UserManager = UserManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserManager = void 0;
|
|
4
|
+
const CrudServiceManager_1 = require("../CrudServiceManager");
|
|
5
|
+
class UserManager extends CrudServiceManager_1.CrudServiceManager {
|
|
6
|
+
url;
|
|
7
|
+
constructor(url) {
|
|
8
|
+
super();
|
|
9
|
+
this.url = url;
|
|
10
|
+
}
|
|
11
|
+
find(details) {
|
|
12
|
+
return this.sendFinding(`${this.url}/users?credentialsId=${details.credentialsId}`, details.config);
|
|
13
|
+
}
|
|
14
|
+
findById(details) {
|
|
15
|
+
return this.sendFinding(`${this.url}/users?id=${details.id}`, details.config);
|
|
16
|
+
}
|
|
17
|
+
async count(details) {
|
|
18
|
+
let url = this.buildRequestUrl(`${this.url}/users`, details);
|
|
19
|
+
return (await this.sendCounting(url, details.config)) ?? 0;
|
|
20
|
+
}
|
|
21
|
+
async findAll(details) {
|
|
22
|
+
let users = [];
|
|
23
|
+
let url = this.buildRequestUrl(`${this.url}/users`, details);
|
|
24
|
+
if (details.limit) {
|
|
25
|
+
users = (await this.sendAllFinding(`${url}${url.indexOf('?') !== -1 ? '&' : '?'}limit=${details.limit}&offset=${details.offset}`, details.config)) ?? [];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
let limit = 5000, offset = 0, isEmpty = false;
|
|
29
|
+
do {
|
|
30
|
+
let values = await this.sendAllFinding(`${url}${url.indexOf('?') !== -1 ? '&' : '?'}limit=${limit}&offset=${offset}`, details.config);
|
|
31
|
+
if (values)
|
|
32
|
+
users = users.concat(values);
|
|
33
|
+
isEmpty = values == undefined || values.length == 0;
|
|
34
|
+
offset += limit;
|
|
35
|
+
} while (!isEmpty);
|
|
36
|
+
}
|
|
37
|
+
return users;
|
|
38
|
+
}
|
|
39
|
+
buildRequestUrl(url, details) {
|
|
40
|
+
let suffix = `${details.id ? `&id=${details.id}` : ""}${details.credentials ? `&credentials=${details.credentials}` : ""}${details.credentialsId ? `&credentialsId=${details.credentialsId}` : ""}`;
|
|
41
|
+
return `${url}?${suffix.substring(1)}`;
|
|
42
|
+
}
|
|
43
|
+
create(details) {
|
|
44
|
+
return this.sendCreation(`${this.url}/users`, {
|
|
45
|
+
statusId: details.statusId,
|
|
46
|
+
credentialsId: details.credentialsId
|
|
47
|
+
}, details.config);
|
|
48
|
+
}
|
|
49
|
+
createMany(details) {
|
|
50
|
+
return this.sendCreationMany(`${this.url}/users`, details.values ?? [], details.config);
|
|
51
|
+
}
|
|
52
|
+
modify(user) {
|
|
53
|
+
return this.sendModification(`${this.url}/users/${user.userId}`, {
|
|
54
|
+
statusId: user.statusId,
|
|
55
|
+
credentialsId: user.credentialsId
|
|
56
|
+
}, user.config);
|
|
57
|
+
}
|
|
58
|
+
destroy(user) {
|
|
59
|
+
return this.sendDestruction(`${this.url}/users/${user.userId}`, user.config);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.UserManager = UserManager;
|
|
63
63
|
//# sourceMappingURL=UserManager.js.map
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { ApiResponse, PaginationMeta } from "../../types/api";
|
|
2
|
-
export declare class ApiServiceError extends Error {
|
|
3
|
-
readonly httpStatus: number;
|
|
4
|
-
readonly code: string;
|
|
5
|
-
readonly details?: any | undefined;
|
|
6
|
-
constructor(httpStatus: number, code: string, message: string, details?: any | undefined);
|
|
7
|
-
}
|
|
8
|
-
export declare class ResponseUtils {
|
|
9
|
-
static success<T = null>(payload: T, message?: string, meta?: Partial<ApiResponse['meta']>): ApiResponse<T>;
|
|
10
|
-
static error(apiError: ApiServiceError, meta?: Partial<ApiResponse['meta']>): ApiResponse<null>;
|
|
11
|
-
static paginated<T>(payload: T[], pagination: PaginationMeta, message?: string): ApiResponse<T[]>;
|
|
12
|
-
}
|
|
13
|
-
export declare function mapErrorCodeToHttpStatus(code: string): number;
|
|
14
|
-
export declare enum HttpCode {
|
|
15
|
-
OK = 200,
|
|
16
|
-
CREATED = 201,
|
|
17
|
-
NO_CONTENT = 204,
|
|
18
|
-
BAD_REQUEST = 400,
|
|
19
|
-
UNAUTHORIZED = 401,
|
|
20
|
-
FORBIDDEN = 403,
|
|
21
|
-
NOT_FOUND = 404,
|
|
22
|
-
CONFLICT = 409,
|
|
23
|
-
INTERNAL_SERVER_ERROR = 500,
|
|
24
|
-
SERVICE_UNAVAILABLE = 503
|
|
25
|
-
}
|
|
1
|
+
import { ApiResponse, PaginationMeta } from "../../types/api";
|
|
2
|
+
export declare class ApiServiceError extends Error {
|
|
3
|
+
readonly httpStatus: number;
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly details?: any | undefined;
|
|
6
|
+
constructor(httpStatus: number, code: string, message: string, details?: any | undefined);
|
|
7
|
+
}
|
|
8
|
+
export declare class ResponseUtils {
|
|
9
|
+
static success<T = null>(payload: T, message?: string, meta?: Partial<ApiResponse['meta']>): ApiResponse<T>;
|
|
10
|
+
static error(apiError: ApiServiceError, meta?: Partial<ApiResponse['meta']>): ApiResponse<null>;
|
|
11
|
+
static paginated<T>(payload: T[], pagination: PaginationMeta, message?: string): ApiResponse<T[]>;
|
|
12
|
+
}
|
|
13
|
+
export declare function mapErrorCodeToHttpStatus(code: string): number;
|
|
14
|
+
export declare enum HttpCode {
|
|
15
|
+
OK = 200,
|
|
16
|
+
CREATED = 201,
|
|
17
|
+
NO_CONTENT = 204,
|
|
18
|
+
BAD_REQUEST = 400,
|
|
19
|
+
UNAUTHORIZED = 401,
|
|
20
|
+
FORBIDDEN = 403,
|
|
21
|
+
NOT_FOUND = 404,
|
|
22
|
+
CONFLICT = 409,
|
|
23
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
24
|
+
SERVICE_UNAVAILABLE = 503
|
|
25
|
+
}
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpCode = exports.ResponseUtils = exports.ApiServiceError = void 0;
|
|
4
|
-
exports.mapErrorCodeToHttpStatus = mapErrorCodeToHttpStatus;
|
|
5
|
-
class ApiServiceError extends Error {
|
|
6
|
-
httpStatus;
|
|
7
|
-
code;
|
|
8
|
-
details;
|
|
9
|
-
constructor(httpStatus, code, message, details) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.httpStatus = httpStatus;
|
|
12
|
-
this.code = code;
|
|
13
|
-
this.details = details;
|
|
14
|
-
// Maintains proper stack trace
|
|
15
|
-
Object.setPrototypeOf(this, ApiServiceError.prototype);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.ApiServiceError = ApiServiceError;
|
|
19
|
-
class ResponseUtils {
|
|
20
|
-
static success(payload, message, meta) {
|
|
21
|
-
return {
|
|
22
|
-
success: true,
|
|
23
|
-
payload,
|
|
24
|
-
message,
|
|
25
|
-
meta: {
|
|
26
|
-
timestamp: new Date().toISOString(),
|
|
27
|
-
...meta,
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
static error(apiError, meta) {
|
|
32
|
-
return {
|
|
33
|
-
success: false,
|
|
34
|
-
payload: null,
|
|
35
|
-
error: {
|
|
36
|
-
code: apiError.code,
|
|
37
|
-
message: apiError.message,
|
|
38
|
-
details: apiError.details,
|
|
39
|
-
},
|
|
40
|
-
meta: {
|
|
41
|
-
timestamp: new Date().toISOString(),
|
|
42
|
-
...meta,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
static paginated(payload, pagination, message) {
|
|
47
|
-
return {
|
|
48
|
-
success: true,
|
|
49
|
-
payload,
|
|
50
|
-
message,
|
|
51
|
-
meta: {
|
|
52
|
-
timestamp: new Date().toISOString(),
|
|
53
|
-
pagination,
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.ResponseUtils = ResponseUtils;
|
|
59
|
-
function mapErrorCodeToHttpStatus(code) {
|
|
60
|
-
switch (code) {
|
|
61
|
-
case 'NOT_FOUND':
|
|
62
|
-
return HttpCode.NOT_FOUND;
|
|
63
|
-
case 'UNAUTHORIZED':
|
|
64
|
-
return HttpCode.UNAUTHORIZED;
|
|
65
|
-
case 'INTERNAL_SERVER_ERROR':
|
|
66
|
-
return HttpCode.INTERNAL_SERVER_ERROR;
|
|
67
|
-
case 'FORBIDDEN':
|
|
68
|
-
return HttpCode.FORBIDDEN;
|
|
69
|
-
default:
|
|
70
|
-
return HttpCode.BAD_REQUEST;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
var HttpCode;
|
|
74
|
-
(function (HttpCode) {
|
|
75
|
-
HttpCode[HttpCode["OK"] = 200] = "OK";
|
|
76
|
-
HttpCode[HttpCode["CREATED"] = 201] = "CREATED";
|
|
77
|
-
HttpCode[HttpCode["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
78
|
-
HttpCode[HttpCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
79
|
-
HttpCode[HttpCode["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
80
|
-
HttpCode[HttpCode["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
81
|
-
HttpCode[HttpCode["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
82
|
-
HttpCode[HttpCode["CONFLICT"] = 409] = "CONFLICT";
|
|
83
|
-
HttpCode[HttpCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
84
|
-
HttpCode[HttpCode["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
85
|
-
})(HttpCode || (exports.HttpCode = HttpCode = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpCode = exports.ResponseUtils = exports.ApiServiceError = void 0;
|
|
4
|
+
exports.mapErrorCodeToHttpStatus = mapErrorCodeToHttpStatus;
|
|
5
|
+
class ApiServiceError extends Error {
|
|
6
|
+
httpStatus;
|
|
7
|
+
code;
|
|
8
|
+
details;
|
|
9
|
+
constructor(httpStatus, code, message, details) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.httpStatus = httpStatus;
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.details = details;
|
|
14
|
+
// Maintains proper stack trace
|
|
15
|
+
Object.setPrototypeOf(this, ApiServiceError.prototype);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ApiServiceError = ApiServiceError;
|
|
19
|
+
class ResponseUtils {
|
|
20
|
+
static success(payload, message, meta) {
|
|
21
|
+
return {
|
|
22
|
+
success: true,
|
|
23
|
+
payload,
|
|
24
|
+
message,
|
|
25
|
+
meta: {
|
|
26
|
+
timestamp: new Date().toISOString(),
|
|
27
|
+
...meta,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
static error(apiError, meta) {
|
|
32
|
+
return {
|
|
33
|
+
success: false,
|
|
34
|
+
payload: null,
|
|
35
|
+
error: {
|
|
36
|
+
code: apiError.code,
|
|
37
|
+
message: apiError.message,
|
|
38
|
+
details: apiError.details,
|
|
39
|
+
},
|
|
40
|
+
meta: {
|
|
41
|
+
timestamp: new Date().toISOString(),
|
|
42
|
+
...meta,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
static paginated(payload, pagination, message) {
|
|
47
|
+
return {
|
|
48
|
+
success: true,
|
|
49
|
+
payload,
|
|
50
|
+
message,
|
|
51
|
+
meta: {
|
|
52
|
+
timestamp: new Date().toISOString(),
|
|
53
|
+
pagination,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.ResponseUtils = ResponseUtils;
|
|
59
|
+
function mapErrorCodeToHttpStatus(code) {
|
|
60
|
+
switch (code) {
|
|
61
|
+
case 'NOT_FOUND':
|
|
62
|
+
return HttpCode.NOT_FOUND;
|
|
63
|
+
case 'UNAUTHORIZED':
|
|
64
|
+
return HttpCode.UNAUTHORIZED;
|
|
65
|
+
case 'INTERNAL_SERVER_ERROR':
|
|
66
|
+
return HttpCode.INTERNAL_SERVER_ERROR;
|
|
67
|
+
case 'FORBIDDEN':
|
|
68
|
+
return HttpCode.FORBIDDEN;
|
|
69
|
+
default:
|
|
70
|
+
return HttpCode.BAD_REQUEST;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
var HttpCode;
|
|
74
|
+
(function (HttpCode) {
|
|
75
|
+
HttpCode[HttpCode["OK"] = 200] = "OK";
|
|
76
|
+
HttpCode[HttpCode["CREATED"] = 201] = "CREATED";
|
|
77
|
+
HttpCode[HttpCode["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
78
|
+
HttpCode[HttpCode["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
79
|
+
HttpCode[HttpCode["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
80
|
+
HttpCode[HttpCode["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
81
|
+
HttpCode[HttpCode["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
82
|
+
HttpCode[HttpCode["CONFLICT"] = 409] = "CONFLICT";
|
|
83
|
+
HttpCode[HttpCode["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
84
|
+
HttpCode[HttpCode["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
85
|
+
})(HttpCode || (exports.HttpCode = HttpCode = {}));
|
|
86
86
|
//# sourceMappingURL=Response.js.map
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { JWTPayload } from 'jose';
|
|
2
|
-
export interface CustomJWTPayload extends JWTPayload {
|
|
3
|
-
userId: string;
|
|
4
|
-
rolesByPlatform: Record<string, string>;
|
|
5
|
-
status: string;
|
|
6
|
-
application: string;
|
|
7
|
-
metadata?: Record<string, boolean>;
|
|
8
|
-
}
|
|
9
|
-
export interface JwtConfig {
|
|
10
|
-
algorithm?: string;
|
|
11
|
-
expirationTime?: number;
|
|
12
|
-
}
|
|
13
|
-
export declare class JwtUtils {
|
|
14
|
-
private readonly config;
|
|
15
|
-
constructor(config: JwtConfig);
|
|
16
|
-
sign(payload: CustomJWTPayload, secretKey: string): Promise<string | undefined>;
|
|
17
|
-
verify(token: string, secretKey: string): Promise<CustomJWTPayload | undefined>;
|
|
18
|
-
}
|
|
1
|
+
import { JWTPayload } from 'jose';
|
|
2
|
+
export interface CustomJWTPayload extends JWTPayload {
|
|
3
|
+
userId: string;
|
|
4
|
+
rolesByPlatform: Record<string, string>;
|
|
5
|
+
status: string;
|
|
6
|
+
application: string;
|
|
7
|
+
metadata?: Record<string, boolean>;
|
|
8
|
+
}
|
|
9
|
+
export interface JwtConfig {
|
|
10
|
+
algorithm?: string;
|
|
11
|
+
expirationTime?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class JwtUtils {
|
|
14
|
+
private readonly config;
|
|
15
|
+
constructor(config: JwtConfig);
|
|
16
|
+
sign(payload: CustomJWTPayload, secretKey: string): Promise<string | undefined>;
|
|
17
|
+
verify(token: string, secretKey: string): Promise<CustomJWTPayload | undefined>;
|
|
18
|
+
}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JwtUtils = void 0;
|
|
4
|
-
const jose_1 = require("jose");
|
|
5
|
-
class JwtUtils {
|
|
6
|
-
config;
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.config = config;
|
|
9
|
-
}
|
|
10
|
-
async sign(payload, secretKey) {
|
|
11
|
-
try {
|
|
12
|
-
const keyToUse = new TextEncoder().encode(secretKey);
|
|
13
|
-
const jwt = new jose_1.SignJWT(payload)
|
|
14
|
-
.setProtectedHeader({ alg: this.config.algorithm ?? 'HS512' })
|
|
15
|
-
.setIssuedAt()
|
|
16
|
-
.setExpirationTime(Date.now() + (this.config.expirationTime ?? 3600) * 1000);
|
|
17
|
-
return await jwt.sign(keyToUse);
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.error(`Failed to sign JWT: ${error}`);
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async verify(token, secretKey) {
|
|
25
|
-
try {
|
|
26
|
-
const keyToUse = new TextEncoder().encode(secretKey);
|
|
27
|
-
const { payload } = await (0, jose_1.jwtVerify)(token, keyToUse);
|
|
28
|
-
return payload;
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
console.error(`Failed to verify JWT: ${error}`);
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.JwtUtils = JwtUtils;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JwtUtils = void 0;
|
|
4
|
+
const jose_1 = require("jose");
|
|
5
|
+
class JwtUtils {
|
|
6
|
+
config;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
async sign(payload, secretKey) {
|
|
11
|
+
try {
|
|
12
|
+
const keyToUse = new TextEncoder().encode(secretKey);
|
|
13
|
+
const jwt = new jose_1.SignJWT(payload)
|
|
14
|
+
.setProtectedHeader({ alg: this.config.algorithm ?? 'HS512' })
|
|
15
|
+
.setIssuedAt()
|
|
16
|
+
.setExpirationTime(Date.now() + (this.config.expirationTime ?? 3600) * 1000);
|
|
17
|
+
return await jwt.sign(keyToUse);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.error(`Failed to sign JWT: ${error}`);
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async verify(token, secretKey) {
|
|
25
|
+
try {
|
|
26
|
+
const keyToUse = new TextEncoder().encode(secretKey);
|
|
27
|
+
const { payload } = await (0, jose_1.jwtVerify)(token, keyToUse);
|
|
28
|
+
return payload;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error(`Failed to verify JWT: ${error}`);
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.JwtUtils = JwtUtils;
|
|
37
37
|
//# sourceMappingURL=JwtUtils.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare class PasswordUtils {
|
|
2
|
-
private readonly iterations;
|
|
3
|
-
constructor(iterations?: number);
|
|
4
|
-
hashPassword(password: string): Promise<string>;
|
|
5
|
-
comparePasswords(password: string, storedHash: string): Promise<boolean>;
|
|
6
|
-
}
|
|
1
|
+
export declare class PasswordUtils {
|
|
2
|
+
private readonly iterations;
|
|
3
|
+
constructor(iterations?: number);
|
|
4
|
+
hashPassword(password: string): Promise<string>;
|
|
5
|
+
comparePasswords(password: string, storedHash: string): Promise<boolean>;
|
|
6
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PasswordUtils = void 0;
|
|
4
|
-
const crypto_js_1 = require("crypto-js");
|
|
5
|
-
class PasswordUtils {
|
|
6
|
-
iterations;
|
|
7
|
-
constructor(iterations = 600000) {
|
|
8
|
-
this.iterations = iterations;
|
|
9
|
-
}
|
|
10
|
-
async hashPassword(password) {
|
|
11
|
-
const salt = crypto_js_1.lib.WordArray.random(128 / 8); // 128-bit salt is standard
|
|
12
|
-
const hash = (0, crypto_js_1.PBKDF2)(password, salt, {
|
|
13
|
-
keySize: 512 / 32, // 512-bit key
|
|
14
|
-
iterations: this.iterations,
|
|
15
|
-
hasher: crypto_js_1.algo.SHA256,
|
|
16
|
-
});
|
|
17
|
-
return `${crypto_js_1.enc.Hex.stringify(salt)}:${crypto_js_1.enc.Hex.stringify(hash)}`;
|
|
18
|
-
}
|
|
19
|
-
async comparePasswords(password, storedHash) {
|
|
20
|
-
const [saltHex, originalHashHex] = storedHash.split(':');
|
|
21
|
-
if (!saltHex || !originalHashHex) {
|
|
22
|
-
throw new Error("Invalid stored hash format. Expected 'salt:hash'.");
|
|
23
|
-
}
|
|
24
|
-
const salt = crypto_js_1.enc.Hex.parse(saltHex);
|
|
25
|
-
const hash = (0, crypto_js_1.PBKDF2)(password, salt, {
|
|
26
|
-
keySize: 512 / 32,
|
|
27
|
-
iterations: this.iterations,
|
|
28
|
-
hasher: crypto_js_1.algo.SHA256,
|
|
29
|
-
});
|
|
30
|
-
const inputPasswordHashHex = crypto_js_1.enc.Hex.stringify(hash);
|
|
31
|
-
return inputPasswordHashHex === originalHashHex;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.PasswordUtils = PasswordUtils;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PasswordUtils = void 0;
|
|
4
|
+
const crypto_js_1 = require("crypto-js");
|
|
5
|
+
class PasswordUtils {
|
|
6
|
+
iterations;
|
|
7
|
+
constructor(iterations = 600000) {
|
|
8
|
+
this.iterations = iterations;
|
|
9
|
+
}
|
|
10
|
+
async hashPassword(password) {
|
|
11
|
+
const salt = crypto_js_1.lib.WordArray.random(128 / 8); // 128-bit salt is standard
|
|
12
|
+
const hash = (0, crypto_js_1.PBKDF2)(password, salt, {
|
|
13
|
+
keySize: 512 / 32, // 512-bit key
|
|
14
|
+
iterations: this.iterations,
|
|
15
|
+
hasher: crypto_js_1.algo.SHA256,
|
|
16
|
+
});
|
|
17
|
+
return `${crypto_js_1.enc.Hex.stringify(salt)}:${crypto_js_1.enc.Hex.stringify(hash)}`;
|
|
18
|
+
}
|
|
19
|
+
async comparePasswords(password, storedHash) {
|
|
20
|
+
const [saltHex, originalHashHex] = storedHash.split(':');
|
|
21
|
+
if (!saltHex || !originalHashHex) {
|
|
22
|
+
throw new Error("Invalid stored hash format. Expected 'salt:hash'.");
|
|
23
|
+
}
|
|
24
|
+
const salt = crypto_js_1.enc.Hex.parse(saltHex);
|
|
25
|
+
const hash = (0, crypto_js_1.PBKDF2)(password, salt, {
|
|
26
|
+
keySize: 512 / 32,
|
|
27
|
+
iterations: this.iterations,
|
|
28
|
+
hasher: crypto_js_1.algo.SHA256,
|
|
29
|
+
});
|
|
30
|
+
const inputPasswordHashHex = crypto_js_1.enc.Hex.stringify(hash);
|
|
31
|
+
return inputPasswordHashHex === originalHashHex;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.PasswordUtils = PasswordUtils;
|
|
35
35
|
//# sourceMappingURL=PasswordUtils.js.map
|