zumjs-v2
v0.5.0
Published
Javascript library for interacting with zum server
Downloads
3
Readme
ZUM JS V2
Zum Js v2 is a version without njwt dependency. Outgoing data relies on https security as is the normal internet standard, rather than being encoded into tokens. Before using these modules install and require the library
npm install zumjs-v2
const zum = require('zumjs-v2')
configure
This is a required module for the client to interact with the zum server. It configures the client with the necessary details like appName and server endpoints. No other module will work unless the client is configured.
zum.configure({
// all values default to null unless specified
})
These values can be passed inside the configuration object to undertake various operations using the library
- appName : Every app registered in zum has a unique app name. It serves as an id to identify the app.
- mk : Master key endpoint
- register : Registration endpoint
- users : Users endpoint
- login : Login endpoint
- logout : Logout endpoint
- verify : Token verification endpoint
- stats : Endpoint for server and user stats
zum.configure({
appName : 'myapp',
register: 'http://www.myapp.com/register',
login: 'http://www.myapp.com/login',
verify: 'http://www.myapp.com/verify',
users: 'http://www.myapp.com/users',
mk: 'http://www.myapp.com/mk'
});
register
Create a new user. User will need to verify the email address before signing in, unless verified flag is set to true
zum.register(claims, callback)
- claims : User data
zum.register({
username : 'zaygo',
password : 'Mypass@123',
name : 'Arjun Nair',
email : '[email protected]',
scope : 'admin',
country : 'Austria',
verified : false
}, (err, res) => {
if (err) throw err;
console.log(res.status); // successful if status is 200
});
login
Acquire access token for a user
zum.login(username, password, callback)
- username : Unique username
- password : User password
zum.login('zaygo', 'Mypass@123', (err,res) => {
if (err) throw err;
console.log(res.status); // successful if status is 200
console.log(res.headers['x-auth-token']); // access token can be found inside the response header
});
update
Update user account
zum.update(username, update_object, callback)
- username : Unique username
- update_object : Object containing parameters to update
zum.update('zaygo', {
name : 'Zaygo',
country : 'Germany'
}, (err,res) => {
if (err) throw err;
console.log(res.status); // successful if status is 200
});
terminate
Delete user account. User will receive an email.
zum.terminate(username, delete_object, callback)
- username : Unique username
- delete_object : Contains the reason and initiator for the termination. These details will be passed to the user via email.
fetchUser
Fetch user details using the username or email
zum.fetchUser(user, callback)
- user : username or registered email of the user
serverStats
Get raw server stats of the zum server. Currently provides cpu, memory and disk stats.
zum.serverStats(callback)
Callback will contain :
- cpu : Real time cpu utilization
- mem : Real time memory utilization
- disk : Real time disk utilization
userStats
Get general user stats
zum.userStats(callback)
Callback will contain :
- registered : Number of registered users on the server
- logged : Number of users currently logged in
- disabled : Number of users currently disabled
disable & enable
Disable a user for a certain number of days or manually re-enable a disabled user. The user will receive an email.
zum.disable(username, days, reason, callback)
zum.enable(username, callback)
- username : Unique username
- days : Number of days before the ban ends
- reason : Reason for the ban
zum.disable('arjun', 7, 'You violated rule 4', (err,res) => {
if (err) throw err;
console.log(res.status);
});
zum.enable('arjun', (err,res) => {
if (err) throw err;
console.log(res.status);
});
verify
Verify access token
zum.verify(username, token, callback)
- username : Unique username
- token : Access token received from zum server
otpLogin
Login using otp
zum.otpLogin(receiver, callback)
- receiver : Registered mail id or mobile number
verifyOtp
Check the validity of otp
zum.verifyOtp(receiver, otp, callback)
- receiver : User's registered mail id or mobile number
- otp : Digital code received on mail or mobile and supplied by the user
logout
Logs out the user and invalidates the access token
zum.logout(username, callback)
- username : Unique username