Sdks
Express Kit JS

ExpressKit JS SDK

ExpressKit JS is a client SDK for interacting with a backend toolkit that provides authentication, user management, and file system functions. This SDK is built using Axios to make HTTP requests to the backend API.

Installation

To install ExpressKit JS, you can use npm or yarn:

npm install express-kit-js

or

yarn add express-kit-js

or

pnpm add express-kit-js

Usage

First, import the ExpressKit class and create an instance with your backend's base URL It is recommended to configure your instance in a seperate file:

kit.js
import ExpressKit from 'express-kit-js';
 
const kit = new ExpressKit('https://your-backend-url.com');

Authentication Functions

signInUser(userCredentials: UserCredentionals): Promise<string>

Signs in a user with the given credentials.

const token = await kit.signInUser({ email: 'user@example.com', password: 'password' });

signOut(): Promise<string>

Signs out the current user.

const message = await kit.signOut();

requestEmailVerfication(email: string): Promise<string>

Requests email verification for the given email.

const message = await kit.requestEmailVerfication('user@example.com');

requestPasswordReset(email: string): Promise<string>

Requests a password reset for the given email.

const message = await kit.requestPasswordReset('user@example.com');

resetPassword(info: PasswordResetCreds): Promise<string>

Resets the password with the given credentials.

const message = await kit.resetPassword({ currentPassword: 'oldPassword', newPassword: 'newPassword' });

File System Functions

getUploadedFiles(): Promise<KitFile[]>

Gets a list of uploaded files.

const files = await kit.getUploadedFiles();

getUploadedFile(id: string): Promise<Buffer>

Gets an uploaded file by its ID.

const file = await kit.getUploadedFile('fileId');

uploadFile(file: File): Promise<string>

Uploads a file.

const message = await kit.uploadFile(file);

updateFileUsingFile(id: string, file: File): Promise<string>

Updates an existing file with a new file.

const message = await kit.updateFileUsingFile('fileId', file);

deleteFile(id: string): Promise<string>

Deletes a file by its ID.

const message = await kit.deleteFile('fileId');

User Functions

getAllUsers(): Promise<User[]>

Gets a list of all users.

const users = await kit.getAllUsers();

getCurrentUser(): Promise<User>

Gets the current user.

const user = await kit.getCurrentUser();

updateCurrentUser(data: any): Promise<User>

Updates the current user with the given data.

const updatedUser = await kit.updateCurrentUser({ displayName: 'New Name' });

createNewUser(user: User): Promise<User>

Creates a new user with the given data.

const newUser = await kit.createNewUser({ email: 'newuser@example.com', passwordHash: 'hashedPassword' });

getUser(id: string): Promise<User>

Gets a user by their ID.

const user = await kit.getUser('userId');

updateUser(id: string, data: any): Promise<User>

Updates a user with the given ID and data.

const updatedUser = await kit.updateUser('userId', { displayName: 'Updated Name' });

deleteUser(id: string): Promise<string>

Deletes a user by their ID.

const message = await kit.deleteUser('userId');

General Request Function

request(method: string, url: string, options?: AxiosRequestConfig): Promise<AxiosResponse>

Makes a general request with the given method, URL, and options.

const response = await kit.request('GET', '/custom-endpoint');

Types

User

export interface User {
  email: string;
  displayName?: string;
  passwordHash?: string;
  isVerified?: boolean;
  id?: string;
}

UserCredentionals

export interface UserCredentionals {
  email: string;
  password: string;
}

PasswordResetCreds

export interface PasswordResetCreds {
  currentPassword: string;
  newPassword: string;
}

KitFile

export interface KitFile {
  filename: string;
  ContentType: string;
  size: number;
  id: string;
}

Custom Methods

You can also add your own custom http requests and utillity functions to the ExpressKit Class as the following:

kit.js
import ExpressKit from 'express-kit-js'
 
class Kit extends ExpressKit {
    async DoSomthing() {
        try {
            const response = await this.request("GET", "/current-user");
            return response.data;
        } catch (err) {
            throw err;
        }
    }
}
 
const kit = new Kit('https://your-backend-url.com');

And then you can call from anywhere you want:

component.js
import kit from './modules/kit.js'
import { useQuery } from 'react-query';
 
export default function Component() {
    const { data: currentUser } = useQuery({
        async queryFn(){
            const currentUser = await kit.DoSomthing();
            return currentUser;
        }
    })
 
    //rest of your component here...
}

Conclusion

This documentation covers the basic usage and functionality of the ExpressKit JS SDK.