@mnfst/sdk
Version:
Manifest JavaScript SDK
166 lines (165 loc) • 5.2 kB
TypeScript
import { Paginator } from "../../core/types/src";
import { BaseSDK } from "../../core/common/src";
export default class Manifest extends BaseSDK {
/**
* The Manifest backend base URL (Without ending slash).
*/
baseUrl: string;
/**
* The headers of the request.
*/
private headers;
/**
* Create a new instance of the client.
*
* @param baseUrl The Manifest backend URL address (Without ending slash). Default: http://localhost:1111
*/
constructor(baseUrl?: string);
/**
* Set the slug of the single entity to query.
*
* @param slug The slug of the single entity to query.
*
* @returns an object containing the methods to get and update the single entity.
*
* @example client.single('about').get()
* @example client.single('home').update({ title: 'New title' })
*/
single(slug: string): {
get: <T>() => Promise<T>;
update: <T>(data: unknown) => Promise<T>;
patch: <T>(data: unknown) => Promise<T>;
};
/**
* Get the paginated list of items of the entity.
*
* @param paginationParams - Optional pagination parameters.
*
* @returns A Promise that resolves a Paginator object containing entities of type T, based on the input.
*/
find<T>(paginationParams?: {
page?: number;
perPage?: number;
}): Promise<Paginator<T>>;
/**
* Get an item of the entity.
*
* @param id The id of the item to get.
*
* @returns The item of the entity.
* @example client.from('cats').findOne(1);
*
**/
findOneById<T>(id: string): Promise<T>;
/**
* Create an item of the entity.
*
* @param itemDto The DTO of the item to create.
*
* @returns The created item.
*/
create<T>(itemDto: unknown): Promise<T>;
/**
* Update an item of the entity doing a full replace. Leaving blank fields and relations will remove them. Use patch for partial updates.
*
* @param id The id of the item to update.
* @param itemDto The DTO of the item to update.
*
* @returns The updated item.
* @example client.from('cats').update(1, { name: 'updated name' });
*/
update<T>(id: string, itemDto: unknown): Promise<T>;
/**
* Partially update an item of the entity. Leaving blank fields and relations will not remove them. Use update for full replaces.
*
* @param id The id of the item to update.
* @param itemDto The DTO of the item to update.
*
* @returns The updated item.
* @example client.from('cats').update(1, { name: 'updated name' });
*/
patch<T>(id: string, itemDto: unknown): Promise<T>;
/**
*
* Delete an item of the entity.
*
* @param id The id of the item to delete.
*
* @returns The id of the deleted item.
* @example client.from('cats').delete(1);
*/
delete<T>(id: string): Promise<T>;
/**
*
* Login as any authenticable entity.
*
* @param entitySlug The slug of the entity to login as.
* @param email The email of the entity to login as.
* @param password The password of the entity to login as.
*
* @returns an object with the token if logged in, false otherwise.
*/
login(entitySlug: string, email: string, password: string): Promise<{
token: string;
}>;
/**
*
* Logout as any authenticable entity.
*
* @returns void
*/
logout(): void;
/**
* Signup as any authenticable entity but Admin and login.
*
* @param entitySlug The slug of the entity to signup as.
* @param email The email of the entity to signup as.
* @param password The password of the entity to signup as.
*
* @returns true if the signup was successful.
*/
signup(entitySlug: string, email: string, password: string): Promise<boolean>;
/**
* Gets the current logged in user (me). Use "from('your-entity')" before calling this method.
*
* @returns The current logged in user.
* @example client.from('users').me();
*
*/
me(): Promise<{
email: string;
}>;
private fetch;
/**
* Upload a file to the entity.
*
* @param property The property of the entity to upload the file to.
* @param file The file to upload.
*
* @returns the path of the uploaded file.
*/
upload(property: string, file: Blob): Promise<{
path: string;
}>;
/**
* Upload an image to the entity.
*
* @param property The property of the entity to upload the image to.
* @param image The image to upload.
*
* @returns an object containing the path of the uploaded image in different sizes.
* */
uploadImage(property: string, image: Blob): Promise<{
[key: string]: string;
}>;
/**
* Helper that returns the absolute URL of the image.
*
* @param image The image object containing the different sizes of the image.
*
* @returns The absolute URL of the image.
*/
imageUrl(image: {
[key: string]: string;
}, size: string): string;
}