@zlspace/z-auth 1.0.2 → 1.0.4
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/README.md +8 -7
- package/dist/index.d.mts +25 -20
- package/dist/index.d.ts +25 -20
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,16 +80,17 @@ Output:
|
|
|
80
80
|
### User Service
|
|
81
81
|
|
|
82
82
|
```javascript
|
|
83
|
-
createUser(data: I_Users)
|
|
84
|
-
login(data: I_LoginRequest)
|
|
85
|
-
forgotPassword(data: I_ForgotPasswordRequest)
|
|
83
|
+
createUser(data: I_Users) // {data: email, password, contactNumber, recoveryEmail, recoveryNumber, roleId; all optional}
|
|
84
|
+
login(data: I_LoginRequest) // {data: email, password, contactNumber(optional)}
|
|
85
|
+
forgotPassword(data: I_ForgotPasswordRequest) // {data: email, contactNumber, recoveryEmail, recoveryNumber; all optional}
|
|
86
86
|
getUserById(id: string)
|
|
87
|
-
resetPassword(token: string, data: I_ResetPassword)
|
|
88
|
-
changePassword(id: string, data: I_ChangePassword)
|
|
87
|
+
resetPassword(token: string, tenantId:number, data: I_ResetPassword) //{data: password, confirmPassword}
|
|
88
|
+
changePassword(id: string, data: I_ChangePassword) //{data: currentPassword, newPassword, confirmPassword}
|
|
89
89
|
deleteUserById(id: string)
|
|
90
90
|
logout(id: string)
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
sendVerificationEmail(email: string)
|
|
92
|
+
verifyEmail(token: string, tenantId:number)
|
|
93
|
+
updateUserById(userId: string, data: I_UpdateUserByIdRequest) //{data: email, contactNumber, recoveryEmail, recoveryNumber, isBlocked, roleId; all optional}
|
|
93
94
|
|
|
94
95
|
```
|
|
95
96
|
### Role Service
|
package/dist/index.d.mts
CHANGED
|
@@ -11,10 +11,10 @@ declare class ZAuthClient {
|
|
|
11
11
|
apiSecretKey: string;
|
|
12
12
|
});
|
|
13
13
|
private getHeaders;
|
|
14
|
-
get(url: string): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
15
|
-
post(url: string, data?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
16
|
-
patch(url: string, data?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
17
|
-
delete(url: string): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
14
|
+
get(url: string, params?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
15
|
+
post(url: string, data?: any, params?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
16
|
+
patch(url: string, data?: any, params?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
17
|
+
delete(url: string, params?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
18
18
|
}
|
|
19
19
|
declare function createConnection(config: {
|
|
20
20
|
baseURL: string;
|
|
@@ -31,18 +31,22 @@ interface I_Users {
|
|
|
31
31
|
recoveryEmail?: string | null;
|
|
32
32
|
recoveryNumber?: string | null;
|
|
33
33
|
}
|
|
34
|
+
interface I_ResetPassword {
|
|
35
|
+
password?: string;
|
|
36
|
+
confirmPassword?: string;
|
|
37
|
+
}
|
|
34
38
|
interface I_VerficationToken {
|
|
35
|
-
verificationToken
|
|
36
|
-
verificationTokenExpiresAt
|
|
39
|
+
verificationToken?: string;
|
|
40
|
+
verificationTokenExpiresAt?: string;
|
|
37
41
|
}
|
|
38
42
|
interface I_ResetPasswordToken {
|
|
39
|
-
resetToken
|
|
40
|
-
resetTokenExpiresAt
|
|
43
|
+
resetToken?: string;
|
|
44
|
+
resetTokenExpiresAt?: string;
|
|
41
45
|
}
|
|
42
46
|
interface I_LoginRequest {
|
|
43
47
|
email?: string;
|
|
44
48
|
contactNumber?: string;
|
|
45
|
-
password
|
|
49
|
+
password?: string;
|
|
46
50
|
}
|
|
47
51
|
interface I_LoginResponse {
|
|
48
52
|
access_token: string;
|
|
@@ -65,7 +69,11 @@ interface I_ChangePassword {
|
|
|
65
69
|
}
|
|
66
70
|
interface I_CreatedUser {
|
|
67
71
|
id: string;
|
|
72
|
+
verificationToken?: string;
|
|
73
|
+
expiryHours?: string;
|
|
74
|
+
verificationLink?: string;
|
|
68
75
|
message?: string;
|
|
76
|
+
tenantId?: number;
|
|
69
77
|
}
|
|
70
78
|
interface I_ForgotPasswordRequest {
|
|
71
79
|
email?: string;
|
|
@@ -74,7 +82,10 @@ interface I_ForgotPasswordRequest {
|
|
|
74
82
|
recoveryNumber?: string;
|
|
75
83
|
}
|
|
76
84
|
interface I_ForgotPasswordResponse {
|
|
77
|
-
resetToken
|
|
85
|
+
resetToken?: string;
|
|
86
|
+
tenantId?: number;
|
|
87
|
+
message?: string;
|
|
88
|
+
expiryHours?: string;
|
|
78
89
|
}
|
|
79
90
|
interface I_UpdateUserByIdRequest {
|
|
80
91
|
email?: string;
|
|
@@ -84,14 +95,6 @@ interface I_UpdateUserByIdRequest {
|
|
|
84
95
|
isBlocked?: boolean;
|
|
85
96
|
roleId?: number[];
|
|
86
97
|
}
|
|
87
|
-
interface I_ResetPassword {
|
|
88
|
-
password: string;
|
|
89
|
-
confirmPassword: string;
|
|
90
|
-
}
|
|
91
|
-
interface I_ResetPassword {
|
|
92
|
-
password: string;
|
|
93
|
-
confirmPassword: string;
|
|
94
|
-
}
|
|
95
98
|
|
|
96
99
|
declare class UserService {
|
|
97
100
|
private client;
|
|
@@ -99,12 +102,13 @@ declare class UserService {
|
|
|
99
102
|
createUser(data: I_Users): Promise<any>;
|
|
100
103
|
login(data: I_LoginRequest): Promise<any>;
|
|
101
104
|
forgotPassword(data: I_ForgotPasswordRequest): Promise<any>;
|
|
102
|
-
resetPassword(token: string, data: I_ResetPassword): Promise<any>;
|
|
105
|
+
resetPassword(token: string, tenantId: number, data: I_ResetPassword): Promise<any>;
|
|
103
106
|
changePassword(id: string, data: I_ChangePassword): Promise<any>;
|
|
104
107
|
getUserById(id: string): Promise<any>;
|
|
105
108
|
deleteUserById(id: string): Promise<any>;
|
|
109
|
+
sendVerificationEmail(email: string): Promise<any>;
|
|
106
110
|
logout(id: string): Promise<any>;
|
|
107
|
-
verifyEmail(token: string): Promise<any>;
|
|
111
|
+
verifyEmail(token: string, tenantId: number): Promise<any>;
|
|
108
112
|
updateUserById(userId: string, data: I_UpdateUserByIdRequest): Promise<any>;
|
|
109
113
|
getAccessToken(): Promise<any>;
|
|
110
114
|
getRefreshToken(): Promise<any>;
|
|
@@ -131,6 +135,7 @@ declare class PermissionsService {
|
|
|
131
135
|
deletePermissionById(id: number): Promise<any>;
|
|
132
136
|
setPermissionByRoleId(roleId: number, permissionId: number[]): Promise<any>;
|
|
133
137
|
setAllPermissions(roleId: number): Promise<any>;
|
|
138
|
+
deleteAllPermissionByRoleId(roleId: number): Promise<any>;
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
export { type I_ChangePassword, type I_CreatedUser, type I_ForgotPasswordRequest, type I_ForgotPasswordResponse, type I_LoginRequest, type I_LoginResponse, type I_Payload, type I_ResetPassword, type I_ResetPasswordToken, type I_UpdateUserByIdRequest, type I_Users, type I_VerficationToken, PermissionsService, RoleService, UserService, createConnection };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,10 +11,10 @@ declare class ZAuthClient {
|
|
|
11
11
|
apiSecretKey: string;
|
|
12
12
|
});
|
|
13
13
|
private getHeaders;
|
|
14
|
-
get(url: string): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
15
|
-
post(url: string, data?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
16
|
-
patch(url: string, data?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
17
|
-
delete(url: string): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
14
|
+
get(url: string, params?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
15
|
+
post(url: string, data?: any, params?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
16
|
+
patch(url: string, data?: any, params?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
17
|
+
delete(url: string, params?: any): Promise<axios.AxiosResponse<any, any, {}>>;
|
|
18
18
|
}
|
|
19
19
|
declare function createConnection(config: {
|
|
20
20
|
baseURL: string;
|
|
@@ -31,18 +31,22 @@ interface I_Users {
|
|
|
31
31
|
recoveryEmail?: string | null;
|
|
32
32
|
recoveryNumber?: string | null;
|
|
33
33
|
}
|
|
34
|
+
interface I_ResetPassword {
|
|
35
|
+
password?: string;
|
|
36
|
+
confirmPassword?: string;
|
|
37
|
+
}
|
|
34
38
|
interface I_VerficationToken {
|
|
35
|
-
verificationToken
|
|
36
|
-
verificationTokenExpiresAt
|
|
39
|
+
verificationToken?: string;
|
|
40
|
+
verificationTokenExpiresAt?: string;
|
|
37
41
|
}
|
|
38
42
|
interface I_ResetPasswordToken {
|
|
39
|
-
resetToken
|
|
40
|
-
resetTokenExpiresAt
|
|
43
|
+
resetToken?: string;
|
|
44
|
+
resetTokenExpiresAt?: string;
|
|
41
45
|
}
|
|
42
46
|
interface I_LoginRequest {
|
|
43
47
|
email?: string;
|
|
44
48
|
contactNumber?: string;
|
|
45
|
-
password
|
|
49
|
+
password?: string;
|
|
46
50
|
}
|
|
47
51
|
interface I_LoginResponse {
|
|
48
52
|
access_token: string;
|
|
@@ -65,7 +69,11 @@ interface I_ChangePassword {
|
|
|
65
69
|
}
|
|
66
70
|
interface I_CreatedUser {
|
|
67
71
|
id: string;
|
|
72
|
+
verificationToken?: string;
|
|
73
|
+
expiryHours?: string;
|
|
74
|
+
verificationLink?: string;
|
|
68
75
|
message?: string;
|
|
76
|
+
tenantId?: number;
|
|
69
77
|
}
|
|
70
78
|
interface I_ForgotPasswordRequest {
|
|
71
79
|
email?: string;
|
|
@@ -74,7 +82,10 @@ interface I_ForgotPasswordRequest {
|
|
|
74
82
|
recoveryNumber?: string;
|
|
75
83
|
}
|
|
76
84
|
interface I_ForgotPasswordResponse {
|
|
77
|
-
resetToken
|
|
85
|
+
resetToken?: string;
|
|
86
|
+
tenantId?: number;
|
|
87
|
+
message?: string;
|
|
88
|
+
expiryHours?: string;
|
|
78
89
|
}
|
|
79
90
|
interface I_UpdateUserByIdRequest {
|
|
80
91
|
email?: string;
|
|
@@ -84,14 +95,6 @@ interface I_UpdateUserByIdRequest {
|
|
|
84
95
|
isBlocked?: boolean;
|
|
85
96
|
roleId?: number[];
|
|
86
97
|
}
|
|
87
|
-
interface I_ResetPassword {
|
|
88
|
-
password: string;
|
|
89
|
-
confirmPassword: string;
|
|
90
|
-
}
|
|
91
|
-
interface I_ResetPassword {
|
|
92
|
-
password: string;
|
|
93
|
-
confirmPassword: string;
|
|
94
|
-
}
|
|
95
98
|
|
|
96
99
|
declare class UserService {
|
|
97
100
|
private client;
|
|
@@ -99,12 +102,13 @@ declare class UserService {
|
|
|
99
102
|
createUser(data: I_Users): Promise<any>;
|
|
100
103
|
login(data: I_LoginRequest): Promise<any>;
|
|
101
104
|
forgotPassword(data: I_ForgotPasswordRequest): Promise<any>;
|
|
102
|
-
resetPassword(token: string, data: I_ResetPassword): Promise<any>;
|
|
105
|
+
resetPassword(token: string, tenantId: number, data: I_ResetPassword): Promise<any>;
|
|
103
106
|
changePassword(id: string, data: I_ChangePassword): Promise<any>;
|
|
104
107
|
getUserById(id: string): Promise<any>;
|
|
105
108
|
deleteUserById(id: string): Promise<any>;
|
|
109
|
+
sendVerificationEmail(email: string): Promise<any>;
|
|
106
110
|
logout(id: string): Promise<any>;
|
|
107
|
-
verifyEmail(token: string): Promise<any>;
|
|
111
|
+
verifyEmail(token: string, tenantId: number): Promise<any>;
|
|
108
112
|
updateUserById(userId: string, data: I_UpdateUserByIdRequest): Promise<any>;
|
|
109
113
|
getAccessToken(): Promise<any>;
|
|
110
114
|
getRefreshToken(): Promise<any>;
|
|
@@ -131,6 +135,7 @@ declare class PermissionsService {
|
|
|
131
135
|
deletePermissionById(id: number): Promise<any>;
|
|
132
136
|
setPermissionByRoleId(roleId: number, permissionId: number[]): Promise<any>;
|
|
133
137
|
setAllPermissions(roleId: number): Promise<any>;
|
|
138
|
+
deleteAllPermissionByRoleId(roleId: number): Promise<any>;
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
export { type I_ChangePassword, type I_CreatedUser, type I_ForgotPasswordRequest, type I_ForgotPasswordResponse, type I_LoginRequest, type I_LoginResponse, type I_Payload, type I_ResetPassword, type I_ResetPasswordToken, type I_UpdateUserByIdRequest, type I_Users, type I_VerficationToken, PermissionsService, RoleService, UserService, createConnection };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var C=require('axios'),expressValidator=require('express-validator');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var C__default=/*#__PURE__*/_interopDefault(C);var w=r=>C__default.default.create({baseURL:r});var m=class{constructor(e){this.baseURL=e.baseURL,this.apiKey=e.apiKey,this.apiSecretKey=e.apiSecretKey,this.client=w(this.baseURL);}getHeaders(){return {apikey:this.apiKey,apisecretkey:this.apiSecretKey}}async get(e){return this.client.get(e,{headers:this.getHeaders()})}async post(e,s){return this.client.post(e,s,{headers:this.getHeaders()})}async patch(e,s){return this.client.patch(e,s,{headers:this.getHeaders()})}async delete(e){return this.client.delete(e,{headers:this.getHeaders()})}};function L(r){return new m(r)}function i(r,e){return new Promise((s,t)=>{let o={body:e};(async()=>{for(let p of r.flat())await p(o,{},()=>{});let h=expressValidator.validationResult(o);if(h.isEmpty())s(true);else {let p=h.array().map(x=>x.msg);t(p);}})();})}var y=[expressValidator.body("email").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),expressValidator.body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("recoveryNumber").optional().isLength({min:6}).withMessage("Recovery number must be at least 6 characters long"),expressValidator.body("password").notEmpty().isString().withMessage("Password is required"),expressValidator.body("password").isLength({min:8}).withMessage("Password must be at least 8 characters long"),expressValidator.body("password").matches(/[A-Z]/).withMessage("Password must contain at least one uppercase letter"),expressValidator.body("password").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("Password must contain at least one symbol"),expressValidator.body("roleId").notEmpty().isArray({min:1}).withMessage("Atleast one role is required"),expressValidator.body("roleId").custom(r=>Array.isArray(r)?r.every(e=>typeof e=="number"&&!isNaN(e)):false).withMessage("Each role ID must be a number"),expressValidator.body().custom(r=>{if(!r.email&&!r.contactNumber)throw new Error("Either email or contact number is required");return true})],b=[expressValidator.body("password").notEmpty().withMessage("Password is required"),expressValidator.body("password").isLength({min:8}).withMessage("Password must be at least 8 characters long"),expressValidator.body("password").matches(/[A-Z]/).withMessage("Password must contain at least one uppercase letter"),expressValidator.body("password").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("Password must contain at least one symbol"),expressValidator.body("confirmPassword").notEmpty().withMessage("Confirm Password is required"),expressValidator.body("confirmPassword").custom((r,{req:e})=>r===e.body.password).withMessage("Confirm Password must match Password")],f=[expressValidator.body("currentPassword").notEmpty().withMessage("Current Password is required"),expressValidator.body("currentPassword").isString().withMessage("Current Password must be a string"),expressValidator.body("newPassword").notEmpty().withMessage("New Password is required"),expressValidator.body("newPassword").isLength({min:8}).withMessage("New Password must be at least 8 characters long"),expressValidator.body("newPassword").matches(/[A-Z]/).withMessage("New Password must contain at least one uppercase letter"),expressValidator.body("newPassword").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("New Password must contain at least one symbol"),expressValidator.body("confirmPassword").notEmpty().withMessage("Confirm Password is required"),expressValidator.body("confirmPassword").custom((r,{req:e})=>r===e.body.newPassword).withMessage("Confirm Password must match New Password")],P=[expressValidator.body("email").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),expressValidator.body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("recoveryNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),expressValidator.body().custom(r=>{if(r.recoveryEmail&&!r.email&&!r.contactNumber)throw new Error("Contact number or Email is also required to recover");if(r.recoveryNumber&&!r.contactNumber&&!r.email)throw new Error("Contact number or Email is also required to recover");if(!r.email&&!r.contactNumber)throw new Error("Either email or contact number is required");return true})],M=[expressValidator.body("email").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),expressValidator.body("roleId").optional().isArray({min:1}).withMessage("Atleast one role is required"),expressValidator.body("roleId").optional().custom(r=>Array.isArray(r)?r.every(e=>typeof e=="number"&&!isNaN(e)):false).withMessage("Each role ID must be a number"),expressValidator.body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("recoveryNumber").optional().isLength({min:6}).withMessage("Recovery number must be at least 6 characters long")];var d=class{constructor(e){this.client=e;}async createUser(e){try{return await i(y,e),(await this.client.post("/users",e)).data}catch(s){return Array.isArray(s)?{error:s.join(", "),status:400}:{error:s.response?.data||s.message,status:s.response?.status||500}}}async login(e){try{return (await this.client.post("/users/login",e)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async forgotPassword(e){try{return await i(P,e),(await this.client.post("/users/forgot-password",e)).data}catch(s){return Array.isArray(s)?{error:s.join(", "),status:400}:{error:s.response?.data||s.message,status:s.response?.status||500}}}async resetPassword(e,s){try{return await i(b,s),(await this.client.patch(`/users/reset-password/${e}`,s)).data}catch(t){return Array.isArray(t)?{error:t.join(", "),status:400}:{error:t.response?.data||t.message,status:t.response?.status||500}}}async changePassword(e,s){try{return await i(f,s),(await this.client.patch(`/users/change-password/${e}`,s)).data}catch(t){return Array.isArray(t)?{error:t.join(", "),status:400}:{error:t.response?.data||t.message,status:t.response?.status||500}}}async getUserById(e){try{return (await this.client.get(`/users/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async deleteUserById(e){try{return (await this.client.delete(`/users/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async logout(e){try{return (await this.client.get(`/users/logout/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async verifyEmail(e){try{return (await this.client.get(`/users/verify-email/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async updateUserById(e,s){try{return await i(M,s),(await this.client.patch(`/users/${e}`,s)).data}catch(t){return Array.isArray(t)?{error:t.join(", "),status:400}:{error:t.response?.data||t.message,status:t.response?.status||500}}}async getAccessToken(){try{return (await this.client.get("/users/jwt-secert")).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async getRefreshToken(){try{return (await this.client.get("/users/refresh-secert")).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}};var I=[expressValidator.body("name").notEmpty().withMessage("Name is required"),expressValidator.body("name").isString().withMessage("Name must be a string"),expressValidator.body("name").trim().customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")),expressValidator.body("name").isLength({min:3,max:16}).withMessage("Name must be between 3 and 16 characters"),expressValidator.body("description").optional().isString().withMessage("Description must be a string")],A=[expressValidator.body("name").optional().isString().trim().isLength({min:3,max:16}).withMessage("Name must be between 3 and 16 characters").customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")),expressValidator.body("description").optional().isString().withMessage("Description must be a string")];var l=class{constructor(e){this.client=e;}async createRole(e,s){try{await i(I,{name:e,description:s});let t={name:e,description:s};return (await this.client.post("/roles",t)).data}catch(t){return Array.isArray(t)?{error:t.join(", "),status:400}:{error:t.response?.data||t.message,status:t.response?.status||500}}}async getAllRole(){try{return (await this.client.get("/roles")).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async getRoleById(e){try{return (await this.client.get(`/roles/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async updateRoleById(e,s,t){try{await i(A,{name:s,description:t});let o={name:s,description:t};return (await this.client.patch(`/roles/${e}`,o)).data}catch(o){return Array.isArray(o)?{error:o.join(", "),status:400}:{error:o.response?.data||o.message,status:o.response?.status||500}}}async deleteRoleById(e){try{return (await this.client.delete(`/roles/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async getPermissionsByRoleId(e){try{return (await this.client.get(`/roles/permissions/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}};var R=[expressValidator.body("module").notEmpty().withMessage("Module is required"),expressValidator.body("module").isString().withMessage("Module must be a string"),expressValidator.body("module").trim().customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")),expressValidator.body("module").isLength({min:3,max:16}).withMessage("Module must be between 3 and 16 characters"),expressValidator.body("access").notEmpty().withMessage("Access is required"),expressValidator.body("access").isString().withMessage("Access must be a string"),expressValidator.body("access").trim().customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")),expressValidator.body("access").isIn(["create","read","update","delete"]).withMessage("Access is must be create, read, update, delete"),expressValidator.body("description").optional().isString().withMessage("Description must be a string")],v=[expressValidator.body("module").optional().isString().trim().isLength({min:3,max:16}).withMessage("Module must be between 3 and 16 characters").customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")),expressValidator.body("access").optional().isString().trim().customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")).isIn(["create","read","update","delete"]),expressValidator.body("description").optional().isString().withMessage("Description must be a string")],E=[expressValidator.body("permissionId").notEmpty().withMessage("Permission ID is required"),expressValidator.body("permissionId").isArray({min:1}).withMessage("Atleast one permission ID is required"),expressValidator.body("permissionId").custom(r=>Array.isArray(r)?r.every(e=>typeof e=="number"&&!isNaN(e)):false).withMessage("Each permission ID must be a number")];var g=class{constructor(e){this.client=e;}async createPermission(e,s,t){try{return await i(R,{module:e,access:s,description:t}),(await this.client.post("/permissions",{module:e,access:s,description:t})).data}catch(o){return Array.isArray(o)?{error:o.join(", "),status:400}:{error:o.response?.data||o.message,status:o.response?.status||500}}}async getAllPermissions(){try{return (await this.client.get("/permissions")).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async getPermissionById(e){try{return (await this.client.get(`/permissions/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async updatePermissionById(e,s,t,o){try{return await i(v,{module:s,access:t,description:o}),(await this.client.patch(`/permissions/${e}`,{module:s,access:t,description:o})).data}catch(c){return Array.isArray(c)?{error:c.join(", "),status:400}:{error:c.response?.data||c.message,status:c.response?.status||500}}}async deletePermissionById(e){try{return (await this.client.delete(`/permissions/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async setPermissionByRoleId(e,s){try{return await i(E,{roleId:e,permissionId:s}),(await this.client.patch(`/permissions/set-permission/${e}`,{permissionId:s})).data}catch(t){return Array.isArray(t)?{error:t.join(", "),status:400}:{error:t.response?.data||t.message,status:t.response?.status||500}}}async setAllPermissions(e){try{return (await this.client.patch(`/permissions/set-all-permission/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}};exports.PermissionsService=g;exports.RoleService=l;exports.UserService=d;exports.createConnection=L;
|
|
1
|
+
'use strict';var C=require('axios'),expressValidator=require('express-validator');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var C__default=/*#__PURE__*/_interopDefault(C);var y=t=>C__default.default.create({baseURL:t});var m=class{constructor(s){this.baseURL=s.baseURL,this.apiKey=s.apiKey,this.apiSecretKey=s.apiSecretKey,this.client=y(this.baseURL);}getHeaders(){return {apikey:this.apiKey,apisecretkey:this.apiSecretKey}}async get(s,e){return this.client.get(s,{headers:this.getHeaders(),params:e})}async post(s,e,r){return this.client.post(s,e,{headers:this.getHeaders(),params:r})}async patch(s,e,r){return this.client.patch(s,e,{headers:this.getHeaders(),params:r})}async delete(s,e){return this.client.delete(s,{headers:this.getHeaders(),params:e})}};function L(t){return new m(t)}function i(t,s){return new Promise((e,r)=>{let n={body:s};(async()=>{for(let p of t.flat())await p(n,{},()=>{});let h=expressValidator.validationResult(n);if(h.isEmpty())e(true);else {let p=h.array().map(x=>x.msg);r(p);}})();})}var w=[expressValidator.body("email").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),expressValidator.body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("recoveryNumber").optional().isLength({min:6}).withMessage("Recovery number must be at least 6 characters long"),expressValidator.body("password").notEmpty().isString().withMessage("Password is required"),expressValidator.body("password").isLength({min:8}).withMessage("Password must be at least 8 characters long"),expressValidator.body("password").matches(/[A-Z]/).withMessage("Password must contain at least one uppercase letter"),expressValidator.body("password").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("Password must contain at least one symbol"),expressValidator.body("roleId").notEmpty().isArray({min:1}).withMessage("Atleast one role is required"),expressValidator.body("roleId").custom(t=>Array.isArray(t)?t.every(s=>typeof s=="number"&&!isNaN(s)):false).withMessage("Each role ID must be a number"),expressValidator.body().custom(t=>{if(!t.email&&!t.contactNumber)throw new Error("Either email or contact number is required");return true})],b=[expressValidator.body("password").notEmpty().withMessage("Password is required"),expressValidator.body("password").isLength({min:8}).withMessage("Password must be at least 8 characters long"),expressValidator.body("password").matches(/[A-Z]/).withMessage("Password must contain at least one uppercase letter"),expressValidator.body("password").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("Password must contain at least one symbol"),expressValidator.body("confirmPassword").notEmpty().withMessage("Confirm Password is required"),expressValidator.body("confirmPassword").custom((t,{req:s})=>t===s.body.password).withMessage("Confirm Password must match Password")],f=[expressValidator.body("currentPassword").notEmpty().withMessage("Current Password is required"),expressValidator.body("currentPassword").isString().withMessage("Current Password must be a string"),expressValidator.body("newPassword").notEmpty().withMessage("New Password is required"),expressValidator.body("newPassword").isLength({min:8}).withMessage("New Password must be at least 8 characters long"),expressValidator.body("newPassword").matches(/[A-Z]/).withMessage("New Password must contain at least one uppercase letter"),expressValidator.body("newPassword").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("New Password must contain at least one symbol"),expressValidator.body("confirmPassword").notEmpty().withMessage("Confirm Password is required"),expressValidator.body("confirmPassword").custom((t,{req:s})=>t===s.body.newPassword).withMessage("Confirm Password must match New Password")],P=[expressValidator.body("email").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),expressValidator.body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("recoveryNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),expressValidator.body().custom(t=>{if(t.recoveryEmail&&!t.email&&!t.contactNumber)throw new Error("Contact number or Email is also required to recover");if(t.recoveryNumber&&!t.contactNumber&&!t.email)throw new Error("Contact number or Email is also required to recover");if(!t.email&&!t.contactNumber)throw new Error("Either email or contact number is required");return true})],M=[expressValidator.body("email").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),expressValidator.body("roleId").optional().isArray({min:1}).withMessage("Atleast one role is required"),expressValidator.body("roleId").optional().custom(t=>Array.isArray(t)?t.every(s=>typeof s=="number"&&!isNaN(s)):false).withMessage("Each role ID must be a number"),expressValidator.body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),expressValidator.body("recoveryNumber").optional().isLength({min:6}).withMessage("Recovery number must be at least 6 characters long")];var d=class{constructor(s){this.client=s;}async createUser(s){try{return await i(w,s),(await this.client.post("/users",s)).data}catch(e){return Array.isArray(e)?{error:e.join(", "),status:400}:{error:e.response?.data||e.message,status:e.response?.status||500}}}async login(s){try{return (await this.client.post("/users/login",s)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async forgotPassword(s){try{return await i(P,s),(await this.client.post("/users/forgot-password",s)).data}catch(e){return Array.isArray(e)?{error:e.join(", "),status:400}:{error:e.response?.data||e.message,status:e.response?.status||500}}}async resetPassword(s,e,r){try{return await i(b,r),(await this.client.patch(`/users/reset-password?tenantId=${e}&resetToken=${s}`,r)).data}catch(n){return Array.isArray(n)?{error:n.join(", "),status:400}:{error:n.response?.data||n.message,status:n.response?.status||500}}}async changePassword(s,e){try{return await i(f,e),(await this.client.patch(`/users/change-password/${s}`,e)).data}catch(r){return Array.isArray(r)?{error:r.join(", "),status:400}:{error:r.response?.data||r.message,status:r.response?.status||500}}}async getUserById(s){try{return (await this.client.get(`/users/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async deleteUserById(s){try{return (await this.client.delete(`/users/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async sendVerificationEmail(s){try{return (await this.client.post("/users/send-email-verification",{email:s})).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async logout(s){try{return (await this.client.get(`/users/logout/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async verifyEmail(s,e){try{return (await this.client.get(`/users/verify-email?tenantId=${e}&verificationToken=${s}`)).data}catch(r){return {error:r.response?.data||r.message,status:r.response?.status||500}}}async updateUserById(s,e){try{return await i(M,e),(await this.client.patch(`/users/${s}`,e)).data}catch(r){return Array.isArray(r)?{error:r.join(", "),status:400}:{error:r.response?.data||r.message,status:r.response?.status||500}}}async getAccessToken(){try{return (await this.client.get("/users/jwt-secert")).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async getRefreshToken(){try{return (await this.client.get("/users/refresh-secert")).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}};var I=[expressValidator.body("name").notEmpty().withMessage("Name is required"),expressValidator.body("name").isString().withMessage("Name must be a string"),expressValidator.body("name").trim().customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")),expressValidator.body("name").isLength({min:3,max:16}).withMessage("Name must be between 3 and 16 characters"),expressValidator.body("description").optional().isString().withMessage("Description must be a string")],A=[expressValidator.body("name").optional().isString().trim().isLength({min:3,max:16}).withMessage("Name must be between 3 and 16 characters").customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")),expressValidator.body("description").optional().isString().withMessage("Description must be a string")];var l=class{constructor(s){this.client=s;}async createRole(s,e){try{await i(I,{name:s,description:e});let r={name:s,description:e};return (await this.client.post("/roles",r)).data}catch(r){return Array.isArray(r)?{error:r.join(", "),status:400}:{error:r.response?.data||r.message,status:r.response?.status||500}}}async getAllRole(){try{return (await this.client.get("/roles")).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async getRoleById(s){try{return (await this.client.get(`/roles/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async updateRoleById(s,e,r){try{await i(A,{name:e,description:r});let n={name:e,description:r};return (await this.client.patch(`/roles/${s}`,n)).data}catch(n){return Array.isArray(n)?{error:n.join(", "),status:400}:{error:n.response?.data||n.message,status:n.response?.status||500}}}async deleteRoleById(s){try{return (await this.client.delete(`/roles/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async getPermissionsByRoleId(s){try{return (await this.client.get(`/roles/permissions/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}};var R=[expressValidator.body("module").notEmpty().withMessage("Module is required"),expressValidator.body("module").isString().withMessage("Module must be a string"),expressValidator.body("module").trim().customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")),expressValidator.body("module").isLength({min:3,max:16}).withMessage("Module must be between 3 and 16 characters"),expressValidator.body("access").notEmpty().withMessage("Access is required"),expressValidator.body("access").isString().withMessage("Access must be a string"),expressValidator.body("access").trim().customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")),expressValidator.body("access").isIn(["create","read","update","delete"]).withMessage("Access is must be create, read, update, delete"),expressValidator.body("description").optional().isString().withMessage("Description must be a string")],v=[expressValidator.body("module").optional().isString().trim().isLength({min:3,max:16}).withMessage("Module must be between 3 and 16 characters").customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")),expressValidator.body("access").optional().isString().trim().customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")).isIn(["create","read","update","delete"]),expressValidator.body("description").optional().isString().withMessage("Description must be a string")],E=[expressValidator.body("permissionId").notEmpty().withMessage("Permission ID is required"),expressValidator.body("permissionId").isArray({min:1}).withMessage("Atleast one permission ID is required"),expressValidator.body("permissionId").custom(t=>Array.isArray(t)?t.every(s=>typeof s=="number"&&!isNaN(s)):false).withMessage("Each permission ID must be a number")];var g=class{constructor(s){this.client=s;}async createPermission(s,e,r){try{return await i(R,{module:s,access:e,description:r}),(await this.client.post("/permissions",{module:s,access:e,description:r})).data}catch(n){return Array.isArray(n)?{error:n.join(", "),status:400}:{error:n.response?.data||n.message,status:n.response?.status||500}}}async getAllPermissions(){try{return (await this.client.get("/permissions")).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async getPermissionById(s){try{return (await this.client.get(`/permissions/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async updatePermissionById(s,e,r,n){try{return await i(v,{module:e,access:r,description:n}),(await this.client.patch(`/permissions/${s}`,{module:e,access:r,description:n})).data}catch(c){return Array.isArray(c)?{error:c.join(", "),status:400}:{error:c.response?.data||c.message,status:c.response?.status||500}}}async deletePermissionById(s){try{return (await this.client.delete(`/permissions/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async setPermissionByRoleId(s,e){try{return await i(E,{roleId:s,permissionId:e}),(await this.client.patch(`/permissions/set-permission/${s}`,{permissionId:e})).data}catch(r){return Array.isArray(r)?{error:r.join(", "),status:400}:{error:r.response?.data||r.message,status:r.response?.status||500}}}async setAllPermissions(s){try{return (await this.client.patch(`/permissions/set-all-permission/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async deleteAllPermissionByRoleId(s){try{return (await this.client.delete(`/permissions/delete-all-permissions/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}};exports.PermissionsService=g;exports.RoleService=l;exports.UserService=d;exports.createConnection=L;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import C from'axios';import {body,validationResult}from'express-validator';var w=r=>C.create({baseURL:r});var m=class{constructor(e){this.baseURL=e.baseURL,this.apiKey=e.apiKey,this.apiSecretKey=e.apiSecretKey,this.client=w(this.baseURL);}getHeaders(){return {apikey:this.apiKey,apisecretkey:this.apiSecretKey}}async get(e){return this.client.get(e,{headers:this.getHeaders()})}async post(e,s){return this.client.post(e,s,{headers:this.getHeaders()})}async patch(e,s){return this.client.patch(e,s,{headers:this.getHeaders()})}async delete(e){return this.client.delete(e,{headers:this.getHeaders()})}};function L(r){return new m(r)}function i(r,e){return new Promise((s,t)=>{let o={body:e};(async()=>{for(let p of r.flat())await p(o,{},()=>{});let h=validationResult(o);if(h.isEmpty())s(true);else {let p=h.array().map(x=>x.msg);t(p);}})();})}var y=[body("email").optional().isEmail().withMessage("Must be a valid email address"),body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),body("recoveryNumber").optional().isLength({min:6}).withMessage("Recovery number must be at least 6 characters long"),body("password").notEmpty().isString().withMessage("Password is required"),body("password").isLength({min:8}).withMessage("Password must be at least 8 characters long"),body("password").matches(/[A-Z]/).withMessage("Password must contain at least one uppercase letter"),body("password").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("Password must contain at least one symbol"),body("roleId").notEmpty().isArray({min:1}).withMessage("Atleast one role is required"),body("roleId").custom(r=>Array.isArray(r)?r.every(e=>typeof e=="number"&&!isNaN(e)):false).withMessage("Each role ID must be a number"),body().custom(r=>{if(!r.email&&!r.contactNumber)throw new Error("Either email or contact number is required");return true})],b=[body("password").notEmpty().withMessage("Password is required"),body("password").isLength({min:8}).withMessage("Password must be at least 8 characters long"),body("password").matches(/[A-Z]/).withMessage("Password must contain at least one uppercase letter"),body("password").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("Password must contain at least one symbol"),body("confirmPassword").notEmpty().withMessage("Confirm Password is required"),body("confirmPassword").custom((r,{req:e})=>r===e.body.password).withMessage("Confirm Password must match Password")],f=[body("currentPassword").notEmpty().withMessage("Current Password is required"),body("currentPassword").isString().withMessage("Current Password must be a string"),body("newPassword").notEmpty().withMessage("New Password is required"),body("newPassword").isLength({min:8}).withMessage("New Password must be at least 8 characters long"),body("newPassword").matches(/[A-Z]/).withMessage("New Password must contain at least one uppercase letter"),body("newPassword").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("New Password must contain at least one symbol"),body("confirmPassword").notEmpty().withMessage("Confirm Password is required"),body("confirmPassword").custom((r,{req:e})=>r===e.body.newPassword).withMessage("Confirm Password must match New Password")],P=[body("email").optional().isEmail().withMessage("Must be a valid email address"),body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),body("recoveryNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),body().custom(r=>{if(r.recoveryEmail&&!r.email&&!r.contactNumber)throw new Error("Contact number or Email is also required to recover");if(r.recoveryNumber&&!r.contactNumber&&!r.email)throw new Error("Contact number or Email is also required to recover");if(!r.email&&!r.contactNumber)throw new Error("Either email or contact number is required");return true})],M=[body("email").optional().isEmail().withMessage("Must be a valid email address"),body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),body("roleId").optional().isArray({min:1}).withMessage("Atleast one role is required"),body("roleId").optional().custom(r=>Array.isArray(r)?r.every(e=>typeof e=="number"&&!isNaN(e)):false).withMessage("Each role ID must be a number"),body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),body("recoveryNumber").optional().isLength({min:6}).withMessage("Recovery number must be at least 6 characters long")];var d=class{constructor(e){this.client=e;}async createUser(e){try{return await i(y,e),(await this.client.post("/users",e)).data}catch(s){return Array.isArray(s)?{error:s.join(", "),status:400}:{error:s.response?.data||s.message,status:s.response?.status||500}}}async login(e){try{return (await this.client.post("/users/login",e)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async forgotPassword(e){try{return await i(P,e),(await this.client.post("/users/forgot-password",e)).data}catch(s){return Array.isArray(s)?{error:s.join(", "),status:400}:{error:s.response?.data||s.message,status:s.response?.status||500}}}async resetPassword(e,s){try{return await i(b,s),(await this.client.patch(`/users/reset-password/${e}`,s)).data}catch(t){return Array.isArray(t)?{error:t.join(", "),status:400}:{error:t.response?.data||t.message,status:t.response?.status||500}}}async changePassword(e,s){try{return await i(f,s),(await this.client.patch(`/users/change-password/${e}`,s)).data}catch(t){return Array.isArray(t)?{error:t.join(", "),status:400}:{error:t.response?.data||t.message,status:t.response?.status||500}}}async getUserById(e){try{return (await this.client.get(`/users/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async deleteUserById(e){try{return (await this.client.delete(`/users/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async logout(e){try{return (await this.client.get(`/users/logout/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async verifyEmail(e){try{return (await this.client.get(`/users/verify-email/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async updateUserById(e,s){try{return await i(M,s),(await this.client.patch(`/users/${e}`,s)).data}catch(t){return Array.isArray(t)?{error:t.join(", "),status:400}:{error:t.response?.data||t.message,status:t.response?.status||500}}}async getAccessToken(){try{return (await this.client.get("/users/jwt-secert")).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async getRefreshToken(){try{return (await this.client.get("/users/refresh-secert")).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}};var I=[body("name").notEmpty().withMessage("Name is required"),body("name").isString().withMessage("Name must be a string"),body("name").trim().customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")),body("name").isLength({min:3,max:16}).withMessage("Name must be between 3 and 16 characters"),body("description").optional().isString().withMessage("Description must be a string")],A=[body("name").optional().isString().trim().isLength({min:3,max:16}).withMessage("Name must be between 3 and 16 characters").customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")),body("description").optional().isString().withMessage("Description must be a string")];var l=class{constructor(e){this.client=e;}async createRole(e,s){try{await i(I,{name:e,description:s});let t={name:e,description:s};return (await this.client.post("/roles",t)).data}catch(t){return Array.isArray(t)?{error:t.join(", "),status:400}:{error:t.response?.data||t.message,status:t.response?.status||500}}}async getAllRole(){try{return (await this.client.get("/roles")).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async getRoleById(e){try{return (await this.client.get(`/roles/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async updateRoleById(e,s,t){try{await i(A,{name:s,description:t});let o={name:s,description:t};return (await this.client.patch(`/roles/${e}`,o)).data}catch(o){return Array.isArray(o)?{error:o.join(", "),status:400}:{error:o.response?.data||o.message,status:o.response?.status||500}}}async deleteRoleById(e){try{return (await this.client.delete(`/roles/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async getPermissionsByRoleId(e){try{return (await this.client.get(`/roles/permissions/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}};var R=[body("module").notEmpty().withMessage("Module is required"),body("module").isString().withMessage("Module must be a string"),body("module").trim().customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")),body("module").isLength({min:3,max:16}).withMessage("Module must be between 3 and 16 characters"),body("access").notEmpty().withMessage("Access is required"),body("access").isString().withMessage("Access must be a string"),body("access").trim().customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")),body("access").isIn(["create","read","update","delete"]).withMessage("Access is must be create, read, update, delete"),body("description").optional().isString().withMessage("Description must be a string")],v=[body("module").optional().isString().trim().isLength({min:3,max:16}).withMessage("Module must be between 3 and 16 characters").customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")),body("access").optional().isString().trim().customSanitizer(r=>r.toLowerCase().replace(/\s+/g,"-")).isIn(["create","read","update","delete"]),body("description").optional().isString().withMessage("Description must be a string")],E=[body("permissionId").notEmpty().withMessage("Permission ID is required"),body("permissionId").isArray({min:1}).withMessage("Atleast one permission ID is required"),body("permissionId").custom(r=>Array.isArray(r)?r.every(e=>typeof e=="number"&&!isNaN(e)):false).withMessage("Each permission ID must be a number")];var g=class{constructor(e){this.client=e;}async createPermission(e,s,t){try{return await i(R,{module:e,access:s,description:t}),(await this.client.post("/permissions",{module:e,access:s,description:t})).data}catch(o){return Array.isArray(o)?{error:o.join(", "),status:400}:{error:o.response?.data||o.message,status:o.response?.status||500}}}async getAllPermissions(){try{return (await this.client.get("/permissions")).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async getPermissionById(e){try{return (await this.client.get(`/permissions/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async updatePermissionById(e,s,t,o){try{return await i(v,{module:s,access:t,description:o}),(await this.client.patch(`/permissions/${e}`,{module:s,access:t,description:o})).data}catch(c){return Array.isArray(c)?{error:c.join(", "),status:400}:{error:c.response?.data||c.message,status:c.response?.status||500}}}async deletePermissionById(e){try{return (await this.client.delete(`/permissions/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async setPermissionByRoleId(e,s){try{return await i(E,{roleId:e,permissionId:s}),(await this.client.patch(`/permissions/set-permission/${e}`,{permissionId:s})).data}catch(t){return Array.isArray(t)?{error:t.join(", "),status:400}:{error:t.response?.data||t.message,status:t.response?.status||500}}}async setAllPermissions(e){try{return (await this.client.patch(`/permissions/set-all-permission/${e}`)).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}};export{g as PermissionsService,l as RoleService,d as UserService,L as createConnection};
|
|
1
|
+
import C from'axios';import {body,validationResult}from'express-validator';var y=t=>C.create({baseURL:t});var m=class{constructor(s){this.baseURL=s.baseURL,this.apiKey=s.apiKey,this.apiSecretKey=s.apiSecretKey,this.client=y(this.baseURL);}getHeaders(){return {apikey:this.apiKey,apisecretkey:this.apiSecretKey}}async get(s,e){return this.client.get(s,{headers:this.getHeaders(),params:e})}async post(s,e,r){return this.client.post(s,e,{headers:this.getHeaders(),params:r})}async patch(s,e,r){return this.client.patch(s,e,{headers:this.getHeaders(),params:r})}async delete(s,e){return this.client.delete(s,{headers:this.getHeaders(),params:e})}};function L(t){return new m(t)}function i(t,s){return new Promise((e,r)=>{let n={body:s};(async()=>{for(let p of t.flat())await p(n,{},()=>{});let h=validationResult(n);if(h.isEmpty())e(true);else {let p=h.array().map(x=>x.msg);r(p);}})();})}var w=[body("email").optional().isEmail().withMessage("Must be a valid email address"),body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),body("recoveryNumber").optional().isLength({min:6}).withMessage("Recovery number must be at least 6 characters long"),body("password").notEmpty().isString().withMessage("Password is required"),body("password").isLength({min:8}).withMessage("Password must be at least 8 characters long"),body("password").matches(/[A-Z]/).withMessage("Password must contain at least one uppercase letter"),body("password").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("Password must contain at least one symbol"),body("roleId").notEmpty().isArray({min:1}).withMessage("Atleast one role is required"),body("roleId").custom(t=>Array.isArray(t)?t.every(s=>typeof s=="number"&&!isNaN(s)):false).withMessage("Each role ID must be a number"),body().custom(t=>{if(!t.email&&!t.contactNumber)throw new Error("Either email or contact number is required");return true})],b=[body("password").notEmpty().withMessage("Password is required"),body("password").isLength({min:8}).withMessage("Password must be at least 8 characters long"),body("password").matches(/[A-Z]/).withMessage("Password must contain at least one uppercase letter"),body("password").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("Password must contain at least one symbol"),body("confirmPassword").notEmpty().withMessage("Confirm Password is required"),body("confirmPassword").custom((t,{req:s})=>t===s.body.password).withMessage("Confirm Password must match Password")],f=[body("currentPassword").notEmpty().withMessage("Current Password is required"),body("currentPassword").isString().withMessage("Current Password must be a string"),body("newPassword").notEmpty().withMessage("New Password is required"),body("newPassword").isLength({min:8}).withMessage("New Password must be at least 8 characters long"),body("newPassword").matches(/[A-Z]/).withMessage("New Password must contain at least one uppercase letter"),body("newPassword").matches(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/).withMessage("New Password must contain at least one symbol"),body("confirmPassword").notEmpty().withMessage("Confirm Password is required"),body("confirmPassword").custom((t,{req:s})=>t===s.body.newPassword).withMessage("Confirm Password must match New Password")],P=[body("email").optional().isEmail().withMessage("Must be a valid email address"),body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),body("recoveryNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),body().custom(t=>{if(t.recoveryEmail&&!t.email&&!t.contactNumber)throw new Error("Contact number or Email is also required to recover");if(t.recoveryNumber&&!t.contactNumber&&!t.email)throw new Error("Contact number or Email is also required to recover");if(!t.email&&!t.contactNumber)throw new Error("Either email or contact number is required");return true})],M=[body("email").optional().isEmail().withMessage("Must be a valid email address"),body("contactNumber").optional().isLength({min:6}).withMessage("Contact number must be at least 6 characters long"),body("roleId").optional().isArray({min:1}).withMessage("Atleast one role is required"),body("roleId").optional().custom(t=>Array.isArray(t)?t.every(s=>typeof s=="number"&&!isNaN(s)):false).withMessage("Each role ID must be a number"),body("recoveryEmail").optional().isEmail().withMessage("Must be a valid email address"),body("recoveryNumber").optional().isLength({min:6}).withMessage("Recovery number must be at least 6 characters long")];var d=class{constructor(s){this.client=s;}async createUser(s){try{return await i(w,s),(await this.client.post("/users",s)).data}catch(e){return Array.isArray(e)?{error:e.join(", "),status:400}:{error:e.response?.data||e.message,status:e.response?.status||500}}}async login(s){try{return (await this.client.post("/users/login",s)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async forgotPassword(s){try{return await i(P,s),(await this.client.post("/users/forgot-password",s)).data}catch(e){return Array.isArray(e)?{error:e.join(", "),status:400}:{error:e.response?.data||e.message,status:e.response?.status||500}}}async resetPassword(s,e,r){try{return await i(b,r),(await this.client.patch(`/users/reset-password?tenantId=${e}&resetToken=${s}`,r)).data}catch(n){return Array.isArray(n)?{error:n.join(", "),status:400}:{error:n.response?.data||n.message,status:n.response?.status||500}}}async changePassword(s,e){try{return await i(f,e),(await this.client.patch(`/users/change-password/${s}`,e)).data}catch(r){return Array.isArray(r)?{error:r.join(", "),status:400}:{error:r.response?.data||r.message,status:r.response?.status||500}}}async getUserById(s){try{return (await this.client.get(`/users/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async deleteUserById(s){try{return (await this.client.delete(`/users/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async sendVerificationEmail(s){try{return (await this.client.post("/users/send-email-verification",{email:s})).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async logout(s){try{return (await this.client.get(`/users/logout/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async verifyEmail(s,e){try{return (await this.client.get(`/users/verify-email?tenantId=${e}&verificationToken=${s}`)).data}catch(r){return {error:r.response?.data||r.message,status:r.response?.status||500}}}async updateUserById(s,e){try{return await i(M,e),(await this.client.patch(`/users/${s}`,e)).data}catch(r){return Array.isArray(r)?{error:r.join(", "),status:400}:{error:r.response?.data||r.message,status:r.response?.status||500}}}async getAccessToken(){try{return (await this.client.get("/users/jwt-secert")).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async getRefreshToken(){try{return (await this.client.get("/users/refresh-secert")).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}};var I=[body("name").notEmpty().withMessage("Name is required"),body("name").isString().withMessage("Name must be a string"),body("name").trim().customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")),body("name").isLength({min:3,max:16}).withMessage("Name must be between 3 and 16 characters"),body("description").optional().isString().withMessage("Description must be a string")],A=[body("name").optional().isString().trim().isLength({min:3,max:16}).withMessage("Name must be between 3 and 16 characters").customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")),body("description").optional().isString().withMessage("Description must be a string")];var l=class{constructor(s){this.client=s;}async createRole(s,e){try{await i(I,{name:s,description:e});let r={name:s,description:e};return (await this.client.post("/roles",r)).data}catch(r){return Array.isArray(r)?{error:r.join(", "),status:400}:{error:r.response?.data||r.message,status:r.response?.status||500}}}async getAllRole(){try{return (await this.client.get("/roles")).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async getRoleById(s){try{return (await this.client.get(`/roles/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async updateRoleById(s,e,r){try{await i(A,{name:e,description:r});let n={name:e,description:r};return (await this.client.patch(`/roles/${s}`,n)).data}catch(n){return Array.isArray(n)?{error:n.join(", "),status:400}:{error:n.response?.data||n.message,status:n.response?.status||500}}}async deleteRoleById(s){try{return (await this.client.delete(`/roles/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async getPermissionsByRoleId(s){try{return (await this.client.get(`/roles/permissions/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}};var R=[body("module").notEmpty().withMessage("Module is required"),body("module").isString().withMessage("Module must be a string"),body("module").trim().customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")),body("module").isLength({min:3,max:16}).withMessage("Module must be between 3 and 16 characters"),body("access").notEmpty().withMessage("Access is required"),body("access").isString().withMessage("Access must be a string"),body("access").trim().customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")),body("access").isIn(["create","read","update","delete"]).withMessage("Access is must be create, read, update, delete"),body("description").optional().isString().withMessage("Description must be a string")],v=[body("module").optional().isString().trim().isLength({min:3,max:16}).withMessage("Module must be between 3 and 16 characters").customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")),body("access").optional().isString().trim().customSanitizer(t=>t.toLowerCase().replace(/\s+/g,"-")).isIn(["create","read","update","delete"]),body("description").optional().isString().withMessage("Description must be a string")],E=[body("permissionId").notEmpty().withMessage("Permission ID is required"),body("permissionId").isArray({min:1}).withMessage("Atleast one permission ID is required"),body("permissionId").custom(t=>Array.isArray(t)?t.every(s=>typeof s=="number"&&!isNaN(s)):false).withMessage("Each permission ID must be a number")];var g=class{constructor(s){this.client=s;}async createPermission(s,e,r){try{return await i(R,{module:s,access:e,description:r}),(await this.client.post("/permissions",{module:s,access:e,description:r})).data}catch(n){return Array.isArray(n)?{error:n.join(", "),status:400}:{error:n.response?.data||n.message,status:n.response?.status||500}}}async getAllPermissions(){try{return (await this.client.get("/permissions")).data}catch(s){return {error:s.response?.data||s.message,status:s.response?.status||500}}}async getPermissionById(s){try{return (await this.client.get(`/permissions/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async updatePermissionById(s,e,r,n){try{return await i(v,{module:e,access:r,description:n}),(await this.client.patch(`/permissions/${s}`,{module:e,access:r,description:n})).data}catch(c){return Array.isArray(c)?{error:c.join(", "),status:400}:{error:c.response?.data||c.message,status:c.response?.status||500}}}async deletePermissionById(s){try{return (await this.client.delete(`/permissions/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async setPermissionByRoleId(s,e){try{return await i(E,{roleId:s,permissionId:e}),(await this.client.patch(`/permissions/set-permission/${s}`,{permissionId:e})).data}catch(r){return Array.isArray(r)?{error:r.join(", "),status:400}:{error:r.response?.data||r.message,status:r.response?.status||500}}}async setAllPermissions(s){try{return (await this.client.patch(`/permissions/set-all-permission/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async deleteAllPermissionByRoleId(s){try{return (await this.client.delete(`/permissions/delete-all-permissions/${s}`)).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}};export{g as PermissionsService,l as RoleService,d as UserService,L as createConnection};
|