isleclient v1.0.0-d
IsleClient
Frontend library to make the use of the ManyIsles API easier
The library is compiled to ES2016 with commonjs modules, thus it can be used in nodejs and in the browser.
To use it in the browser you need to use a bundler like webpack or rollup.
Installation
npm install isleclient
Description:
The package exports a Client
class which needs to be constructed with a
baseUrl
parameter. This is the base url of the API.
In most cases this will be ToAdd
Token
To use the API you need to have a token. This token can be obtained during the login process.
Usage
The Client
class has 4 subfields:
authentication
- Authentication related methodsusers
- User related methodsgroups
- Group related methodspermissions
- Permission related methods
Authentication
Methods
class AuthenticationEndpoints {
login(data: LoginRequest): Promise<LoginResponse>
checkToken(token: string): Promise<void>
checkCredentials(data: LoginRequest): Promise<void>
updatePassword(id: string, data: UpdatePasswordRequest): Promise<void>
}
Types
Either username
or email
is required
username
- The username of the user string optionalemail
- The email of the user string optionalpassword
- The password of the user string required
Either username
or email
is required
username
- The username of the user string optionalemail
- The email of the user string optionaloldPassword
- The old password of the user string requirednewPassword
- The new password of the user string required
Users
Methods
class UserEndpoints {
getById(id: string): Promise<PublicUser | SelfUser | AdminUser>;
getByUsername(username: string): Promise<PublicUser | SelfUser | AdminUser>;
getByEmail(email: string): Promise<AdminUser>;
query(data?: UserSearchRequest): Promise<(PublicUser | SelfUser | AdminUser)[]>;
register(data: UserCreateRequest): Promise<PublicUser>;
update(id: string, data: UserPatchRequest): Promise<(SelfUser | AdminUser)>;
delete(id: string): Promise<void>;
getPermissions(id: string, hierarchical?: boolean): Promise<Permission[]>;
}
Types
id
- The id of the user stringusername
- The username of the user stringtitle
- The title of the user stringgroups
- The groups of the user Group[]
Extends PublicUser
email
- The email of the user stringfirstName
- The first name of the user stringlastName
- The last name of the user string
Extends SelfUser
emailVerified
- Whether the email of the user is verified booleandeactivated
- Whether the user is deactivated booleankeycloakId
- The keycloak id of the user string
username
- The username of the user string requiredemail
- The email of the user string requiredfirstName
- The first name of the user string requiredlastName
- The last name of the user string requiredtitle
- The title of the user string requiredgroups
- The groups of the user [string[]] requiredpassword
- The password of the user string requiredemailVerified
- Whether the email of the user is verified boolean optional admin onlydeactivated
- Whether the user is deactivated boolean optional admin only
username
- The username of the user string optionalemail
- The email of the user string optionalfirstName
- The first name of the user string optionallastName
- The last name of the user string optionaltitle
- The title of the user string optionalgroupsToAdd
- The groups to add to the user [string[]] optional admin onlygroupsToRemove
- The groups to remove from the user [string[]] optional admin onlyemailVerified
- Whether the email of the user is verified boolean optional admin onlydeactivated
- Whether the user is deactivated boolean optional admin only
username
- The username of the user string optionalemail
- The email of the user string optional admin onlyfirstName
- The first name of the user string optional admin onlylastName
- The last name of the user string optional admin onlyemailVerified
- Whether the email of the user is verified boolean optional admin only
Groups
Methods
class GroupEndpoints {
getById(id: string): Promise<Group>;
getMembers(id: string): Promise<SelfUser[]>;
create(data: GroupCreateRequest): Promise<Group>;
update(id: string, data: GroupPatchRequest): Promise<Group>;
delete(id: string): Promise<void>;
}
Types
id
- The id of the group stringname
- The name of the group stringpermissions
- The permissions of the group [string[]]parent
- The parent group of the group ParentGroup optional
name
- The name of the group string requiredparent
- The parent group of the group string optionalpermissions
- The permissions of the group [string[]] optional
name
- The name of the group string optionalparent
- The parent group of the group string optionalpermissionsToAdd
- The permissions to add to the group [string[]] optionalpermissionsToRemove
- The permissions to remove from the group [string[]] optional
Permissions
Methods
class PermissionEndpoints {
getAll(): Promise<Permission[]>;
getById(id: string): Promise<Permission>;
create(data: PermissionCreateRequest): Promise<Permission>;
delete(id: string): Promise<void>;
}
Types
id
- The id of the permission stringname
- The name of the permission stringdescription
- The description of the permission string
name
- The name of the permission string requireddescription
- The description of the permission string optional
Example
Register and login
import { Client } from 'isleclient';
const client = new Client('https://api.example.com');
await client.users.register({
username: 'username',
email: 'username@example.com',
firstName: 'Your',
lastName: 'Name',
title: 'Master',
groups: ['group1', 'group2'],
password: 'password'
});
const {token,data} = await client.authentication.login({
username: 'username',
password: 'password'
});
client.setToken(token);
// Do other stuff
Change your first and last name
import { Client } from 'isleclient';
const client = new Client('https://api.example.com');
const {token, data} = await client.authentication.login({
username: 'username',
password: 'password'
});
client.setToken(token);
await client.users.update(data.id, {
firstName: 'John',
lastName: 'Doe'
});