1.0.0-d • Published 7 months ago

isleclient v1.0.0-d

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
7 months ago

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

Either username or email is required

  • data - The data of the response SelfUser
  • token - The token of the user string

Either username or email is 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 string
  • username - The username of the user string
  • title - The title of the user string
  • groups - The groups of the user Group[]

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

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

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 string
  • name - The name of the group string
  • permissions - The permissions of the group [string[]]
  • parent- The parent group of the group ParentGroup optional
  • id - The id of the parent group string
  • name - The name of the parent group string
  • 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

  • id - The id of the permission string
  • name - The name of the permission string
  • description - The description of the permission string

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

7 months ago

1.0.0-c

7 months ago

1.0.0-b

7 months ago

1.0.0

7 months ago