@zlspace/z-auth 1.0.5 → 1.0.6

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
@@ -91,8 +91,8 @@ logout(id: string)
91
91
  sendVerificationEmail(email: string)
92
92
  verifyEmail(token: string, tenantId:number)
93
93
  updateUserById(userId: string, data: I_UpdateUserByIdRequest) //{data: email, contactNumber, recoveryEmail, recoveryNumber, isBlocked, roleId; all optional}
94
- googleAuth(token: string, roleId: string) //idtoken returned from google, role id optional
95
- facebookAuth(token: string, roleId: string) //access_token returned from facebook, role id optional
94
+ authLogin(token: string) //idtoken returned from google, role id optional
95
+ authRegister(token: string, roleId: string) //access_token returned from facebook, role id optional
96
96
 
97
97
  ```
98
98
  ### Role Service
package/dist/index.d.mts CHANGED
@@ -115,8 +115,8 @@ declare class UserService {
115
115
  updateUserById(userId: string, data: I_UpdateUserByIdRequest): Promise<any>;
116
116
  getAccessToken(): Promise<any>;
117
117
  getRefreshToken(): Promise<any>;
118
- googleAuth(token: string, roleId: string): Promise<any>;
119
- facebookAuth(token: string, roleId: string): Promise<any>;
118
+ authLogin(token: string): Promise<any>;
119
+ authRegister(token: string, roleId: string): Promise<any>;
120
120
  }
121
121
 
122
122
  declare class RoleService {
package/dist/index.d.ts CHANGED
@@ -115,8 +115,8 @@ declare class UserService {
115
115
  updateUserById(userId: string, data: I_UpdateUserByIdRequest): Promise<any>;
116
116
  getAccessToken(): Promise<any>;
117
117
  getRefreshToken(): Promise<any>;
118
- googleAuth(token: string, roleId: string): Promise<any>;
119
- facebookAuth(token: string, roleId: string): Promise<any>;
118
+ authLogin(token: string): Promise<any>;
119
+ authRegister(token: string, roleId: string): Promise<any>;
120
120
  }
121
121
 
122
122
  declare class RoleService {
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 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})}getBaseUrl(){return this.client.defaults.baseURL}getApiKey(){return this.apiKey}getApiSecretKey(){return this.apiSecretKey}};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}}}async googleAuth(s,e){try{return (await this.client.post("/auth/google",{token:s,roleId:e})).data}catch(r){return {error:r.response?.data||r.message,status:r.response?.status||500}}}async facebookAuth(s,e){try{return (await this.client.post("/auth/facebook",{token:s,roleId:e})).data}catch(r){return {error:r.response?.data||r.message,status:r.response?.status||500}}}};var A=[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")],I=[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(A,{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(I,{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;
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})}getBaseUrl(){return this.client.defaults.baseURL}getApiKey(){return this.apiKey}getApiSecretKey(){return this.apiSecretKey}};function q(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}}}async authLogin(s){try{return (await this.client.post("/auth/login",{token:s})).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async authRegister(s,e){try{return (await this.client.post("/auth/register",{token:s,roleId:e})).data}catch(r){return {error:r.response?.data||r.message,status:r.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=q;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
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})}getBaseUrl(){return this.client.defaults.baseURL}getApiKey(){return this.apiKey}getApiSecretKey(){return this.apiSecretKey}};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}}}async googleAuth(s,e){try{return (await this.client.post("/auth/google",{token:s,roleId:e})).data}catch(r){return {error:r.response?.data||r.message,status:r.response?.status||500}}}async facebookAuth(s,e){try{return (await this.client.post("/auth/facebook",{token:s,roleId:e})).data}catch(r){return {error:r.response?.data||r.message,status:r.response?.status||500}}}};var A=[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")],I=[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(A,{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(I,{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};
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})}getBaseUrl(){return this.client.defaults.baseURL}getApiKey(){return this.apiKey}getApiSecretKey(){return this.apiSecretKey}};function q(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}}}async authLogin(s){try{return (await this.client.post("/auth/login",{token:s})).data}catch(e){return {error:e.response?.data||e.message,status:e.response?.status||500}}}async authRegister(s,e){try{return (await this.client.post("/auth/register",{token:s,roleId:e})).data}catch(r){return {error:r.response?.data||r.message,status:r.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,q as createConnection};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zlspace/z-auth",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "ZAuth is a authentication service for ZLS.NP",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",