This class provides methods to manage organization users, roles, and user roles.
Syntax:
constructor(orgAuthId: string, orgAuthToken: string)
Parameters:
orgAuthId
: A string representing the organization's authentication ID.orgAuthToken
: A string representing the organization's authentication token.
Example:
const karmaAuth = new KarmaAuth('your_org_auth_id', 'your_org_auth_token');
Users
: Instance ofOrgUsers
to manage organization users.Roles
: Instance ofOrgRoles
to manage organization roles.UserRoles
: Instance ofOrgUserRoles
to manage organization user roles.
The methods are part of the instantiated classes OrgUsers
, OrgRoles
, and OrgUserRoles
.
This class provides methods to manage user-specific operations.
Syntax:
constructor(token: string)
Parameters:
token
: A string representing the user's token.
Example:
const karmaUser = new KarmaUser('your_user_token');
Users
: Instance ofUsers
to manage user-specific operations.
This class provides methods to manage organization users.
Syntax:
constructor(config: Config)
Parameters:
config
: An instance of theConfig
class.
Creates a new user.
Syntax:
createUser(userData: any): Promise<any>
Parameters:
userData
: An object containing user data.
Example:
karmaAuth.Users.createUser({ name: "John Doe", email: "[email protected]" });
Fetches a user by UID.
Syntax:
getUser(uid: string): Promise<any>
Parameters:
uid
: A string representing the user's ID.
Example:
karmaAuth.Users.getUser('user_id');
Authenticates a user by email and password.
Syntax:
authenticateUserByEmail(email: string, password: string): Promise<any>
Parameters:
email
: A string representing the user's email.password
: A string representing the user's password.
Example:
karmaAuth.Users.authenticateUserByEmail('[email protected]', 'password123');
Authenticates a user by phone and password.
Syntax:
authenticateUserByPhone(phone: string, password: string): Promise<any>
Parameters:
phone
: A string representing the user's phone number.password
: A string representing the user's password.
Example:
karmaAuth.Users.authenticateUserByPhone('1234567890', 'password123');
Updates user information by UID.
Syntax:
updateUser(uid: string, updateData: any): Promise<any>
Parameters:
uid
: A string representing the user's ID.updateData
: An object containing the updated user data.
Example:
karmaAuth.Users.updateUser('user_id', { name: "Jane Doe", email: "[email protected]" });
Deletes a user by UID.
Syntax:
deleteUser(uid: string): Promise<any>
Parameters:
uid
: A string representing the user's ID.
Example:
karmaAuth.Users.deleteUser('user_id');
This class provides methods to manage user roles within the organization.
Syntax:
constructor(baseURL: string, config: Config)
Parameters:
baseURL
: A string representing the base URL for the API.config
: An instance of theConfig
class.
Creates a user role.
Syntax:
createUserRole(roleID: string, userID: string): Promise<any>
Parameters:
roleID
: A string representing the role's ID.userID
: A string representing the user's ID.
Example:
karmaAuth.UserRoles.createUserRole('role_id', 'user_id');
This class provides methods to manage roles within the organization.
Syntax:
constructor(baseURL: string, config: Config)
Parameters:
baseURL
: A string representing the base URL for the API.config
: An instance of theConfig
class.
Creates a new role.
Syntax:
createRole(name: string, permissions: Permissions): Promise<any>
Parameters:
name
: A string representing the name of the role.permissions
: An object representing the permissions assigned to the role.
Example:
karmaAuth.Roles.createRole('Admin', { read: true, write: true, delete: false });
Fetches a role by RID.
Syntax:
getRole(rid: string): Promise<any>
Parameters:
rid
: A string representing the role's ID.
Example:
karmaAuth.Roles.getRole('role_id');
Fetches all roles.
Syntax:
getAllRoles(): Promise<any>
Example:
karmaAuth.Roles.getAllRoles();
Fetches a role by name.
Syntax:
getRoleByName(name: string): Promise<any>
Parameters:
name
: A string representing the role's name.
Example:
karmaAuth.Roles.getRoleByName('Admin');
Updates a role by RID.
Syntax:
updateRole(rid: string, updateData: {name: string, permissions: Permissions}): Promise<any>
Parameters:
rid
: A string representing the role's ID.updateData
: An object containing the updated role data.
Example:
karmaAuth.Roles.updateRole('role_id', { name: "Moderator", permissions: { read: true, write: true, delete: true } });
Deletes a role by RID.
Syntax:
deleteRole(rid: string): Promise<any>
Parameters:
rid
: A string representing the role's ID.
Example:
karmaAuth.Roles.deleteRole('role_id');
This class provides methods to manage user-specific operations outside of an organization context.
Syntax:
constructor(token: string)
Parameters:
token
: A string representing the user's token.
Fetches the current user's information.
Syntax:
getUser(userData: any): Promise<any>
Parameters:
userData
: An object representing the user data.
Example:
karmaUser.Users.getUser({ token: 'your_token' });
Fetches roles for the user, optionally by RID.
Syntax:
getUserRoles(rid?: string): Promise<any>
Parameters:
rid
: An optional string representing the role's ID.
Example:
karmaUser.Users.getUserRoles('role_id');
Deletes a user role by RID.
Syntax:
deleteUserRole(rid: string): Promise<any>
Parameters:
rid
: A string representing the role's ID.
Example:
karmaUser.Users.deleteUserRole('role_id');