isleclient
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-d • Public • Published

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 methods
  • users - User related methods
  • groups - Group related methods
  • permissions - 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

LoginRequest

Either username or email is required

  • username - The username of the user [string] [optional]
  • email - The email of the user [string] [optional]
  • password - The password of the user [string] [required]
LoginResponse
  • data - The data of the response SelfUser
  • token - The token of the user [string]
PasswordUpdateRequest

Either username or email is required

  • username - The username of the user [string] [optional]
  • email - The email of the user [string] [optional]
  • oldPassword - The old password of the user [string] [required]
  • newPassword - 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

PublicUser
  • id - The id of the user [string]

  • username - The username of the user [string]

  • title - The title of the user [string]

  • groups - The groups of the user Group[]

SelfUser

Extends PublicUser

  • email - The email of the user [string]

  • firstName - The first name of the user [string]

  • lastName - The last name of the user [string]

AdminUser

Extends SelfUser

  • emailVerified - Whether the email of the user is verified [boolean]

  • deactivated - Whether the user is deactivated [boolean]

  • keycloakId - The keycloak id of the user [string]

UserCreateRequest
  • username - The username of the user [string] [required]
  • email - The email of the user [string] [required]
  • firstName - The first name of the user [string] [required]
  • lastName - The last name of the user [string] [required]
  • title - The title of the user [string] [required]
  • groups - The groups of the user [string[]] [required]
  • password - The password of the user [string] [required]
  • emailVerified - Whether the email of the user is verified [boolean] [optional] [admin only]
  • deactivated - Whether the user is deactivated [boolean] [optional] [admin only]
UserPatchRequest
  • username - The username of the user [string] [optional]
  • email - The email of the user [string] [optional]
  • firstName - The first name of the user [string] [optional]
  • lastName - The last name of the user [string] [optional]
  • title - The title of the user [string] [optional]
  • groupsToAdd - The groups to add to the user [string[]] [optional] [admin only]
  • groupsToRemove - The groups to remove from the user [string[]] [optional] [admin only]
  • emailVerified - Whether the email of the user is verified [boolean] [optional] [admin only]
  • deactivated - Whether the user is deactivated [boolean] [optional] [admin only]
UserSearchRequest
  • username - The username of the user [string] [optional]
  • email - The email of the user [string] [optional] [admin only]
  • firstName - The first name of the user [string] [optional] [admin only]
  • lastName - The last name of the user [string] [optional] [admin only]
  • emailVerified - 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

Group
  • id - The id of the group [string]
  • name - The name of the group [string]
  • permissions - The permissions of the group [string[]]
  • parent- The parent group of the group ParentGroup [optional]
ParentGroup
  • id - The id of the parent group [string]
  • name - The name of the parent group [string]
GroupCreateRequest
  • name - The name of the group [string] [required]
  • parent - The parent group of the group [string] [optional]
  • permissions - The permissions of the group [string[]] [optional]
GroupPatchRequest
  • name - The name of the group [string] [optional]
  • parent - The parent group of the group [string] [optional]
  • permissionsToAdd - The permissions to add to the group [string[]] [optional]
  • permissionsToRemove - 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

Permission
  • id - The id of the permission [string]
  • name - The name of the permission [string]
  • description - The description of the permission [string]
PermissionCreateRequest
  • name - The name of the permission [string] [required]
  • description - 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'
});

Readme

Keywords

none

Package Sidebar

Install

npm i isleclient

Weekly Downloads

2

Version

1.0.0-d

License

MIT

Unpacked Size

40.2 kB

Total Files

52

Last publish

Collaborators

  • fypeex