express-kit-js
v1.1.0
Published
ExpressKit JS is a client SDK for interacting with my [express-kit](https://www.npmjs.com/package/@roee1454/express-kit) backend starter kit
Downloads
20
Readme
ExpressKit JS SDK
ExpressKit JS is a client SDK for interacting with my express-kit backend starter kit
Installation
To install ExpressKit JS, you can use npm or yarn:
npm install express-kit-js
or
yarn add express-kit-js
Usage
First, import the ExpressKit
class and create an instance with your backend's base URL:
import ExpressKit from 'express-kit-js';
const kit = new ExpressKit('https://your-backend-url.com');
Orrr, you can even create an expendable class to add new functions to it:
import ExpressKit from 'express-kit-js;
class ExpendableKit extends ExpressKit {
async requestSomthingFromFiles() {
try {
return await this.request("GET", "/files?id=asdfarwe32");
} catch (err){
throw err;
}
}
}
const kit = new ExpendableKit("https://your-backend-url.com");
Authentication Functions
signInUser(userCredentials: UserCredentionals): Promise<string>
Signs in a user with the given credentials.
await kit.signInUser({ email: '[email protected]', password: 'password' });
signOut(): Promise<string>
Signs out the current user.
await kit.signOut();
requestEmailVerfication(email: string): Promise<string>
Requests email verification for the given email.
const message = await kit.requestEmailVerfication('[email protected]');
requestPasswordReset(email: string): Promise<string>
Requests a password reset for the given email.
const message = await kit.requestPasswordReset('[email protected]');
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: '[email protected]', 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;
}
Conclusion
This documentation covers the basic usage and functionality of the ExpressKit JS SDK. For more detailed information, refer to the backend source coude