karma-auth.npm
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Karma Auth Library

KarmaAuth

This class provides methods to manage organization users, roles, and user roles.

Constructor

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');

Properties

  • Users: Instance of OrgUsers to manage organization users.
  • Roles: Instance of OrgRoles to manage organization roles.
  • UserRoles: Instance of OrgUserRoles to manage organization user roles.

Methods

The methods are part of the instantiated classes OrgUsers, OrgRoles, and OrgUserRoles.


KarmaUser

This class provides methods to manage user-specific operations.

Constructor

Syntax:

constructor(token: string)

Parameters:

  • token: A string representing the user's token.

Example:

const karmaUser = new KarmaUser('your_user_token');

Properties

  • Users: Instance of Users to manage user-specific operations.

OrgUsers

This class provides methods to manage organization users.

Constructor

Syntax:

constructor(config: Config)

Parameters:

  • config: An instance of the Config class.

Methods

createUser

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: "john@example.com" });

getUser

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');

authenticateUserByEmail

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('john@example.com', 'password123');

authenticateUserByPhone

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');

updateUser

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: "jane@example.com" });

deleteUser

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');

OrgUserRoles

This class provides methods to manage user roles within the organization.

Constructor

Syntax:

constructor(baseURL: string, config: Config)

Parameters:

  • baseURL: A string representing the base URL for the API.
  • config: An instance of the Config class.

Methods

createUserRole

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');

OrgRoles

This class provides methods to manage roles within the organization.

Constructor

Syntax:

constructor(baseURL: string, config: Config)

Parameters:

  • baseURL: A string representing the base URL for the API.
  • config: An instance of the Config class.

Methods

createRole

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 });

getRole

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');

getAllRoles

Fetches all roles.

Syntax:

getAllRoles(): Promise<any>

Example:

karmaAuth.Roles.getAllRoles();

getRoleByName

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');

updateRole

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 } });

deleteRole

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');

Users

This class provides methods to manage user-specific operations outside of an organization context.

Constructor

Syntax:

constructor(token: string)

Parameters:

  • token: A string representing the user's token.

Methods

getUser

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' });

getUserRoles

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');

deleteUserRole

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');

Readme

Keywords

Package Sidebar

Install

npm i karma-auth.npm

Weekly Downloads

13

Version

1.1.0

License

MIT

Unpacked Size

35 kB

Total Files

30

Last publish

Collaborators

  • mellob