vr-commons 1.0.23 → 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/utils/index.d.ts +1 -1
- package/dist/utils/index.js +24 -10
- package/dist/utils/profiles.utils.d.ts +193 -34
- package/dist/utils/profiles.utils.js +439 -132
- package/dist/validations/index.d.ts +1 -0
- package/dist/validations/index.js +18 -1
- package/dist/validations/profiles.validations.d.ts +362 -75
- package/dist/validations/profiles.validations.js +202 -25
- package/package.json +2 -2
package/dist/utils/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { checkAccountDependencies, hasActiveDependencies, } from "./account.util
|
|
|
2
2
|
export { generateAdminToken, generatePassengerToken, generateRiderToken, verifyToken, } from "./authTokens.utils";
|
|
3
3
|
export { logEvent } from "./eventLog.utils";
|
|
4
4
|
export { sendSuccessResponse, sendErrorResponse } from "./response.utils";
|
|
5
|
-
export {
|
|
5
|
+
export { formatUserProfile, formatUserListResponse, hasRole, hasPermission, hasAnyPermission, hasAllPermissions, canModifyAccount, isAccountAccessible, getUserById, getUsersByRole, findSecurityClearanceByRole, generateUserSearchConditions, generateEventSearchConditions, getSortOrder, generateJacketId, validateUniqueFields, validatePassword, hashPassword, softDeleteUser, } from "./profiles.utils";
|
package/dist/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.softDeleteUser = exports.hashPassword = exports.validatePassword = exports.validateUniqueFields = exports.generateJacketId = exports.getSortOrder = exports.generateEventSearchConditions = exports.generateUserSearchConditions = exports.findSecurityClearanceByRole = exports.getUsersByRole = exports.getUserById = exports.isAccountAccessible = exports.canModifyAccount = exports.hasAllPermissions = exports.hasAnyPermission = exports.hasPermission = exports.hasRole = exports.formatUserListResponse = exports.formatUserProfile = exports.sendErrorResponse = exports.sendSuccessResponse = exports.logEvent = exports.verifyToken = exports.generateRiderToken = exports.generatePassengerToken = exports.generateAdminToken = exports.hasActiveDependencies = exports.checkAccountDependencies = void 0;
|
|
4
4
|
var account_utils_1 = require("./account.utils");
|
|
5
5
|
Object.defineProperty(exports, "checkAccountDependencies", { enumerable: true, get: function () { return account_utils_1.checkAccountDependencies; } });
|
|
6
6
|
Object.defineProperty(exports, "hasActiveDependencies", { enumerable: true, get: function () { return account_utils_1.hasActiveDependencies; } });
|
|
@@ -15,15 +15,29 @@ var response_utils_1 = require("./response.utils");
|
|
|
15
15
|
Object.defineProperty(exports, "sendSuccessResponse", { enumerable: true, get: function () { return response_utils_1.sendSuccessResponse; } });
|
|
16
16
|
Object.defineProperty(exports, "sendErrorResponse", { enumerable: true, get: function () { return response_utils_1.sendErrorResponse; } });
|
|
17
17
|
var profiles_utils_1 = require("./profiles.utils");
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(exports, "
|
|
20
|
-
Object.defineProperty(exports, "
|
|
21
|
-
|
|
22
|
-
Object.defineProperty(exports, "
|
|
23
|
-
Object.defineProperty(exports, "
|
|
18
|
+
// Formatting functions
|
|
19
|
+
Object.defineProperty(exports, "formatUserProfile", { enumerable: true, get: function () { return profiles_utils_1.formatUserProfile; } });
|
|
20
|
+
Object.defineProperty(exports, "formatUserListResponse", { enumerable: true, get: function () { return profiles_utils_1.formatUserListResponse; } });
|
|
21
|
+
// Role check functions
|
|
22
|
+
Object.defineProperty(exports, "hasRole", { enumerable: true, get: function () { return profiles_utils_1.hasRole; } });
|
|
23
|
+
Object.defineProperty(exports, "hasPermission", { enumerable: true, get: function () { return profiles_utils_1.hasPermission; } });
|
|
24
|
+
Object.defineProperty(exports, "hasAnyPermission", { enumerable: true, get: function () { return profiles_utils_1.hasAnyPermission; } });
|
|
25
|
+
Object.defineProperty(exports, "hasAllPermissions", { enumerable: true, get: function () { return profiles_utils_1.hasAllPermissions; } });
|
|
26
|
+
Object.defineProperty(exports, "canModifyAccount", { enumerable: true, get: function () { return profiles_utils_1.canModifyAccount; } });
|
|
27
|
+
Object.defineProperty(exports, "isAccountAccessible", { enumerable: true, get: function () { return profiles_utils_1.isAccountAccessible; } });
|
|
28
|
+
// Database query functions
|
|
24
29
|
Object.defineProperty(exports, "getUserById", { enumerable: true, get: function () { return profiles_utils_1.getUserById; } });
|
|
30
|
+
Object.defineProperty(exports, "getUsersByRole", { enumerable: true, get: function () { return profiles_utils_1.getUsersByRole; } });
|
|
25
31
|
Object.defineProperty(exports, "findSecurityClearanceByRole", { enumerable: true, get: function () { return profiles_utils_1.findSecurityClearanceByRole; } });
|
|
26
|
-
Object.defineProperty(exports, "
|
|
32
|
+
Object.defineProperty(exports, "generateUserSearchConditions", { enumerable: true, get: function () { return profiles_utils_1.generateUserSearchConditions; } });
|
|
33
|
+
Object.defineProperty(exports, "generateEventSearchConditions", { enumerable: true, get: function () { return profiles_utils_1.generateEventSearchConditions; } });
|
|
34
|
+
Object.defineProperty(exports, "getSortOrder", { enumerable: true, get: function () { return profiles_utils_1.getSortOrder; } });
|
|
35
|
+
// Generation functions
|
|
36
|
+
Object.defineProperty(exports, "generateJacketId", { enumerable: true, get: function () { return profiles_utils_1.generateJacketId; } });
|
|
37
|
+
// Validation functions
|
|
27
38
|
Object.defineProperty(exports, "validateUniqueFields", { enumerable: true, get: function () { return profiles_utils_1.validateUniqueFields; } });
|
|
28
|
-
Object.defineProperty(exports, "
|
|
29
|
-
|
|
39
|
+
Object.defineProperty(exports, "validatePassword", { enumerable: true, get: function () { return profiles_utils_1.validatePassword; } });
|
|
40
|
+
// Password functions
|
|
41
|
+
Object.defineProperty(exports, "hashPassword", { enumerable: true, get: function () { return profiles_utils_1.hashPassword; } });
|
|
42
|
+
// Account management functions
|
|
43
|
+
Object.defineProperty(exports, "softDeleteUser", { enumerable: true, get: function () { return profiles_utils_1.softDeleteUser; } });
|
|
@@ -1,52 +1,211 @@
|
|
|
1
|
-
import { User, SecurityClearance, UserRole } from "vr-models";
|
|
2
|
-
|
|
1
|
+
import { User, SecurityClearance, UserRole, Permission } from "vr-models";
|
|
2
|
+
import { Transaction, WhereOptions } from "sequelize";
|
|
3
|
+
export type UserType = "RIDER" | "PASSENGER" | "AGENT" | "ADMIN" | "SUPER_ADMIN";
|
|
4
|
+
export interface ProfileFormatOptions {
|
|
5
|
+
includeSensitive?: boolean;
|
|
6
|
+
includeSecurity?: boolean;
|
|
7
|
+
includeFinancial?: boolean;
|
|
8
|
+
userType?: UserType;
|
|
9
|
+
}
|
|
10
|
+
export interface BaseUserProfile {
|
|
3
11
|
id: string;
|
|
4
12
|
firstName: string;
|
|
5
13
|
lastName: string;
|
|
6
14
|
phoneNumber: string;
|
|
7
15
|
email: string | null;
|
|
8
16
|
nationalId: string;
|
|
17
|
+
isActive: boolean;
|
|
18
|
+
lastLoginAt: Date | null;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
}
|
|
21
|
+
export interface RiderSpecificFields {
|
|
22
|
+
jacketId: string;
|
|
23
|
+
plateNumber: string | null;
|
|
24
|
+
}
|
|
25
|
+
export interface PassengerSpecificFields {
|
|
26
|
+
jacketId: string;
|
|
27
|
+
plateNumber: string | null;
|
|
28
|
+
}
|
|
29
|
+
export interface AdminSpecificFields {
|
|
9
30
|
jacketId: string;
|
|
10
31
|
plateNumber: string | null;
|
|
11
|
-
isActive: boolean;
|
|
12
32
|
isSuspended: boolean;
|
|
13
33
|
isDeactivated: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface SuperAdminSpecificFields extends AdminSpecificFields {
|
|
36
|
+
bannedAt: Date | null;
|
|
37
|
+
banReason: string | null;
|
|
38
|
+
suspendedAt: Date | null;
|
|
39
|
+
suspensionReason: string | null;
|
|
14
40
|
deactivatedAt: Date | null;
|
|
15
|
-
|
|
16
|
-
createdAt: Date;
|
|
17
|
-
role?: string;
|
|
18
|
-
level?: number;
|
|
19
|
-
permissions: string[];
|
|
41
|
+
securityClearanceId: string;
|
|
20
42
|
}
|
|
21
|
-
export interface
|
|
22
|
-
id: string;
|
|
23
|
-
firstName: string;
|
|
24
|
-
lastName: string;
|
|
25
|
-
phoneNumber: string;
|
|
26
|
-
email: string | null;
|
|
27
|
-
nationalId: string;
|
|
28
|
-
isActive: boolean;
|
|
29
|
-
lastLoginAt: Date | null;
|
|
30
|
-
createdAt: Date;
|
|
43
|
+
export interface SecurityFields {
|
|
31
44
|
role?: string;
|
|
32
45
|
level?: number;
|
|
33
|
-
permissions
|
|
34
|
-
}
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
export
|
|
39
|
-
export
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
permissions?: string[];
|
|
47
|
+
}
|
|
48
|
+
export type RiderProfile = BaseUserProfile & RiderSpecificFields & Partial<SecurityFields>;
|
|
49
|
+
export type PassengerProfile = BaseUserProfile & PassengerSpecificFields & Partial<SecurityFields>;
|
|
50
|
+
export type AgentProfile = BaseUserProfile & Partial<SecurityFields>;
|
|
51
|
+
export type AdminProfile = BaseUserProfile & AdminSpecificFields & SecurityFields;
|
|
52
|
+
export type SuperAdminProfile = BaseUserProfile & SuperAdminSpecificFields & SecurityFields;
|
|
53
|
+
export interface UserListResponse {
|
|
54
|
+
data: Array<RiderProfile | PassengerProfile | AgentProfile | AdminProfile | SuperAdminProfile>;
|
|
55
|
+
pagination: {
|
|
56
|
+
total: number;
|
|
57
|
+
page: number;
|
|
58
|
+
limit: number;
|
|
59
|
+
pages: number;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface UserSearchFilters {
|
|
63
|
+
role?: UserRole;
|
|
64
|
+
isActive?: boolean;
|
|
65
|
+
isSuspended?: boolean;
|
|
66
|
+
isBanned?: boolean;
|
|
67
|
+
isDeactivated?: boolean;
|
|
68
|
+
startDate?: string;
|
|
69
|
+
endDate?: string;
|
|
70
|
+
search?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface EventSearchFilters {
|
|
73
|
+
action?: string;
|
|
74
|
+
entity?: string;
|
|
75
|
+
startDate?: string;
|
|
76
|
+
endDate?: string;
|
|
77
|
+
}
|
|
78
|
+
export interface ValidationError {
|
|
45
79
|
field: string;
|
|
46
80
|
message: string;
|
|
47
|
-
}
|
|
48
|
-
export
|
|
49
|
-
|
|
81
|
+
}
|
|
82
|
+
export interface GetUsersResult {
|
|
83
|
+
users: User[];
|
|
84
|
+
total: number;
|
|
85
|
+
}
|
|
86
|
+
export declare const PHONE_REGEX: RegExp;
|
|
87
|
+
export declare const NATIONAL_ID_REGEX: RegExp;
|
|
88
|
+
export declare const JACKET_ID_REGEX: RegExp;
|
|
89
|
+
export declare const JACKET_ID_PREFIX = "JKT";
|
|
90
|
+
/**
|
|
91
|
+
* Format user profile based on viewer type and options
|
|
92
|
+
*/
|
|
93
|
+
export declare const formatUserProfile: (user: User, viewerType?: UserType, options?: ProfileFormatOptions) => RiderProfile | PassengerProfile | AgentProfile | AdminProfile | SuperAdminProfile;
|
|
94
|
+
/**
|
|
95
|
+
* Format user list for response (paginated)
|
|
96
|
+
*/
|
|
97
|
+
export declare const formatUserListResponse: (users: User[], total: number, page: number, limit: number, viewerType?: UserType) => UserListResponse;
|
|
98
|
+
/**
|
|
99
|
+
* Check if user has a specific role
|
|
100
|
+
*/
|
|
101
|
+
export declare const hasRole: (user: User, role: UserRole | UserRole[]) => boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Check if user has a specific permission
|
|
104
|
+
*/
|
|
105
|
+
export declare const hasPermission: (user: User, permission: Permission) => boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Check if user has any of the given permissions
|
|
108
|
+
*/
|
|
109
|
+
export declare const hasAnyPermission: (user: User, permissions: Permission[]) => boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Check if user has all of the given permissions
|
|
112
|
+
*/
|
|
113
|
+
export declare const hasAllPermissions: (user: User, permissions: Permission[]) => boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Check if account can be modified (not deactivated/suspended)
|
|
116
|
+
*/
|
|
117
|
+
export declare const canModifyAccount: (user: User) => boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Check if account is active and accessible
|
|
120
|
+
*/
|
|
121
|
+
export declare const isAccountAccessible: (user: User) => boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Get user by ID with security clearance
|
|
124
|
+
*/
|
|
125
|
+
export declare const getUserById: (userId: string, includeSecurity?: boolean, excludeSensitive?: boolean) => Promise<User | null>;
|
|
126
|
+
/**
|
|
127
|
+
* Get users by role with optional filters
|
|
128
|
+
*/
|
|
129
|
+
export declare const getUsersByRole: (role: UserRole, filters?: UserSearchFilters, pagination?: {
|
|
130
|
+
page: number;
|
|
131
|
+
limit: number;
|
|
132
|
+
}) => Promise<GetUsersResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Find security clearance by role
|
|
135
|
+
*/
|
|
136
|
+
export declare const findSecurityClearanceByRole: (role: UserRole, requireDefault?: boolean) => Promise<SecurityClearance | null>;
|
|
137
|
+
/**
|
|
138
|
+
* Generate search conditions for user queries
|
|
139
|
+
*/
|
|
140
|
+
export declare const generateUserSearchConditions: (filters: UserSearchFilters) => WhereOptions;
|
|
141
|
+
/**
|
|
142
|
+
* Generate search conditions for event logs
|
|
143
|
+
*/
|
|
144
|
+
export declare const generateEventSearchConditions: (userId: string, filters: EventSearchFilters) => WhereOptions;
|
|
145
|
+
/**
|
|
146
|
+
* Get sort order for queries
|
|
147
|
+
*/
|
|
148
|
+
export declare const getSortOrder: (sortBy?: string, order?: string) => any[];
|
|
149
|
+
/**
|
|
150
|
+
* Generate unique jacket ID
|
|
151
|
+
*/
|
|
152
|
+
export declare const generateJacketId: () => Promise<string>;
|
|
153
|
+
/**
|
|
154
|
+
* Validate unique user fields
|
|
155
|
+
*/
|
|
156
|
+
export declare const validateUniqueFields: (fields: {
|
|
157
|
+
phoneNumber?: string;
|
|
158
|
+
nationalId?: string;
|
|
159
|
+
email?: string | null;
|
|
160
|
+
jacketId?: string;
|
|
161
|
+
}, excludeUserId?: string) => Promise<ValidationError[]>;
|
|
162
|
+
/**
|
|
163
|
+
* Validate password
|
|
164
|
+
*/
|
|
165
|
+
export declare const validatePassword: (plainPassword: string, hashedPassword: string | null) => Promise<boolean>;
|
|
166
|
+
/**
|
|
167
|
+
* Hash password
|
|
168
|
+
*/
|
|
169
|
+
export declare const hashPassword: (password: string) => Promise<string>;
|
|
170
|
+
/**
|
|
171
|
+
* Soft delete user
|
|
172
|
+
*/
|
|
173
|
+
export declare const softDeleteUser: (userId: string, options?: {
|
|
50
174
|
reason?: string;
|
|
175
|
+
deletedBy?: string;
|
|
176
|
+
transaction?: Transaction;
|
|
177
|
+
}) => Promise<void>;
|
|
178
|
+
declare const _default: {
|
|
179
|
+
formatUserProfile: (user: User, viewerType?: UserType, options?: ProfileFormatOptions) => RiderProfile | PassengerProfile | AgentProfile | AdminProfile | SuperAdminProfile;
|
|
180
|
+
formatUserListResponse: (users: User[], total: number, page: number, limit: number, viewerType?: UserType) => UserListResponse;
|
|
181
|
+
hasRole: (user: User, role: UserRole | UserRole[]) => boolean;
|
|
182
|
+
hasPermission: (user: User, permission: Permission) => boolean;
|
|
183
|
+
hasAnyPermission: (user: User, permissions: Permission[]) => boolean;
|
|
184
|
+
hasAllPermissions: (user: User, permissions: Permission[]) => boolean;
|
|
185
|
+
canModifyAccount: (user: User) => boolean;
|
|
186
|
+
isAccountAccessible: (user: User) => boolean;
|
|
187
|
+
getUserById: (userId: string, includeSecurity?: boolean, excludeSensitive?: boolean) => Promise<User | null>;
|
|
188
|
+
getUsersByRole: (role: UserRole, filters?: UserSearchFilters, pagination?: {
|
|
189
|
+
page: number;
|
|
190
|
+
limit: number;
|
|
191
|
+
}) => Promise<GetUsersResult>;
|
|
192
|
+
findSecurityClearanceByRole: (role: UserRole, requireDefault?: boolean) => Promise<SecurityClearance | null>;
|
|
193
|
+
generateUserSearchConditions: (filters: UserSearchFilters) => WhereOptions;
|
|
194
|
+
generateEventSearchConditions: (userId: string, filters: EventSearchFilters) => WhereOptions;
|
|
195
|
+
getSortOrder: (sortBy?: string, order?: string) => any[];
|
|
196
|
+
generateJacketId: () => Promise<string>;
|
|
197
|
+
validateUniqueFields: (fields: {
|
|
198
|
+
phoneNumber?: string;
|
|
199
|
+
nationalId?: string;
|
|
200
|
+
email?: string | null;
|
|
201
|
+
jacketId?: string;
|
|
202
|
+
}, excludeUserId?: string) => Promise<ValidationError[]>;
|
|
203
|
+
validatePassword: (plainPassword: string, hashedPassword: string | null) => Promise<boolean>;
|
|
204
|
+
hashPassword: (password: string) => Promise<string>;
|
|
205
|
+
softDeleteUser: (userId: string, options?: {
|
|
206
|
+
reason?: string;
|
|
207
|
+
deletedBy?: string;
|
|
208
|
+
transaction?: Transaction;
|
|
209
|
+
}) => Promise<void>;
|
|
51
210
|
};
|
|
52
|
-
export
|
|
211
|
+
export default _default;
|