@zlspace/z-auth 1.0.0 → 1.0.2

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 CHANGED
@@ -89,7 +89,7 @@ changePassword(id: string, data: I_ChangePassword)
89
89
  deleteUserById(id: string)
90
90
  logout(id: string)
91
91
  verifyEmail(token: string)
92
- updateUserRole(userId: string, data: I_UpdateUserByIdRequest)
92
+ updateUserById(userId: string, data: I_UpdateUserByIdRequest)
93
93
 
94
94
  ```
95
95
  ### Role Service
package/dist/index.d.mts CHANGED
@@ -25,8 +25,11 @@ declare function createConnection(config: {
25
25
  interface I_Users {
26
26
  email?: string;
27
27
  contactNumber?: string;
28
- password: string;
29
- roleId: number[];
28
+ password?: string;
29
+ isBlocked?: boolean;
30
+ roleId?: number[];
31
+ recoveryEmail?: string | null;
32
+ recoveryNumber?: string | null;
30
33
  }
31
34
  interface I_VerficationToken {
32
35
  verificationToken: string;
@@ -67,6 +70,8 @@ interface I_CreatedUser {
67
70
  interface I_ForgotPasswordRequest {
68
71
  email?: string;
69
72
  contactNumber?: string;
73
+ recoveryEmail?: string;
74
+ recoveryNumber?: string;
70
75
  }
71
76
  interface I_ForgotPasswordResponse {
72
77
  resetToken: string;
@@ -74,7 +79,10 @@ interface I_ForgotPasswordResponse {
74
79
  interface I_UpdateUserByIdRequest {
75
80
  email?: string;
76
81
  contactNumber?: string;
77
- roleId: number[];
82
+ recoveryEmail?: string;
83
+ recoveryNumber?: string;
84
+ isBlocked?: boolean;
85
+ roleId?: number[];
78
86
  }
79
87
  interface I_ResetPassword {
80
88
  password: string;
@@ -97,7 +105,7 @@ declare class UserService {
97
105
  deleteUserById(id: string): Promise<any>;
98
106
  logout(id: string): Promise<any>;
99
107
  verifyEmail(token: string): Promise<any>;
100
- updateUserRole(userId: string, data: I_UpdateUserByIdRequest): Promise<any>;
108
+ updateUserById(userId: string, data: I_UpdateUserByIdRequest): Promise<any>;
101
109
  getAccessToken(): Promise<any>;
102
110
  getRefreshToken(): Promise<any>;
103
111
  }
package/dist/index.d.ts CHANGED
@@ -25,8 +25,11 @@ declare function createConnection(config: {
25
25
  interface I_Users {
26
26
  email?: string;
27
27
  contactNumber?: string;
28
- password: string;
29
- roleId: number[];
28
+ password?: string;
29
+ isBlocked?: boolean;
30
+ roleId?: number[];
31
+ recoveryEmail?: string | null;
32
+ recoveryNumber?: string | null;
30
33
  }
31
34
  interface I_VerficationToken {
32
35
  verificationToken: string;
@@ -67,6 +70,8 @@ interface I_CreatedUser {
67
70
  interface I_ForgotPasswordRequest {
68
71
  email?: string;
69
72
  contactNumber?: string;
73
+ recoveryEmail?: string;
74
+ recoveryNumber?: string;
70
75
  }
71
76
  interface I_ForgotPasswordResponse {
72
77
  resetToken: string;
@@ -74,7 +79,10 @@ interface I_ForgotPasswordResponse {
74
79
  interface I_UpdateUserByIdRequest {
75
80
  email?: string;
76
81
  contactNumber?: string;
77
- roleId: number[];
82
+ recoveryEmail?: string;
83
+ recoveryNumber?: string;
84
+ isBlocked?: boolean;
85
+ roleId?: number[];
78
86
  }
79
87
  interface I_ResetPassword {
80
88
  password: string;
@@ -97,7 +105,7 @@ declare class UserService {
97
105
  deleteUserById(id: string): Promise<any>;
98
106
  logout(id: string): Promise<any>;
99
107
  verifyEmail(token: string): Promise<any>;
100
- updateUserRole(userId: string, data: I_UpdateUserByIdRequest): Promise<any>;
108
+ updateUserById(userId: string, data: I_UpdateUserByIdRequest): Promise<any>;
101
109
  getAccessToken(): Promise<any>;
102
110
  getRefreshToken(): Promise<any>;
103
111
  }
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var _=require('axios'),expressValidator=require('express-validator');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ___default=/*#__PURE__*/_interopDefault(_);var w=t=>___default.default.create({baseURL:t});var d=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 U(t){return new d(t)}function i(t,e){return new Promise((s,r)=>{let o={body:e};(async()=>{for(let p of t.flat())await p(o,{},()=>{});let h=expressValidator.validationResult(o);if(h.isEmpty())s(true);else {let p=h.array().map(C=>C.msg);r(p);}})();})}var y=[expressValidator.body("email").optional().isEmail().withMessage("Must be valid email address."),expressValidator.body("contactNumber").optional().isLength({min:6}).withMessage("Contact 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().withMessage("Role ID is required"),expressValidator.body("roleId").isArray({min:1}).withMessage("Atleast one role ID is required"),expressValidator.body("roleId").custom(t=>Array.isArray(t)?t.every(e=>typeof e=="number"&&!isNaN(e)):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:e})=>t===e.body.password).withMessage("Confirm Password must match Password")],P=[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:e})=>t===e.body.newPassword).withMessage("Confirm Password must match New Password")],f=[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().custom(t=>{if(!t.email&&!t.contactNumber)throw new Error("Either email or contact number is required");return true})],I=[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").notEmpty().withMessage("Role ID is required"),expressValidator.body("roleId").isArray({min:1}).withMessage("Atleast one role ID is required"),expressValidator.body("roleId").custom(t=>Array.isArray(t)?t.every(e=>typeof e=="number"&&!isNaN(e)):false).withMessage("Each role ID must be a number")];var m=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(f,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(r){return Array.isArray(r)?{error:r.join(", "),status:400}:{error:r.response?.data||r.message,status:r.response?.status||500}}}async changePassword(e,s){try{return await i(P,s),(await this.client.patch(`/users/change-password/${e}`,s)).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(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 updateUserRole(e,s){try{return await i(I,s),(await this.client.patch(`/users/update-role/${e}`,s)).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(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 M=[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(e){this.client=e;}async createRole(e,s){try{await i(M,{name:e,description:s});let r={name:e,description:s};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(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,r){try{await i(A,{name:s,description:r});let o={name:s,description:r};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(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")],x=[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")],q=[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(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,r){try{return await i(R,{module:e,access:s,description:r}),(await this.client.post("/permissions",{module:e,access:s,description:r})).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,r,o){try{return await i(x,{module:s,access:r,description:o}),(await this.client.patch(`/permissions/${e}`,{module:s,access:r,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(q,{roleId:e,permissionId:s}),(await this.client.patch(`/permissions/set-permission/${e}`,{permissionId:s})).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(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=m;exports.createConnection=U;
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;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import _ from'axios';import {body,validationResult}from'express-validator';var w=t=>_.create({baseURL:t});var d=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 U(t){return new d(t)}function i(t,e){return new Promise((s,r)=>{let o={body:e};(async()=>{for(let p of t.flat())await p(o,{},()=>{});let h=validationResult(o);if(h.isEmpty())s(true);else {let p=h.array().map(C=>C.msg);r(p);}})();})}var y=[body("email").optional().isEmail().withMessage("Must be valid email address."),body("contactNumber").optional().isLength({min:6}).withMessage("Contact 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().withMessage("Role ID is required"),body("roleId").isArray({min:1}).withMessage("Atleast one role ID is required"),body("roleId").custom(t=>Array.isArray(t)?t.every(e=>typeof e=="number"&&!isNaN(e)):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:e})=>t===e.body.password).withMessage("Confirm Password must match Password")],P=[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:e})=>t===e.body.newPassword).withMessage("Confirm Password must match New Password")],f=[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().custom(t=>{if(!t.email&&!t.contactNumber)throw new Error("Either email or contact number is required");return true})],I=[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").notEmpty().withMessage("Role ID is required"),body("roleId").isArray({min:1}).withMessage("Atleast one role ID is required"),body("roleId").custom(t=>Array.isArray(t)?t.every(e=>typeof e=="number"&&!isNaN(e)):false).withMessage("Each role ID must be a number")];var m=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(f,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(r){return Array.isArray(r)?{error:r.join(", "),status:400}:{error:r.response?.data||r.message,status:r.response?.status||500}}}async changePassword(e,s){try{return await i(P,s),(await this.client.patch(`/users/change-password/${e}`,s)).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(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 updateUserRole(e,s){try{return await i(I,s),(await this.client.patch(`/users/update-role/${e}`,s)).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(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 M=[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(e){this.client=e;}async createRole(e,s){try{await i(M,{name:e,description:s});let r={name:e,description:s};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(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,r){try{await i(A,{name:s,description:r});let o={name:s,description:r};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(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")],x=[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")],q=[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(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,r){try{return await i(R,{module:e,access:s,description:r}),(await this.client.post("/permissions",{module:e,access:s,description:r})).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,r,o){try{return await i(x,{module:s,access:r,description:o}),(await this.client.patch(`/permissions/${e}`,{module:s,access:r,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(q,{roleId:e,permissionId:s}),(await this.client.patch(`/permissions/set-permission/${e}`,{permissionId:s})).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(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,m as UserService,U as createConnection};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zlspace/z-auth",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "ZAuth is a authentication service for ZLS.NP",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",